[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


utime

Sets a file's modification time.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <utime.h>
int utime(const char *path, 
   const struct utimbuf *buf);
Parameters:

Parameters for this facility are:

path  
const char *  
The pathname as a string  
buf  
const struct utimbuf *  
The address of a stuct that will hold a file's time infornation  

Remarks:

This function sets the modification time for the file specified in path. Since the Macintosh does not have anything that corresponds to a file's access time, it ignores the actime field in the utimbuf structure.

If buf is NULL, utime() sets the modification time to the current time. If buf points to a utimbuf structure, utime() sets the modification time to the time specified in the modtime field of the structure.

The utimbuf structures contains the fields in Table 32.2.

The utimbuf structure:

This field
is the
time_t  
actime  
Access time for the file. Since the Macintosh has nothing that corresponds to this, utime() ignores this field.  
time_t  
modtime  
The last time this file was modified.  

Return:

If it is successful, utime() returns zero. If it encounters an error, utime() returns -1 and sets errno.

See Also:

"utimes"

"ctime"

"mktime"

"stat"

"fstat"

Example for utime():
#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