Debian Codegraph @

m4/fdopendir.m4

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