xref: /netbsd-src/lib/libc/sys/utimes.2 (revision a4ddc2c8fb9af816efe3b1c375a5530aef0e89e9)
1.\"	$NetBSD: utimes.2,v 1.37 2013/03/08 16:52:11 christos Exp $
2.\"
3.\" Copyright (c) 1990, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     @(#)utimes.2	8.1 (Berkeley) 6/4/93
31.\"
32.Dd March 8, 2013
33.Dt UTIMES 2
34.Os
35.Sh NAME
36.Nm utimes ,
37.Nm lutimes ,
38.Nm futimes ,
39.Nm utimens ,
40.Nm lutimens ,
41.Nm futimens ,
42.Nm utimensat
43.Nd set file access and modification times
44.Sh LIBRARY
45.Lb libc
46.Sh SYNOPSIS
47.In sys/time.h
48.Ft int
49.Fn utimes "const char *path" "const struct timeval times[2]"
50.Ft int
51.Fn lutimes "const char *path" "const struct timeval times[2]"
52.Ft int
53.Fn futimes "int fd" "const struct timeval times[2]"
54.Ft int
55.Fn utimens "const char *path" "const struct timespec times[2]"
56.Ft int
57.Fn lutimens "const char *path" "const struct timespec times[2]"
58.Ft int
59.Fn futimens "int fd" "const struct timespec times[2]"
60.In fcntl.h
61.Ft int
62.Fn utimensat "int fd" "const char *path" "const struct timespec times[2]" \
63 "int flag"
64.Sh DESCRIPTION
65The access and modification times of the file named by
66.Fa path
67or referenced by
68.Fa fd
69are changed as specified by the argument
70.Fa times .
71.Pp
72If
73.Fa times
74is
75.Dv NULL ,
76the access and modification times are set to the current time.
77The caller must be the owner of the file, have permission to
78write the file, or be the super-user.
79.Pp
80If
81.Fa times
82is
83.Pf non- Dv NULL ,
84it is assumed to point to an array of two timeval structures.
85The access time is set to the value of the first element, and the
86modification time is set to the value of the second element.
87For file systems that support file birth (creation) times (such as
88UFS2), the birth time will be set to the value of the second element
89if the second element is older than the currently set birth time.
90To set both a birth time and a modification time, two calls are
91required; the first to set the birth time and the second to set
92the (presumably newer) modification time.
93Ideally a new system call will be added that allows the setting of
94all three times at once.
95The caller must be the owner of the file or be the super-user.
96.Pp
97In either case, the inode-change-time of the file is set to the current
98time.
99.Pp
100.Fn lutimes
101is like
102.Fn utimes
103except in the case where the named file is a symbolic link,
104in which case
105.Fn lutimes
106changes the access and modification times of the link,
107while
108.Fn utimes
109changes the times of the file the link references.
110.Pp
111.Fn utimens ,
112.Fn lutimens ,
113and
114.Fn futimens
115are like
116.Fn utimes ,
117.Fn lutimes ,
118and
119.Fn futimes
120respectively except that time is specified with nanosecond instead of
121microsecond precision.
122.Pp
123.Fn utimensat
124works the same way as
125.Fn utimens
126except if
127.Fa path
128is relative.
129In that case, it is looked up from a directory whose file
130descriptor was passed as
131.Fa fd .
132Search permission is required on this directory.
133.\"    (These alternatives await a decision about the semantics of O_SEARCH)
134.\" Search permission is required on this directory
135.\" except if
136.\" .Fa fd
137.\" was opened with the
138.\" .Dv O_SEARCH
139.\" flag.
140.\"    - or -
141.\" This file descriptor must have been opened with the
142.\" .Dv O_SEARCH
143.\" flag.
144.Fa fd
145can be set to
146.Dv AT_FDCWD
147in order to specify the current directory.
148.Pp
149When it operates on a symbolic link,
150.Fn utimensat
151will change the target's time unless
152.Dv AT_SYMLINK_NOFOLLOW
153is set in
154.Fa flag .
155In that later case, the symbolic link's dates are changed.
156.Pp
157The nanosecond fields for
158.Fn utimens ,
159.Fn lutimens ,
160.Fn futimens ,
161and
162.Fn utimensat
163can be set to the special value
164.Dv UTIME_NOW
165to set the current time, or to
166.Dv UTIME_OMIT
167to let the time unchanged (this allows changing access time but not
168modification time, and vice-versa).
169.Sh RETURN VALUES
170Upon successful completion, a value of 0 is returned.
171Otherwise, a value of \-1 is returned and
172.Va errno
173is set to indicate the error.
174.Sh ERRORS
175.Fn utimes ,
176.Fn lutimes ,
177.Fn utimens ,
178.Fn lutimens ,
179and
180.Fn utimensat
181will fail if:
182.Bl -tag -width Er
183.It Bq Er EACCES
184Search permission is denied for a component of the path prefix;
185or the
186.Fa times
187argument is
188.Dv NULL
189and the effective user ID of the process does not
190match the owner of the file, and is not the super-user, and write
191access is denied.
192.It Bq Er EFAULT
193.Fa path
194or
195.Fa times
196points outside the process's allocated address space.
197.It Bq Er EIO
198An I/O error occurred while reading or writing the affected inode.
199.It Bq Er ELOOP
200Too many symbolic links were encountered in translating the pathname.
201.It Bq Er ENAMETOOLONG
202A component of a pathname exceeded
203.Brq Dv NAME_MAX
204characters, or an entire path name exceeded
205.Brq Dv PATH_MAX
206characters.
207.It Bq Er ENOENT
208The named file does not exist.
209.It Bq Er ENOTDIR
210A component of the path prefix is not a directory.
211.It Bq Er EPERM
212The
213.Fa times
214argument is not
215.Dv NULL
216and the calling process's effective user ID
217does not match the owner of the file and is not the super-user.
218.It Bq Er EROFS
219The file system containing the file is mounted read-only.
220.El
221.Pp
222.Fn futimes
223and
224.Fn futimens
225will fail if:
226.Bl -tag -width Er
227.It Bq Er EACCES
228The
229.Fa times
230argument is
231.Dv NULL
232and the effective user ID of the process does not
233match the owner of the file, and is not the super-user, and write
234access is denied.
235.It Bq Er EBADF
236.Fa fd
237does not refer to a valid descriptor.
238.It Bq Er EFAULT
239.Fa times
240points outside the process's allocated address space.
241.It Bq Er EIO
242An I/O error occurred while reading or writing the affected inode.
243.It Bq Er EPERM
244The
245.Fa times
246argument is not
247.Dv NULL
248and the calling process's effective user ID
249does not match the owner of the file and is not the super-user.
250.It Bq Er EROFS
251The file system containing the file is mounted read-only.
252.El
253.Sh SEE ALSO
254.Xr stat 2 ,
255.Xr utime 3 ,
256.Xr symlink 7
257.Sh STANDARDS
258The
259.Fn utimes
260function conforms to
261.St -p1003.1-2001 .
262It was however marked as legacy in the
263.St -p1003.1-2004
264revision.
265.Fn futimens
266and
267.Fn utimensat
268functions conform to
269.St -p1003.1-2008 .
270.Sh HISTORY
271The
272.Fn utimes
273function call appeared in
274.Bx 4.2 .
275The
276.Fn futimes
277function call appeared in
278.Nx 1.2 .
279The
280.Fn lutimes
281function call appeared in
282.Nx 1.3 .
283Birthtime setting support was added in
284.Nx 5.0 .
285.Fn futimens
286and
287.Fn utimensat
288functions calls appreared in
289.Nx 6.0 .
290