2 dnl Copyright (C) 2009, 2010 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_AC_DOS])
10 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
11 AC_REQUIRE([AC_CANONICAL_HOST])
12 dnl Detect Solaris 9 and FreeBSD 7.2 bug.
13 AC_CACHE_CHECK([whether unlink honors trailing slashes],
14 [gl_cv_func_unlink_honors_slashes],
16 # Assume that if we have lstat, we can also check symlinks.
17 if test $ac_cv_func_lstat = yes; then
18 ln -s conftest.file conftest.lnk
24 ]], [[if (!unlink ("conftest.file/") || errno != ENOTDIR) return 1;
26 if (!unlink ("conftest.lnk/") || errno != ENOTDIR) return 2;
29 [gl_cv_func_unlink_honors_slashes=yes],
30 [gl_cv_func_unlink_honors_slashes=no],
31 [gl_cv_func_unlink_honors_slashes="guessing no"])
32 rm -f conftest.file conftest.lnk])
33 dnl Detect MacOS X 10.5.6 bug: On read-write HFS mounts, unlink("..") or
34 dnl unlink("../..") succeeds without doing anything.
35 AC_CACHE_CHECK([whether unlink of a parent directory fails is it should],
36 [gl_cv_func_unlink_parent_fails],
40 # Use the mktemp program if available. If not available, hide the error
42 tmp=`(umask 077 && mktemp -d /tmp/gtXXXXXX) 2>/dev/null` &&
43 test -n "$tmp" && test -d "$tmp"
46 # Use a simple mkdir command. It is guaranteed to fail if the directory
47 # already exists. $RANDOM is bash specific and expands to empty in shells
48 # other than bash, ksh and zsh. Its use does not increase security;
49 # rather, it minimizes the probability of failure in a very cluttered /tmp
52 (umask 077 && mkdir "$tmp")
62 if (chdir (getenv ("tmp")) != 0)
64 return unlink ("..") == 0;
67 [gl_cv_func_unlink_parent_fails=yes],
68 [gl_cv_func_unlink_parent_fails=no],
69 [gl_cv_func_unlink_parent_fails="guessing no"])
73 gl_cv_func_unlink_parent_fails="guessing no"
77 gl_cv_func_unlink_parent_fails="guessing yes"
81 case "$gl_cv_func_unlink_parent_fails" in
83 AC_DEFINE([UNLINK_PARENT_BUG], [1],
84 [Define to 1 if unlink() on a parent directory may succeed])
87 if test "$gl_cv_func_unlink_honors_slashes" != yes \
88 || { case "$gl_cv_func_unlink_parent_fails" in