UTIMENSAT(2) | System Calls Manual | UTIMENSAT(2) |
futimens
,
utimensat
— set file access
and modification times
#include
<sys/stat.h>
int
futimens
(int
fd, const struct timespec
times[2]);
int
utimensat
(int fd,
const char *path, const struct
timespec times[2], int flag);
The access and modification times of the file named by path or referenced by fd are changed as specified by the argument times. The inode-change-time of the file is set to the current time.
If path specifies a relative path, it is
relative to the current working directory if fd is
AT_FDCWD
and otherwise relative to the directory
associated with the file descriptor fd.
The tv_nsec field of a
timespec structure can be set to the special value
UTIME_NOW
to set the current time, or to
UTIME_OMIT
to leave the time unchanged. In either
case, the tv_sec field is ignored.
If times is
non-NULL
, it is assumed to
point to an array of two timespec structures. The access time is set to the
value of the first element, and the modification time is set to the value of
the second element. If times is
NULL
, this is equivalent to passing a pointer to an
array of two timespec structures with both tv_nsec
fields set to UTIME_NOW
.
If both tv_nsec fields are
UTIME_OMIT
, the timestamps remain unchanged and no
permissions are needed for the file itself, although search permissions may
be required for the path prefix. The call may or may not succeed if the
named file does not exist.
If both tv_nsec fields are
UTIME_NOW
, the caller must be the owner of the file,
have permission to write the file, or be the super-user.
For all other values of the timestamps, the caller must be the owner of the file or be the super-user.
The values for the flag
argument of the
utimensat
()
system call are constructed by a bitwise-inclusive OR of flags from the
following list, defined in
<fcntl.h>
:
AT_SYMLINK_NOFOLLOW
utimensat
() changes
the times of the file referenced by the symbolic link.
AT_SYMLINK_NOFOLLOW_ANY
utimensat
() changes the times of the
file referenced by the symbolic link.Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error.
These system calls will fail if:
EACCES
]NULL
,
or both tv_nsec values are
UTIME_NOW
, and the effective user ID of the
process does not match the owner of the file, and is not the super-user,
and write access is denied.EINVAL
]UTIME_NOW
or
UTIME_OMIT
.EIO
]EPERM
]NULL
nor are both tv_nsec
values UTIME_NOW
, nor are both
tv_nsec values UTIME_OMIT
and the calling process's effective user ID does not match the owner of
the file and is not the super-user.EPERM
]EROFS
]The futimens
() system call will fail
if:
EBADF
]The utimensat
() system call will fail
if:
EACCES
]EBADF
]AT_FDCWD
nor a valid file descriptor.EFAULT
]ELOOP
]ENAMETOOLONG
]NAME_MAX
characters, or an entire path name exceeded
PATH_MAX
characters.ENOENT
]ENOTDIR
]ENOTDIR
]AT_FDCWD
nor a
file descriptor associated with a directory.chflags(2), stat(2), symlink(2), utimes(2), utime(3), symlink(7)
The futimens
() and
utimensat
() system calls are expected to conform to
IEEE Std 1003.1-2008 (“POSIX.1”).
January 17, 2016 | Mac OS X 12 |