]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/utime.2
ffix
[thirdparty/man-pages.git] / man2 / utime.2
CommitLineData
fea681da
MK
1.\" Hey Emacs! This file is -*- nroff -*- source.
2.\"
3.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
4.\"
5.\" Permission is granted to make and distribute verbatim copies of this
6.\" manual provided the copyright notice and this permission notice are
7.\" preserved on all copies.
8.\"
9.\" Permission is granted to copy and distribute modified versions of this
10.\" manual under the conditions for verbatim copying, provided that the
11.\" entire resulting derived work is distributed under the terms of a
12.\" permission notice identical to this one.
c13182ef 13.\"
fea681da
MK
14.\" Since the Linux kernel and libraries are constantly changing, this
15.\" manual page may be incorrect or out-of-date. The author(s) assume no
16.\" responsibility for errors or omissions, or for damages resulting from
17.\" the use of the information contained herein. The author(s) may not
18.\" have taken the same level of care in the production of this manual,
19.\" which is licensed free of charge, as they might when working
20.\" professionally.
c13182ef 21.\"
fea681da
MK
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
24.\"
25.\" Modified by Michael Haardt <michael@moria.de>
26.\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
27.\" Modified 1995-06-10 by Andries Brouwer <aeb@cwi.nl>
305a0578 28.\" Modified 2004-06-23 by Michael Kerrisk <mtk-manpages@gmx.net>
fea681da
MK
29.\" Modified 2004-10-10 by Andries Brouwer <aeb@cwi.nl>
30.\"
d9343c5c 31.TH UTIME 2 2004-10-10 "Linux" "Linux Programmer's Manual"
fea681da
MK
32.SH NAME
33utime, utimes \- change access and/or modification times of an inode
34.SH SYNOPSIS
35.nf
36.B #include <sys/types.h>
37.br
38.B #include <utime.h>
39.sp
40.BI "int utime(const char *" filename ", const struct utimbuf *" buf );
521bf584 41.sp
fea681da
MK
42.B #include <sys/time.h>
43.sp
69b7b9e5 44.BI "int utimes(const char *" filename ", const struct timeval " times [2]);
fea681da
MK
45.fi
46.SH DESCRIPTION
e511ffb6 47.BR utime ()
fea681da
MK
48changes the access and modification times of the inode specified by
49.I filename
50to the
51.IR actime " and " modtime
c13182ef 52fields of
fea681da
MK
53.I buf
54respectively.
55
56If
57.I buf
58is NULL, then the access and modification times of the file are set
59to the current time.
60
61Changing time stamps is permitted when: either
62the process has appropriate privileges (Linux: has the
63.B CAP_FOWNER
64capability), or the effective user ID equals the user ID
65of the file, or
66.I buf
67must is NULL and the process has write permission to the file.
68
69The
70.I utimbuf
71structure is:
72
73.RS
74.nf
75struct utimbuf {
69b7b9e5
MK
76 time_t actime; /* access time */
77 time_t modtime; /* modification time */
fea681da
MK
78};
79.fi
80.RE
81
82The function
e511ffb6 83.BR utime ()
fea681da
MK
84allows specification of time stamps with a resolution of 1 second.
85The function
e511ffb6 86.BR utimes ()
fea681da
MK
87is similar, but allows a resolution of 1 microsecond.
88Here
69b7b9e5 89.IR times [0]
fea681da 90refers to access time, and
69b7b9e5 91.IR times [1]
fea681da
MK
92to modification time.
93
94The
95.I timeval
96structure is:
97
98.RS
99.nf
100struct timeval {
69b7b9e5
MK
101 long tv_sec; /* seconds */
102 long tv_usec; /* microseconds */
fea681da
MK
103};
104.fi
105.RE
106.SH "RETURN VALUE"
c13182ef
MK
107On success, zero is returned.
108On error, \-1 is returned, and
fea681da
MK
109.I errno
110is set appropriately.
111.SH ERRORS
112.TP
113.B EACCES
114Search permission is denied for one of the directories in
115the path prefix of
116.I path
117(see also
ad7cc990 118.BR path_resolution (7)),
fea681da
MK
119or
120.I buf
121is NULL and the process does not have permission to change the time stamps
122(see above).
123.TP
124.B ENOENT
125.I filename
126does not exist.
127.TP
128.B EPERM
129.I buf
130is not NULL and the process does not have permission to change the time stamps.
131.TP
132.B EROFS
133.I path
134resides on a read-only file system.
2dd578fd
MK
135.SH "CONFORMING TO"
136.BR utime ():
137SVr4, POSIX.1-2001.
138.\" SVr4 documents additional error conditions EFAULT,
139.\" EINTR, ELOOP, EMULTIHOP, ENAMETOOLONG, ENOLINK, ENOLINK, ENOTDIR.
140.br
141.BR utimes ():
1424.3BSD
fea681da
MK
143.SH NOTES
144Linux does not allow changing the time stamps on an immutable file,
145or setting the time stamps to something other than the current time
146on an append-only file.
147
148In libc4 and libc5,
e511ffb6 149.BR utimes ()
fea681da 150is just a wrapper for
e511ffb6 151.BR utime ()
fea681da
MK
152and hence does not allow a subsecond resolution.
153
69b7b9e5 154POSIX.1-2001 marks
e511ffb6 155.BR utimes ()
69b7b9e5
MK
156legacy, which is strange since it provides more functionality than
157.BR utime ().
fea681da 158.SH BUGS
1274071a
MK
159Linux is not careful to distinguish between the
160.B EACCES
2f0af33b
MK
161and
162.B EPERM
163error returns.
97c1eac8 164On the other hand, POSIX.1-2001 is buggy in its error description for
e511ffb6 165.BR utimes ().
fea681da
MK
166.SH "SEE ALSO"
167.BR chattr (1),
22e3b8b1 168.BR futimesat (2),
51fa356e
MK
169.BR stat (2),
170.BR futimes (3)