1UTIME(3P) POSIX Programmer's Manual UTIME(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 utime — set file access and modification times
13
15 #include <utime.h>
16
17 int utime(const char *path, const struct utimbuf *times);
18
20 The utime() function shall set the access and modification times of the
21 file named by the path argument.
22
23 If times is a null pointer, the access and modification times of the
24 file shall be set to the current time. The effective user ID of the
25 process shall match the owner of the file, or the process has write
26 permission to the file or has appropriate privileges, to use utime() in
27 this manner.
28
29 If times is not a null pointer, times shall be interpreted as a pointer
30 to a utimbuf structure and the access and modification times shall be
31 set to the values contained in the designated structure. Only a process
32 with the effective user ID equal to the user ID of the file or a
33 process with appropriate privileges may use utime() this way.
34
35 The utimbuf structure is defined in the <utime.h> header. The times in
36 the structure utimbuf are measured in seconds since the Epoch.
37
38 Upon successful completion, the utime() function shall mark the last
39 file status change timestamp for update; see <sys/stat.h>.
40
42 Upon successful completion, 0 shall be returned. Otherwise, -1 shall be
43 returned and errno shall be set to indicate the error, and the file
44 times shall not be affected.
45
47 The utime() function shall fail if:
48
49 EACCES Search permission is denied by a component of the path prefix;
50 or the times argument is a null pointer and the effective user
51 ID of the process does not match the owner of the file, the
52 process does not have write permission for the file, and the
53 process does not have appropriate privileges.
54
55 ELOOP A loop exists in symbolic links encountered during resolution of
56 the path argument.
57
58 ENAMETOOLONG
59 The length of a component of a pathname is longer than
60 {NAME_MAX}.
61
62 ENOENT A component of path does not name an existing file or path is an
63 empty string.
64
65 ENOTDIR
66 A component of the path prefix names an existing file that is
67 neither a directory nor a symbolic link to a directory, or the
68 path argument contains at least one non-<slash> character and
69 ends with one or more trailing <slash> characters and the last
70 pathname component names an existing file that is neither a
71 directory nor a symbolic link to a directory.
72
73 EPERM The times argument is not a null pointer and the effective user
74 ID of the calling process does not match the owner of the file
75 and the calling process does not have appropriate privileges.
76
77 EROFS The file system containing the file is read-only.
78
79 The utime() function may fail if:
80
81 ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during
82 resolution of the path argument.
83
84 ENAMETOOLONG
85 The length of a pathname exceeds {PATH_MAX}, or pathname resolu‐
86 tion of a symbolic link produced an intermediate result with a
87 length that exceeds {PATH_MAX}.
88
89 The following sections are informative.
90
92 None.
93
95 Since the utimbuf structure only contains time_t variables and is not
96 accurate to fractions of a second, applications should use the utimen‐
97 sat() function instead of the obsolescent utime() function.
98
100 The actime structure member must be present so that an application may
101 set it, even though an implementation may ignore it and not change the
102 last data access timestamp on the file. If an application intends to
103 leave one of the times of a file unchanged while changing the other, it
104 should use stat() or fstat() to retrieve the file's st_atim and st_mtim
105 parameters, set actime and modtime in the buffer, and change one of
106 them before making the utime() call.
107
109 The utime() function may be removed in a future version.
110
112 fstat(), fstatat(), futimens()
113
114 The Base Definitions volume of POSIX.1‐2017, <sys_stat.h>, <utime.h>
115
117 Portions of this text are reprinted and reproduced in electronic form
118 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
119 table Operating System Interface (POSIX), The Open Group Base Specifi‐
120 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
121 Electrical and Electronics Engineers, Inc and The Open Group. In the
122 event of any discrepancy between this version and the original IEEE and
123 The Open Group Standard, the original IEEE and The Open Group Standard
124 is the referee document. The original Standard can be obtained online
125 at http://www.opengroup.org/unix/online.html .
126
127 Any typographical or formatting errors that appear in this page are
128 most likely to have been introduced during the conversion of the source
129 files to man page format. To report such errors, see https://www.ker‐
130 nel.org/doc/man-pages/reporting_bugs.html .
131
132
133
134IEEE/The Open Group 2017 UTIME(3P)