Import upstream version 1.26
[debian/tar] / m4 / utimensat.m4
index 1110e07c63fcb5bd46b59a9cc1a2991755ffbac3..78472a5fbd7edcbfd569161e9c0b7f8753748d21 100644 (file)
@@ -1,7 +1,7 @@
-# serial 3
+# serial 4
 # See if we need to provide utimensat replacement.
 
-dnl Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+dnl Copyright (C) 2009-2011 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.
@@ -19,22 +19,39 @@ AC_DEFUN([gl_FUNC_UTIMENSAT],
   else
     AC_CACHE_CHECK([whether utimensat works],
       [gl_cv_func_utimensat_works],
-      [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+      [AC_RUN_IFELSE(
+         [AC_LANG_PROGRAM([[
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <unistd.h>
-]], [[struct timespec ts[2] = { { 1, UTIME_OMIT }, { 1, UTIME_NOW } };
-      struct stat st;
-      const char *f = "conftest.file";
-      if (close (creat (f, 0600))) return 1;
-      if (utimensat (AT_FDCWD, f, NULL, AT_SYMLINK_NOFOLLOW)) return 2;
-      if (utimensat (AT_FDCWD, f, ts, 0)) return 3;
-      sleep (1);
-      ts[0].tv_nsec = UTIME_NOW;
-      ts[1].tv_nsec = UTIME_OMIT;
-      if (utimensat (AT_FDCWD, f, ts, 0)) return 4;
-      if (stat (f, &st)) return 5;
-      if (st.st_ctime < st.st_atime) return 6;]])],
+]],         [[int result = 0;
+              const char *f = "conftest.file";
+              if (close (creat (f, 0600)))
+                return 1;
+              /* Test whether the AT_SYMLINK_NOFOLLOW flag is supported.  */
+              {
+                if (utimensat (AT_FDCWD, f, NULL, AT_SYMLINK_NOFOLLOW))
+                  result |= 2;
+              }
+              /* Test whether UTIME_NOW and UTIME_OMIT work.  */
+              {
+                struct timespec ts[2] = { { 1, UTIME_OMIT }, { 1, UTIME_NOW } };
+                if (utimensat (AT_FDCWD, f, ts, 0))
+                  result |= 4;
+              }
+              sleep (1);
+              {
+                struct timespec ts[2] = { { 1, UTIME_NOW }, { 1, UTIME_OMIT } };
+                struct stat st;
+                if (utimensat (AT_FDCWD, f, ts, 0))
+                  result |= 8;
+                if (stat (f, &st))
+                  result |= 16;
+                else if (st.st_ctime < st.st_atime)
+                  result |= 32;
+              }
+              return result;
+            ]])],
 dnl FIXME: simplify this in 2012, when file system bugs are no longer common
          [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 #ifdef __linux__