2 # See if we need to use our replacement for Solaris' openat et al functions.
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.
9 # Written by Jim Meyering.
11 AC_DEFUN([gl_FUNC_OPENAT],
13 AC_LIBOBJ([openat-proc])
14 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15 AC_CHECK_FUNCS_ONCE([lchmod])
16 AC_REPLACE_FUNCS([fchmodat mkdirat openat])
17 AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
18 case $ac_cv_func_openat+$ac_cv_func_lstat_dereferences_slashed_symlink in
26 HAVE_UNLINKAT=0 # No known system with unlinkat but not openat
27 HAVE_FSTATAT=0 # No known system with fstatat but not openat
30 if test $ac_cv_func_fchmodat != yes; then
33 if test $ac_cv_func_mkdirat != yes; then
40 # gl_FUNC_FCHOWNAT_DEREF_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
41 AC_DEFUN([gl_FUNC_FCHOWNAT_DEREF_BUG],
43 AC_CACHE_CHECK([whether fchownat works with AT_SYMLINK_NOFOLLOW],
44 gl_cv_func_fchownat_nofollow_works,
46 gl_dangle=conftest.dangle
47 # Remove any remnants of a previous test.
49 # Arrange for deletion of the temporary file this test creates.
50 ac_clean_files="$ac_clean_files $gl_dangle"
51 ln -s conftest.no-such $gl_dangle
59 #include <sys/types.h>
63 return (fchownat (AT_FDCWD, "$gl_dangle", -1, getgid (),
64 AT_SYMLINK_NOFOLLOW) != 0
68 [gl_cv_func_fchownat_nofollow_works=yes],
69 [gl_cv_func_fchownat_nofollow_works=no],
70 [gl_cv_func_fchownat_nofollow_works=no],
73 AS_IF([test $gl_cv_func_fchownat_nofollow_works = no], [$1], [$2])
76 # If we have the fchownat function, and it has the bug (in glibc-2.4)
77 # that it dereferences symlinks even with AT_SYMLINK_NOFOLLOW, then
78 # use the replacement function.
79 # Also use the replacement function if fchownat is simply not available.
80 AC_DEFUN([gl_FUNC_FCHOWNAT],
82 AC_CHECK_FUNC([fchownat],
83 [gl_FUNC_FCHOWNAT_DEREF_BUG([REPLACE_FCHOWNAT=1])],
85 if test $HAVE_FCHOWNAT = 0 || test $REPLACE_FCHOWNAT = 1; then
90 AC_DEFUN([gl_PREREQ_OPENAT],
92 AC_REQUIRE([gl_PROMOTED_TYPE_MODE_T])
96 AC_DEFUN([gl_OPENAT_DEFAULTS],
98 GNULIB_OPENAT=0; AC_SUBST([GNULIB_OPENAT])
99 dnl Assume proper GNU behavior unless another module says otherwise.
100 HAVE_FCHMODAT=1; AC_SUBST([HAVE_FCHMODAT])
101 HAVE_FCHOWNAT=1; AC_SUBST([HAVE_FCHOWNAT])
102 HAVE_FSTATAT=1; AC_SUBST([HAVE_FSTATAT])
103 HAVE_MKDIRAT=1; AC_SUBST([HAVE_MKDIRAT])
104 HAVE_OPENAT=1; AC_SUBST([HAVE_OPENAT])
105 HAVE_UNLINKAT=1; AC_SUBST([HAVE_UNLINKAT])
106 REPLACE_FCHOWNAT=0; AC_SUBST([REPLACE_FCHOWNAT])
107 REPLACE_FSTATAT=0; AC_SUBST([REPLACE_FSTATAT])