strndup: fix improper m4 caching
[pspp] / m4 / openat.m4
1 # serial 21
2 # See if we need to use our replacement for Solaris' openat et al functions.
3
4 dnl Copyright (C) 2004-2009 Free Software Foundation, Inc.
5 dnl This file is free software; the Free Software Foundation
6 dnl gives unlimited permission to copy and/or distribute it,
7 dnl with or without modifications, as long as this notice is preserved.
8
9 # Written by Jim Meyering.
10
11 AC_DEFUN([gl_FUNC_OPENAT],
12 [
13   AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
14   GNULIB_OPENAT=1
15
16   AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
17   GNULIB_FCHMODAT=1
18   GNULIB_FSTATAT=1
19   GNULIB_MKDIRAT=1
20
21   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
22   GNULIB_FCHOWNAT=1
23   GNULIB_UNLINKAT=1
24
25   AC_LIBOBJ([openat-proc])
26   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
27   AC_CHECK_FUNCS_ONCE([lchmod])
28   AC_REPLACE_FUNCS([fchmodat mkdirat openat])
29   AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
30   case $ac_cv_func_openat+$ac_cv_func_lstat_dereferences_slashed_symlink in
31   yes+yes) ;;
32   yes+*)
33     AC_LIBOBJ([fstatat])
34     REPLACE_FSTATAT=1
35     ;;
36   *)
37     HAVE_OPENAT=0
38     HAVE_UNLINKAT=0 # No known system with unlinkat but not openat
39     HAVE_FSTATAT=0 # No known system with fstatat but not openat
40     gl_PREREQ_OPENAT;;
41   esac
42   if test $ac_cv_func_fchmodat != yes; then
43     HAVE_FCHMODAT=0
44   fi
45   if test $ac_cv_func_mkdirat != yes; then
46     HAVE_MKDIRAT=0
47   fi
48   gl_FUNC_FCHOWNAT
49 ])
50
51 # gl_FUNC_FCHOWNAT_DEREF_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
52 AC_DEFUN([gl_FUNC_FCHOWNAT_DEREF_BUG],
53 [
54   AC_CACHE_CHECK([whether fchownat works with AT_SYMLINK_NOFOLLOW],
55     gl_cv_func_fchownat_nofollow_works,
56     [
57      gl_dangle=conftest.dangle
58      # Remove any remnants of a previous test.
59      rm -f $gl_dangle
60      # Arrange for deletion of the temporary file this test creates.
61      ac_clean_files="$ac_clean_files $gl_dangle"
62      ln -s conftest.no-such $gl_dangle
63      AC_RUN_IFELSE(
64        [AC_LANG_SOURCE(
65           [[
66 #include <fcntl.h>
67 #include <unistd.h>
68 #include <stdlib.h>
69 #include <errno.h>
70 #include <sys/types.h>
71 int
72 main ()
73 {
74   return (fchownat (AT_FDCWD, "$gl_dangle", -1, getgid (),
75                     AT_SYMLINK_NOFOLLOW) != 0
76           && errno == ENOENT);
77 }
78           ]])],
79     [gl_cv_func_fchownat_nofollow_works=yes],
80     [gl_cv_func_fchownat_nofollow_works=no],
81     [gl_cv_func_fchownat_nofollow_works=no],
82     )
83   ])
84   AS_IF([test $gl_cv_func_fchownat_nofollow_works = no], [$1], [$2])
85 ])
86
87 # If we have the fchownat function, and it has the bug (in glibc-2.4)
88 # that it dereferences symlinks even with AT_SYMLINK_NOFOLLOW, then
89 # use the replacement function.
90 # Also use the replacement function if fchownat is simply not available.
91 AC_DEFUN([gl_FUNC_FCHOWNAT],
92 [
93   AC_CHECK_FUNC([fchownat],
94     [gl_FUNC_FCHOWNAT_DEREF_BUG([REPLACE_FCHOWNAT=1])],
95     [HAVE_FCHOWNAT=0])
96   if test $HAVE_FCHOWNAT = 0 || test $REPLACE_FCHOWNAT = 1; then
97     AC_LIBOBJ([fchownat])
98   fi
99 ])
100
101 AC_DEFUN([gl_PREREQ_OPENAT],
102 [
103   AC_REQUIRE([gl_PROMOTED_TYPE_MODE_T])
104   :
105 ])