Linux服务器编程之:utime()函数

1.依赖的头文件

#include<sys/types.h>

#include<utime.h>

2函数声明

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

#include<sys/time.h>

int utimes(const char *filename,const struct timeval times[2]);

函数说明:

The  utime()  system  call changes the access and modification times of
       the inode specified by filename to the actime  and  modtime  fields  of
       times respectively.

       翻译:调用utime来修改inode中的信息,传递的值有:文件名,访问时间和更改时间。

If  times  is  NULL, then the access and modification times of the file
       are set to the current time.

      翻译:如果时间为NULL,访问时间和修改时间默认设置成了当前时间。


      成功放回0,失败返回1

3.下面是    utimbuf这个结构体:

     struct utimbuf

     {

              time_t atime;          /*access time :访问时间*/

              time_t modtime;     /*modification time : 更改时间*/

     };

4.utimes()调用也

The utimes() system call is similar, but the times argument  refers  to
       an  array  rather  than  a  structure.   The elements of this array are
       timeval structures, which allow a precision of 1 microsecond for speci‐
       fying timestamps.  The timeval structure is:

           struct timeval {
               long tv_sec;        /* seconds */
               long tv_usec;       /* microseconds */
           };

       times[0]  specifies the new access time, and times[1] specifies the new
       modification time.  If times is NULL, then analogously to utime(),  the
       access and modification times of the file are set to the current time.

utimes()的调用也相似,但是这个时间指定的是一个数组,而不是一个结构体,数组的每个元素师一个timeval结构体

这个结构体中允许一个为timestamps所用的精确的微秒值(微秒,百万分之一秒),其中timeval结构体如下:

       struct timeval

       {

             long tv_sec;          /*seconds 秒*/

             long tv_usec;        /*microseconds 微秒,百万分之一秒*/

       }

times[0]这个元素指定的是访问时间,times[1]指定的是修改时间。如果时间为NULL,那么,类似(analogously)utime(),

访问时间和修改时间被设置成当前时间。









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

涂作权的博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值