#include #include #include #include int main (void) { char const *filename = "test.txt"; int fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666); if (fd < 0) return perror ("open"), 1; static char const message[] = "This is a test.\n"; int messagelen = sizeof message - 1; if (write (fd, message, messagelen) != messagelen) return perror ("write"), 1; if (fsync (fd) != 0) return perror ("fsync"), 1; struct stat st1, st2; if (fstat (fd, &st1) != 0) return perror ("fstat"), 1; if (close (fd) != 0) return perror ("close"), 1; sleep (2); if (stat (filename, &st2) != 0) return perror ("stat"), 1; if (! (st1.st_mtim.tv_sec == st2.st_mtim.tv_sec && st1.st_mtim.tv_nsec == st2.st_mtim.tv_nsec)) { printf ("last-modified times do not conform to:\n" "http://pubs.opengroup.org/onlinepubs/" "9699919799/basedefs/V1_chap04.html#tag_04_08\n"); return 1; } return 0; }