1FUTIMENS(3P)               POSIX Programmer's Manual              FUTIMENS(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       futimens, utimensat, utimes — set file access and modification times
14

SYNOPSIS

16       #include <sys/stat.h>
17
18       int futimens(int fd, const struct timespec times[2]);
19       int utimensat(int fd, const char *path, const struct timespec times[2],
20           int flag);
21
22       #include <sys/time.h>
23
24       int utimes(const char *path, const struct timeval times[2]);
25

DESCRIPTION

27       The futimens() and utimensat() functions shall set the access and modi‐
28       fication times of a file to the values of the times argument. The futi‐
29       mens() function changes the times of the file associated with the  file
30       descriptor  fd.  The utimensat() function changes the times of the file
31       pointed to by the path argument, relative to the  directory  associated
32       with  the file descriptor fd.  Both functions allow time specifications
33       accurate to the nanosecond.
34
35       For futimens() and utimensat(), the times argument is an array  of  two
36       timespec  structures.  The  first  array member represents the date and
37       time of last access, and the second member represents the date and time
38       of  last modification. The times in the timespec structure are measured
39       in seconds and nanoseconds since the Epoch. The file's  relevant  time‐
40       stamp  shall  be set to the greatest value supported by the file system
41       that is not greater than the specified time.
42
43       If the tv_nsec field of a timespec  structure  has  the  special  value
44       UTIME_NOW,  the  file's relevant timestamp shall be set to the greatest
45       value supported by the file system that is not greater than the current
46       time. If the tv_nsec field has the special value UTIME_OMIT, the file's
47       relevant timestamp shall not be changed. In  either  case,  the  tv_sec
48       field shall be ignored.
49
50       If  the times argument is a null pointer, both the access and modifica‐
51       tion timestamps shall be set to the greatest  value  supported  by  the
52       file  system  that is not greater than the current time. If utimensat()
53       is passed a relative path in the path argument, the  file  to  be  used
54       shall  be relative to the directory associated with the file descriptor
55       fd instead of the current working directory. If the file descriptor was
56       opened  without  O_SEARCH,  the  function shall check whether directory
57       searches are permitted using the current permissions of  the  directory
58       underlying  the file descriptor. If the file descriptor was opened with
59       O_SEARCH, the function shall not perform the check.
60
61       If utimensat() is passed the special value AT_FDCWD in the  fd  parame‐
62       ter, the current working directory shall be used.
63
64       Only  a  process with the effective user ID equal to the user ID of the
65       file, or with write access to the file, or with appropriate  privileges
66       may  use  futimens()  or  utimensat()  with a null pointer as the times
67       argument  or  with  both  tv_nsec  fields  set  to  the  special  value
68       UTIME_NOW.  Only a process with the effective user ID equal to the user
69       ID of the file or with appropriate privileges  may  use  futimens()  or
70       utimensat()  with  a  non-null  times  argument that does not have both
71       tv_nsec fields set to UTIME_NOW and does not have both  tv_nsec  fields
72       set  to  UTIME_OMIT.  If  both tv_nsec fields are set to UTIME_OMIT, no
73       ownership or permissions check shall be performed  for  the  file,  but
74       other error conditions may still be detected (including [EACCES] errors
75       related to the path prefix).
76
77       Values for the flag argument of utimensat() are constructed by  a  bit‐
78       wise-inclusive  OR  of  flags  from  the  following  list,  defined  in
79       <fcntl.h>:
80
81       AT_SYMLINK_NOFOLLOW
82             If path names a symbolic link, then the access  and  modification
83             times of the symbolic link are changed.
84
85       Upon  completion,  futimens()  and utimensat() shall mark the last file
86       status change timestamp for update.
87
88       The utimes() function shall be equivalent to the  utimensat()  function
89       with  the  special value AT_FDCWD as the fd argument and the flag argu‐
90       ment set to zero, except that the times argument is a timeval structure
91       rather than a timespec structure, and accuracy is only to the microsec‐
92       ond, not nanosecond, and rounding towards the nearest second may occur.
93

RETURN VALUE

95       Upon successful completion, these functions shall return 0.  Otherwise,
96       these functions shall return −1 and set errno to indicate the error. If
97       −1 is returned, the file times shall not be affected.
98

ERRORS

