forked from wenjun1055/c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
4.6.c
35 lines (28 loc) · 783 Bytes
/
4.6.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include <stdlib.h>
#include <utime.h>
#include <fcntl.h>
int main(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) {
printf("%s : stat error!\n", *(argv + i));
continue;
}
if ((fd = open(*(argv + i), O_RDWR | O_TRUNC)) < 0) {
printf("%s : open error!\n", *(argv + i));
continue;
}
close(fd);
timebuf.actime = statbuf.st_atime;
timebuf.modtime = statbuf.st_mtime;
if (utime(*(argv + i), &timebuf) < 0) {
printf("%s : utime error!\n", *(argv + i));
continue;
}
}
return 0;
}