1 #include "apue.h"
2 #include <fcntl.h>
3
4 int main(int argc, char * argv[])
5 {
6 int fd;
7 struct timespec times[2];
8 struct stat statbuf;
9 int i;
10 for( i = 1; i < argc; ++i )
11 {
12 if( stat(argv[i], &statbuf) < 0 )
13 {
14 err_sys("stat error");
15 continue;
16 }
17
18 times[0] = statbuf.st_atim;
19 times[1] = statbuf.st_mtim;
20
21 if( (fd = open(argv[i], O_RDWR | O_TRUNC)) < 0 )
22 {
23 err_sys("open error");
24 continue;
25 }
26
27 if( futimens(fd, times) < 0)
28 {
29 err_sys("futimens error");
30 close(fd);
31 continue;
32 }
33
34 close(fd);
35 }
36 exit (0);
2 #include <fcntl.h>
3
4 int main(int argc, char * argv[])
5 {
6 int fd;
7 struct timespec times[2];
8 struct stat statbuf;
9 int i;
10 for( i = 1; i < argc; ++i )
11 {
12 if( stat(argv[i], &statbuf) < 0 )
13 {
14 err_sys("stat error");
15 continue;
16 }
17
18 times[0] = statbuf.st_atim;
19 times[1] = statbuf.st_mtim;
20
21 if( (fd = open(argv[i], O_RDWR | O_TRUNC)) < 0 )
22 {
23 err_sys("open error");
24 continue;
25 }
26
27 if( futimens(fd, times) < 0)
28 {
29 err_sys("futimens error");
30 close(fd);
31 continue;
32 }
33
34 close(fd);
35 }
36 exit (0);
37 }
-rw------- 1 tingbinz tingbinz 2314909 Sep 10 21:36 core
<usnavsvmh15:/home/tingbinz/apue.3e/SBSCODE/4>R*_*G:./cut_without_time_change core
<usnavsvmh15:/home/tingbinz/apue.3e/SBSCODE/4>R*_*G:ls -l core
-rw------- 1 tingbinz tingbinz 0 Sep 10 21:36 core