Name
utime - Sets file modification time.
Syntax
#include <sys/types.h>
#include <sys/utime.h>
int utime(path, times)
char *path;
struct utimbuf *times;
Description
The utime function sets the modification time for the file
specified by path. The process must have write access to the
file; otherwise, the time cannot be changed.
Although the utimbuf structure contains a field for access
time, under DOS and OS/2 only the modification time is set.
If times is a null pointer, the modification time is 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.
Return Value
The utime function returns the value 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
EACCES Path name specifies directory or read-only file
EINVAL Invalid argument; the times argument is invalid
EMFILE Too many open files (the file must be opened to
change its modification time)
ENOENT File or path name not found
See Also
asctime(S), ctime(S), fstat(DOS), ftime(DOS), gmtime(S),
localtime(S), stat(DOS), time(S)
Example
#include <stdio.h> #include <stdlib.h> #include
<sys/types.h> #include <sys/utime.h>
main()
{
int savestderr;
if (utime("/tmp/data",NULL) == -1)
perror("utime failed");
else
printf("File time modified.\n");
}
This program uses utime to set the file-modification time to
the current time.
(printed 6/18/89)