1 # serial 20 -*- Autoconf -*-
3 dnl Find out how to get the file descriptor associated with an open DIR*.
5 # Copyright (C) 2001-2006, 2008-2011 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.
12 AC_DEFUN([gl_FUNC_DIRFD],
14 AC_REQUIRE([gl_DIRENT_H_DEFAULTS])
16 dnl Persuade glibc <dirent.h> to declare dirfd().
17 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
19 AC_CHECK_FUNCS([dirfd])
20 AC_CHECK_DECLS([dirfd], , ,
21 [#include <sys/types.h>
23 if test $ac_cv_have_decl_dirfd = no; then
27 AC_CACHE_CHECK([whether dirfd is a macro],
28 gl_cv_func_dirfd_macro,
29 [AC_EGREP_CPP([dirent_header_defines_dirfd], [
30 #include <sys/types.h>
33 dirent_header_defines_dirfd
35 gl_cv_func_dirfd_macro=yes,
36 gl_cv_func_dirfd_macro=no)])
38 # Use the replacement only if we have no function or macro with that name.
39 if test $ac_cv_func_dirfd,$gl_cv_func_dirfd_macro = no,no; then
40 if test $ac_cv_have_decl_dirfd = yes; then
41 # If the system declares dirfd already, let's declare rpl_dirfd instead.
46 [how to get the file descriptor associated with an open DIR*],
47 gl_cv_sys_dir_fd_member_name,
49 dirfd_save_CFLAGS=$CFLAGS
50 for ac_expr in d_fd dd_fd; do
52 CFLAGS="$CFLAGS -DDIR_FD_MEMBER_NAME=$ac_expr"
53 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
54 #include <sys/types.h>
55 #include <dirent.h>]],
56 [[DIR *dir_p = opendir("."); (void) dir_p->DIR_FD_MEMBER_NAME;]])],
59 CFLAGS=$dirfd_save_CFLAGS
60 test "$dir_fd_found" = yes && break
62 test "$dir_fd_found" = yes || ac_expr=no_such_member
64 gl_cv_sys_dir_fd_member_name=$ac_expr
67 if test $gl_cv_sys_dir_fd_member_name != no_such_member; then
68 AC_DEFINE_UNQUOTED([DIR_FD_MEMBER_NAME],
69 $gl_cv_sys_dir_fd_member_name,
70 [the name of the file descriptor member of DIR])
72 AH_VERBATIM(DIR_TO_FD,
73 [#ifdef DIR_FD_MEMBER_NAME
74 # define DIR_TO_FD(Dir_p) ((Dir_p)->DIR_FD_MEMBER_NAME)
76 # define DIR_TO_FD(Dir_p) -1