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([fchmodat lchmod mkdirat openat unlinkat])
27 AC_REQUIRE([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
28 AC_REQUIRE([gl_FUNC_UNLINK])
29 case $ac_cv_func_openat+$gl_cv_func_lstat_dereferences_slashed_symlink in
31 # GNU/Hurd has unlinkat, but it has the same bug as unlink.
32 if test $REPLACE_UNLINK = 1; then
36 # Solaris 9 has *at functions, but uniformly mishandles trailing
37 # slash in all of them.
43 HAVE_UNLINKAT=0 # No known system with unlinkat but not openat
46 if test $ac_cv_func_fchmodat != yes; then
49 if test $ac_cv_func_mkdirat != yes; then
55 dnl This is tested at least via getcwd.c.
56 gl_MODULE_INDICATOR([openat])
59 # gl_FUNC_FCHOWNAT_DEREF_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
60 AC_DEFUN([gl_FUNC_FCHOWNAT_DEREF_BUG],
62 dnl Persuade glibc's <unistd.h> to declare fchownat().
63 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
65 AC_CACHE_CHECK([whether fchownat works with AT_SYMLINK_NOFOLLOW],
66 gl_cv_func_fchownat_nofollow_works,
68 gl_dangle=conftest.dangle
69 # Remove any remnants of a previous test.
71 # Arrange for deletion of the temporary file this test creates.
72 ac_clean_files="$ac_clean_files $gl_dangle"
73 ln -s conftest.no-such $gl_dangle
81 #include <sys/types.h>
85 return (fchownat (AT_FDCWD, "$gl_dangle", -1, getgid (),
86 AT_SYMLINK_NOFOLLOW) != 0
90 [gl_cv_func_fchownat_nofollow_works=yes],
91 [gl_cv_func_fchownat_nofollow_works=no],
92 [gl_cv_func_fchownat_nofollow_works=no],
95 AS_IF([test $gl_cv_func_fchownat_nofollow_works = no], [$1], [$2])
98 # gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
99 AC_DEFUN([gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG],
101 dnl Persuade glibc's <unistd.h> to declare fchownat().
102 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
104 AC_CACHE_CHECK([whether fchownat works with an empty file name],
105 [gl_cv_func_fchownat_empty_filename_works],
108 [[#include <unistd.h>
113 if (mkdir ("conftestdir", 0700) < 0)
115 fd = open ("conftestdir", O_RDONLY);
118 ret = fchownat (fd, "", -1, -1, 0);
120 rmdir ("conftestdir");
123 [gl_cv_func_fchownat_empty_filename_works=yes],
124 [gl_cv_func_fchownat_empty_filename_works=no],
125 [gl_cv_func_fchownat_empty_filename_works="guessing no"])
127 AS_IF([test "$gl_cv_func_fchownat_empty_filename_works" != yes], [$1], [$2])
130 # If we have the fchownat function, and it has the bug (in glibc-2.4)
131 # that it dereferences symlinks even with AT_SYMLINK_NOFOLLOW, then
132 # use the replacement function.
133 # Also if the fchownat function, like chown, has the trailing slash bug,
134 # use the replacement function.
135 # Also use the replacement function if fchownat is simply not available.
136 AC_DEFUN([gl_FUNC_FCHOWNAT],
138 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
139 AC_REQUIRE([gl_FUNC_CHOWN])
140 AC_CHECK_FUNC([fchownat],
141 [gl_FUNC_FCHOWNAT_DEREF_BUG(
143 AC_DEFINE([FCHOWNAT_NOFOLLOW_BUG], [1],
144 [Define to 1 if your platform has fchownat, but it cannot
145 perform lchown tasks.])
147 gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG(
149 AC_DEFINE([FCHOWNAT_EMPTY_FILENAME_BUG], [1],
150 [Define to 1 if your platform has fchownat, but it does
151 not reject an empty file name.])
153 if test $REPLACE_CHOWN = 1; then
159 # If we have the fstatat function, and it has the bug (in AIX 7.1)
160 # that it does not fill in st_size correctly, use the replacement function.
161 AC_DEFUN([gl_FUNC_FSTATAT],
163 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
164 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
165 AC_REQUIRE([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
166 AC_CHECK_FUNCS_ONCE([fstatat])
168 if test $ac_cv_func_fstatat = no; then
171 dnl Test for an AIX 7.1 bug; see
172 dnl <http://lists.gnu.org/archive/html/bug-tar/2011-09/msg00015.html>.
173 AC_CACHE_CHECK([whether fstatat (..., 0) works],
174 [gl_cv_func_fstatat_zero_flag],
175 [gl_cv_func_fstatat_zero_flag=no
180 #include <sys/stat.h>
185 return fstatat (AT_FDCWD, ".", &a, 0) != 0;
188 [gl_cv_func_fstatat_zero_flag=yes])])
190 case $gl_cv_func_fstatat_zero_flag+$gl_cv_func_lstat_dereferences_slashed_symlink in
193 if test $gl_cv_func_fstatat_zero_flag != yes; then
194 AC_DEFINE([FSTATAT_ZERO_FLAG_BROKEN], [1],
195 [Define to 1 if fstatat (..., 0) does not work,
203 AC_DEFUN([gl_PREREQ_OPENAT],
205 AC_REQUIRE([AC_C_INLINE])
206 AC_REQUIRE([gl_PROMOTED_TYPE_MODE_T])