utime()

NAME

utime() - set file times

SYNOPSIS

#include <sys/types.h>
#include <utime.h>

int utime (const char *file, const struct utimbuf *timep)

DESCRIPTION

The utime(2) function sets the access and modification times of the named file from the members of the timep argument.

If the times are specified (the timep argument is non-NULL) the caller must be the owner of the file.

If the times are not specified (the timep argument is NULL) the caller must be the owner of the file and have permission to write the file. In this case, the file times are set to the current time (now).

The timebuf structure timep is defined in <utime.h> and contains the following members:

time_t actime Access time
time_t modtime Modification time

RETURN VALUE

Upon successful completion, 0 is returned. Otherwise, -1 is returned, errno is set to indicate the error, and the file times are not affected.

ERRORS

The utime(2) function may fail and set errno for any of these errors:

[EACCES]
The effective user ID of the process doesn't own the file and write access is denied, or search permission is denied on some directory in the file pathname.
[EINVAL]
The file is on a device that does not allow the operation.
[ENAMETOOLONG]
The file was longer than {PATHMAX} characters, or a component of file exceeded {NAMEMAX} characters.
[ENOENT]
The file doesn't exist or is an empty string.
[ENOTDIR]
Some component of the pathname prefix of file is not a directory.
[EPERM]
The times argument is non-NULL, and the effective user ID of the process is not the owner of the file, nor does it have the appropriate privileges.
[EROFS]
The file is on a read-only file system.

SEE ALSO

stat(2)