3 dnl Find out how to get the file descriptor associated with an open DIR*.
6 AC_DEFUN([UTILS_FUNC_DIRFD],
8 dnl Work around a bug of AC_EGREP_CPP in autoconf-2.57.
9 AC_REQUIRE([AC_PROG_CPP])
10 AC_REQUIRE([AC_PROG_EGREP])
16 #else /* not HAVE_DIRENT_H */
17 # define dirent direct
19 # include <sys/ndir.h>
20 # endif /* HAVE_SYS_NDIR_H */
23 # endif /* HAVE_SYS_DIR_H */
26 # endif /* HAVE_NDIR_H */
27 #endif /* HAVE_DIRENT_H */
30 AC_CHECK_DECLS([dirfd], , , $dirfd_headers)
32 AC_CACHE_CHECK([whether dirfd is a macro],
33 jm_cv_func_dirfd_macro,
34 [AC_EGREP_CPP([dirent_header_defines_dirfd], [$dirfd_headers
36 dirent_header_defines_dirfd
38 jm_cv_func_dirfd_macro=yes,
39 jm_cv_func_dirfd_macro=no)])
41 # Use the replacement only if we have no function, macro,
42 # or declaration with that name.
43 if test $ac_cv_func_dirfd,$ac_cv_have_decl_dirfd,$jm_cv_func_dirfd_macro \
45 AC_REPLACE_FUNCS([dirfd])
47 [how to get the file descriptor associated with an open DIR*],
48 gl_cv_sys_dir_fd_member_name,
50 dirfd_save_CFLAGS=$CFLAGS
51 for ac_expr in d_fd dd_fd; do
53 CFLAGS="$CFLAGS -DDIR_FD_MEMBER_NAME=$ac_expr"
57 [DIR *dir_p = opendir("."); (void) dir_p->DIR_FD_MEMBER_NAME;],
60 CFLAGS=$dirfd_save_CFLAGS
61 test "$dir_fd_found" = yes && break
63 test "$dir_fd_found" = yes || ac_expr=no_such_member
65 gl_cv_sys_dir_fd_member_name=$ac_expr
68 if test $gl_cv_sys_dir_fd_member_name != no_such_member; then
69 AC_DEFINE_UNQUOTED(DIR_FD_MEMBER_NAME,
70 $gl_cv_sys_dir_fd_member_name,
71 [the name of the file descriptor member of DIR])
73 AH_VERBATIM(DIR_TO_FD,
74 [#ifdef DIR_FD_MEMBER_NAME
75 # define DIR_TO_FD(Dir_p) ((Dir_p)->DIR_FD_MEMBER_NAME)
77 # define DIR_TO_FD(Dir_p) -1