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 AC_DEFUN([gl_FUNC_FCHMODAT],
11 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
12 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
13 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
14 AC_CHECK_FUNCS_ONCE([fchmodat lchmod])
15 if test $ac_cv_func_fchmodat != yes; then
19 [whether fchmodat+AT_SYMLINK_NOFOLLOW works on non-symlinks],
20 [gl_cv_func_fchmodat_works],
21 [dnl This test fails on GNU/Linux with glibc 2.31 (but not on
22 dnl GNU/kFreeBSD nor GNU/Hurd) and Cygwin 2.9.
45 int permissive = S_IRWXU | S_IRWXG | S_IRWXO;
46 int desired = S_IRUSR | S_IWUSR;
47 static char const f[] = "conftest.fchmodat";
49 if (creat (f, permissive) < 0)
51 if (fchmodat (AT_FDCWD, f, desired, AT_SYMLINK_NOFOLLOW) != 0)
53 if (stat (f, &st) != 0)
55 return ! ((st.st_mode & permissive) == desired);
57 [gl_cv_func_fchmodat_works=yes],
58 [gl_cv_func_fchmodat_works=no],
60 dnl Guess no on Linux with glibc and Cygwin, yes otherwise.
61 linux-gnu* | cygwin*) gl_cv_func_fchmodat_works="guessing no" ;;
62 *) gl_cv_func_fchmodat_works="$gl_cross_guess_normal" ;;
65 rm -f conftest.fchmodat])
66 case $gl_cv_func_fchmodat_works in
69 AC_DEFINE([NEED_FCHMODAT_NONSYMLINK_FIX], [1],
70 [Define to 1 if fchmodat+AT_SYMLINK_NOFOLLOW does not work right on non-symlinks.])
77 # Prerequisites of lib/fchmodat.c.
78 AC_DEFUN([gl_PREREQ_FCHMODAT],
80 AC_CHECK_FUNCS_ONCE([lchmod])