]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/utime.2
ffix
[thirdparty/man-pages.git] / man2 / utime.2
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.
13 .\"
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.
21 .\"
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>
28 .\" Modified 2004-06-23 by Michael Kerrisk <mtk-manpages@gmx.net>
29 .\" Modified 2004-10-10 by Andries Brouwer <aeb@cwi.nl>
30 .\"
31 .TH UTIME 2 2004-10-10 "Linux" "Linux Programmer's Manual"
32 .SH NAME
33 utime, 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 );
41 .sp
42 .B #include <sys/time.h>
43 .sp
44 .BI "int utimes(const char *" filename ", const struct timeval " times [2]);
45 .fi
46 .SH DESCRIPTION
47 .BR utime ()
48 changes the access and modification times of the inode specified by
49 .I filename
50 to the
51 .IR actime " and " modtime
52 fields of
53 .I buf
54 respectively.
55
56 If
57 .I buf
58 is NULL, then the access and modification times of the file are set
59 to the current time.
60
61 Changing time stamps is permitted when: either
62 the process has appropriate privileges (Linux: has the
63 .B CAP_FOWNER
64 capability), or the effective user ID equals the user ID
65 of the file, or
66 .I buf
67 must is NULL and the process has write permission to the file.
68
69 The
70 .I utimbuf
71 structure is:
72
73 .RS
74 .nf
75 struct utimbuf {
76 time_t actime; /* access time */
77 time_t modtime; /* modification time */
78 };
79 .fi
80 .RE
81
82 The function
83 .BR utime ()
84 allows specification of time stamps with a resolution of 1 second.
85 The function
86 .BR utimes ()
87 is similar, but allows a resolution of 1 microsecond.
88 Here
89 .IR times [0]
90 refers to access time, and
91 .IR times [1]
92 to modification time.
93
94 The
95 .I timeval
96 structure is:
97
98 .RS
99 .nf
100 struct timeval {
101 long tv_sec; /* seconds */
102 long tv_usec; /* microseconds */
103 };
104 .fi
105 .RE
106 .SH "RETURN VALUE"
107 On success, zero is returned.
108 On error, \-1 is returned, and
109 .I errno
110 is set appropriately.
111 .SH ERRORS
112 .TP
113 .B EACCES
114 Search permission is denied for one of the directories in
115 the path prefix of
116 .I path
117 (see also
118 .BR path_resolution (7)),
119 or
120 .I buf
121 is NULL and the process does not have permission to change the time stamps
122 (see above).
123 .TP
124 .B ENOENT
125 .I filename
126 does not exist.
127 .TP
128 .B EPERM
129 .I buf
130 is not NULL and the process does not have permission to change the time stamps.
131 .TP
132 .B EROFS
133 .I path
134 resides on a read-only file system.
135 .SH "CONFORMING TO"
136 .BR utime ():
137 SVr4, POSIX.1-2001.
138 .\" SVr4 documents additional error conditions EFAULT,
139 .\" EINTR, ELOOP, EMULTIHOP, ENAMETOOLONG, ENOLINK, ENOLINK, ENOTDIR.
140 .br
141 .BR utimes ():
142 4.3BSD
143 .SH NOTES
144 Linux does not allow changing the time stamps on an immutable file,
145 or setting the time stamps to something other than the current time
146 on an append-only file.
147
148 In libc4 and libc5,
149 .BR utimes ()
150 is just a wrapper for
151 .BR utime ()
152 and hence does not allow a subsecond resolution.
153
154 POSIX.1-2001 marks
155 .BR utimes ()
156 legacy, which is strange since it provides more functionality than
157 .BR utime ().
158 .SH BUGS
159 Linux is not careful to distinguish between the
160 .B EACCES
161 and
162 .B EPERM
163 error returns.
164 On the other hand, POSIX.1-2001 is buggy in its error description for
165 .BR utimes ().
166 .SH "SEE ALSO"
167 .BR chattr (1),
168 .BR futimesat (2),
169 .BR stat (2),
170 .BR futimes (3)