summaryrefslogtreecommitdiffstats
path: root/upstream/archlinux/man3p/futimens.3p
blob: 8569303e093aafb86faab2a41cdf607f51cbff0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
'\" et
.TH FUTIMENS "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\"
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.\"
.SH NAME
futimens, utimensat, utimes
\(em set file access and modification times
.SH SYNOPSIS
.LP
.nf
#include <sys/stat.h>
.P
int futimens(int \fIfd\fP, const struct timespec \fItimes\fP[2]);
.P
#include <fcntl.h>
.P
int utimensat(int \fIfd\fP, const char *\fIpath\fP, const struct timespec \fItimes\fP[2],
    int \fIflag\fP);
.P
#include <sys/time.h>
.P
int utimes(const char *\fIpath\fP, const struct timeval \fItimes\fP[2]);
.fi
.SH DESCRIPTION
The
\fIfutimens\fR()
and
\fIutimensat\fR()
functions shall set the access and modification times of a file
to the values of the
.IR times
argument. The
\fIfutimens\fR()
function changes the times of the file associated with the file
descriptor
.IR fd .
The
\fIutimensat\fR()
function changes the times of the file pointed to by the
.IR path
argument, relative to the directory associated with the file
descriptor
.IR fd .
Both functions allow time specifications accurate to the nanosecond.
.P
For
\fIfutimens\fR()
and
\fIutimensat\fR(),
the
.IR times
argument is an array of two
.BR timespec
structures. The first array member represents the date and time of
last access, and the second member represents the date and time of last
modification. The times in the
.BR 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.
.P
If the
.IR tv_nsec
field of a
.BR 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
.IR tv_nsec
field has the special value UTIME_OMIT, the file's relevant timestamp
shall not be changed. In either case, the
.IR tv_sec
field shall be ignored.
.P
If the
.IR 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
\fIutimensat\fR()
is passed a relative path in the
.IR path
argument, the file to be used shall be relative to the directory
associated with the file descriptor
.IR fd
instead of the current working directory. If the access mode of
the open file description associated with the file descriptor is not
O_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.
.P
If
\fIutimensat\fR()
is passed the special value AT_FDCWD in the
.IR fd
parameter, the current working directory shall be used.
.P
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
\fIfutimens\fR()
or
\fIutimensat\fR()
with a null pointer as the
.IR times
argument or with both
.IR tv_nsec
fields set to the special value UTIME_NOW. Only a process with the
effective user ID equal to the user ID of the file or with appropriate
privileges may use
\fIfutimens\fR()
or
\fIutimensat\fR()
with a non-null
.IR times
argument that does not have both
.IR tv_nsec
fields set to UTIME_NOW and does not have both
.IR tv_nsec
fields set to UTIME_OMIT. If both
.IR 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
.BR [EACCES] 
errors related to the path prefix).
.P
Values for the
.IR flag
argument of
\fIutimensat\fR()
are constructed by a bitwise-inclusive OR of flags from the following
list, defined in
.IR <fcntl.h> :
.IP AT_SYMLINK_NOFOLLOW 6
.br
If
.IR path
names a symbolic link, then the access and modification times
of the symbolic link are changed.
.br
.P
Upon successful completion,
\fIfutimens\fR()
and
\fIutimensat\fR()
shall mark the last file status change timestamp for update,
with the exception that if both
.IR tv_nsec
fields are set to UTIME_OMIT, the file status change timestamp
need not be marked for update.
.P
The
\fIutimes\fR()
function shall be equivalent to the
\fIutimensat\fR()
function with the special value AT_FDCWD as the
.IR fd
argument and the
.IR flag
argument set to zero, except that the
.IR times
argument is a
.BR timeval
structure rather than a
.BR timespec
structure, and accuracy is only to the microsecond, not nanosecond,
and rounding towards the nearest second may occur.
.SH "RETURN VALUE"
Upon successful completion, these functions shall return 0.
Otherwise, these functions shall return \-1 and set
.IR errno
to indicate the error. If \-1 is returned, the file times shall
not be affected.
.SH ERRORS
These functions shall fail if:
.TP
.BR EACCES
The
.IR times
argument is a null pointer, or both
.IR tv_nsec
values are UTIME_NOW, and the effective user ID of the process
does not match the owner of the file and write access is denied.
.TP
.BR EINVAL
Either of the
.IR times
argument structures specified a
.IR tv_nsec
value that was neither UTIME_NOW nor UTIME_OMIT, and was a value less
than zero or greater than or equal to 1\|000 million.
.TP
.BR EINVAL
A new file timestamp would be a value whose
.IR tv_sec
component is not a value supported by the file system.
.TP
.BR EPERM
The
.IR times
argument is not a null pointer, does not have both
.IR tv_nsec
fields set to UTIME_NOW, does not have both
.IR tv_nsec
fields set to UTIME_OMIT, the calling process' effective user ID does
not match the owner of the file, and the calling process does not have
appropriate privileges.
.TP
.BR EROFS
The file system containing the file is read-only.
.P
The
\fIfutimens\fR()
function shall fail if:
.TP
.BR EBADF
The
.IR fd
argument is not a valid file descriptor.
.P
The
\fIutimensat\fR()
function shall fail if:
.TP
.BR EACCES
The access mode of the open file description associated with
.IR fd
is not O_SEARCH and the permissions of the directory underlying
.IR fd
do not permit directory searches.
.TP
.BR EBADF
The
.IR path
argument does not specify an absolute path and the
.IR fd
argument is neither AT_FDCWD nor a valid file descriptor open
for reading or searching.
.TP
.BR ENOTDIR
The
.IR path
argument is not an absolute path and
.IR fd
is a file descriptor associated with a non-directory file.
.P
The
\fIutimensat\fR()
and
\fIutimes\fR()
functions shall fail if:
.TP
.BR EACCES
Search permission is denied by a component of the path prefix.
.TP
.BR ELOOP
A loop exists in symbolic links encountered during resolution of the
.IR path
argument.
.TP
.BR ENAMETOOLONG
.br
The length of a component of a pathname is longer than
{NAME_MAX}.
.TP
.BR ENOENT
A component of
.IR path
does not name an existing file or
.IR path
is an empty string.
.TP
.BR ENOTDIR
A component of the path prefix names an existing file that is neither
a directory nor a symbolic link to a directory, or the
.IR path
argument contains at least one non-\c
<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.
.P
The
\fIutimensat\fR()
and
\fIutimes\fR()
functions may fail if:
.TP
.BR ELOOP
More than
{SYMLOOP_MAX}
symbolic links were encountered during resolution of the
.IR path
argument.
.TP
.BR ENAMETOOLONG
.br
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}.
.P
The
\fIutimensat\fR()
function may fail if:
.TP
.BR EINVAL
The value of the
.IR flag
argument is not valid.
.LP
.IR "The following sections are informative."
.SH EXAMPLES
None.
.SH "APPLICATION USAGE"
None.
.SH RATIONALE
The purpose of the
\fIutimensat\fR()
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
\fIutimes\fR(),
resulting in unspecified behavior. By opening a file descriptor for
the target directory and using the
\fIutimensat\fR()
function it can be guaranteed that the changed file is located relative
to the desired directory.
.P
The standard developers considered including a special case for the
permissions required by
\fIutimensat\fR()
when one
.IR 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
.IR 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
\fIread\fR())
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
\fIutime\fR()
and
\fIutimes\fR()
functions on which
\fIutimensat\fR()
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.
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "\fIread\fR\^(\|)",
.IR "\fIutime\fR\^(\|)"
.P
The Base Definitions volume of POSIX.1\(hy2017,
.IR "\fB<fcntl.h>\fP",
.IR "\fB<sys_stat.h>\fP",
.IR "\fB<sys_time.h>\fP"
.\"
.SH 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 .
.PP
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 .