3 dnl Find out how to get the file descriptor associated with an open DIR*.
6 AC_DEFUN([UTILS_FUNC_DIRFD],
12 #else /* not HAVE_DIRENT_H */
13 # define dirent direct
15 # include <sys/ndir.h>
16 # endif /* HAVE_SYS_NDIR_H */
19 # endif /* HAVE_SYS_DIR_H */
22 # endif /* HAVE_NDIR_H */
23 #endif /* HAVE_DIRENT_H */
26 AC_CHECK_DECLS([dirfd], , , $dirfd_headers)
28 AC_CACHE_CHECK([whether dirfd is a macro],
29 jm_cv_func_dirfd_macro,
30 AC_EGREP_CPP([dirent_header_defines_dirfd], [$dirfd_headers
32 dirent_header_defines_dirfd
34 jm_cv_func_dirfd_macro=yes,
35 jm_cv_func_dirfd_macro=no))
37 # Use the replacement only if we have no function, macro,
38 # or declaration with that name.
39 if test $ac_cv_func_dirfd,$ac_cv_have_decl_dirfd,$jm_cv_func_dirfd_macro \
41 AC_REPLACE_FUNCS([dirfd])
43 [how to get the file descriptor associated with an open DIR*],
44 ac_cv_sys_dir_fd_member_name,
46 dirfd_save_CFLAGS=$CFLAGS
47 for ac_expr in d_fd dd_fd; do
49 CFLAGS="$CFLAGS -DDIR_FD_MEMBER_NAME=$ac_expr"
53 [DIR *dir_p = opendir("."); (void) dir_p->DIR_FD_MEMBER_NAME;],
56 CFLAGS=$dirfd_save_CFLAGS
57 test "$dir_fd_found" = yes && break
59 test "$dir_fd_found" = yes || ac_expr=-1
61 ac_cv_sys_dir_fd_member_name=$ac_expr
64 if test $ac_cv_have_decl_dirfd = -1; then
65 AC_DEFINE_UNQUOTED(DIR_FD_MEMBER_NAME,
66 $ac_cv_sys_dir_fd_member_name,
67 [the name of the file descriptor member of DIR])
69 AH_VERBATIM(DIR_TO_FD,
70 [#ifdef DIR_FD_MEMBER_NAME
71 # define DIR_TO_FD(Dir_p) ((Dir_p)->DIR_FD_MEMBER_NAME)
73 # define DIR_TO_FD(Dir_p) -1