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

NAME

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

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

100       Upon successful completion, these functions shall return 0.  Otherwise,
101       these functions shall return -1 and set errno to indicate the error. If
102       -1 is returned, the file times shall not be affected.
103

ERRORS

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

EXAMPLES

183       None.
184

APPLICATION USAGE

186       None.
187

RATIONALE

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

FUTURE DIRECTIONS

214       None.
215

SEE ALSO

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