17 char fname
[] = "/tmp/jXXXXXX";
18 int fd
= mkstemp (fname
);
21 puts ("mkstemp failed");
25 write (fd
, "hello", 5);
29 if (stat64 (fname
, &st
) == -1)
31 puts ("first stat failed");
35 /* Make sure there is enough time between the creation and the access. */
38 fd
= open (fname
, O_RDONLY
| O_NOATIME
);
41 puts ("first open failed");
46 read(fd
, buf
, sizeof (buf
));
50 if (stat64 (fname
, &st2
) == -1)
52 puts ("second stat failed");
56 bool no_noatime
= false;
57 #ifdef _STATBUF_ST_NSEC
58 if (st
.st_atim
.tv_sec
!= st2
.st_atim
.tv_sec
59 || st
.st_atim
.tv_nsec
!= st2
.st_atim
.tv_nsec
)
61 if (st
.st_atime
!= st2
.st_atime
)
64 puts ("file atime changed");
70 strcpy(fname
, "/tmp/dXXXXXX");
71 char *d
= mkdtemp (fname
);
74 puts ("mkdtemp failed");
78 if (stat64 (d
, &st
) == -1)
80 puts ("third stat failed");
85 fd
= open64 (d
, O_RDONLY
|O_NDELAY
|O_DIRECTORY
|O_NOATIME
);
88 puts ("second open failed");
91 DIR *dir
= fdopendir (fd
);
94 puts ("fdopendir failed");
99 while ((de
= readdir (dir
)) != NULL
)
104 if (stat64 (d
, &st2
) == -1)
106 puts ("fourth stat failed");
109 #ifdef _STATBUF_ST_NSEC
111 && (st
.st_atim
.tv_sec
!= st2
.st_atim
.tv_sec
112 || st
.st_atim
.tv_nsec
!= st2
.st_atim
.tv_nsec
))
114 if (!no_noatime
&& st
.st_atime
!= st2
.st_atime
)
117 puts ("directory atime changed");
127 #define TEST_FUNCTION do_test ()
128 #include "../test-skeleton.c"