Bug 26022 - futimesat and utimensat handle NULL filenames
futimesat and utimensat handle NULL filenames
Product: Documentation
Classification: Unclassified
Component: man-pages
All Linux
: P1 normal
Assigned To: documentation_man-pages@kernel-bugs.osdl.org
Depends on:
  Show dependency treegraph
Reported: 2011-01-02 02:44 UTC by Mike Frysinger
Modified: 2014-01-22 13:05 UTC (History)
1 user (show)

See Also:
Kernel Version:
Tree: Mainline
Regression: No


Description Mike Frysinger 2011-01-02 02:44:24 UTC
if you pass futimesat or utimensat a NULL path, the functions will operate on the fd as given.  in which case it can be either a fd for a directory or a file.

for example, the two calls to futimesat() below will do the same thing:
#include <fcntl.h>
#include <stdio.h>
int main() {
    int fd = open("f", O_CREAT|O_RDWR, 0777);
    printf("futimesat = %i\n", futimesat(fd, NULL, NULL));
    printf("futimesat = %i\n", futimesat(AT_FDCWD, "f", NULL));
    return 0;

same behavior can be observed with utimensat(), but it seems only at the Linux syscall level.  the POSIX/C library level will reject a NULL filename with errno==EINVAL, but the Linux kernel will treat the dirfd as an fd.  funny enough, while glibc rejects pathname==NULL at its ABI, it relies on the Linux ABI to accept pathname==NULL while implementing other functions.
Comment 1 Michael Kerrisk 2014-01-22 13:05:30 UTC

The utimensat() behavior is discussed under NOTES in its man page.

The futimesat() behavior is discssed under NOTES in its man page.

So, I'm closing as invalid. If you think something is still missing, please reopen and let me know what it is..

Note You need to log in before you can comment on or make changes to this bug.