Sets a file's modification time.
Compatibility:This function is compatible with the following targets:
|
|
#include <utime.h>
int utime(const char *path,
   const struct utimbuf *buf);
Parameters for this facility are:
The utimbuf structures contains the fields in Table 32.2.
|
This field
|
is the
| |
|---|---|---|
#include <stdio.h>
#include <stdlib.h>
#include <unix.h>
int main(void)
{
struct utimbuf timebuf;
struct tm date;
struct stat info;
FILE * fp;
fp = fopen("mytest", "w");
if(!fp)
{
fprintf(stderr,"Could not open file");
exit(EXIT_FAILURE);
}
fprintf(fp,"test");
fclose(fp);
/* Create a calendar time for
Midnight, Apr. 4, 1994. */
date.tm_sec=0; /* Zero seconds */
date.tm_min=0; /* Zero minutes */
date.tm_hour=0; /* Zero hours */
date.tm_mday=4; /* 4th day */
date.tm_mon=3; /* .. of April */
date.tm_year=94; /* ...in 1994 */
date.tm_isdst=-1; /* Not daylight savings */
timebuf.modtime=mktime(&date);
/* Convert to calendar time. */
/* Change modification date to *
* midnight, Apr. 4, 1994. */
utime("mytest", &timebuf);
stat("mytest", &info);
printf("Mod date is %s", ctime(&info.st_mtime));
/* Change modification date *
* to current time */
utime("mytest", NULL);
stat("mytest", &info);
printf("Mod date is %s", ctime(&info.st_mtime));
return 0;
}
This program might display the following to standard output:
Mod date is Mon Apr 4 00:00:00 1994
Mod date is Mon Jul 10 17:45:17 2000
[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.
Last updated: August 16, 2000