OpenBSD manual page server

Manual Page Search Parameters

UTIMES(2) System Calls Manual UTIMES(2)

utimes, futimes, utimensat, futimensset file access and modification times

#include <sys/time.h>

int
utimes(const char *path, const struct timeval times[2]);

int
futimes(int fd, const struct timeval times[2]);

#include <sys/stat.h>
#include <fcntl.h>

int
utimensat(int fd, const char *path, const struct timespec times[2], int flag);

int
futimens(int fd, const struct timespec times[2]);

The access and modification times of the file named by path or referenced by fd are changed as specified by the argument times.

If times is NULL, the access and modification times are set to the current time. The caller must be the owner of the file, have permission to write the file, or be the superuser.

If times is non-null, it is assumed to point to an array of two timeval 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. The caller must be the owner of the file or be the superuser.

In either case, the file status change time is set to the current time.

The () and () are equivalent to () and (), respectively, with the following differences.

Both () and () take two timespec values instead of two timeval values. Further, either of the tv_nsec fields can be set to one of the following special values defined in <sys/stat.h>, in which case the value of tv_sec is ignored:

Set the respective timestamp to the greatest value supported that is not greater than the current time.
Do not change the respective timestamp.

Additionally, if the path argument to () specifies a relative path, the file whose timestamps are changed is determined relative to the directory associated with file descriptor fd instead of the current working directory.

If () is passed the special value AT_FDCWD (defined in <fcntl.h>) in the fd parameter, the current working directory is used.

The flag argument is the bitwise OR of zero or more of the following values:

If path names a symbolic link, then the timestamps of the symbolic link are changed.

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.

utimes() and utimensat() will fail if:

[]
Search permission is denied for a component of the path prefix; or the times argument is NULL and the effective user ID of the process does not match the owner of the file, and is not the superuser, and write access is denied.
[]
path or times points outside the process's allocated address space.
[]
An I/O error occurred while reading or writing the affected inode.
[]
Too many symbolic links were encountered in translating the pathname.
[]
A component of a pathname exceeded NAME_MAX characters, or an entire pathname (including the terminating NUL) exceeded PATH_MAX bytes.
[]
The named file does not exist.
[]
A component of the path prefix is not a directory.
[]
The times argument is not NULL and the calling process's effective user ID does not match the owner of the file and is not the superuser.
[]
The file system containing the file is mounted read-only.

Additionally, utimensat() will fail if:

[]
The value of the flag argument was neither zero nor AT_SYMLINK_NOFOLLOW.
[]
The path argument specifies a relative path and the fd argument is neither AT_FDCWD nor a valid file descriptor.
[]
The path argument specifies a relative path and the fd argument is a valid file descriptor but it does not reference a directory.
[]
The path argument specifies a relative path but search permission is denied for the directory which the fd file descriptor references.

futimes() and futimens() will fail if:

[]
fd does not refer to a valid descriptor.
[]
The times argument is NULL and the effective user ID of the process does not match the owner of the file, and is not the superuser, and write access is denied.
[]
times points outside the process's allocated address space.
[]
An I/O error occurred while reading or writing the affected inode.
[]
The times argument is not NULL and the calling process's effective user ID does not match the owner of the file and is not the superuser.
[]
The file system containing the file is mounted read-only.

utimes() and futimes() will fail if:

[]
Either of the times arguments specified a microsecond value less than zero or greater than or equal to 1 million, or a second value less than zero.

utimesat() and futimens() will fail if:

[]
Either of the times argument specified a nanosecond value less than zero or greater than or equal to 1000 million, or a second value less than zero.

clock_gettime(2), stat(2), utime(3)

The utimes(), utimensat(), and futimens() functions conform to IEEE Std 1003.1-2008 (“POSIX.1”).

The predecessors of utimes() were smdate() in Version 1 AT&T UNIX, mdate() in Version 3 AT&T UNIX, and utime() in Version 7 AT&T UNIX; the latter first supported the concept of an access time in addition to the modification time.

The utimes() function call appeared in 4.2BSD. The futimes() function call appeared in NetBSD 1.2. The utimensat() and futimens() function calls appeared in OpenBSD 5.0.

Some filesystems, such as FAT, use the same timestamp for both modification and file status change; on those filesystems, the file status change timestamp will not be updated if UTIME_OMIT is specified for the modification timestamp argument. Similarly, on NFS the file status change timestamp will not be updated if UTIME_OMIT is specified for both the access and the modification timestamp arguments.

September 30, 2020 OpenBSD-7.4