xref: /netbsd-src/lib/libc/gen/utime.3 (revision 0b9f50897e9a9c6709320fafb4c3787fddcc0a45)
1.\" Copyright (c) 1980, 1991 Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     @(#)utime.3	6.3 (Berkeley) 4/19/91
33.\"
34.Dd August 13, 1993
35.Dt UTIME 3
36.Os BSD 4
37.Sh NAME
38.Nm utime
39.Nd set file times
40.Sh SYNOPSIS
41.Fd #include <sys/types.h>
42.Fd #include <utime.h>
43.Ft int
44.Fn utime "const char *file" "const struct utimbuf *timep"
45.Sh DESCRIPTION
46The
47.Fn utime
48function sets the access and modification times of the named file.
49.Pp
50If
51.Fa timep
52is
53.Dv NULL ,
54the access and modification times are set to the current time.
55The calling process must be the owner of the file or have permission to
56write the file.
57.Pp
58If
59.Fa timep
60is
61.Pf non- Dv NULL ,
62.Fa time
63is assumed to be a pointer to a utimbuf structure, as defined in
64.Aq Pa utime.h :
65.Bd -literal -offset indent
66struct utimbuf {
67	time_t actime;          /* Access time */
68	time_t modtime;         /* Modification time */
69} ;
70.Ed
71.Pp
72The access time is set to the value of the actime member, and the modification
73time is set to the value of the modtime member.  The times are measured in
74seconds since 0 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated
75Universal Time.
76The calling process must be the owner of the file or be the super-user.
77.Pp
78In either case, the inode-change-time of the file is set to the current
79time.
80.Sh RETURN VALUES
81Upon successful completion, a value of 0 is returned.
82Otherwise, a value of -1 is returned and
83.Va errno
84is set to indicate the error.
85.Sh ERRORS
86.Fn Utime
87will fail if:
88.Bl -tag -width Er
89.It Bq Er EACCES
90Search permission is denied for a component of the path prefix;
91or the
92.Fa times
93argument is
94.Dv NULL
95and the effective user ID of the process does not
96match the owner of the file, and is not the super-user, and write
97access is denied.
98.It Bq Er EFAULT
99.Xr File
100or
101.Fa times
102points outside the process's allocated address space.
103.It Bq Er EINVAL
104The pathname contains a character with the high-order bit set.
105.It Bq Er EIO
106An I/O error occurred while reading or writing the affected inode.
107.It Bq Er ELOOP
108Too many symbolic links were encountered in translating the pathname.
109.It Bq Er ENAMETOOLONG
110A component of a pathname exceeded 255 characters,
111or an entire path name exceeded 1023 characters.
112.It Bq Er ENOENT
113The named file does not exist.
114.It Bq Er ENOTDIR
115A component of the path prefix is not a directory.
116.It Bq Er EPERM
117The
118.Fa times
119argument is not
120.Dv NULL
121and the calling process's effective user ID
122does not match the owner of the file and is not the super-user.
123.It Bq Er EROFS
124The file system containing the file is mounted read-only.
125.El
126.Sh SEE ALSO
127.Xr stat 2 ,
128.Xr utimes 2
129.Sh STANDARDS
130The
131.Fn utime
132function
133conforms to
134.St -p1003.1-88 .
135