summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2005-09-26 09:10:50 +0000
committerJim Meyering <jim@meyering.net>2005-09-26 09:10:50 +0000
commit99fa7a0e8e14a0e0711ec1d549668c65ed047b4c (patch)
treeab7c775e0879317bd6deeaafd5e77e456d630a6b /m4
parent8149b5a566449d225a3be3d2141b588243289136 (diff)
downloadcoreutils-99fa7a0e8e14a0e0711ec1d549668c65ed047b4c.tar.xz
(gl_FUNC_UTIMES): Detect the version of utimes
from glibc-2.2.5 that fails for read-only files.
Diffstat (limited to 'm4')
-rw-r--r--m4/utimes.m411
1 files changed, 11 insertions, 0 deletions
diff --git a/m4/utimes.m4 b/m4/utimes.m4
index ba74b3f6e..7efb2b026 100644
--- a/m4/utimes.m4
+++ b/m4/utimes.m4
@@ -12,6 +12,8 @@ dnl with or without modifications, as long as this notice is preserved.
# Then, there was code to round rather than truncate.
# Then, there was an implementation (sparc64, Linux-2.4.28, glibc-2.3.3)
# that didn't honor the NULL-means-set-to-current-time semantics.
+# Finally, there was also a version of utimes that failed on read-only
+# files, while utime worked fine (linux-2.2.20, glibc-2.2.5).
#
# From Jim Meyering, with suggestions from Paul Eggert.
@@ -23,6 +25,7 @@ AC_DEFUN([gl_FUNC_UTIMES],
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <sys/types.h>
#include <sys/stat.h>
+#include <fcntl.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
@@ -38,6 +41,7 @@ main ()
char const *file = "conftest.utimes";
FILE *f;
time_t now;
+ int fd;
int ok = ((f = fopen (file, "w"))
&& fclose (f) == 0
@@ -58,6 +62,13 @@ main ()
&& now - sbuf.st_atime <= 2
&& now - sbuf.st_mtime <= 2);
unlink (file);
+ if (!ok)
+ exit (1);
+
+ ok = (0 <= (fd = open (file, O_WRONLY|O_CREAT, 0444))
+ && close (fd) == 0
+ && utimes (file, NULL) == 0);
+ unlink (file);
exit (!ok);
}