#include #include #include #include #include #define FAIL(x) do { printf(x "\n"); unlink(path); return -1; } while(0) int main(int argc, char *argv[]) { struct stat s1, s2; int h, got; int sanity; const char *path = "/home/larry/testofile"; if (argc > 1) path = argv[1]; h = open(path, O_WRONLY | O_CREAT); if (h < 0) FAIL("fail open"); write(h, "abc", 3); close(h); got = stat(path, &s1); if (got) FAIL("fail stat 1"); utimensat(AT_FDCWD, path, NULL, 0); /* utimes(path, NULL); */ if (got) FAIL("fail utimensat"); stat(path, &s2); if (got) FAIL("fail stat 2"); unlink(path); printf("Before: %ld %ld\n", s1.st_mtime, s1.st_mtim.tv_nsec); printf(" After: %ld %ld\n", s2.st_mtime, s2.st_mtim.tv_nsec); sanity = ( (s1.st_mtime <= s2.st_mtime) && (s1.st_mtim.tv_nsec <= s2.st_mtim.tv_nsec) ); printf("Before <= After %d\n", sanity); if (!sanity) printf("This is insane!\n"); else printf("Everything is okay.\n"); return 0; }