1UTIME(2)                   Linux Programmer's Manual                  UTIME(2)
2
3
4

NAME

6       utime, utimes - change access and/or modification times of an inode
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <utime.h>
11
12       int utime(const char *filename, const struct utimbuf *buf);
13
14
15       #include <sys/time.h>
16
17       int utimes(const char *filename, const struct timeval times[2]);
18

DESCRIPTION

20       utime()  changes  the access and modification times of the inode speci‐
21       fied by filename to the actime and modtime fields of buf respectively.
22
23       If buf is NULL, then the access and modification times of the file  are
24       set to the current time.
25
26       Changing  time  stamps is permitted when: either the process has appro‐
27       priate privileges (Linux: has the CAP_FOWNER capability), or the effec‐
28       tive  user  ID  equals the user ID of the file, or buf must is NULL and
29       the process has write permission to the file.
30
31       The utimbuf structure is:
32
33              struct utimbuf {
34                  time_t actime;       /* access time */
35                  time_t modtime;      /* modification time */
36              };
37
38       The function utime() allows specification of time stamps with a resolu‐
39       tion of 1 second.  The function utimes() is similar, but allows a reso‐
40       lution of 1 microsecond.  Here times[0]  refers  to  access  time,  and
41       times[1] to modification time.
42
43       The timeval structure is:
44
45              struct timeval {
46                  long tv_sec;        /* seconds */
47                  long tv_usec;       /* microseconds */
48              };
49

RETURN VALUE

51       On  success,  zero is returned.  On error, -1 is returned, and errno is
52       set appropriately.
53

ERRORS

55       EACCES Search permission is denied for one of the  directories  in  the
56              path  prefix  of  path  (see also path_resolution(2)), or buf is
57              NULL and the process does not have permission to change the time
58              stamps (see above).
59
60       ENOENT filename does not exist.
61
62       EPERM  buf  is  not  NULL  and  the process does not have permission to
63              change the time stamps.
64
65       EROFS  path resides on a read-only file system.
66

NOTES

68       Linux does not allow changing the time stamps on an immutable file,  or
69       setting  the time stamps to something other than the current time on an
70       append-only file.
71
72       In libc4 and libc5, utimes() is just a wrapper for  utime()  and  hence
73       does not allow a subsecond resolution.
74
75       POSIX.1-2001  marks utimes() legacy, which is strange since it provides
76       more functionality than utime().
77

BUGS

79       Linux is not careful to distinguish between the EACCES and EPERM  error
80       returns.   On  the  other  hand,  POSIX.1-2001  is  buggy  in its error
81       description for utimes().
82

CONFORMING TO

84       utime(): SVr4, POSIX.1-2001.
85       utimes(): 4.3BSD
86

SEE ALSO

88       chattr(1), futimesat(2), stat(2), futimes(3)
89
90
91
92Linux 2.6.8                       2004-10-10                          UTIME(2)
Impressum