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

Source: Internet
Author: User
Tags error code

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.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.