delete trailing whitespace from control files
[debian/gzip] / m4 / utimes.m4
index 417103a7b72d5c14dfd5d55a9c3e9b6060ef697a..f62d5f8b6558c3c333fe1fed43f6e062e9ced397 100644 (file)
@@ -1,7 +1,7 @@
 # Detect some bugs in glibc's implementation of utimes.
-# serial 3
+# serial 5
 
-dnl Copyright (C) 2003-2005, 2009-2012 Free Software Foundation, Inc.
+dnl Copyright (C) 2003-2005, 2009-2018 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -20,10 +20,10 @@ dnl with or without modifications, as long as this notice is preserved.
 
 AC_DEFUN([gl_FUNC_UTIMES],
 [
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
   AC_CACHE_CHECK([whether the utimes function works],
                  [gl_cv_func_working_utimes],
-  [
-  AC_RUN_IFELSE([AC_LANG_SOURCE([[
+    [AC_RUN_IFELSE([AC_LANG_SOURCE([[
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -33,6 +33,7 @@ AC_DEFUN([gl_FUNC_UTIMES],
 #include <stdlib.h>
 #include <stdio.h>
 #include <utime.h>
+#include <errno.h>
 
 static int
 inorder (time_t a, time_t b, time_t c)
@@ -45,7 +46,10 @@ main ()
 {
   int result = 0;
   char const *file = "conftest.utimes";
-  static struct timeval timeval[2] = {{9, 10}, {999999, 999999}};
+  /* On OS/2, file timestamps must be on or after 1980 in local time,
+     with an even number of seconds.  */
+  static struct timeval timeval[2] = {{315620000 + 10, 10},
+                                      {315620000 + 1000000, 999998}};
 
   /* Test whether utimes() essentially works.  */
   {
@@ -82,9 +86,19 @@ main ()
           result |= 1;
         else if (fstat (fd, &st0) != 0)
           result |= 1;
-        else if (utimes (file, timeval) != 0)
+        else if (utimes (file, timeval) != 0
+                 && (errno != EACCES
+                     /* OS/2 kLIBC utimes fails on opened files.  */
+                     || close (fd) != 0
+                     || utimes (file, timeval) != 0
+                     || (fd = open (file, O_WRONLY)) < 0))
           result |= 2;
-        else if (utimes (file, NULL) != 0)
+        else if (utimes (file, NULL) != 0
+                 && (errno != EACCES
+                     /* OS/2 kLIBC utimes fails on opened files.  */
+                     || close (fd) != 0
+                     || utimes (file, NULL) != 0
+                     || (fd = open (file, O_WRONLY)) < 0))
           result |= 8;
         else if (fstat (fd, &st1) != 0)
           result |= 1;
@@ -128,9 +142,17 @@ main ()
   ]])],
        [gl_cv_func_working_utimes=yes],
        [gl_cv_func_working_utimes=no],
-       [gl_cv_func_working_utimes=no])])
+       [case "$host_os" in
+                  # Guess no on native Windows.
+          mingw*) gl_cv_func_working_utimes="guessing no" ;;
+          *)      gl_cv_func_working_utimes="guessing no" ;;
+        esac
+       ])
+    ])
 
-  if test $gl_cv_func_working_utimes = yes; then
-    AC_DEFINE([HAVE_WORKING_UTIMES], [1], [Define if utimes works properly. ])
-  fi
+  case "$gl_cv_func_working_utimes" in
+    *yes)
+      AC_DEFINE([HAVE_WORKING_UTIMES], [1], [Define if utimes works properly.])
+      ;;
+  esac
 ])