10 #include <support/xunistd.h>
19 char fname
[] = "/tmp/jXXXXXX";
20 int fd
= mkstemp (fname
);
23 puts ("mkstemp failed");
27 xwrite (fd
, "hello", 5);
31 if (stat64 (fname
, &st
) == -1)
33 puts ("first stat failed");
37 /* Make sure there is enough time between the creation and the access. */
40 fd
= open (fname
, O_RDONLY
| O_NOATIME
);
43 puts ("first open failed");
48 xread(fd
, buf
, sizeof (buf
));
53 if (stat64 (fname
, &st2
) == -1)
55 puts ("second stat failed");
59 bool no_noatime
= false;
60 #ifdef _STATBUF_ST_NSEC
61 if (st
.st_atim
.tv_sec
!= st2
.st_atim
.tv_sec
62 || st
.st_atim
.tv_nsec
!= st2
.st_atim
.tv_nsec
)
64 if (st
.st_atime
!= st2
.st_atime
)
67 puts ("file atime changed");
73 strcpy(fname
, "/tmp/dXXXXXX");
74 char *d
= mkdtemp (fname
);
77 puts ("mkdtemp failed");
81 if (stat64 (d
, &st
) == -1)
83 puts ("third stat failed");
88 fd
= open64 (d
, O_RDONLY
|O_NDELAY
|O_DIRECTORY
|O_NOATIME
);
91 puts ("second open failed");
94 DIR *dir
= fdopendir (fd
);
97 puts ("fdopendir failed");
102 while ((de
= readdir (dir
)) != NULL
)
107 if (stat64 (d
, &st2
) == -1)
109 puts ("fourth stat failed");
112 #ifdef _STATBUF_ST_NSEC
114 && (st
.st_atim
.tv_sec
!= st2
.st_atim
.tv_sec
115 || st
.st_atim
.tv_nsec
!= st2
.st_atim
.tv_nsec
))
117 if (!no_noatime
&& st
.st_atime
!= st2
.st_atime
)
120 puts ("directory atime changed");
129 #define TEST_FUNCTION do_test ()
130 #include "../test-skeleton.c"