OSDN Git Service

(split) LDP man-pages の original/ を v3.30 に更新。
[linuxjm/LDP_man-pages.git] / original / 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@gmail.com>
29 .\" Modified 2004-10-10 by Andries Brouwer <aeb@cwi.nl>
30 .\"
31 .TH UTIME 2 2008-08-06 "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 The
48 .BR utime ()
49 system call
50 changes the access and modification times of the inode specified by
51 .I filename
52 to the
53 .IR actime " and " modtime
54 fields of
55 .I times
56 respectively.
57
58 If
59 .I times
60 is NULL, then the access and modification times of the file are set
61 to the current time.
62
63 Changing timestamps is permitted when: either
64 the process has appropriate privileges,
65 or the effective user ID equals the user ID
66 of the file, or
67 .I times
68 is NULL and the process has write permission for the file.
69
70 The
71 .I utimbuf
72 structure is:
73
74 .in +4n
75 .nf
76 struct utimbuf {
77     time_t actime;       /* access time */
78     time_t modtime;      /* modification time */
79 };
80 .fi
81 .in
82
83 The
84 .BR utime ()
85 system call
86 allows specification of timestamps with a resolution of 1 second.
87
88 The
89 .BR utimes ()
90 system call
91 is similar, but the
92 .I times
93 argument refers to an array rather than a structure.
94 The elements of this array are
95 .I timeval
96 structures, which allow a precision of 1 microsecond for specifying timestamps.
97 The
98 .I timeval
99 structure is:
100
101 .in +4n
102 .nf
103 struct timeval {
104     long tv_sec;        /* seconds */
105     long tv_usec;       /* microseconds */
106 };
107 .fi
108 .in
109 .PP
110 .IR times [0]
111 specifies the new access time, and
112 .IR times [1]
113 specifies the new modification time.
114 If
115 .I times
116 is NULL, then analogously to
117 .BR utime (),
118 the access and modification times of the file are
119 set to the current time.
120 .SH "RETURN VALUE"
121 On success, zero is returned.
122 On error, \-1 is returned, and
123 .I errno
124 is set appropriately.
125 .SH ERRORS
126 .TP
127 .B EACCES
128 Search permission is denied for one of the directories in
129 the path prefix of
130 .I path
131 (see also
132 .BR path_resolution (7)).
133 .TP
134 .B EACCES
135 .I times
136 is NULL,
137 the caller's effective user ID does not match the owner of the file,
138 the caller does not have write access to the file,
139 and the caller is not privileged
140 (Linux: does not have either the
141 .B CAP_DAC_OVERRIDE
142 or the
143 .B CAP_FOWNER
144 capability).
145 .TP
146 .B ENOENT
147 .I filename
148 does not exist.
149 .TP
150 .B EPERM
151 .I times
152 is not NULL,
153 the caller's effective UID does not match the owner of the file,
154 and the caller is not privileged
155 (Linux: does not have the
156 .B CAP_FOWNER
157 capability).
158 .TP
159 .B EROFS
160 .I path
161 resides on a read-only file system.
162 .SH "CONFORMING TO"
163 .BR utime ():
164 SVr4, POSIX.1-2001.
165 POSIX.1-2008 marks
166 .BR utime ()
167 as obsolete.
168 .br
169 .BR utimes ():
170 4.3BSD, POSIX.1-2001.
171 .SH NOTES
172 Linux does not allow changing the timestamps on an immutable file,
173 or setting the timestamps to something other than the current time
174 on an append-only file.
175
176 In libc4 and libc5,
177 .BR utimes ()
178 is just a wrapper for
179 .BR utime ()
180 and hence does not allow a subsecond resolution.
181 .SH "SEE ALSO"
182 .BR chattr (1),
183 .BR futimesat (2),
184 .BR stat (2),
185 .BR utimensat (2),
186 .BR futimens (3),
187 .BR futimes (3)