#include <fcntl.h> /* Definition of AT_* constants */#include <sys/stat.h> int utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags);int futimens(int fd, const struct timespec times[2]);
Feature Test Macro Requirements for glibc (see feature_test_macros(7) ):
utimensat():
_ATFILE_SOURCE
- Since glibc 2.10:
- _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
- Before glibc 2.10:
futimens():
_GNU_SOURCE
- Since glibc 2.10:
- _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
- Before glibc 2.10:
With utimensat() the file is specified via the pathname given in pathname. With futimens() the file whose timestamps are to be updated is specified via an open file descriptor, fd.
For both calls, the new file
timestamps are specified in the array times: times[0] specifies the new
"last access time" (atime); times[1] specifies the new "last modification
time" (mtime). Each of the elements of times specifies a time as the number
of seconds and nanoseconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
This information is conveyed in a structure of the following form:
struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ };
Updated file timestamps are set to the greatest value supported by the filesystem that is not greater than the specified time.
If the tv_nsec field of one of the timespec structures has the special value UTIME_NOW, then the corresponding file timestamp is set to the current time. If the tv_nsec field of one of the timespec structures has the special value UTIME_OMIT, then the corresponding file timestamp is left unchanged. In both of these cases, the value of the corresponding tv_sec field is ignored.
If times is NULL, then both timestamps are set to the current time.
To make any change other than setting both timestamps to the current time (i.e., times is not NULL, and neither tv_nsec field is UTIME_NOW and neither tv_nsec field is UTIME_OMIT), either condition 2 or 3 above must apply.
If both tv_nsec fields are specified as UTIME_OMIT, then no file ownership or permission checks are performed, and the file timestamps are not modified, but other error conditions may still be detected.
If pathname is relative and dirfd is the special value AT_FDCWD, then pathname is interpreted relative to the current working directory of the calling process (like utimes(2) ).
If pathname is absolute, then dirfd is ignored.
The flags field is a bit mask that may be 0, or include the following constant, defined in <fcntl.h>:
Support for futimens() first appeared in glibc 2.6.
On Linux, timestamps cannot be changed for a file marked immutable, and the only change permitted for files marked append-only is to set the timestamps to the current time. (This is consistent with the historical behavior of utime(2) and utimes(2) on Linux.)
On Linux, futimens()
is a library function implemented on top of the utimensat() system call.
To support this, the Linux utimensat() system call implements a nonstandard
feature: if pathname is NULL, then the call modifies the timestamps of
the file referred to by the file descriptor dirfd (which may refer to any
type of file). Using this feature, the call futimens(fd, times) is implemented
as:
utimensat(fd, NULL, times, 0);
If both tv_nsec fields are specified as UTIME_OMIT, then the Linux implementation of utimensat() succeeds even if the file referred to by dirfd and pathname does not exist.