man-pages/man2/utime.2

183 lines
4.7 KiB
Groff
Raw Normal View History

2004-11-03 13:51:07 +00:00
.\" Hey Emacs! This file is -*- nroff -*- source.
.\"
.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
2004-11-03 13:51:07 +00:00
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
2004-11-03 13:51:07 +00:00
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.\" Modified by Michael Haardt <michael@moria.de>
.\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
.\" Modified 1995-06-10 by Andries Brouwer <aeb@cwi.nl>
2007-09-20 06:52:22 +00:00
.\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
2004-11-03 13:51:07 +00:00
.\" Modified 2004-10-10 by Andries Brouwer <aeb@cwi.nl>
.\"
.TH UTIME 2 2008-04-23 "Linux" "Linux Programmer's Manual"
2004-11-03 13:51:07 +00:00
.SH NAME
utime, utimes \- change file last access and modification times
2004-11-03 13:51:07 +00:00
.SH SYNOPSIS
.nf
.B #include <sys/types.h>
.br
.B #include <utime.h>
.sp
.BI "int utime(const char *" filename ", const struct utimbuf *" buf );
2007-04-03 14:04:54 +00:00
.sp
2004-11-03 13:51:07 +00:00
.B #include <sys/time.h>
.sp
2006-04-22 00:00:13 +00:00
.BI "int utimes(const char *" filename ", const struct timeval " times [2]);
2004-11-03 13:51:07 +00:00
.fi
.SH DESCRIPTION
.BR utime ()
2004-11-03 13:51:07 +00:00
changes the access and modification times of the inode specified by
.I filename
to the
.IR actime " and " modtime
fields of
2004-11-03 13:51:07 +00:00
.I buf
respectively.
If
.I buf
is NULL, then the access and modification times of the file are set
to the current time.
Changing timestamps is permitted when: either
2004-11-03 13:51:07 +00:00
the process has appropriate privileges (Linux: has the
.B CAP_FOWNER
capability), or the effective user ID equals the user ID
of the file, or
.I buf
2007-06-24 17:06:42 +00:00
is NULL and the process has write permission to the file.
2004-11-03 13:51:07 +00:00
The
.I utimbuf
structure is:
.in +4n
2004-11-03 13:51:07 +00:00
.nf
struct utimbuf {
2006-04-22 00:00:13 +00:00
time_t actime; /* access time */
time_t modtime; /* modification time */
2004-11-03 13:51:07 +00:00
};
.fi
.in
2004-11-03 13:51:07 +00:00
The function
.BR utime ()
allows specification of timestamps with a resolution of 1 second.
2004-11-03 13:51:07 +00:00
The function
.BR utimes ()
is similar, but the
.I times
argument allows a resolution of 1 microsecond for the timestamps.
2004-11-03 13:51:07 +00:00
The
.I timeval
structure is:
.in +4n
2004-11-03 13:51:07 +00:00
.nf
struct timeval {
2006-04-22 00:00:13 +00:00
long tv_sec; /* seconds */
long tv_usec; /* microseconds */
2004-11-03 13:51:07 +00:00
};
.fi
.in
.PP
.IR times [0]
specifies the new access time, and
.IR times [1]
specifies the new modification time.
If
.I times
is NULL, then analogously to
.BR utime (),
the access and modification times of the file are
set to the current time.
2004-11-03 13:51:07 +00:00
.SH "RETURN VALUE"
On success, zero is returned.
On error, \-1 is returned, and
2004-11-03 13:51:07 +00:00
.I errno
is set appropriately.
.SH ERRORS
.TP
.B EACCES
Search permission is denied for one of the directories in
the path prefix of
.I path
(see also
.BR path_resolution (7)),
2004-11-03 13:51:07 +00:00
or
.I buf
is NULL and the process does not have permission to change the timestamps
2004-11-03 13:51:07 +00:00
(see above).
.TP
.B ENOENT
.I filename
does not exist.
.TP
.B EPERM
.I buf
is not NULL and the process does not have permission to change the timestamps.
2004-11-03 13:51:07 +00:00
.TP
.B EROFS
.I path
resides on a read-only file system.
2007-05-18 16:30:46 +00:00
.SH "CONFORMING TO"
.BR utime ():
SVr4, POSIX.1-2001.
2008-03-19 15:09:59 +00:00
.\" FIXME . Mar 08: The next POSIX.1 revisions marks utime() obsolete.
2007-05-18 16:30:46 +00:00
.\" SVr4 documents additional error conditions EFAULT,
.\" EINTR, ELOOP, EMULTIHOP, ENAMETOOLONG, ENOLINK, ENOLINK, ENOTDIR.
.br
.BR utimes ():
4.3BSD, POSIX.1-2001.
2004-11-03 13:51:07 +00:00
.SH NOTES
Linux does not allow changing the timestamps on an immutable file,
or setting the timestamps to something other than the current time
2004-11-03 13:51:07 +00:00
on an append-only file.
In libc4 and libc5,
.BR utimes ()
2004-11-03 13:51:07 +00:00
is just a wrapper for
.BR utime ()
2004-11-03 13:51:07 +00:00
and hence does not allow a subsecond resolution.
2006-04-22 00:00:13 +00:00
POSIX.1-2001 marks
.BR utimes ()
2006-04-22 00:00:13 +00:00
legacy, which is strange since it provides more functionality than
.BR utime ().
.\" FIXME .
.\" POSIX.1-2008 reverses things, removing the LEGACY marking for
.\" utimes() and marking utime() OBSOLESCENT.
2004-11-03 13:51:07 +00:00
.SH BUGS
2007-06-22 18:25:23 +00:00
Linux is not careful to distinguish between the
.B EACCES
2007-06-22 19:42:52 +00:00
and
.B EPERM
error returns.
2006-08-03 13:57:17 +00:00
On the other hand, POSIX.1-2001 is buggy in its error description for
.BR utimes ().
2004-11-03 13:51:07 +00:00
.SH "SEE ALSO"
.BR chattr (1),
.BR futimesat (2),
2006-03-06 04:36:54 +00:00
.BR stat (2),
.BR futimes (3)