#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, st3; if (fstat (fd, &st1) != 0) return perror ("fstat"), 1; if (close (fd) != 0) return perror ("close"), 1; int fd2 = open(filename, O_WRONLY|O_CLOEXEC); if (fd2 < 0) return perror ("open 2"), 1; if (fstat (fd2, &st2) != 0) return perror ("fstat 2"), 1; if (close (fd2) != 0) return perror ("close 2"), 1; if (! (st1.st_mtim.tv_sec == st2.st_mtim.tv_sec && st1.st_mtim.tv_nsec == st2.st_mtim.tv_nsec)) printf ("Emacs should work around this POSIX-conformance bug.\n"); sleep (2); if (stat (filename, &st3) != 0) return perror ("stat"), 1; if (! (st2.st_mtim.tv_sec == st3.st_mtim.tv_sec && st2.st_mtim.tv_nsec == st3.st_mtim.tv_nsec)) { printf ("Emacs does not work around this POSIX-conformance bug.\n"); return 1; } return 0; }