xref: /netbsd-src/lib/libc/sys/utimes.2 (revision a5847cc334d9a7029f6352b847e9e8d71a0f9e0c)
1.\"	$NetBSD: utimes.2,v 1.30 2011/10/25 09:26:53 wiz 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 August 17, 2011
33.Dt UTIMES 2
34.Os
35.Sh NAME
36.Nm utimes ,
37.Nm lutimes ,
38.Nm futimes ,
39.Nm futimens ,
40.Nm utimensat
41.Nd set file access and modification times
42.Sh LIBRARY
43.Lb libc
44.Sh SYNOPSIS
45.In sys/time.h
46.Ft int
47.Fn utimes "const char *path" "const struct timeval times[2]"
48.Ft int
49.Fn lutimes "const char *path" "const struct timeval times[2]"
50.Ft int
51.Fn futimes "int fd" "const struct timeval times[2]"
52.Ft int
53.Fn futimens "int fd" "const struct timespec times[2]"
54.Ft int
55.Fn utimensat "int fd" "const char *path" "const struct timespec times[2]" "int flag"
56.Sh DESCRIPTION
57The access and modification times of the file named by
58.Fa path
59or referenced by
60.Fa fd
61are changed as specified by the argument
62.Fa times .
63.Pp
64If
65.Fa times
66is
67.Dv NULL ,
68the access and modification times are set to the current time.
69The caller must be the owner of the file, have permission to
70write the file, or be the super-user.
71.Pp
72If
73.Fa times
74is
75.Pf non- Dv NULL ,
76it is assumed to point to an array of two timeval structures.
77The access time is set to the value of the first element, and the
78modification time is set to the value of the second element.
79For file systems that support file birth (creation) times (such as
80UFS2), the birth time will be set to the value of the second element
81if the second element is older than the currently set birth time.
82To set both a birth time and a modification time, two calls are
83required; the first to set the birth time and the second to set
84the (presumably newer) modification time.
85Ideally a new system call will be added that allows the setting of
86all three times at once.
87The caller must be the owner of the file or be the super-user.
88.Pp
89In either case, the inode-change-time of the file is set to the current
90time.
91.Pp
92.Fn lutimes
93is like
94.Fn utimes
95except in the case where the named file is a symbolic link,
96in which case
97.Fn lutimes
98changes the access and modification times of the link,
99while
100.Fn utimes
101changes the times of the file the link references.
102.Pp
103.Fn futimens
104is like
105.Fn futimes
106except that time is specified with nanosecond instead of microseconds.
107.Pp
108.Fn utimensat
109also allows time to be specifed with nanoseconds.
110When it operates on a symbolic link, it will change the target's time if
111.Ar follow
112is unset.
113If
114.Ar follow
115is set to
116.Dv AT_SYMLINK_NOFOLLOW ,
117the symbolic link's dates are changed.
118.Pp
119The nanosecond fields for
120.Fn futimens
121and
122.Fn utimensat
123can be set to the special value
124.Dv UTIME_NOW
125to set the current time, or to
126.Dv UTIME_OMIT
127to let the time unchanged (this allows changing access time but not
128modification time, and vice-versa).
129.Pp
130.Fn utimensat
131is partially implemented.
132It will return
133.Er ENOSYS
134for
135.Fa fd
136values different than
137.Dv AT_FDCWD .
138.Sh RETURN VALUES
139Upon successful completion, a value of 0 is returned.
140Otherwise, a value of \-1 is returned and
141.Va errno
142is set to indicate the error.
143.Sh ERRORS
144.Fn utimes ,
145.Fn lutimes ,
146and
147.Fn utimensat
148will fail if:
149.Bl -tag -width Er
150.It Bq Er EACCES
151Search permission is denied for a component of the path prefix;
152or the
153.Fa times
154argument is
155.Dv NULL
156and the effective user ID of the process does not
157match the owner of the file, and is not the super-user, and write
158access is denied.
159.It Bq Er EFAULT
160.Fa path
161or
162.Fa times
163points outside the process's allocated address space.
164.It Bq Er EIO
165An I/O error occurred while reading or writing the affected inode.
166.It Bq Er ELOOP
167Too many symbolic links were encountered in translating the pathname.
168.It Bq Er ENAMETOOLONG
169A component of a pathname exceeded
170.Brq Dv NAME_MAX
171characters, or an entire path name exceeded
172.Brq Dv PATH_MAX
173characters.
174.It Bq Er ENOENT
175The named file does not exist.
176.It Bq Er ENOTDIR
177A component of the path prefix is not a directory.
178.It Bq Er EPERM
179The
180.Fa times
181argument is not
182.Dv NULL
183and the calling process's effective user ID
184does not match the owner of the file and is not the super-user.
185.It Bq Er EROFS
186The file system containing the file is mounted read-only.
187.El
188.Pp
189.Fn futimes
190and
191.Fn futimens
192will fail if:
193.Bl -tag -width Er
194.It Bq Er EACCES
195The
196.Fa times
197argument is
198.Dv NULL
199and the effective user ID of the process does not
200match the owner of the file, and is not the super-user, and write
201access is denied.
202.It Bq Er EBADF
203.Fa fd
204does not refer to a valid descriptor.
205.It Bq Er EFAULT
206.Fa times
207points outside the process's allocated address space.
208.It Bq Er EIO
209An I/O error occurred while reading or writing the affected inode.
210.It Bq Er EPERM
211The
212.Fa times
213argument is not
214.Dv NULL
215and the calling process's effective user ID
216does not match the owner of the file and is not the super-user.
217.It Bq Er EROFS
218The file system containing the file is mounted read-only.
219.El
220.Sh SEE ALSO
221.Xr stat 2 ,
222.Xr utime 3 ,
223.Xr symlink 7
224.Sh STANDARDS
225The
226.Fn utimes
227function conforms to
228.St -p1003.1-2001 .
229It was however marked as legacy in the
230.St -p1003.1-2004
231revision.
232.Fn futimens
233and
234.Fn utimensat
235functions conform to
236.St -p1003.1-2008 .
237.Sh HISTORY
238The
239.Fn utimes
240function call appeared in
241.Bx 4.2 .
242The
243.Fn futimes
244function call appeared in
245.Nx 1.2 .
246The
247.Fn lutimes
248function call appeared in
249.Nx 1.3 .
250Birthtime setting support was added in
251.Nx 5.0 .
252.Fn futimens
253and
254.Fn utimensat
255functions calls appreared in
256.Nx 6.0 .
257.Sh BUGS
258.Fn utimensat
259is partially implemented.
260