| 1 |
# fchdir.m4 |
| 2 |
# serial 32 |
| 3 |
dnl Copyright (C) 2006-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. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
AC_DEFUN([gl_FUNC_FCHDIR], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) |
| 12 |
AC_REQUIRE([gl_DIRENT_H_DEFAULTS]) |
| 13 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 14 |
|
| 15 |
AC_CHECK_DECLS_ONCE([fchdir]) |
| 16 |
if test $ac_cv_have_decl_fchdir = no; then |
| 17 |
HAVE_DECL_FCHDIR=0 |
| 18 |
fi |
| 19 |
|
| 20 |
AC_REQUIRE([gl_TEST_FCHDIR]) |
| 21 |
if test $HAVE_FCHDIR = 1; then |
| 22 |
AC_REQUIRE([gl_DIRENT_DIR]) |
| 23 |
if test $DIR_HAS_FD_MEMBER = 0; then |
| 24 |
dnl fchdir() should be replaced if dirfd() does not work. |
| 25 |
REPLACE_FCHDIR=1 |
| 26 |
fi |
| 27 |
fi |
| 28 |
|
| 29 |
if test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1; then |
| 30 |
AC_DEFINE([REPLACE_FCHDIR], [1], |
| 31 |
[Define to 1 if gnulib's fchdir() replacement is used.]) |
| 32 |
dnl We must also replace anything that can manipulate a directory fd, |
| 33 |
dnl to keep our bookkeeping up-to-date. We don't have to replace |
| 34 |
dnl fstatat, since no platform has fstatat but lacks fchdir. |
| 35 |
AC_CACHE_CHECK([whether open can visit directories], |
| 36 |
[gl_cv_func_open_directory_works], |
| 37 |
[AC_RUN_IFELSE( |
| 38 |
[AC_LANG_PROGRAM( |
| 39 |
[[#include <fcntl.h> |
| 40 |
]GL_MDA_DEFINES], |
| 41 |
[[return open(".", O_RDONLY) < 0;]])], |
| 42 |
[gl_cv_func_open_directory_works=yes], |
| 43 |
[gl_cv_func_open_directory_works=no], |
| 44 |
[case "$host_os" in |
| 45 |
# Guess yes on Linux systems. |
| 46 |
linux-* | linux) gl_cv_func_open_directory_works="guessing yes" ;; |
| 47 |
# Guess yes on systems that emulate the Linux system calls. |
| 48 |
midipix*) gl_cv_func_open_directory_works="guessing yes" ;; |
| 49 |
# Guess yes on glibc systems. |
| 50 |
*-gnu* | gnu*) gl_cv_func_open_directory_works="guessing yes" ;; |
| 51 |
# Guess no on native Windows. |
| 52 |
mingw* | windows*) gl_cv_func_open_directory_works="guessing no" ;; |
| 53 |
# If we don't know, obey --enable-cross-guesses. |
| 54 |
*) gl_cv_func_open_directory_works="$gl_cross_guess_normal" ;; |
| 55 |
esac |
| 56 |
])]) |
| 57 |
case "$gl_cv_func_open_directory_works" in |
| 58 |
*yes) ;; |
| 59 |
*) |
| 60 |
AC_DEFINE([REPLACE_OPEN_DIRECTORY], [1], [Define to 1 if open() should |
| 61 |
work around the inability to open a directory.]) |
| 62 |
;; |
| 63 |
esac |
| 64 |
fi |
| 65 |
]) |
| 66 |
|
| 67 |
# Determine whether to use the overrides in lib/fchdir.c. |
| 68 |
AC_DEFUN([gl_TEST_FCHDIR], |
| 69 |
[ |
| 70 |
AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) |
| 71 |
AC_CHECK_FUNCS_ONCE([fchdir]) |
| 72 |
if test $ac_cv_func_fchdir = no; then |
| 73 |
HAVE_FCHDIR=0 |
| 74 |
fi |
| 75 |
]) |
| 76 |
|
| 77 |
# Prerequisites of lib/fchdir.c. |
| 78 |
AC_DEFUN([gl_PREREQ_FCHDIR], [:]) |