OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man2 / utime.2
1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
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@gmail.com>
29 .\" Modified 2004-10-10 by Andries Brouwer <aeb@cwi.nl>
30 .\"
31 .TH UTIME 2 2014-08-19 "Linux" "Linux Programmer's Manual"
32 .SH NAME
33 utime, utimes \- change file last access and modification times
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 *" times );
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 .B Note:
48 modern applications may prefer to use the interfaces described in
49 .BR utimensat (2).
50
51 The
52 .BR utime ()
53 system call
54 changes the access and modification times of the inode specified by
55 .I filename
56 to the
57 .IR actime " and " modtime
58 fields of
59 .I times
60 respectively.
61
62 If
63 .I times
64 is NULL, then the access and modification times of the file are set
65 to the current time.
66
67 Changing timestamps is permitted when: either
68 the process has appropriate privileges,
69 or the effective user ID equals the user ID
70 of the file, or
71 .I times
72 is NULL and the process has write permission for the file.
73
74 The
75 .I utimbuf
76 structure is:
77
78 .in +4n
79 .nf
80 struct utimbuf {
81     time_t actime;       /* access time */
82     time_t modtime;      /* modification time */
83 };
84 .fi
85 .in
86
87 The
88 .BR utime ()
89 system call
90 allows specification of timestamps with a resolution of 1 second.
91
92 The
93 .BR utimes ()
94 system call
95 is similar, but the
96 .I times
97 argument refers to an array rather than a structure.
98 The elements of this array are
99 .I timeval
100 structures, which allow a precision of 1 microsecond for specifying timestamps.
101 The
102 .I timeval
103 structure is:
104
105 .in +4n
106 .nf
107 struct timeval {
108     long tv_sec;        /* seconds */
109     long tv_usec;       /* microseconds */
110 };
111 .fi
112 .in
113 .PP
114 .IR times [0]
115 specifies the new access time, and
116 .IR times [1]
117 specifies the new modification time.
118 If
119 .I times
120 is NULL, then analogously to
121 .BR utime (),
122 the access and modification times of the file are
123 set to the current time.
124 .SH RETURN VALUE
125 On success, zero is returned.
126 On error, \-1 is returned, and
127 .I errno
128 is set appropriately.
129 .SH ERRORS
130 .TP
131 .B EACCES
132 Search permission is denied for one of the directories in
133 the path prefix of
134 .I path
135 (see also
136 .BR path_resolution (7)).
137 .TP
138 .B EACCES
139 .I times
140 is NULL,
141 the caller's effective user ID does not match the owner of the file,
142 the caller does not have write access to the file,
143 and the caller is not privileged
144 (Linux: does not have either the
145 .B CAP_DAC_OVERRIDE
146 or the
147 .B CAP_FOWNER
148 capability).
149 .TP
150 .B ENOENT
151 .I filename
152 does not exist.
153 .TP
154 .B EPERM
155 .I times
156 is not NULL,
157 the caller's effective UID does not match the owner of the file,
158 and the caller is not privileged
159 (Linux: does not have the
160 .B CAP_FOWNER
161 capability).
162 .TP
163 .B EROFS
164 .I path
165 resides on a read-only filesystem.
166 .SH CONFORMING TO
167 .BR utime ():
168 SVr4, POSIX.1-2001.
169 POSIX.1-2008 marks
170 .BR utime ()
171 as obsolete.
172 .br
173 .BR utimes ():
174 4.3BSD, POSIX.1-2001.
175 .SH NOTES
176 Linux does not allow changing the timestamps on an immutable file,
177 or setting the timestamps to something other than the current time
178 on an append-only file.
179 .\"
180 .\" In libc4 and libc5,
181 .\" .BR utimes ()
182 .\" is just a wrapper for
183 .\" .BR utime ()
184 .\" and hence does not allow a subsecond resolution.
185 .SH SEE ALSO
186 .BR chattr (1),
187 .BR futimesat (2),
188 .BR stat (2),
189 .BR utimensat (2),
190 .BR futimens (3),
191 .BR futimes (3)
192 .SH COLOPHON
193 This page is part of release 3.79 of the Linux
194 .I man-pages
195 project.
196 A description of the project,
197 information about reporting bugs,
198 and the latest version of this page,
199 can be found at
200 \%http://www.kernel.org/doc/man\-pages/.