fix indentation of cpp `#'s
[gnulib.git] / m4 / dirfd.m4
1 #serial 1
2
3 dnl Find out how to get the file descriptor associated with an open DIR*.
4 dnl From Jim Meyering
5
6 AC_DEFUN([UTILS_FUNC_DIRFD],
7 [
8   AC_HEADER_DIRENT
9   dirfd_headers='
10 #if HAVE_DIRENT_H
11 # include <dirent.h>
12 #else /* not HAVE_DIRENT_H */
13 # define dirent direct
14 # if HAVE_SYS_NDIR_H
15 #  include <sys/ndir.h>
16 # endif /* HAVE_SYS_NDIR_H */
17 # if HAVE_SYS_DIR_H
18 #  include <sys/dir.h>
19 # endif /* HAVE_SYS_DIR_H */
20 # if HAVE_NDIR_H
21 #  include <ndir.h>
22 # endif /* HAVE_NDIR_H */
23 #endif /* HAVE_DIRENT_H */
24 '
25   AC_CHECK_FUNCS(dirfd)
26   AC_CHECK_DECLS([dirfd], , , $dirfd_headers)
27
28   # Use the replacement only if we have neither the function
29   # nor a declaration.
30   if test $ac_cv_func_dirfd,$ac_cv_have_decl_dirfd = no,no; then
31     AC_REPLACE_FUNCS([dirfd])
32     AC_CACHE_CHECK(
33               [how to get the file descriptor associated with an open DIR*],
34                    ac_cv_sys_dir_fd_member_name,
35       [
36         dirfd_save_DEFS=$DEFS
37         for ac_expr in d_fd dd_fd; do
38
39           DEFS="$DEFS -DDIR_FD_MEMBER_NAME=$ac_expr"
40           AC_TRY_COMPILE(
41             [$dirfd_headers
42             ],
43             [DIR *dir_p = opendir("."); (void) dir_p->DIR_FD_MEMBER_NAME;],
44             dir_fd_found=yes
45           )
46           DEFS=$dirfd_save_DEFS
47           test "$dir_fd_found" = yes && break
48         done
49         test "$dir_fd_found" = yes || ac_expr=-1
50
51         ac_cv_sys_dir_fd_member_name=$ac_expr
52       ]
53     )
54     if test $ac_cv_have_decl_dirfd = -1; then
55       AC_DEFINE_UNQUOTED(DIR_FD_MEMBER_NAME,
56         $ac_cv_sys_dir_fd_member_name,
57         [the name of the file descriptor member of DIR])
58     fi
59     AH_VERBATIM(DIR_TO_FD,
60                 [#ifdef DIR_FD_MEMBER_NAME
61 # define DIR_TO_FD(Dir_p) ((Dir_p)->DIR_FD_MEMBER_NAME)
62 #else
63 # define DIR_TO_FD(Dir_p) -1
64 #endif
65 ]
66     )
67   fi
68 ])