3 dnl Copyright (C) 2004-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 # Written by Jim Meyering.
10 # If we have the fchownat function, and it has the bug (in glibc-2.4)
11 # that it dereferences symlinks even with AT_SYMLINK_NOFOLLOW, then
12 # use the replacement function.
13 # Also if the fchownat function, like chown, has the trailing slash bug,
14 # use the replacement function.
15 # Also use the replacement function if fchownat is simply not available.
16 AC_DEFUN([gl_FUNC_FCHOWNAT],
18 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
19 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
20 AC_REQUIRE([gl_FUNC_CHOWN])
21 AC_CHECK_FUNC([fchownat],
22 [gl_FUNC_FCHOWNAT_DEREF_BUG(
24 AC_DEFINE([FCHOWNAT_NOFOLLOW_BUG], [1],
25 [Define to 1 if your platform has fchownat, but it cannot
26 perform lchown tasks.])
28 gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG(
30 AC_DEFINE([FCHOWNAT_EMPTY_FILENAME_BUG], [1],
31 [Define to 1 if your platform has fchownat, but it does
32 not reject an empty file name.])
34 if test $REPLACE_CHOWN = 1; then
40 # gl_FUNC_FCHOWNAT_DEREF_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
41 AC_DEFUN([gl_FUNC_FCHOWNAT_DEREF_BUG],
43 dnl Persuade glibc's <unistd.h> to declare fchownat().
44 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
46 AC_CACHE_CHECK([whether fchownat works with AT_SYMLINK_NOFOLLOW],
47 [gl_cv_func_fchownat_nofollow_works],
49 gl_dangle=conftest.dangle
50 # Remove any remnants of a previous test.
52 # Arrange for deletion of the temporary file this test creates.
53 ac_clean_files="$ac_clean_files $gl_dangle"
54 ln -s conftest.no-such $gl_dangle
60 /* Android 4.3 declares fchownat() in <sys/stat.h> instead. */
64 #include <sys/types.h>
68 return (fchownat (AT_FDCWD, "$gl_dangle", (uid_t)(-1), getgid (),
69 AT_SYMLINK_NOFOLLOW) != 0
73 [gl_cv_func_fchownat_nofollow_works=yes],
74 [gl_cv_func_fchownat_nofollow_works=no],
75 [gl_cv_func_fchownat_nofollow_works="$gl_cross_guess_normal"])
77 AS_IF([test "$gl_cv_func_fchownat_nofollow_works" != yes], [$1], [$2])
80 # gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
81 AC_DEFUN([gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG],
83 dnl Persuade glibc's <unistd.h> to declare fchownat().
84 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
86 AC_CACHE_CHECK([whether fchownat works with an empty file name],
87 [gl_cv_func_fchownat_empty_filename_works],
92 /* Android 4.3 declares fchownat() in <sys/stat.h> instead. */
97 if (mkdir ("conftestdir", 0700) < 0)
99 fd = open ("conftestdir", O_RDONLY);
102 ret = fchownat (fd, "", (uid_t)(-1), (gid_t)(-1), 0);
104 rmdir ("conftestdir");
107 [gl_cv_func_fchownat_empty_filename_works=yes],
108 [gl_cv_func_fchownat_empty_filename_works=no],
109 [gl_cv_func_fchownat_empty_filename_works="$gl_cross_guess_normal"])
111 AS_IF([test "$gl_cv_func_fchownat_empty_filename_works" != yes], [$1], [$2])