_utime

Description

Sets the file modification time.

#include <sys\types.h>

#include <sys\utime.h>

int _utime( char *filename, struct _utimbuf *times );

filename Filename  
times Pointer to stored time values  

Remarks

The _utime function sets the modification time for the file specified by filename. 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 with DOS. 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.

Return Value

The _utime function returns the value 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:

Value Meaning

EACCES Path name specifies directory or read-only file
EINVAL Invalid argument; the times argument is invalid
EMFILE Too many open files (the file must be opened to change its modification time)
ENOENT File or path name not found

Compatibility

Standards:UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

Use _utime for compatibility with ANSI naming conventions of non-ANSI functions. Use utime and link with OLDNAMES.LIB for UNIX compatibility.

See Also

asctime, ctime, _fstat, _ftime, gmtime, localtime, _stat, time

Example

/* UTIME.C: This program uses _utime to set the file-modification time to

* the current time.

*/

#include <stdio.h>

#include <stdlib.h>

#include <sys\types.h>

#include <sys\utime.h>

void main( void )

{

/* Show file time before and after. */

system( "dir _utime.c" );

if( _utime( "_utime.c", NULL ) == -1 )

perror( "_utime failed\n" );

else

printf( "File time modified\n" );

system( "dir _utime.c" );

}

Output

The volume label in drive C is ZEPPELIN.

Directory of C:\LIBREF

UTIME C 397 6-20-99 2:11p

1 File(s) 12974080 bytes free

File time modified

The volume label in drive C is ZEPPELIN.

Directory of C:\LIBREF

UTIME C 397 6-20-99 2:12p

1 File(s) 12974080 bytes free