check for decl, too
[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_REPLACE_FUNCS([dirfd])
9   AC_CHECK_DECLS([dirfd])
10   if test $ac_cv_func_dirfd = no; then
11     AC_CACHE_CHECK(
12               [how to get the file descriptor associated with an open DIR*],
13                    ac_cv_sys_dir_to_fd,
14       [
15         dirfd_save_DEFS=$DEFS
16         for ac_expr in                                          \
17                                                                 \
18             '# Solaris'                                         \
19             'dir_p->d_fd'                                       \
20                                                                 \
21             '# Solaris'                                         \
22             'dir_p->dd_fd'                                      \
23                                                                 \
24             '# systems for which the info is not available'     \
25             -1                                                  \
26             ; do
27
28           # Skip each embedded comment.
29           case "$ac_expr" in '#'*) continue;; esac
30
31           DEFS="$DEFS -DDIR_TO_FD=$ac_expr"
32           AC_TRY_COMPILE(
33             [#include <sys/types.h>
34              #include <dirent.h>
35             ],
36             [DIR *dir_p = opendir("."); (void) ($ac_expr);],
37             dir_fd_done=yes
38           )
39           DEFS=$dirfd_save_DEFS
40           test "$dir_fd_done" = yes && break
41         done
42
43         ac_cv_sys_dir_to_fd=$ac_expr
44       ]
45     )
46     AC_DEFINE_UNQUOTED(DIR_TO_FD,
47       $ac_cv_sys_dir_to_fd,
48       [the file descriptor associated with `dir_p'])
49   fi
50 ])