Debian Codegraph @

m4/dirfd.m4

raw
1 # serial 28 -*- Autoconf -*-
2
3 dnl Find out how to get the file descriptor associated with an open DIR*.
4
5 # Copyright (C) 2001-2006, 2008-2023 Free Software Foundation, Inc.
6 # This file is free software; the Free Software Foundation
7 # gives unlimited permission to copy and/or distribute it,
8 # with or without modifications, as long as this notice is preserved.
9
10 dnl From Jim Meyering
11
12 AC_DEFUN([gl_FUNC_DIRFD],
13 [
14 AC_REQUIRE([gl_DIRENT_H_DEFAULTS])
15 AC_REQUIRE([AC_CANONICAL_HOST])
16
17 dnl Persuade glibc <dirent.h> to declare dirfd().
18 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
19
20 AC_CHECK_FUNCS([dirfd])
21 AC_CHECK_DECLS([dirfd], , ,
22 [[#include <sys/types.h>
23 #include <dirent.h>]])
24 if test $ac_cv_have_decl_dirfd = no; then
25 HAVE_DECL_DIRFD=0
26 fi
27
28 AC_CACHE_CHECK([whether dirfd is a macro],
29 [gl_cv_func_dirfd_macro],
30 [AC_EGREP_CPP([dirent_header_defines_dirfd], [
31 #include <sys/types.h>
32 #include <dirent.h>
33 #ifdef dirfd
34 dirent_header_defines_dirfd
35 #endif],
36 [gl_cv_func_dirfd_macro=yes],
37 [gl_cv_func_dirfd_macro=no])])
38
39 if test $ac_cv_func_dirfd = no && test $gl_cv_func_dirfd_macro = no; then
40 HAVE_DIRFD=0
41 else
42 HAVE_DIRFD=1
43 dnl Replace dirfd() on native Windows, to support fdopendir().
44 AC_REQUIRE([gl_DIRENT_DIR])
45 if test $DIR_HAS_FD_MEMBER = 0; then
46 REPLACE_DIRFD=1
47 fi
48 dnl OS/2 kLIBC dirfd() does not work.
49 case "$host_os" in
50 os2*) REPLACE_DIRFD=1 ;;
51 esac
52 fi
53 ])
54
55 dnl Prerequisites of lib/dirfd.c.
56 AC_DEFUN([gl_PREREQ_DIRFD],
57 [
58 AC_CACHE_CHECK([how to get the file descriptor associated with an open DIR*],
59 [gl_cv_sys_dir_fd_member_name],
60 [
61 dirfd_save_CFLAGS=$CFLAGS
62 for ac_expr in d_fd dd_fd; do
63
64 CFLAGS="$CFLAGS -DDIR_FD_MEMBER_NAME=$ac_expr"
65 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
66 #include <sys/types.h>
67 #include <dirent.h>]],
68 [[DIR *dir_p = opendir("."); (void) dir_p->DIR_FD_MEMBER_NAME;]])],
69 [dir_fd_found=yes]
70 )
71 CFLAGS=$dirfd_save_CFLAGS
72 test "$dir_fd_found" = yes && break
73 done
74 test "$dir_fd_found" = yes || ac_expr=no_such_member
75
76 gl_cv_sys_dir_fd_member_name=$ac_expr
77 ]
78 )
79 if test $gl_cv_sys_dir_fd_member_name != no_such_member; then
80 AC_DEFINE_UNQUOTED([DIR_FD_MEMBER_NAME],
81 [$gl_cv_sys_dir_fd_member_name],
82 [the name of the file descriptor member of DIR])
83 fi
84 AH_VERBATIM([DIR_TO_FD],
85 [#ifdef DIR_FD_MEMBER_NAME
86 # define DIR_TO_FD(Dir_p) ((Dir_p)->DIR_FD_MEMBER_NAME)
87 #else
88 # define DIR_TO_FD(Dir_p) -1
89 #endif
90 ])
91 ])