2 dnl Copyright (C) 2004-2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 # Written by Jim Meyering.
9 # If we have the fchownat function, and it has the bug (in glibc-2.4)
10 # that it dereferences symlinks even with AT_SYMLINK_NOFOLLOW, then
11 # use the replacement function.
12 # Also if the fchownat function, like chown, has the trailing slash bug,
13 # use the replacement function.
14 # Also use the replacement function if fchownat is simply not available.
15 AC_DEFUN([gl_FUNC_FCHOWNAT],
17 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
18 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
19 AC_REQUIRE([gl_FUNC_CHOWN])
20 AC_CHECK_FUNC([fchownat],
21 [gl_FUNC_FCHOWNAT_DEREF_BUG(
23 AC_DEFINE([FCHOWNAT_NOFOLLOW_BUG], [1],
24 [Define to 1 if your platform has fchownat, but it cannot
25 perform lchown tasks.])
27 gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG(
29 AC_DEFINE([FCHOWNAT_EMPTY_FILENAME_BUG], [1],
30 [Define to 1 if your platform has fchownat, but it does
31 not reject an empty file name.])
33 if test $REPLACE_CHOWN = 1; then
39 # gl_FUNC_FCHOWNAT_DEREF_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
40 AC_DEFUN([gl_FUNC_FCHOWNAT_DEREF_BUG],
42 dnl Persuade glibc's <unistd.h> to declare fchownat().
43 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
45 AC_CACHE_CHECK([whether fchownat works with AT_SYMLINK_NOFOLLOW],
46 [gl_cv_func_fchownat_nofollow_works],
48 gl_dangle=conftest.dangle
49 # Remove any remnants of a previous test.
51 # Arrange for deletion of the temporary file this test creates.
52 ac_clean_files="$ac_clean_files $gl_dangle"
53 ln -s conftest.no-such $gl_dangle
59 /* Android 4.3 declares fchownat() in <sys/stat.h> instead. */
63 #include <sys/types.h>
67 return (fchownat (AT_FDCWD, "$gl_dangle", (uid_t)(-1), getgid (),
68 AT_SYMLINK_NOFOLLOW) != 0
72 [gl_cv_func_fchownat_nofollow_works=yes],
73 [gl_cv_func_fchownat_nofollow_works=no],
74 [gl_cv_func_fchownat_nofollow_works="$gl_cross_guess_normal"])
76 AS_IF([test "$gl_cv_func_fchownat_nofollow_works" != yes], [$1], [$2])
79 # gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
80 AC_DEFUN([gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG],
82 dnl Persuade glibc's <unistd.h> to declare fchownat().
83 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
85 AC_CACHE_CHECK([whether fchownat works with an empty file name],
86 [gl_cv_func_fchownat_empty_filename_works],
91 /* Android 4.3 declares fchownat() in <sys/stat.h> instead. */
96 if (mkdir ("conftestdir", 0700) < 0)
98 fd = open ("conftestdir", O_RDONLY);
101 ret = fchownat (fd, "", (uid_t)(-1), (gid_t)(-1), 0);
103 rmdir ("conftestdir");
106 [gl_cv_func_fchownat_empty_filename_works=yes],
107 [gl_cv_func_fchownat_empty_filename_works=no],
108 [gl_cv_func_fchownat_empty_filename_works="$gl_cross_guess_normal"])
110 AS_IF([test "$gl_cv_func_fchownat_empty_filename_works" != yes], [$1], [$2])