2 # See if we need to use our replacement for Solaris' openat et al functions.
4 dnl Copyright (C) 2004-2011 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_REQUIRE([gl_FCNTL_H_DEFAULTS])
16 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
21 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
25 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
26 AC_CHECK_FUNCS_ONCE([lchmod])
27 AC_CHECK_FUNCS([fchmodat fstatat mkdirat openat unlinkat])
28 AC_REQUIRE([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
29 AC_REQUIRE([gl_FUNC_UNLINK])
30 case $ac_cv_func_openat+$gl_cv_func_lstat_dereferences_slashed_symlink in
32 # GNU/Hurd has unlinkat, but it has the same bug as unlink.
33 if test $REPLACE_UNLINK = 1; then
37 # Solaris 9 has *at functions, but uniformly mishandles trailing
38 # slash in all of them.
45 HAVE_UNLINKAT=0 # No known system with unlinkat but not openat
46 HAVE_FSTATAT=0 # No known system with fstatat but not openat
49 if test $ac_cv_func_fchmodat != yes; then
52 if test $ac_cv_func_mkdirat != yes; then
58 # gl_FUNC_FCHOWNAT_DEREF_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
59 AC_DEFUN([gl_FUNC_FCHOWNAT_DEREF_BUG],
61 dnl Persuade glibc's <unistd.h> to declare fchownat().
62 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
64 AC_CACHE_CHECK([whether fchownat works with AT_SYMLINK_NOFOLLOW],
65 gl_cv_func_fchownat_nofollow_works,
67 gl_dangle=conftest.dangle
68 # Remove any remnants of a previous test.
70 # Arrange for deletion of the temporary file this test creates.
71 ac_clean_files="$ac_clean_files $gl_dangle"
72 ln -s conftest.no-such $gl_dangle
80 #include <sys/types.h>
84 return (fchownat (AT_FDCWD, "$gl_dangle", -1, getgid (),
85 AT_SYMLINK_NOFOLLOW) != 0
89 [gl_cv_func_fchownat_nofollow_works=yes],
90 [gl_cv_func_fchownat_nofollow_works=no],
91 [gl_cv_func_fchownat_nofollow_works=no],
94 AS_IF([test $gl_cv_func_fchownat_nofollow_works = no], [$1], [$2])
97 # gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
98 AC_DEFUN([gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG],
100 dnl Persuade glibc's <unistd.h> to declare fchownat().
101 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
103 AC_CACHE_CHECK([whether fchownat works with an empty file name],
104 [gl_cv_func_fchownat_empty_filename_works],
107 [[#include <unistd.h>
112 if (mkdir ("conftestdir", 0700) < 0)
114 fd = open ("conftestdir", O_RDONLY);
117 ret = fchownat (fd, "", -1, -1, 0);
119 rmdir ("conftestdir");
122 [gl_cv_func_fchownat_empty_filename_works=yes],
123 [gl_cv_func_fchownat_empty_filename_works=no],
124 [gl_cv_func_fchownat_empty_filename_works="guessing no"])
126 AS_IF([test "$gl_cv_func_fchownat_empty_filename_works" != yes], [$1], [$2])
129 # If we have the fchownat function, and it has the bug (in glibc-2.4)
130 # that it dereferences symlinks even with AT_SYMLINK_NOFOLLOW, then
131 # use the replacement function.
132 # Also if the fchownat function, like chown, has the trailing slash bug,
133 # use the replacement function.
134 # Also use the replacement function if fchownat is simply not available.
135 AC_DEFUN([gl_FUNC_FCHOWNAT],
137 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
138 AC_REQUIRE([gl_FUNC_CHOWN])
139 AC_CHECK_FUNC([fchownat],
140 [gl_FUNC_FCHOWNAT_DEREF_BUG(
142 AC_DEFINE([FCHOWNAT_NOFOLLOW_BUG], [1],
143 [Define to 1 if your platform has fchownat, but it cannot
144 perform lchown tasks.])
146 gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG(
148 AC_DEFINE([FCHOWNAT_EMPTY_FILENAME_BUG], [1],
149 [Define to 1 if your platform has fchownat, but it does
150 not reject an empty file name.])
152 if test $REPLACE_CHOWN = 1; then
158 AC_DEFUN([gl_PREREQ_OPENAT],
160 AC_REQUIRE([AC_C_INLINE])
161 AC_REQUIRE([gl_PROMOTED_TYPE_MODE_T])