Import upstream version 1.27
[debian/tar] / m4 / unlink.m4
index a49a692878d0a844de254bcd43fa1803bdfdbfda..b6b99d1743b4e69be869faf1bdb6a878be5c925a 100644 (file)
@@ -1,5 +1,5 @@
-# unlink.m4 serial 7
-dnl Copyright (C) 2009-2011 Free Software Foundation, Inc.
+# unlink.m4 serial 11
+dnl Copyright (C) 2009-2013 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.
@@ -8,6 +8,8 @@ AC_DEFUN([gl_FUNC_UNLINK],
 [
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
   AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_CHECK_HEADERS_ONCE([unistd.h])
+
   dnl Detect FreeBSD 7.2, AIX 7.1, Solaris 9 bug.
   AC_CACHE_CHECK([whether unlink honors trailing slashes],
     [gl_cv_func_unlink_honors_slashes],
@@ -18,7 +20,11 @@ AC_DEFUN([gl_FUNC_UNLINK],
      fi
      AC_RUN_IFELSE(
        [AC_LANG_PROGRAM(
-         [[#include <unistd.h>
+         [[#if HAVE_UNISTD_H
+           # include <unistd.h>
+           #else /* on Windows with MSVC */
+           # include <io.h>
+           #endif
            #include <errno.h>
          ]],
          [[int result = 0;
@@ -36,16 +42,28 @@ AC_DEFUN([gl_FUNC_UNLINK],
          ]])],
       [gl_cv_func_unlink_honors_slashes=yes],
       [gl_cv_func_unlink_honors_slashes=no],
-      [gl_cv_func_unlink_honors_slashes="guessing no"])
+      [case "$host_os" in
+                 # Guess yes on glibc systems.
+         *-gnu*) gl_cv_func_unlink_honors_slashes="guessing yes" ;;
+                 # If we don't know, assume the worst.
+         *)      gl_cv_func_unlink_honors_slashes="guessing no" ;;
+       esac
+      ])
      rm -f conftest.file conftest.lnk])
-  dnl Detect MacOS X 10.5.6 bug: On read-write HFS mounts, unlink("..") or
+  case "$gl_cv_func_unlink_honors_slashes" in
+    *no)
+      REPLACE_UNLINK=1
+      ;;
+  esac
+
+  dnl Detect Mac OS X 10.5.6 bug: On read-write HFS mounts, unlink("..") or
   dnl unlink("../..") succeeds without doing anything.
   AC_CACHE_CHECK([whether unlink of a parent directory fails as it should],
     [gl_cv_func_unlink_parent_fails],
     [case "$host_os" in
        darwin*)
          dnl Try to unlink a subdirectory of /tmp, because /tmp is usually on a
-         dnl HFS mount on MacOS X. Use a subdirectory, owned by the current
+         dnl HFS mount on Mac OS X. Use a subdirectory, owned by the current
          dnl user, because otherwise unlink() may fail due to permissions
          dnl reasons, and because when running as root we don't want to risk
          dnl destroying the entire /tmp.
@@ -70,7 +88,12 @@ AC_DEFUN([gl_FUNC_UNLINK],
            AC_RUN_IFELSE(
              [AC_LANG_SOURCE([[
                 #include <stdlib.h>
-                #include <unistd.h>
+                #if HAVE_UNISTD_H
+                # include <unistd.h>
+                #else /* on Windows with MSVC */
+                # include <direct.h>
+                # include <io.h>
+                #endif
                 int main ()
                 {
                   int result = 0;
@@ -83,7 +106,9 @@ AC_DEFUN([gl_FUNC_UNLINK],
               ]])],
              [gl_cv_func_unlink_parent_fails=yes],
              [gl_cv_func_unlink_parent_fails=no],
-             [gl_cv_func_unlink_parent_fails="guessing no"])
+             [# If we don't know, assume the worst.
+              gl_cv_func_unlink_parent_fails="guessing no"
+             ])
            unset GL_SUBDIR_FOR_UNLINK
            rm -rf "$tmp"
          else
@@ -97,17 +122,9 @@ AC_DEFUN([gl_FUNC_UNLINK],
     ])
   case "$gl_cv_func_unlink_parent_fails" in
     *no)
+      REPLACE_UNLINK=1
       AC_DEFINE([UNLINK_PARENT_BUG], [1],
         [Define to 1 if unlink() on a parent directory may succeed])
       ;;
   esac
-  if test "$gl_cv_func_unlink_honors_slashes" != yes \
-     || { case "$gl_cv_func_unlink_parent_fails" in
-            *yes) false;;
-            *no) true;;
-          esac
-        }; then
-    REPLACE_UNLINK=1
-    AC_LIBOBJ([unlink])
-  fi
 ])