Syntax
#include <sys\utime.h> #include <sys\types.h> int utime(char *pathname, struct utimbuf *times);Description
utime sets the modification time for the file specified by pathname. 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, only the modification time is set in the OS/2 operating system. 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.
utime accepts only even numbers of seconds. If you enter an odd number of seconds, the function rounds it down.
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: compact break=fit.
Value
This example sets the last modification time of file utime.dat to the current time. It prints an error message if it cannot.
#include <sys\types.h>#include <sys\utime.h> #include <sys\stat.h> #include <stdio.h> #include <stdlib.h> #define FILENAME "utime.dat" int main(void) { struct utimbuf ubuf; struct stat statbuf; FILE *fp; /* File pointer */ /* creating file, whose date will be changed by calling utime */ fp = fopen(FILENAME, "w"); /* write Hello World in the file */ fprintf(fp, "Hello World\n"); /* close file */ fclose(fp); /* seconds to current date from 1970 Jan 1 */ /* Fri Dec 31 23:59:58 1999 */ ubuf.modtime = 946702799; /* changing file modification time */ if (-1 == utime(FILENAME, &ubuf)) { perror("utime failed"); remove(FILENAME); return EXIT_FAILURE; } /* display the modification time */ if (0 == stat(FILENAME, &statbuf)) printf("The file modification time is %s", ctime(&statbuf.st_mtime)); else printf("File could not be found\n"); remove(FILENAME); return 0; /**************************************************************************** The output should be: The file modification time is Fri Dec 31 23:59:58 1999 ****************************************************************************/ }Related Information