RAD Studio |  |

_utime, _wutime

Header File

utime.h

Category

Input/output Routines

Prototype

int _utime(char *path, struct utimbuf *times);

int _wutime(wchar_t *path, struct _utimbuf *times);

Description

Sets file time and date.

_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 FAT (file allocation table) file system supports only a modification time; therefore, on FAT file systems _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.

_wutime is the Unicode version of _utime. The Unicode version accepts a filename that is a wchar_t character string. Otherwise, the functions perform identically.

Return Value

On success, _utime returns 0.

On error, it returns -1, and sets the global variable errno to one of the following values:

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

Example

Copy Code

    /* 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[1],&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;
    }

Portability

| POSIX | Win32 | ANSI C | ANSI C++
_utime | + | + |  |
_wutime |  | + |  |

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!