summaryrefslogtreecommitdiff
path: root/lib/libc/sys/utimes.2
blob: 8d5c69f57e927d8dd1248b9360f87f4069595f7f (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
.\"	$OpenBSD: utimes.2,v 1.18 2013/03/31 05:07:55 guenther Exp $
.\"	$NetBSD: utimes.2,v 1.9 1996/04/23 10:34:16 mycroft Exp $
.\"
.\" Copyright (c) 1990, 1993
.\"	The Regents of the University of California.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\"     @(#)utimes.2	8.1 (Berkeley) 6/4/93
.\"
.Dd $Mdocdate: March 31 2013 $
.Dt UTIMES 2
.Os
.Sh NAME
.Nm utimes ,
.Nm futimes ,
.Nm utimensat ,
.Nm futimens
.Nd set file access and modification times
.Sh SYNOPSIS
.Fd #include <sys/time.h>
.Ft int
.Fn utimes "const char *file" "const struct timeval *times"
.Ft int
.Fn futimes "int fd" "const struct timeval *times"
.Fd #include <sys/stat.h>
.Fd #include <fcntl.h>
.Ft int
.Fn utimensat "int fd" "const char *file" "const struct timespec times[2]" "int flag"
.Ft int
.Fn futimens "int fd" "const struct timespec times[2]"
.Sh DESCRIPTION
The access and modification times of the file named by
.Fa path
or referenced by
.Fa fd
are changed as specified by the argument
.Fa times .
.Pp
If
.Fa times
is
.Dv 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.
.Pp
If
.Fa 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.
.Pp
In either case, the inode-change-time of the file is set to the current
time.
.Pp
The
.Fn utimensat
and
.Fn futimens
are equivalent to
.Fn utimes
and
.Fn futimes ,
respectively, with the following differences.
.Pp
Both
.Fn utimensat
and
.Fn futimens
take two timespec values instead of two timeval values.
Further, either of the
.Fa tv_nsec
fields can be set to one of the following special values defined in
.In sys/stat.h :
.Pp
.Bl -tag -width UTIME_OMIT -offset indent -compact
.It Dv UTIME_NOW
Set the respective timestamp to the greatest value supported
that is not greater than the current time.
.It Dv UTIME_OMIT
Do not change the respective timestamp.
.El
.Pp
Additionally, if the
.Fa path
argument to
.Fn utimensat
specifies a relative path,
the file whose timestamps are changed is determined relative to
the directory associated with file descriptor
.Fa fd
instead of the current working directory.
.Pp
If
.Fn utimensat
is passed the special value
.Dv AT_FDCWD
(defined in
.In fcntl.h )
in the
.Fa fd
parameter, the current working directory is used.
.Pp
Values for
.Fa flag
are constructed by bitwise-inclusive
.Tn OR Ns ing
flags from the following list defined in
.In fcntl.h :
.Pp
.Bl -tag -width AT_SYMLINK_NOFOLLOW -offset indent -compact
.It Dv AT_SYMLINK_NOFOLLOW
If
.Fa path
names a symbolic link, then the timestamps of the symbolic link are changed.
.El
.Sh RETURN VALUES
Upon successful completion, a value of 0 is returned.
Otherwise, a value of \-1 is returned and
.Va errno
is set to indicate the error.
.Sh ERRORS
.Fn utimes
and
.Fn utimensat
will fail if:
.Bl -tag -width Er
.It Bq Er EACCES
Search permission is denied for a component of the path prefix;
or the
.Fa times
argument is
.Dv 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.
.It Bq Er EFAULT
.Pa File
or
.Fa times
points outside the process's allocated address space.
.It Bq Er EIO
An I/O error occurred while reading or writing the affected inode.
.It Bq Er ELOOP
Too many symbolic links were encountered in translating the pathname.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded
.Dv {NAME_MAX}
characters, or an entire path name exceeded
.Dv {PATH_MAX}
characters.
.It Bq Er ENOENT
The named file does not exist.
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
.It Bq Er EPERM
The
.Fa times
argument is not
.Dv NULL
and the calling process's effective user ID
does not match the owner of the file and is not the superuser.
.It Bq Er EROFS
The file system containing the file is mounted read-only.
.El
.Pp
Additionally,
.Fn utimensat
will fail if:
.Bl -tag -width Er
.It Bq Er EINVAL
The value of the
.Fa flag
argument was neither zero nor
.Dv AT_SYMLINK_NOFOLLOW .
.It Bq Er EBADF
The
.Fa file
argument specifies a relative path and the
.Fa fd
argument is neither
.Dv AT_FDCWD
nor a valid file descriptor.
.It Bq Er ENOTDIR
The
.Fa file
argument specifies a relative path and the
.Fa fd
argument is a valid file descriptor but it does not reference a directory.
.It Bq Er EACCES
The
.Fa file
argument specifies a relative path but search permission is denied
for the directory which the
.Fa fd
file descriptor references.
.El
.Pp
.Fn futimes
and
.Fn futimens
will fail if:
.Bl -tag -width Er
.It Bq Er EBADF
.Fa fd
does not refer to a valid descriptor.
.It Bq Er EACCES
The
.Fa times
argument is
.Dv 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.
.It Bq Er EFAULT
.Fa times
points outside the process's allocated address space.
.It Bq Er EIO
An I/O error occurred while reading or writing the affected inode.
.It Bq Er EPERM
The
.Fa times
argument is not
.Dv NULL
and the calling process's effective user ID
does not match the owner of the file and is not the superuser.
.It Bq Er EROFS
The file system containing the file is mounted read-only.
.El
.Sh SEE ALSO
.Xr stat 2 ,
.Xr utime 3
.Sh STANDARDS
The
.Fn utimes ,
.Fn utimensat ,
and
.Fn futimens
functions conform to
.St -p1003.1-2008 .
.Sh HISTORY
The predecessors of
.Fn utimes
were
.Fn smdate
in
.At v1 ,
.Fn mdate
in
.At v3 ,
and
.Fn utime
in
.At v7 ;
the latter first supported the concept of an access time
in addition to the modification time.
.Pp
The
.Fn utimes
function call appeared in
.Bx 4.2 .
The
.Fn futimes
function call appeared in
.Nx 1.2 .
The
.Fn utimensat
and
.Fn futimens
function calls appeared in
.Ox 5.0 .
.Sh CAVEATS
.St -p1003.1-2008
specifies that
.Fn utimensat
and
.Fn futimens
shall mark the last file status change timestamp (i.e.\&
.Fa st_ctim )
for update upon successful completion.
However, currently some filesystems (e.g. UFS)
will not do so if
.Dv UTIME_OMIT
is specified for the modification timestamp argument.