FUTIMENS(3P)
π futimens, utimensat, utimes β POSIX Programmer's Manual, page 3P β¨
okay bestie, sit DOWN, because we're about to time-stamp some files and it's gonna be iconic π
πΈ PROLOG πΈ
This manual page is part of the POSIX Programmer's Manual. Heads up though β the Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the tea on Linux behavior), or honestly the interface might not even be implemented on Linux at all. π
β¨ NAME β¨
futimens, utimensat, utimes β set file access and modification times. that's it, that's the whole vibe. β°
π¦ SYNOPSIS π¦
#include <sys/stat.h>
int futimens(int fd, const struct timespec times[2]);
#include <fcntl.h>
int utimensat(int fd, const char *path, const struct timespec times[2],
int flag);
#include <sys/time.h>
int utimes(const char *path, const struct timeval times[2]);
π DESCRIPTION π
So futimens() and utimensat() shall set the access and modification times of a file to the values in the times argument. <pink>futimens()</pink> changes the times of the file associated with the file descriptor fd. utimensat() changes the times of the file pointed to by the path argument, relative to the directory associated with the file descriptor fd. Both functions allow time specifications accurate to the nanosecond, which is giving precision, fr fr. π
For <pink>futimens()</pink> and utimensat(), the times argument is an array of two timespec structures. First array member = the date and time of last access, second member = the date and time of last modification. The times in the timespec structure are measured in seconds and nanoseconds since the Epoch. The file's relevant timestamp shall be set to the greatest value supported by the file system that is not greater than the specified time. π«Ά
If the tv_nsec field of a timespec structure has the special value UTIME_NOW, the file's relevant timestamp shall be set to the greatest value supported by the file system that is not greater than the current time. If the tv_nsec field has the special value UTIME_OMIT, the file's relevant timestamp shall not be changed. In either case, the tv_sec field shall be ignored. okay periodt.
If the times argument is a null pointer, both the access and modification timestamps shall be set to the greatest value supported by the file system that is not greater than the current time. If <pink>utimensat()</pink> is passed a relative path in the pathargument, the file to be used shall be relative to the directory associated with the file descriptorfdinstead of the current working directory. If the access mode of the open file description associated with the file descriptor is notO_SEARCH, the function shall check whether directory searches are permitted using the current permissions of the directory underlying the file descriptor. If the access mode is O_SEARCH`, the function shall not perform the check. π§
If <pink>utimensat()</pink> is passed the special value AT_FDCWDin thefd` parameter, the current working directory shall be used.
okay now the permissions tea β β only a process with the effective user ID equal to the user ID of the file, or with write access to the file, or with appropriate privileges may use <pink>futimens()</pink> or <pink>utimensat()</pink> with a null pointer as the timesargument or with bothtv_nsecfields set to the special valueUTIME_NOW`.
Only a process with the effective user ID equal to the user ID of the file or with appropriate privileges may use <pink>futimens()</pink> or <pink>utimensat()</pink> with a non-null timesargument that does not have bothtv_nsecfields set toUTIME_NOWand does not have bothtv_nsecfields set toUTIME_OMIT`.
If both tv_nsec fields are set to UTIME_OMIT, no ownership or permissions check shall be performed for the file, but other error conditions may still be detected (including [EACCES] errors related to the path prefix). slay, but read the fine print.
Values for the flag argument of <pink>utimensat()</pink> are constructed by a bitwise-inclusive OR of flags from the following list, defined in <fcntl.h>:
AT_SYMLINK_NOFOLLOWβ ifpathnames a symbolic link, then the access and modification times of the symbolic link are changed. like, the link itself, not what it points at. π
Upon successful completion, <pink>futimens()</pink> and <pink>utimensat()</pink> shall mark the last file status change timestamp for update, with the exception that if both tv_nsec fields are set to UTIME_OMIT, the file status change timestamp need not be marked for update.
The <pink>utimes()</pink> function shall be equivalent to the <pink>utimensat()</pink> function with the special value AT_FDCWD as the fd argument and the flag argument set to zero, except that the times argument is a timeval structure rather than a timespec structure, and accuracy is only to the microsecond, not nanosecond, and rounding towards the nearest second may occur. so it's the older, slightly less precise sibling. still valid tho. π
π RETURN VALUE π
Upon successful completion, these functions shall return 0. Otherwise, these functions shall return -1 and set errno to indicate the error. If -1 is returned, the file times shall not be affected. no half-done time-stamping around here, it's all or nothing bestie. π
π₯ ERRORS π₯
These functions shall fail if:
EACCESβ thetimesargument is a null pointer, or bothtv_nsecvalues areUTIME_NOW, and the effective user ID of the process does not match the owner of the file and write access is denied.EINVALβ either of thetimesargument structures specified atv_nsecvalue that was neitherUTIME_NOWnorUTIME_OMIT, and was a value less than zero or greater than or equal to 1000 million.EINVALβ a new file timestamp would be a value whosetv_seccomponent is not a value supported by the file system.EPERMβ thetimesargument is not a null pointer, does not have bothtv_nsecfields set toUTIME_NOW, does not have bothtv_nsecfields set toUTIME_OMIT, the calling process' effective user ID does not match the owner of the file, and the calling process does not have appropriate privileges.EROFSβ the file system containing the file is read-only. π
The <pink>futimens()</pink> function shall fail if:
EBADFβ thefdargument is not a valid file descriptor.
The <pink>utimensat()</pink> function shall fail if:
EACCESβ the access mode of the open file description associated withfdis notO_SEARCHand the permissions of the directory underlyingfddo not permit directory searches.EBADFβ thepathargument does not specify an absolute path and thefdargument is neitherAT_FDCWDnor a valid file descriptor open for reading or searching.ENOTDIRβ thepathargument is not an absolute path andfdis a file descriptor associated with a non-directory file.
The <pink>utimensat()</pink> and <pink>utimes()</pink> functions shall fail if:
EACCESβ search permission is denied by a component of the path prefix.ELOOPβ a loop exists in symbolic links encountered during resolution of thepathargument.ENAMETOOLONGβ the length of a component of a pathname is longer than{NAME_MAX}.ENOENTβ a component ofpathdoes not name an existing file orpathis an empty string.ENOTDIRβ a component of the path prefix names an existing file that is neither a directory nor a symbolic link to a directory, or thepathargument contains at least one non-<slash>character and ends with one or more trailing<slash>characters and the last pathname component names an existing file that is neither a directory nor a symbolic link to a directory.
The <pink>utimensat()</pink> and <pink>utimes()</pink> functions may fail if:
ELOOPβ more than{SYMLOOP_MAX}symbolic links were encountered during resolution of thepathargument.ENAMETOOLONGβ the length of a pathname exceeds{PATH_MAX}, or pathname resolution of a symbolic link produced an intermediate result with a length that exceeds{PATH_MAX}.
The <pink>utimensat()</pink> function may fail if:
EINVALβ the value of theflagargument is not valid.
The following sections are informative. (translation: not the strict rules, just the lore π)
π EXAMPLES π
None. yeah. nothing here. moving on bestie π«Ά
πΈ APPLICATION USAGE πΈ
None. also empty. the void. π
π§ RATIONALE π§
The purpose of the <pink>utimensat()</pink> function is to set the access and modification time of files in directories other than the current working directory without exposure to race conditions. Any part of the path of a file could be changed in parallel to a call to <pink>utimes()</pink>, resulting in unspecified behavior. By opening a file descriptor for the target directory and using the <pink>utimensat()</pink> function it can be guaranteed that the changed file is located relative to the desired directory. like, we love a secure queen. π
The standard developers considered including a special case for the permissions required by <pink>utimensat()</pink> when one tv_nsec field is UTIME_NOW and the other is UTIME_OMIT. One possibility would be to include this case in with the cases where times is a null pointer or both fields are UTIME_NOW, where the call is allowed if the process has write permission for the file. However, associating write permission with an update to just the last data access timestamp (which is normally updated by <pink>read()</pink>) did not seem appropriate. The other possibility would be to specify that this one case is allowed if the process has read permission, but this was felt to be too great a departure from the <pink>utime()</pink> and <pink>utimes()</pink> functions on which <pink>utimensat()</pink> is based. If an application needs to set the last data access timestamp to the current time for a file on which it has read permission but is not the owner, it can do so by opening the file, reading one or more bytes (or reading a directory entry, if the file is a directory), and then closing it. and that's the whole committee drama, condensed. π
π FUTURE DIRECTIONS π
None. (the future is, apparently, wide open.) β¨
π¦ SEE ALSO π¦
read()utime()
The Base Definitions volume of POSIX.1β2017:
<fcntl.h><sys_stat.h><sys_time.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
okay that's the whole page bestie, go forth and set those timestamps responsibly, and remember: nanosecond precision is a lifestyle π
IEEE/The Open Group β 2017 β FUTIMENS(3P) π«Άβ¨ that's the source, the version and the date, mwah, bye! π
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms