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


utimes

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 utimes(const char *path,
  struct timeval buf[2]);
Parameters:

Parameters for this facility are:

path  
const char *  
The pathname as a string  
buf  
timeva struct array  
An array of time values used to set the modification dates  

Remarks:

This function sets the modification time for the file specified in path to the second element of the array buf. Each element of the array buf is a timeval structure, which has the fields in Table 32.2.

The timeval structure:

This field
is the
int t  
tv_sec  
Seconds  
int  
tv_usec  
Microseconds. Since the Macintosh does not use microseconds, utimes() ignores this.  

The first element of buf is the access time.


NOTE

Since the Macintosh does not have anything that corresponds to a file's access time, it ignores that element of the array.
Return:

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

See Also:

"utime"

"ctime"

"mktime"

"fstat"

"stat"

Example for utimes():
#include <stdio.h>
#include <unix.h>

int main(void)
{
	struct tm date;
	struct timeval buf[2];
	struct stat info;


/* Create a calendar time for 
Midnight, Sept. 9, 1965.*/	
	date.tm_sec=0;      /* Zero seconds */
	date.tm_min=0;      /* Zero minutes */
	date.tm_hour=0;     /* Zero hours */
	date.tm_mday=9;     /* 9th day */
	date.tm_mon=8;      			/* .. of September  */
	date.tm_year=65;		    /* ...in 1965   */
	date.tm_isdst=-1;   			/* Not daylight savings  */
	buf[1].tv_sec=mktime(&date); 
	/* Convert to calendar time.  */
	
	/* Change modification date to   *
	 * midnight, Sept. 9, 1965.      */
	utimes("mytest", buf);
	stat("mytest", &info);
	printf("Mod date is %s", ctime(&info.st_mtime));

	return 0;
}

This program prints the following to standard output:
Mod date is Thu Sep  9 00:00:00 1965


[ 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