| 1 | # serial 14
|
|---|
| 2 | # See if we need to provide fdopendir.
|
|---|
| 3 |
|
|---|
| 4 | dnl Copyright (C) 2009-2021 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.
|
|---|
| 8 |
|
|---|
| 9 | # Written by Eric Blake.
|
|---|
| 10 |
|
|---|
| 11 | AC_DEFUN([gl_FUNC_FDOPENDIR],
|
|---|
| 12 | [
|
|---|
| 13 | AC_REQUIRE([gl_DIRENT_H_DEFAULTS])
|
|---|
| 14 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
|
|---|
| 15 |
|
|---|
| 16 | AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
|
|---|
| 17 |
|
|---|
| 18 | dnl FreeBSD 7.3 has the function, but failed to declare it.
|
|---|
| 19 | AC_CHECK_DECLS([fdopendir], [], [HAVE_DECL_FDOPENDIR=0], [[
|
|---|
| 20 | #include <dirent.h>
|
|---|
| 21 | ]])
|
|---|
| 22 | AC_CHECK_FUNCS_ONCE([fdopendir])
|
|---|
| 23 | if test $ac_cv_func_fdopendir = no; then
|
|---|
| 24 | HAVE_FDOPENDIR=0
|
|---|
| 25 | else
|
|---|
| 26 | AC_CACHE_CHECK([whether fdopendir works],
|
|---|
| 27 | [gl_cv_func_fdopendir_works],
|
|---|
| 28 | [AC_RUN_IFELSE(
|
|---|
| 29 | [AC_LANG_PROGRAM([[
|
|---|
| 30 | #include <dirent.h>
|
|---|
| 31 | #include <fcntl.h>
|
|---|
| 32 | #include <unistd.h>
|
|---|
| 33 | ]GL_MDA_DEFINES[
|
|---|
| 34 | #if !HAVE_DECL_FDOPENDIR
|
|---|
| 35 | extern
|
|---|
| 36 | # ifdef __cplusplus
|
|---|
| 37 | "C"
|
|---|
| 38 | # endif
|
|---|
| 39 | DIR *fdopendir (int);
|
|---|
| 40 | #endif
|
|---|
| 41 | ]],
|
|---|
| 42 | [[int result = 0;
|
|---|
| 43 | int fd = open ("conftest.c", O_RDONLY);
|
|---|
| 44 | if (fd < 0) result |= 1;
|
|---|
| 45 | if (fdopendir (fd)) result |= 2;
|
|---|
| 46 | if (close (fd)) result |= 4;
|
|---|
| 47 | return result;
|
|---|
| 48 | ]])],
|
|---|
| 49 | [gl_cv_func_fdopendir_works=yes],
|
|---|
| 50 | [gl_cv_func_fdopendir_works=no],
|
|---|
| 51 | [case "$host_os" in
|
|---|
| 52 | # Guess yes on glibc systems.
|
|---|
| 53 | *-gnu*) gl_cv_func_fdopendir_works="guessing yes" ;;
|
|---|
| 54 | # Guess yes on musl systems.
|
|---|
| 55 | *-musl*) gl_cv_func_fdopendir_works="guessing yes" ;;
|
|---|
| 56 | # If we don't know, obey --enable-cross-guesses.
|
|---|
| 57 | *) gl_cv_func_fdopendir_works="$gl_cross_guess_normal" ;;
|
|---|
| 58 | esac
|
|---|
| 59 | ])])
|
|---|
| 60 | case "$gl_cv_func_fdopendir_works" in
|
|---|
| 61 | *yes) ;;
|
|---|
| 62 | *)
|
|---|
| 63 | REPLACE_FDOPENDIR=1
|
|---|
| 64 | ;;
|
|---|
| 65 | esac
|
|---|
| 66 | fi
|
|---|
| 67 | ])
|
|---|