X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=m4%2Funlink.m4;h=094d69a0ba0604198d577e94a3cc9f01d4073f33;hb=HEAD;hp=c01d8482854ddc4deded932edfd4865da2fa6429;hpb=3322ff6164a1e9dd3d1622c64a9b9b7c5f303ef6;p=debian%2Ftar diff --git a/m4/unlink.m4 b/m4/unlink.m4 index c01d8482..094d69a0 100644 --- a/m4/unlink.m4 +++ b/m4/unlink.m4 @@ -1,16 +1,18 @@ -# unlink.m4 serial 3 -dnl Copyright (C) 2009, 2010 Free Software Foundation, Inc. +# unlink.m4 serial 11 +dnl Copyright (C) 2009-2015 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. AC_DEFUN([gl_FUNC_UNLINK], [ - AC_REQUIRE([gl_AC_DOS]) AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) - dnl Detect Solaris 9 and FreeBSD 7.2 bug. + 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_works], + [gl_cv_func_unlink_honors_slashes], [touch conftest.file # Assume that if we have lstat, we can also check symlinks. if test $ac_cv_func_lstat = yes; then @@ -18,18 +20,111 @@ AC_DEFUN([gl_FUNC_UNLINK], fi AC_RUN_IFELSE( [AC_LANG_PROGRAM( - [[#include + [[#if HAVE_UNISTD_H + # include + #else /* on Windows with MSVC */ + # include + #endif #include -]], [[if (!unlink ("conftest.file/") || errno != ENOTDIR) return 1; + ]], + [[int result = 0; + if (!unlink ("conftest.file/")) + result |= 1; + else if (errno != ENOTDIR) + result |= 2; #if HAVE_LSTAT - if (!unlink ("conftest.lnk/") || errno != ENOTDIR) return 2; + if (!unlink ("conftest.lnk/")) + result |= 4; + else if (errno != ENOTDIR) + result |= 8; #endif - ]])], - [gl_cv_func_unlink_works=yes], [gl_cv_func_unlink_works=no], - [gl_cv_func_unlink_works="guessing no"]) + return result; + ]])], + [gl_cv_func_unlink_honors_slashes=yes], + [gl_cv_func_unlink_honors_slashes=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]) - if test x"$gl_cv_func_unlink_works" != xyes; then - REPLACE_UNLINK=1 - AC_LIBOBJ([unlink]) - fi + 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 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. + if { + # Use the mktemp program if available. If not available, hide the error + # message. + tmp=`(umask 077 && mktemp -d /tmp/gtXXXXXX) 2>/dev/null` && + test -n "$tmp" && test -d "$tmp" + } || + { + # Use a simple mkdir command. It is guaranteed to fail if the directory + # already exists. $RANDOM is bash specific and expands to empty in shells + # other than bash, ksh and zsh. Its use does not increase security; + # rather, it minimizes the probability of failure in a very cluttered /tmp + # directory. + tmp=/tmp/gt$$-$RANDOM + (umask 077 && mkdir "$tmp") + }; then + mkdir "$tmp/subdir" + GL_SUBDIR_FOR_UNLINK="$tmp/subdir" + export GL_SUBDIR_FOR_UNLINK + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ + #include + #if HAVE_UNISTD_H + # include + #else /* on Windows with MSVC */ + # include + # include + #endif + int main () + { + int result = 0; + if (chdir (getenv ("GL_SUBDIR_FOR_UNLINK")) != 0) + result |= 1; + else if (unlink ("..") == 0) + result |= 2; + return result; + } + ]])], + [gl_cv_func_unlink_parent_fails=yes], + [gl_cv_func_unlink_parent_fails=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 + gl_cv_func_unlink_parent_fails="guessing no" + fi + ;; + *) + gl_cv_func_unlink_parent_fails="guessing yes" + ;; + esac + ]) + 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 ])