100       These functions shall fail if:
101
102       EACCES The times argument is a null pointer, or both tv_nsec values are
103              UTIME_NOW,  and  the  effective  user ID of the process does not
104              match the owner of the file and write access is denied.
105
106       EINVAL Either of the times  argument  structures  specified  a  tv_nsec
107              value that was neither UTIME_NOW nor UTIME_OMIT, and was a value
108              less than zero or greater than or equal to 1000 million.
109
110       EINVAL A new file timestamp would be a value whose tv_sec component  is
111              not a value supported by the file system.
112
113       EPERM  The  times  argument  is  not a null pointer, does not have both
114              tv_nsec fields set to UTIME_NOW,  does  not  have  both  tv_nsec
115              fields set to UTIME_OMIT, the calling process' effective user ID
116              does not match the owner of the file, and  the  calling  process
117              does not have appropriate privileges.
118
119       EROFS  The file system containing the file is read-only.
120
121       The futimens() function shall fail if:
122
123       EBADF  The fd argument is not a valid file descriptor.
124
125       The utimensat() function shall fail if:
126
127       EACCES fd  was  not  opened  with  O_SEARCH  and the permissions of the
128              directory underlying fd do not permit directory searches.
129
130       EBADF  The path argument does not specify an absolute path and  the  fd
131              argument  is  neither  AT_FDCWD nor a valid file descriptor open
132              for reading or searching.
133
134       ENOTDIR
135              The path argument is not an absolute  path  and  fd  is  a  file
136              descriptor associated with a non-directory file.
137
138       The utimensat() and utimes() functions shall fail if:
139
140       EACCES Search permission is denied by a component of the path prefix.
141
142       ELOOP  A loop exists in symbolic links encountered during resolution of
143              the path argument.
144
145       ENAMETOOLONG
146              The  length  of  a  component  of  a  pathname  is  longer  than
147              {NAME_MAX}.
148
149       ENOENT A component of path does not name an existing file or path is an
150              empty string.
151
152       ENOTDIR
153              A component of the path prefix names an existing  file  that  is
154              neither  a  directory nor a symbolic link to a directory, or the
155              path argument contains at least one  non-<slash>  character  and
156              ends  with  one or more trailing <slash> characters and the last
157              pathname component names an existing  file  that  is  neither  a
158              directory nor a symbolic link to a directory.
159
160       The utimensat() and utimes() functions may fail if:
161
162       ELOOP  More  than  {SYMLOOP_MAX} symbolic links were encountered during
163              resolution of the path argument.
164
165       ENAMETOOLONG
166              The length of a pathname exceeds {PATH_MAX}, or pathname resolu‐
167              tion  of  a symbolic link produced an intermediate result with a
168              length that exceeds {PATH_MAX}.
169
170       The utimensat() function may fail if:
171
172       EINVAL The value of the flag argument is not valid.
173
174       The following sections are informative.
175

EXAMPLES

177       None.
178

APPLICATION USAGE

180       None.
181

RATIONALE

183       The purpose of the utimensat() function is to set the access and  modi‐
184       fication  time  of  files in directories other than the current working
185       directory without exposure to race conditions. Any part of the path  of
186       a file could be changed in parallel to a call to utimes(), resulting in
187       unspecified behavior. By opening  a  file  descriptor  for  the  target
188       directory  and using the utimensat() function it can be guaranteed that
189       the changed file is located relative to the desired directory.
190
191       The standard developers considered including a  special  case  for  the
192       permissions required by utimensat() when one tv_nsec field is UTIME_NOW
193       and the other is UTIME_OMIT. One possibility would be to  include  this
194       case in with the cases where times is a null pointer or both fields are
195       UTIME_NOW, where the call is allowed if the process has  write  permis‐
196       sion for the file. However, associating write permission with an update
197       to just the last data access timestamp (which is  normally  updated  by
198       read())  did  not  seem  appropriate. The other possibility would be to
199       specify that this one case is allowed if the process has  read  permis‐
200       sion,  but  this  was felt to be too great a departure from the utime()
201       and utimes() functions on which utimensat() is based. If an application
202       needs  to  set the last data access timestamp to the current time for a
203       file on which it has read permission but is not the owner, it can do so
204       by  opening the file, reading one or more bytes (or reading a directory
205       entry, if the file is a directory), and then closing it.
206

FUTURE DIRECTIONS

208       None.
209

SEE ALSO

211       read(), utime()
212
213       The Base Definitions volume of POSIX.1‐2008,  <fcntl.h>,  <sys_stat.h>,
214       <sys_time.h>
215
217       Portions  of  this text are reprinted and reproduced in electronic form
218       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
219       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
220       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
221       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
222       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
223       event of any discrepancy between this version and the original IEEE and
224       The Open Group Standard, the original IEEE and The Open Group  Standard
225       is  the  referee document. The original Standard can be obtained online
226       at http://www.unix.org/online.html .
227
228       Any typographical or formatting errors that appear  in  this  page  are
229       most likely to have been introduced during the conversion of the source
230       files to man page format. To report such errors,  see  https://www.ker
231       nel.org/doc/man-pages/reporting_bugs.html .
232
233
234
235IEEE/The Open Group                  2013                         FUTIMENS(3P)
Impressum