]> git.cworth.org Git - tar/blob - m4/unlink.m4
c01d8482854ddc4deded932edfd4865da2fa6429
[tar] / m4 / unlink.m4
1 # unlink.m4 serial 3
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.
6
7 AC_DEFUN([gl_FUNC_UNLINK],
8 [
9   AC_REQUIRE([gl_AC_DOS])
10   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
11   dnl Detect Solaris 9 and FreeBSD 7.2 bug.
12   AC_CACHE_CHECK([whether unlink honors trailing slashes],
13     [gl_cv_func_unlink_works],
14     [touch conftest.file
15      # Assume that if we have lstat, we can also check symlinks.
16      if test $ac_cv_func_lstat = yes; then
17        ln -s conftest.file conftest.lnk
18      fi
19      AC_RUN_IFELSE(
20        [AC_LANG_PROGRAM(
21          [[#include <unistd.h>
22            #include <errno.h>
23 ]], [[if (!unlink ("conftest.file/") || errno != ENOTDIR) return 1;
24 #if HAVE_LSTAT
25       if (!unlink ("conftest.lnk/") || errno != ENOTDIR) return 2;
26 #endif
27       ]])],
28       [gl_cv_func_unlink_works=yes], [gl_cv_func_unlink_works=no],
29       [gl_cv_func_unlink_works="guessing no"])
30      rm -f conftest.file conftest.lnk])
31   if test x"$gl_cv_func_unlink_works" != xyes; then
32     REPLACE_UNLINK=1
33     AC_LIBOBJ([unlink])
34   fi
35 ])