- ok =
- ((f = fopen (file, "w"))
- && fclose (f) == 0
- && time (&now) != (time_t)-1
- && utimes (file, NULL) == 0
- && lstat (file, &sbuf) == 0
- && now - sbuf.st_atime <= 2
- && now - sbuf.st_mtime <= 2);
- unlink (file);
- if (!ok)
- exit (1);
+ /* Test whether utimes() with a NULL argument sets the file's timestamp
+ to the current time. Note that this test fails on NFS file systems
+ if there is a time skew between the host and the NFS server. */
+ {
+ struct stat sbuf;
+ FILE *f = fopen (file, "w");
+ if (f == NULL)
+ result |= 1;
+ else if (fclose (f) != 0)
+ result |= 1;
+ else
+ {
+ time_t now;
+ if (time (&now) == (time_t)-1)
+ result |= 1;
+ else if (utimes (file, NULL) != 0)
+ result |= 8;
+ else if (lstat (file, &sbuf) != 0)
+ result |= 1;
+ else
+ {
+ if (!(now - sbuf.st_atime <= 2))
+ result |= 16;
+ if (!(now - sbuf.st_mtime <= 2))
+ result |= 32;
+ }
+ }
+ unlink (file);
+ }