utime -- set file access and modification times


cc . . . -lc

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

int utime (path, times) char *path; struct utimbuf *times;


The utime function sets the access and modification times of the file named by the path argument.

If times is NULL, the access and modification times of the file are set to the current time. The effective user ID of the process must match the owner of the file, or the process must have write permission to the file or have super user privileges to use utime in this manner.

If times is not NULL, times is interpreted as a pointer to a utimbuf structure and the access and modification times are set to the values contained in the designated structure. Only a process with effective user ID equal to the user ID of the file or a process with super user privileges may use utime this way.

The utimbuf structure is defined by the header <utime.h>. The times in the structure utimbuf are measured in seconds since the ``Epoch'', 1970-01-01 00:00 UTC.

   struct  utimbuf  {
           time_t actime;         /* access time */
           time_t modtime;        /* modification time */
The utime system call fails if one or more of the following is true:

The effective user ID is not super user and not the owner of the file, and times is null and write access is denied, or search permission is denied by a component of the path prefix.

A signal was caught during the utime system call.

Components of path require hopping to multiple remote machines.

The length of the path argument exceeds PATH_MAX or a pathname component is longer than NAME_MAX while _POSIX_NO_TRUNC is in effect.

The named file does not exist or the path argument points to an empty string.

path points to a remote machine, and the link to that machine is no longer active.

A component of the path prefix is not a directory.

The effective user ID has write access to the file, but is not super user and not the owner of the file, and times is not NULL.

The file system containing the file is mounted read-only.


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

See also


Standards conformance

utime is conformant with:

X/Open Portability Guide, Issue 3, 1989 ;
Intel386 Binary Compatibility Specification, Edition 2 (iBCSe2) ;
IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1) ;
and NIST FIPS 151-1 .

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003