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
56 # gl_FUNC_FCHOWNAT_DEREF_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
57 AC_DEFUN([gl_FUNC_FCHOWNAT_DEREF_BUG],
59 dnl Persuade glibc's <unistd.h> to declare fchownat().
60 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
62 AC_CACHE_CHECK([whether fchownat works with AT_SYMLINK_NOFOLLOW],
63 gl_cv_func_fchownat_nofollow_works,
65 gl_dangle=conftest.dangle
66 # Remove any remnants of a previous test.
68 # Arrange for deletion of the temporary file this test creates.
69 ac_clean_files="$ac_clean_files $gl_dangle"
70 ln -s conftest.no-such $gl_dangle
78 #include <sys/types.h>
82 return (fchownat (AT_FDCWD, "$gl_dangle", -1, getgid (),
83 AT_SYMLINK_NOFOLLOW) != 0
87 [gl_cv_func_fchownat_nofollow_works=yes],
88 [gl_cv_func_fchownat_nofollow_works=no],
89 [gl_cv_func_fchownat_nofollow_works=no],
92 AS_IF([test $gl_cv_func_fchownat_nofollow_works = no], [$1], [$2])
95 # gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
96 AC_DEFUN([gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG],
98 dnl Persuade glibc's <unistd.h> to declare fchownat().
99 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
101 AC_CACHE_CHECK([whether fchownat works with an empty file name],
102 [gl_cv_func_fchownat_empty_filename_works],
105 [[#include <unistd.h>
110 if (mkdir ("conftestdir", 0700) < 0)
112 fd = open ("conftestdir", O_RDONLY);
115 ret = fchownat (fd, "", -1, -1, 0);
117 rmdir ("conftestdir");
120 [gl_cv_func_fchownat_empty_filename_works=yes],
121 [gl_cv_func_fchownat_empty_filename_works=no],
122 [gl_cv_func_fchownat_empty_filename_works="guessing no"])
124 AS_IF([test "$gl_cv_func_fchownat_empty_filename_works" != yes], [$1], [$2])
127 # If we have the fchownat function, and it has the bug (in glibc-2.4)
128 # that it dereferences symlinks even with AT_SYMLINK_NOFOLLOW, then
129 # use the replacement function.
130 # Also if the fchownat function, like chown, has the trailing slash bug,
131 # use the replacement function.
132 # Also use the replacement function if fchownat is simply not available.
133 AC_DEFUN([gl_FUNC_FCHOWNAT],
135 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
136 AC_REQUIRE([gl_FUNC_CHOWN])
137 AC_CHECK_FUNC([fchownat],
138 [gl_FUNC_FCHOWNAT_DEREF_BUG(
140 AC_DEFINE([FCHOWNAT_NOFOLLOW_BUG], [1],
141 [Define to 1 if your platform has fchownat, but it cannot
142 perform lchown tasks.])
144 gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG(
146 AC_DEFINE([FCHOWNAT_EMPTY_FILENAME_BUG], [1],
147 [Define to 1 if your platform has fchownat, but it does
148 not reject an empty file name.])
150 if test $REPLACE_CHOWN = 1; then
156 # If we have the fstatat function, and it has the bug (in AIX 7.1)
157 # that it does not fill in st_size correctly, use the replacement function.
158 AC_DEFUN([gl_FUNC_FSTATAT],
160 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
161 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
162 AC_REQUIRE([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
163 AC_CHECK_FUNCS_ONCE([fstatat])
165 if test $ac_cv_func_fstatat = no; then
168 dnl Test for an AIX 7.1 bug; see
169 dnl <http://lists.gnu.org/archive/html/bug-tar/2011-09/msg00015.html>.
170 AC_CACHE_CHECK([whether fstatat (AT_FDCWD, ..., 0) works],
171 [gl_cv_func_fstatat_AT_FDCWD_0],
172 [gl_cv_func_fstatat_AT_FDCWD_0=no
173 echo xxx >conftest.file
178 #include <sys/stat.h>
183 return fstatat (AT_FDCWD, "conftest.file", &a, 0) != 0;
186 [gl_cv_func_fstatat_AT_FDCWD_0=yes])])
188 case $gl_cv_func_fstatat_AT_FDCWD_0+$gl_cv_func_lstat_dereferences_slashed_symlink in
191 if test $gl_cv_func_fstatat_AT_FDCWD_0 != yes; then
192 AC_DEFINE([FSTATAT_AT_FDCWD_0_BROKEN], [1],
193 [Define to 1 if fstatat (AT_FDCWD, ..., 0) does not work,
201 AC_DEFUN([gl_PREREQ_OPENAT],
203 AC_REQUIRE([AC_C_INLINE])
204 AC_REQUIRE([gl_PROMOTED_TYPE_MODE_T])