C language functions to modify the access time of files using the _c language

Source: Internet
Author: User

C language Utime () function: Modify file access time and change time
header file:

#include <sys/types.h>  #include <utime.h>

To define a function:

int utime (const char * filename, struct utimbuf * buf);

Function Description: Utime () is used to modify the Inode access time that the parameter filename file belongs to. The structure UTIMBUF is defined as follows:

struct Utimbuf
{
  time_t actime;
  time_t modtime;
};

Return value: If the parameter buf is a null pointer (NULL), the access time and the change time of the file are all set to the current time ... Successful execution returns 0, failure returns-1, and the error code is stored in errno.

Error code:
1, eaccess access to the file is denied, insufficient permissions.
2, enoent specified file does not exist.

C language Utimes () function: Modify file access time and change time
header file:

 #include <sys/types.h>  #include <utime.h>

To define a function:

int utimes (char * filename, struct timeval *TVP);

Function Description: Utimes () is used to modify the Inode access time and modification time of the parameter filename file. The structure timeval is defined as follows:

struct Timeval
{
  long tv_sec;
  Long tv_usec; Subtlety
};

Return value: Parameter TVP points to two timeval structural spaces, compared to the UTIMEBUF structure used by Utime (), tvp[0].tc_sec to Utimbuf.actime, tvp[1].tv_sec to Utimbuf.modtime. Successful execution returns 0. Failure returns-1, error generation
The code is stored in the errno.

Error code:
1, eaccess access to the file is denied, insufficient permissions.
2, enoent specified file does not exist.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.