一个文件的访问和修改时间可以用utime函数更改。#include <utime.h>int utime( const char *pathname, const struct utimbuf *times );返回值:若成功则返回0,若出错则返回-1此函数所使用的数 ...
一个文件的访问和修改时间可以用utime函数更改。
#include <utime.h>int utime( const char *pathname, const struct utimbuf *times );返回值:若成功则返回0,若出错则返回-1
[root@localhost apue]# cat prog4-6.c #include "apue.h"#include <fcntl.h>#include <utime.h>intmain(int argc, char *argv[]){ int i, fd; struct stat statbuf; struct utimbuf timebuf; for(i=1; i<argc; i++) { if(stat(argv[i], &statbuf) < 0) { err_ret("%s: stat error", argv[i]); continue; } if((fd = open(argv[i], O_RDWR | O_TRUNC)) < 0) { err_ret("%s: open error", argv[i]); continue; } close(fd); timebuf.actime = statbuf.st_atime; timebuf.modtime = statbuf.st_mtime; if(utime(argv[i], &timebuf) < 0) { err_ret("%s: utime error", argv[i]); continue; } } exit(0);}
运行结果:
海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com
原标题:文件和目录之utime函数
关键词:函数
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。