13 char fname
[] = "/tmp/jXXXXXX";
14 int fd
= mkstemp (fname
);
17 puts ("mkstemp failed");
21 write (fd
, "hello", 5);
25 if (stat64 (fname
, &st
) == -1)
27 puts ("first stat failed");
31 /* Make sure there is enough time between the creation and the access. */
34 fd
= open (fname
, O_RDONLY
| O_NOATIME
);
37 puts ("first open failed");
42 read(fd
, buf
, sizeof (buf
));
46 if (stat64 (fname
, &st2
) == -1)
48 puts ("second stat failed");
52 bool no_noatime
= false;
53 #ifdef _STATBUF_ST_NSEC
54 if (st
.st_atim
.tv_sec
!= st2
.st_atim
.tv_sec
55 || st
.st_atim
.tv_nsec
!= st2
.st_atim
.tv_nsec
)
57 if (st
.st_atime
!= st2
.st_atime
)
60 puts ("file atime changed");
66 strcpy(fname
, "/tmp/dXXXXXX");
67 char *d
= mkdtemp (fname
);
70 puts ("mkdtemp failed");
74 if (stat64 (d
, &st
) == -1)
76 puts ("third stat failed");
81 fd
= open64 (d
, O_RDONLY
|O_NDELAY
|O_DIRECTORY
|O_NOATIME
);
84 puts ("second open failed");
87 DIR *dir
= fdopendir (fd
);
90 puts ("fdopendir failed");
95 while ((de
= readdir (dir
)) != NULL
)
100 if (stat64 (d
, &st2
) == -1)
102 puts ("fourth stat failed");
105 #ifdef _STATBUF_ST_NSEC
107 && (st
.st_atim
.tv_sec
!= st2
.st_atim
.tv_sec
108 || st
.st_atim
.tv_nsec
!= st2
.st_atim
.tv_nsec
))
110 if (!no_noatime
&& st
.st_atime
!= st2
.st_atime
)
113 puts ("directory atime changed");
123 #define TEST_FUNCTION do_test ()
124 #include "../test-skeleton.c"