On 10/31/25 13:00, Pavel Cahyna wrote:
Perhaps, since gnulib already provides openat(), the O_RESOLVE_BENEATH
flag (from FreeBSD) could be added to it?
That might be cleaner, yes. Though I expect it should be a new module
resolve-beneath, that adds support for the O_RESOLVE_BENEATH flag to
openat, and similarly adds AT_RESOLVE_BENEATH support to fstatat etc.
I was thinking of something like, if the task is to create
"a/b/c/childdir" :
parentdir = open_beneath(AT_FDCWD, "a/b/c", O_DIRECTORY | O_PATH);
/* safe as mkdir fails in case "childdir" is a symlink */
mkdirat(parentdir, "childdir", 0700);
I was thinking along similar lines.
In hindsight, mkdirat, mknodat, readlinkat, renameat, and symlinkat
should have had int flags argument. For these, we need to use hassly
code such as the above. I was thinking of doing that part in GNU Tar for
now; it could be promoted to Gnulib later.