futimens函数的使用【学习笔记】

 1 #include "apue.h"
 2 #include <fcntl.h>
 3 
 4 int main(int argc,char *argv[])
 5 {
 6 
 7     int  i,fd;
 8     struct stat statbuf;
 9     struct timespec times[2];
10 
11     for(i = 1;i < argc;i ++){
12         if(stat(argv[i],&statbuf) < 0){
13             err_ret("%s stat error",argv[i]);
14             continue;
15         }
16         if((fd = open(argv[i],O_RDWR|O_TRUNC)) < 0){
17             err_ret("%s:open error",argv[i]);
18             continue;
19         }
20         times[0] = statbuf.st_atim;
21         times[1] = statbuf.st_mtim;
22         if(futimens(fd,times) < 0)
23             err_ret("%s:funtimes error",argv[i]);
24         close(fd);
25 
26     }
27 
28 
29     return 0;
30 }
31 ~      

 

原文地址:https://www.cnblogs.com/zzb-Dream-90Time/p/6964046.html