2 dnl Copyright (C) 2009-2013 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_UNLINK],
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10 AC_REQUIRE([AC_CANONICAL_HOST])
11 AC_CHECK_HEADERS_ONCE([unistd.h])
13 dnl Detect FreeBSD 7.2, AIX 7.1, Solaris 9 bug.
14 AC_CACHE_CHECK([whether unlink honors trailing slashes],
15 [gl_cv_func_unlink_honors_slashes],
17 # Assume that if we have lstat, we can also check symlinks.
18 if test $ac_cv_func_lstat = yes; then
19 ln -s conftest.file conftest.lnk
25 #else /* on Windows with MSVC */
31 if (!unlink ("conftest.file/"))
33 else if (errno != ENOTDIR)
36 if (!unlink ("conftest.lnk/"))
38 else if (errno != ENOTDIR)
43 [gl_cv_func_unlink_honors_slashes=yes],
44 [gl_cv_func_unlink_honors_slashes=no],
46 # Guess yes on glibc systems.
47 *-gnu*) gl_cv_func_unlink_honors_slashes="guessing yes" ;;
48 # If we don't know, assume the worst.
49 *) gl_cv_func_unlink_honors_slashes="guessing no" ;;
52 rm -f conftest.file conftest.lnk])
53 case "$gl_cv_func_unlink_honors_slashes" in
59 dnl Detect Mac OS X 10.5.6 bug: On read-write HFS mounts, unlink("..") or
60 dnl unlink("../..") succeeds without doing anything.
61 AC_CACHE_CHECK([whether unlink of a parent directory fails as it should],
62 [gl_cv_func_unlink_parent_fails],
65 dnl Try to unlink a subdirectory of /tmp, because /tmp is usually on a
66 dnl HFS mount on Mac OS X. Use a subdirectory, owned by the current
67 dnl user, because otherwise unlink() may fail due to permissions
68 dnl reasons, and because when running as root we don't want to risk
69 dnl destroying the entire /tmp.
71 # Use the mktemp program if available. If not available, hide the error
73 tmp=`(umask 077 && mktemp -d /tmp/gtXXXXXX) 2>/dev/null` &&
74 test -n "$tmp" && test -d "$tmp"
77 # Use a simple mkdir command. It is guaranteed to fail if the directory
78 # already exists. $RANDOM is bash specific and expands to empty in shells
79 # other than bash, ksh and zsh. Its use does not increase security;
80 # rather, it minimizes the probability of failure in a very cluttered /tmp
83 (umask 077 && mkdir "$tmp")
86 GL_SUBDIR_FOR_UNLINK="$tmp/subdir"
87 export GL_SUBDIR_FOR_UNLINK
93 #else /* on Windows with MSVC */
100 if (chdir (getenv ("GL_SUBDIR_FOR_UNLINK")) != 0)
102 else if (unlink ("..") == 0)
107 [gl_cv_func_unlink_parent_fails=yes],
108 [gl_cv_func_unlink_parent_fails=no],
109 [# If we don't know, assume the worst.
110 gl_cv_func_unlink_parent_fails="guessing no"
112 unset GL_SUBDIR_FOR_UNLINK
115 gl_cv_func_unlink_parent_fails="guessing no"
119 gl_cv_func_unlink_parent_fails="guessing yes"
123 case "$gl_cv_func_unlink_parent_fails" in
126 AC_DEFINE([UNLINK_PARENT_BUG], [1],
127 [Define to 1 if unlink() on a parent directory may succeed])