Blame man2/utime.2

Packit 7cfc04
.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" Modified by Michael Haardt <michael@moria.de>
Packit 7cfc04
.\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
Packit 7cfc04
.\" Modified 1995-06-10 by Andries Brouwer <aeb@cwi.nl>
Packit 7cfc04
.\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\" Modified 2004-10-10 by Andries Brouwer <aeb@cwi.nl>
Packit 7cfc04
.\"
Packit 7cfc04
.TH UTIME 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
utime, utimes \- change file last access and modification times
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <sys/types.h>
Packit 7cfc04
.B #include <utime.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int utime(const char *" filename ", const struct utimbuf *" times );
Packit 7cfc04
.PP
Packit 7cfc04
.B #include <sys/time.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int utimes(const char *" filename ", const struct timeval " times [2]);
Packit 7cfc04
.fi
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.B Note:
Packit 7cfc04
modern applications may prefer to use the interfaces described in
Packit 7cfc04
.BR utimensat (2).
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR utime ()
Packit 7cfc04
system call
Packit 7cfc04
changes the access and modification times of the inode specified by
Packit 7cfc04
.I filename
Packit 7cfc04
to the
Packit 7cfc04
.IR actime " and " modtime
Packit 7cfc04
fields of
Packit 7cfc04
.I times
Packit 7cfc04
respectively.
Packit 7cfc04
.PP
Packit 7cfc04
If
Packit 7cfc04
.I times
Packit 7cfc04
is NULL, then the access and modification times of the file are set
Packit 7cfc04
to the current time.
Packit 7cfc04
.PP
Packit 7cfc04
Changing timestamps is permitted when: either
Packit 7cfc04
the process has appropriate privileges,
Packit 7cfc04
or the effective user ID equals the user ID
Packit 7cfc04
of the file, or
Packit 7cfc04
.I times
Packit 7cfc04
is NULL and the process has write permission for the file.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I utimbuf
Packit 7cfc04
structure is:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct utimbuf {
Packit 7cfc04
    time_t actime;       /* access time */
Packit 7cfc04
    time_t modtime;      /* modification time */
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR utime ()
Packit 7cfc04
system call
Packit 7cfc04
allows specification of timestamps with a resolution of 1 second.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR utimes ()
Packit 7cfc04
system call
Packit 7cfc04
is similar, but the
Packit 7cfc04
.I times
Packit 7cfc04
argument refers to an array rather than a structure.
Packit 7cfc04
The elements of this array are
Packit 7cfc04
.I timeval
Packit 7cfc04
structures, which allow a precision of 1 microsecond for specifying timestamps.
Packit 7cfc04
The
Packit 7cfc04
.I timeval
Packit 7cfc04
structure is:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct timeval {
Packit 7cfc04
    long tv_sec;        /* seconds */
Packit 7cfc04
    long tv_usec;       /* microseconds */
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
.IR times [0]
Packit 7cfc04
specifies the new access time, and
Packit 7cfc04
.IR times [1]
Packit 7cfc04
specifies the new modification time.
Packit 7cfc04
If
Packit 7cfc04
.I times
Packit 7cfc04
is NULL, then analogously to
Packit 7cfc04
.BR utime (),
Packit 7cfc04
the access and modification times of the file are
Packit 7cfc04
set to the current time.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
On success, zero is returned.
Packit 7cfc04
On error, \-1 is returned, and
Packit 7cfc04
.I errno
Packit 7cfc04
is set appropriately.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EACCES
Packit 7cfc04
Search permission is denied for one of the directories in
Packit 7cfc04
the path prefix of
Packit 7cfc04
.I path
Packit 7cfc04
(see also
Packit 7cfc04
.BR path_resolution (7)).
Packit 7cfc04
.TP
Packit 7cfc04
.B EACCES
Packit 7cfc04
.I times
Packit 7cfc04
is NULL,
Packit 7cfc04
the caller's effective user ID does not match the owner of the file,
Packit 7cfc04
the caller does not have write access to the file,
Packit 7cfc04
and the caller is not privileged
Packit 7cfc04
(Linux: does not have either the
Packit 7cfc04
.B CAP_DAC_OVERRIDE
Packit 7cfc04
or the
Packit 7cfc04
.B CAP_FOWNER
Packit 7cfc04
capability).
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOENT
Packit 7cfc04
.I filename
Packit 7cfc04
does not exist.
Packit 7cfc04
.TP
Packit 7cfc04
.B EPERM
Packit 7cfc04
.I times
Packit 7cfc04
is not NULL,
Packit 7cfc04
the caller's effective UID does not match the owner of the file,
Packit 7cfc04
and the caller is not privileged
Packit 7cfc04
(Linux: does not have the
Packit 7cfc04
.B CAP_FOWNER
Packit 7cfc04
capability).
Packit 7cfc04
.TP
Packit 7cfc04
.B EROFS
Packit 7cfc04
.I path
Packit 7cfc04
resides on a read-only filesystem.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
.BR utime ():
Packit 7cfc04
SVr4, POSIX.1-2001.
Packit 7cfc04
POSIX.1-2008 marks
Packit 7cfc04
.BR utime ()
Packit 7cfc04
as obsolete.
Packit 7cfc04
.PP
Packit 7cfc04
.BR utimes ():
Packit 7cfc04
4.3BSD, POSIX.1-2001.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
Linux does not allow changing the timestamps on an immutable file,
Packit 7cfc04
or setting the timestamps to something other than the current time
Packit 7cfc04
on an append-only file.
Packit 7cfc04
.\"
Packit 7cfc04
.\" In libc4 and libc5,
Packit 7cfc04
.\" .BR utimes ()
Packit 7cfc04
.\" is just a wrapper for
Packit 7cfc04
.\" .BR utime ()
Packit 7cfc04
.\" and hence does not allow a subsecond resolution.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR chattr (1),
Packit 7cfc04
.BR touch (1),
Packit 7cfc04
.BR futimesat (2),
Packit 7cfc04
.BR stat (2),
Packit 7cfc04
.BR utimensat (2),
Packit 7cfc04
.BR futimens (3),
Packit 7cfc04
.BR futimes (3),
Packit 7cfc04
.BR inode (7)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.