Borland C++ reference

utime

raw OCR

Sets file time and date.

Defined in header <utime.h>

Syntax

#include <utime.h>
int utime(char *path, structutimbuf *times);

Portability

DOSUNIXWindowsANSI CC++ only
■■■

Remarks

utime sets the modification time for the file path. The modification time is contained in the utimbuf structure pointed to by times. This structure is defined in utime.h, and has the following format:

struct utimbuf {

time_t actime;/* access time */
time_t modtime;/* modification time */

The DOS file system supports only a modification time; therefore, on DOS utime ignores actime and uses only modtime to set the file's modification time.

If times is NULL, the file's modification time is set to the current time.

Return value

utime returns 0 if it is successful. Otherwise, it returns -1, and the global variable errno is set to one of the following:

EACCES Permission denied EMFILE Too many open files ENOENT Path or file name not found

See also

Example

/* copy timestamp from one file to another */
#include <sys\stat.h>
#include <utime.h>
#include <stdio.h>

int main( int argc, char *argv[] )
{
   struct Stat src_stat;
   struct utimbuf times;
   if(argc != 3) {
      printf( "Usage: copytime <source file> <dest  file>\n" );
      return 1;
   }
   if (stat(argv[l],&src_stat)  != 0) {
      perror("Unable to get status of source file");
      return 1;
   }
   times.modtime = times.actime = src_stat .st_mtime;
   if (utime(argv[2],&times) != 0) {
      perror("Unable to set time of destination file");
      return 1;
   }
   return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.