16 char fname
[] = "/tmp/jXXXXXX";
17 int fd
= mkstemp (fname
);
20 puts ("mkstemp failed");
24 write (fd
, "hello", 5);
28 if (stat64 (fname
, &st
) == -1)
30 puts ("first stat failed");
34 /* Make sure there is enough time between the creation and the access. */
37 fd
= open (fname
, O_RDONLY
| O_NOATIME
);
40 puts ("first open failed");
45 read(fd
, buf
, sizeof (buf
));
49 if (stat64 (fname
, &st2
) == -1)
51 puts ("second stat failed");
55 bool no_noatime
= false;
56 #ifdef _STATBUF_ST_NSEC
57 if (st
.st_atim
.tv_sec
!= st2
.st_atim
.tv_sec
58 || st
.st_atim
.tv_nsec
!= st2
.st_atim
.tv_nsec
)
60 if (st
.st_atime
!= st2
.st_atime
)
63 puts ("file atime changed");
69 strcpy(fname
, "/tmp/dXXXXXX");
70 char *d
= mkdtemp (fname
);
73 puts ("mkdtemp failed");
77 if (stat64 (d
, &st
) == -1)
79 puts ("third stat failed");
84 fd
= open64 (d
, O_RDONLY
|O_NDELAY
|O_DIRECTORY
|O_NOATIME
);
87 puts ("second open failed");
90 DIR *dir
= fdopendir (fd
);
93 puts ("fdopendir failed");
98 while ((de
= readdir (dir
)) != NULL
)
103 if (stat64 (d
, &st2
) == -1)
105 puts ("fourth stat failed");
108 #ifdef _STATBUF_ST_NSEC
110 && (st
.st_atim
.tv_sec
!= st2
.st_atim
.tv_sec
111 || st
.st_atim
.tv_nsec
!= st2
.st_atim
.tv_nsec
))
113 if (!no_noatime
&& st
.st_atime
!= st2
.st_atime
)
116 puts ("directory atime changed");
126 #define TEST_FUNCTION do_test ()
127 #include "../test-skeleton.c"