xref: /freebsd-14.2/lib/libc/sys/utimes.2 (revision b2c76c41)
1.\"	$NetBSD: utimes.2,v 1.13 1999/03/22 19:45:11 garbled 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 30, 2020
33.Dt UTIMES 2
34.Os
35.Sh NAME
36.Nm utimes ,
37.Nm lutimes ,
38.Nm futimes ,
39.Nm futimesat
40.Nd set file access and modification times
41.Sh LIBRARY
42.Lb libc
43.Sh SYNOPSIS
44.In sys/time.h
45.Ft int
46.Fn utimes "const char *path" "const struct timeval *times"
47.Ft int
48.Fn lutimes "const char *path" "const struct timeval *times"
49.Ft int
50.Fn futimes "int fd" "const struct timeval *times"
51.Ft int
52.Fn futimesat "int fd" "const char *path" "const struct timeval times[2]"
53.Sh DESCRIPTION
54.Bf -symbolic
55These interfaces are obsoleted by
56.Xr futimens 2
57and
58.Xr utimensat 2
59because they are not accurate to nanoseconds.
60.Ef
61.Pp
62The access and modification times of the file named by
63.Fa path
64or referenced by
65.Fa fd
66are changed as specified by the argument
67.Fa times .
68.Pp
69If
70.Fa times
71is
72.Dv NULL ,
73the access and modification times are set to the current time.
74The caller must be the owner of the file, have permission to
75write the file, or be the super-user.
76.Pp
77If
78.Fa times
79is
80.No non- Ns Dv NULL ,
81it is assumed to point to an array of two timeval structures.
82The access time is set to the value of the first element, and the
83modification time is set to the value of the second element.
84For file systems that support file birth (creation) times (such as
85.Dv UFS2 ) ,
86the birth time will be set to the value of the second element
87if the second element is older than the currently set birth time.
88To set both a birth time and a modification time,
89two calls are required; the first to set the birth time
90and the second to set the (presumably newer) modification time.
91Ideally a new system call will be added that allows the setting
92of all three times at once.
93The caller must be the owner of the file or be the super-user.
94.Pp
95In either case, the inode-change-time of the file is set to the current
96time.
97.Pp
98The
99.Fn lutimes
100system call
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
111The
112.Fn futimesat
113system call is equivalent to
114.Fn utimes
115except in the case where
116.Fa path
117specifies a relative path.
118In this case the access and modification time
119is set to that of a file relative to the directory associated with the file
120descriptor
121.Fa fd
122instead of the current working directory.
123If
124.Fn futimesat
125is passed the special value
126.Dv AT_FDCWD
127in the
128.Fa fd
129parameter, the current working directory is used and the behavior
130is identical to a call to
131.Fn utimes .
132.Sh RETURN VALUES
133.Rv -std
134.Sh ERRORS
135All of the system call will fail if:
136.Bl -tag -width Er
137.It Bq Er EACCES
138Search permission is denied for a component of the path prefix.
139.It Bq Er EACCES
140The
141.Fa times
142argument is
143.Dv NULL
144and the effective user ID of the process does not
145match the owner of the file, and is not the super-user, and write
146access is denied.
147.It Bq Er EFAULT
148The
149.Fa path
150or
151.Fa times
152argument
153points outside the process's allocated address space.
154.It Bq Er EFAULT
155The
156.Fa times
157argument
158points outside the process's allocated address space.
159.It Bq Er EINVAL
160The
161.Va tv_usec
162component of at least one of the values specified by the
163.Fa times
164argument has a value less than 0 or greater than 999999.
165.It Bq Er EIO
166An I/O error occurred while reading or writing the affected inode.
167.It Bq Er EINTEGRITY
168Corrupted data was detected while reading from the file system.
169.It Bq Er ELOOP
170Too many symbolic links were encountered in translating the pathname.
171.It Bq Er ENAMETOOLONG
172A component of a pathname exceeded
173.Dv NAME_MAX
174characters, or an entire path name exceeded
175.Dv PATH_MAX
176characters.
177.It Bq Er ENOENT
178The named file does not exist.
179.It Bq Er ENOTDIR
180A component of the path prefix is not a directory.
181.It Bq Er EPERM
182The
183.Fa times
184argument is not
185.Dv NULL
186and the calling process's effective user ID
187does not match the owner of the file and is not the super-user.
188.It Bq Er EPERM
189The named file has its immutable or append-only flags set.
190See the
191.Xr chflags 2
192manual page for more information.
193.It Bq Er EROFS
194The file system containing the file is mounted read-only.
195.El
196.Pp
197The
198.Fn futimes
199system call
200will fail if:
201.Bl -tag -width Er
202.It Bq Er EBADF
203The
204.Fa fd
205argument
206does not refer to a valid descriptor.
207.El
208.Pp
209In addition to the errors returned by the
210.Fn utimes ,
211the
212.Fn futimesat
213may fail if:
214.Bl -tag -width Er
215.It Bq Er EBADF
216The
217.Fa path
218argument does not specify an absolute path and the
219.Fa fd
220argument is neither
221.Dv AT_FDCWD
222nor a valid file descriptor open for searching.
223.It Bq Er ENOTDIR
224The
225.Fa path
226argument is not an absolute path and
227.Fa fd
228is neither
229.Dv AT_FDCWD
230nor a file descriptor associated with a directory.
231.El
232.Sh SEE ALSO
233.Xr chflags 2 ,
234.Xr stat 2 ,
235.Xr utimensat 2 ,
236.Xr utime 3
237.Sh STANDARDS
238The
239.Fn utimes
240function is expected to conform to
241.St -xpg4.2 .
242The
243.Fn futimesat
244system call follows The Open Group Extended API Set 2 specification
245but was replaced by
246.Fn utimensat
247in
248.St -p1003.1-2008 .
249.Sh HISTORY
250The
251.Fn utimes
252system call appeared in
253.Bx 4.2 .
254The
255.Fn futimes
256and
257.Fn lutimes
258system calls first appeared in
259.Fx 3.0 .
260The
261.Fn futimesat
262system call appeared in
263.Fx 8.0 .
264