record the modification time for a file or directory
#include <sys/types.h> #include <utime.h> int utime( const char *path, const struct utimbuf *times ); struct utimbuf { time_t actime; /* access time */ time_t modtime; /* modification time */ };
The utime() function records the access and modification times for the file or directory identified by path.
If the times argument is NULL, the access and modification times of the file or directory are set to the current time. The effective user ID of the process must match the owner of the file or directory, or the process must have write permission to the file or directory, or appropriate privileges in order to use the utime() function in this way.
If the times argument isn't NULL, it's interpreted as a pointer to a utimbuf structure, and the access and modification times of the file or directory are set to the values contained in the designated structure. Only the owner of the file or directory, and processes with appropriate privileges are permitted to use the utime() function in this way. The access and modification times are taken from the actime and modtime fields in this structure.
#include <stdio.h> #include <utime.h> void main( int argc, char *argv[] ) { if( (utime( argv[1], NULL ) != 0) && (argc > 1) ) { printf( "Unable to set time for %s\n", argv[1] ); } }
POSIX 1003.1
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |