xref: /openbsd/lib/libc/sys/utimes.2 (revision 404b540a)
1.\"	$OpenBSD: utimes.2,v 1.9 2007/05/31 19:19:34 jmc Exp $
2.\"	$NetBSD: utimes.2,v 1.9 1996/04/23 10:34:16 mycroft Exp $
3.\"
4.\" Copyright (c) 1990, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)utimes.2	8.1 (Berkeley) 6/4/93
32.\"
33.Dd $Mdocdate: May 31 2007 $
34.Dt UTIMES 2
35.Os
36.Sh NAME
37.Nm utimes
38.Nd set file access and modification times
39.Sh SYNOPSIS
40.Fd #include <sys/time.h>
41.Ft int
42.Fn utimes "const char *file" "const struct timeval *times"
43.Ft int
44.Fn futimes "int fd" "const struct timeval *times"
45.Sh DESCRIPTION
46The access and modification times of the file named by
47.Fa path
48or referenced by
49.Fa fd
50are changed as specified by the argument
51.Fa times .
52.Pp
53If
54.Fa times
55is
56.Dv NULL ,
57the access and modification times are set to the current time.
58The caller must be the owner of the file, have permission to
59write the file, or be the superuser.
60.Pp
61If
62.Fa times
63is non-null,
64it is assumed to point to an array of two timeval structures.
65The access time is set to the value of the first element, and the
66modification time is set to the value of the second element.
67The caller must be the owner of the file or be the superuser.
68.Pp
69In either case, the inode-change-time of the file is set to the current
70time.
71.Sh RETURN VALUES
72Upon successful completion, a value of 0 is returned.
73Otherwise, a value of \-1 is returned and
74.Va errno
75is set to indicate the error.
76.Sh ERRORS
77.Fn utimes
78will fail if:
79.Bl -tag -width Er
80.It Bq Er EACCES
81Search permission is denied for a component of the path prefix;
82or the
83.Fa times
84argument is
85.Dv NULL
86and the effective user ID of the process does not
87match the owner of the file, and is not the superuser, and write
88access is denied.
89.It Bq Er EFAULT
90.Pa File
91or
92.Fa times
93points outside the process's allocated address space.
94.It Bq Er EIO
95An I/O error occurred while reading or writing the affected inode.
96.It Bq Er ELOOP
97Too many symbolic links were encountered in translating the pathname.
98.It Bq Er ENAMETOOLONG
99A component of a pathname exceeded
100.Dv {NAME_MAX}
101characters, or an entire path name exceeded
102.Dv {PATH_MAX}
103characters.
104.It Bq Er ENOENT
105The named file does not exist.
106.It Bq Er ENOTDIR
107A component of the path prefix is not a directory.
108.It Bq Er EPERM
109The
110.Fa times
111argument is not
112.Dv NULL
113and the calling process's effective user ID
114does not match the owner of the file and is not the superuser.
115.It Bq Er EROFS
116The file system containing the file is mounted read-only.
117.El
118.Fn futimes
119will fail if:
120.Bl -tag -width Er
121.It Bq Er EBADF
122.Fa fd
123does not refer to a valid descriptor.
124.It Bq Er EACCES
125The
126.Fa times
127argument is
128.Dv NULL
129and the effective user ID of the process does not
130match the owner of the file, and is not the superuser, and write
131access is denied.
132.It Bq Er EFAULT
133.Fa times
134points outside the process's allocated address space.
135.It Bq Er EIO
136An I/O error occurred while reading or writing the affected inode.
137.It Bq Er EPERM
138The
139.Fa times
140argument is not
141.Dv NULL
142and the calling process's effective user ID
143does not match the owner of the file and is not the superuser.
144.It Bq Er EROFS
145The file system containing the file is mounted read-only.
146.El
147.Sh SEE ALSO
148.Xr stat 2 ,
149.Xr utime 3
150.Sh HISTORY
151The
152.Fn utimes
153function call appeared in
154.Bx 4.2 .
155The
156.Fn futimes
157function call appeared in
158.Nx 1.2 .
159