2 # See if we need to use our replacement for Solaris' openat et al functions.
4 dnl Copyright (C) 2004-2010 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_LIBOBJ([openat-proc])
26 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
27 AC_CHECK_FUNCS_ONCE([lchmod])
28 AC_REPLACE_FUNCS([fchmodat fstatat mkdirat openat unlinkat])
29 AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
30 AC_REQUIRE([gl_FUNC_UNLINK])
31 case $ac_cv_func_openat+$ac_cv_func_lstat_dereferences_slashed_symlink in
33 # GNU/Hurd has unlinkat, but it has the same bug as unlink.
34 if test $REPLACE_UNLINK = 1; then
39 # Solaris 9 has *at functions, but uniformly mishandles trailing
40 # slash in all of them.
50 HAVE_UNLINKAT=0 # No known system with unlinkat but not openat
51 HAVE_FSTATAT=0 # No known system with fstatat but not openat
54 if test $ac_cv_func_fchmodat != yes; then
57 if test $ac_cv_func_mkdirat != yes; then
63 # gl_FUNC_FCHOWNAT_DEREF_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
64 AC_DEFUN([gl_FUNC_FCHOWNAT_DEREF_BUG],
66 dnl Persuade glibc's <unistd.h> to declare fchownat().
67 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
69 AC_CACHE_CHECK([whether fchownat works with AT_SYMLINK_NOFOLLOW],
70 gl_cv_func_fchownat_nofollow_works,
72 gl_dangle=conftest.dangle
73 # Remove any remnants of a previous test.
75 # Arrange for deletion of the temporary file this test creates.
76 ac_clean_files="$ac_clean_files $gl_dangle"
77 ln -s conftest.no-such $gl_dangle
85 #include <sys/types.h>
89 return (fchownat (AT_FDCWD, "$gl_dangle", -1, getgid (),
90 AT_SYMLINK_NOFOLLOW) != 0
94 [gl_cv_func_fchownat_nofollow_works=yes],
95 [gl_cv_func_fchownat_nofollow_works=no],
96 [gl_cv_func_fchownat_nofollow_works=no],
99 AS_IF([test $gl_cv_func_fchownat_nofollow_works = no], [$1], [$2])
102 # gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
103 AC_DEFUN([gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG],
105 dnl Persuade glibc's <unistd.h> to declare fchownat().
106 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
108 AC_CACHE_CHECK([whether fchownat works with an empty file name],
109 [gl_cv_func_fchownat_empty_filename_works],
112 [[#include <unistd.h>
117 if (mkdir ("conftestdir", 0700) < 0)
119 fd = open ("conftestdir", O_RDONLY);
122 ret = fchownat (fd, "", -1, -1, 0);
124 rmdir ("conftestdir");
127 [gl_cv_func_fchownat_empty_filename_works=yes],
128 [gl_cv_func_fchownat_empty_filename_works=no],
129 [gl_cv_func_fchownat_empty_filename_works="guessing no"])
131 AS_IF([test "$gl_cv_func_fchownat_empty_filename_works" != yes], [$1], [$2])
134 # If we have the fchownat function, and it has the bug (in glibc-2.4)
135 # that it dereferences symlinks even with AT_SYMLINK_NOFOLLOW, then
136 # use the replacement function.
137 # Also if the fchownat function, like chown, has the trailing slash bug,
138 # use the replacement function.
139 # Also use the replacement function if fchownat is simply not available.
140 AC_DEFUN([gl_FUNC_FCHOWNAT],
142 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
143 AC_REQUIRE([gl_FUNC_CHOWN])
144 AC_CHECK_FUNC([fchownat],
145 [gl_FUNC_FCHOWNAT_DEREF_BUG(
147 AC_DEFINE([FCHOWNAT_NOFOLLOW_BUG], [1],
148 [Define to 1 if your platform has fchownat, but it cannot
149 perform lchown tasks.])
151 gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG(
153 AC_DEFINE([FCHOWNAT_EMPTY_FILENAME_BUG], [1],
154 [Define to 1 if your platform has fchownat, but it does
155 not reject an empty file name.])
157 if test $REPLACE_CHOWN = 1; then
161 if test $HAVE_FCHOWNAT = 0 || test $REPLACE_FCHOWNAT = 1; then
162 AC_LIBOBJ([fchownat])
166 AC_DEFUN([gl_PREREQ_OPENAT],
168 AC_REQUIRE([AC_C_INLINE])
169 AC_REQUIRE([gl_PROMOTED_TYPE_MODE_T])