程序4-6 utime函数实例

时间:2023-03-09 01:00:20
程序4-6 utime函数实例
 //http://blog.chinaunix.net/uid-24549279-id-71355.html
/*
============================================================================
Name : test.c
Author : blank
Version :
Copyright : Your copyright notice
Description : 程序4-6 utime函数实例
============================================================================
*/ #include <fcntl.h>
#include <utime.h>
#include <sys/stat.h>
#include "ourhdr.h" int main(int argc, char *argv[])
{
int i, fd;
struct stat statbuf;
struct utimbuf timebuf; for (i=; i<argc; i++){
printf("argv[%d] = %s\n", i, argv[i]);
if (stat(argv[i], &statbuf) < ){//fetch current times
err_ret("%s: stat error", argv[]);
continue;
} if ((fd = open(argv[], O_RDWR|O_TRUNC)) < ){
err_ret("%s: open error", argv[]);
continue;
} close(fd);
timebuf.actime = statbuf.st_atim.tv_sec;
timebuf.modtime = statbuf.st_mtim.tv_sec;
if (utime(argv[i], &timebuf) < ){
// retset time
err_ret("%s: utime error", argv[i]);
continue;
}
}
}