utime -- Set Modification Time

Format

#include <sys\utime.h>
#include <sys\types.h>
int utime(char *pathname, struct utimbuf *times);

Language Level: XPG4, Extension
utime sets the modification and access times for the file specified by pathname. The process must have write access to the file; otherwise, the time cannot be changed.

If times is a NULL pointer, the modification and access times are set to the current time. Otherwise, times must point to a structure of type utimbuf, defined in <sys\utime.h>. The modification time is set from the modtime field in this structure, and the access time is set from the actime field.

On the FAT file system for both OS/2 and Windows, only the modification time is set in the operating system.

utime accepts only even numbers of seconds. If you enter an odd number of seconds, the function rounds it down.

Note: In earlier releases of the C/C++ run-time library, utime began with an underscore (_utime). Because it is defined by the X/Open standard, the underscore has been removed. For compatibility, IBM C and C++ Compilers will map _utime to utime for you.

Return Value
utime returns 0 if the file modification time was changed. A return value of -1 indicates an error, and errno is set to one of the following values:

Value Meaning
EACCESS The path name specifies a directory or read-only file.
EMFILE There are too many open files. You must open the file to change its modification time.
ENOENT The file path name was not found, or the file name was incorrectly specified.

Example



fstat -- Information about Open File
stat -- Get Information about File or Directory
<sys\utime.h>
<sys\types.h>