

#include <utime.h> int utime(char *name, struct utimbuf *time)
utime updates the access and modification times for a file.
name is the filename. time is the pointer to a
utimbuf structure, which contains the new access and
modification times. If time is NULL, the access and
modification times for name are changed to the current time.
utimbuf contains the following:
time_t actime
time_t modtime
utime returns 0 if it is successful and - 1 if it is not successful.
#include <sys/types.h>
#include <sys/stat.h>
#include <utime.h>
#include <stdlib.h>
main(int argc, char *argv[]) {
struct stat fdata;
struct utimbuf tdata;
int rc;
if (argc != 2) {
puts("Incorrect number of arguments");
exit(EXIT_FAILURE);
}
rc = stat(argv[1], &fdata);
if (rc != 0) {
perror("stat failure");
exit(EXIT_FAILURE);
}
tdata.modtime = tdata.actime = fdata.st_atime;
/* Set modification time to access time. */
rc = utime(argv[1], &tdata); /* Update file times. */
if (rc != 0) {
perror("utime failure");
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.