utimes merge from coreutils
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 17 Aug 2003 03:00:14 +0000 (03:00 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 17 Aug 2003 03:00:14 +0000 (03:00 +0000)
m4/utimes-null.m4 [new file with mode: 0644]
m4/utimes.m4
modules/utime

diff --git a/m4/utimes-null.m4 b/m4/utimes-null.m4
new file mode 100644 (file)
index 0000000..f7e7842
--- /dev/null
@@ -0,0 +1,32 @@
+#serial 4
+
+dnl Shamelessly cloned from acspecific.m4's AC_FUNC_UTIME_NULL,
+dnl then do case-insensitive s/utime/utimes/.
+
+AC_DEFUN([jm_FUNC_UTIMES_NULL],
+[AC_CACHE_CHECK(whether utimes accepts a null argument, ac_cv_func_utimes_null,
+[rm -f conftest.data; > conftest.data
+AC_TRY_RUN([
+/* In case stat has been defined to rpl_stat, undef it here.  */
+#undef stat
+#include <sys/types.h>
+#include <sys/stat.h>
+main() {
+struct stat s, t;
+exit(!(stat ("conftest.data", &s) == 0
+       && utimes("conftest.data", (long *)0) == 0
+       && stat("conftest.data", &t) == 0
+       && t.st_mtime >= s.st_mtime
+       && t.st_mtime - s.st_mtime < 120));
+}],
+  ac_cv_func_utimes_null=yes,
+  ac_cv_func_utimes_null=no,
+  ac_cv_func_utimes_null=no)
+rm -f core core.* *.core])
+
+    if test $ac_cv_func_utimes_null = yes; then
+      AC_DEFINE(HAVE_UTIMES_NULL, 1,
+               [Define if utimes accepts a null argument])
+    fi
+  ]
+)
index f7e7842c5a0cae8c1a6250b6b91033a69aa788b7..3b8d945ac25558fc0dd327cf9c4bf1128f5dff93 100644 (file)
@@ -1,32 +1,46 @@
-#serial 4
+# See if we need to work around bugs in glibc's implementation of
+# utimes from around July/August 2003.
+# First, there was a bug that would make utimes set mtime
+# and atime to zero (1970-01-01) unconditionally.
+# Then, there is/was code to round rather than truncate.
+#
+# From Jim Meyering, with suggestions from Paul Eggert.
 
-dnl Shamelessly cloned from acspecific.m4's AC_FUNC_UTIME_NULL,
-dnl then do case-insensitive s/utime/utimes/.
-
-AC_DEFUN([jm_FUNC_UTIMES_NULL],
-[AC_CACHE_CHECK(whether utimes accepts a null argument, ac_cv_func_utimes_null,
-[rm -f conftest.data; > conftest.data
-AC_TRY_RUN([
-/* In case stat has been defined to rpl_stat, undef it here.  */
-#undef stat
+AC_DEFUN([gl_FUNC_UTIMES],
+[
+  AC_CACHE_CHECK([determine whether the utimes function works],
+                gl_cv_func_working_utimes,
+  [
+  AC_RUN_IFELSE([AC_LANG_SOURCE([[
 #include <sys/types.h>
 #include <sys/stat.h>
-main() {
-struct stat s, t;
-exit(!(stat ("conftest.data", &s) == 0
-       && utimes("conftest.data", (long *)0) == 0
-       && stat("conftest.data", &t) == 0
-       && t.st_mtime >= s.st_mtime
-       && t.st_mtime - s.st_mtime < 120));
-}],
-  ac_cv_func_utimes_null=yes,
-  ac_cv_func_utimes_null=no,
-  ac_cv_func_utimes_null=no)
-rm -f core core.* *.core])
+#include <sys/time.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <utime.h>
+
+int
+main ()
+{
+  static struct timeval timeval[2] = {{9, 10}, {999999, 999999}};
+  struct stat sbuf;
+  char const *file = "conftest.utimes";
+  FILE *f;
+
+  exit ( ! ((f = fopen (file, "w"))
+           && fclose (f) == 0
+           && utimes (file, timeval) == 0
+           && lstat (file, &sbuf) == 0
+           && sbuf.st_atime == timeval[0].tv_sec
+           && sbuf.st_mtime == timeval[1].tv_sec) );
+}
+  ]])],
+       [gl_cv_func_working_utimes=yes],
+       [gl_cv_func_working_utimes=no],
+       [gl_cv_func_working_utimes=no])])
 
-    if test $ac_cv_func_utimes_null = yes; then
-      AC_DEFINE(HAVE_UTIMES_NULL, 1,
-               [Define if utimes accepts a null argument])
-    fi
-  ]
-)
+  if test $gl_cv_func_working_utimes = yes; then
+    AC_DEFINE([HAVE_WORKING_UTIMES], 1, [Define if utimes works properly. ])
+  fi
+])
index c2db72edf696aa89f83e165b39c6aa1db317a194..a0d1ae3a471baa8e454fa8576c6832171ffcb7c9 100644 (file)
@@ -4,8 +4,9 @@ utime() function: change access and/or modification times of a file.
 Files:
 lib/utime.c
 m4/utimbuf.m4
-m4/utimes.m4
 m4/utime.m4
+m4/utimes.m4
+m4/utimes-null.m4
 
 Depends-on:
 safe-read