Use an all-permissive copyright notice, recommended by RMS.
[pspp] / m4 / dirfd.m4
1 #serial 9
2
3 dnl Find out how to get the file descriptor associated with an open DIR*.
4
5 # Copyright (C) 2001, 2002, 2003, 2004 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.
9
10 dnl From Jim Meyering
11
12 AC_DEFUN([gl_FUNC_DIRFD],
13 [
14   dnl Work around a bug of AC_EGREP_CPP in autoconf-2.57.
15   AC_REQUIRE([AC_PROG_CPP])
16   AC_REQUIRE([AC_PROG_EGREP])
17
18   AC_HEADER_DIRENT
19   dirfd_headers='
20 #if HAVE_DIRENT_H
21 # include <dirent.h>
22 #else /* not HAVE_DIRENT_H */
23 # define dirent direct
24 # if HAVE_SYS_NDIR_H
25 #  include <sys/ndir.h>
26 # endif /* HAVE_SYS_NDIR_H */
27 # if HAVE_SYS_DIR_H
28 #  include <sys/dir.h>
29 # endif /* HAVE_SYS_DIR_H */
30 # if HAVE_NDIR_H
31 #  include <ndir.h>
32 # endif /* HAVE_NDIR_H */
33 #endif /* HAVE_DIRENT_H */
34 '
35   AC_CHECK_FUNCS(dirfd)
36   AC_CHECK_DECLS([dirfd], , , $dirfd_headers)
37
38   AC_CACHE_CHECK([whether dirfd is a macro],
39     gl_cv_func_dirfd_macro,
40     [AC_EGREP_CPP([dirent_header_defines_dirfd], [$dirfd_headers
41 #ifdef dirfd
42  dirent_header_defines_dirfd
43 #endif],
44        gl_cv_func_dirfd_macro=yes,
45        gl_cv_func_dirfd_macro=no)])
46
47   # Use the replacement only if we have no function, macro,
48   # or declaration with that name.
49   if test $ac_cv_func_dirfd,$ac_cv_have_decl_dirfd,$gl_cv_func_dirfd_macro \
50       = no,no,no; then
51     AC_REPLACE_FUNCS([dirfd])
52     AC_CACHE_CHECK(
53               [how to get the file descriptor associated with an open DIR*],
54                    gl_cv_sys_dir_fd_member_name,
55       [
56         dirfd_save_CFLAGS=$CFLAGS
57         for ac_expr in d_fd dd_fd; do
58
59           CFLAGS="$CFLAGS -DDIR_FD_MEMBER_NAME=$ac_expr"
60           AC_TRY_COMPILE(
61             [$dirfd_headers
62             ],
63             [DIR *dir_p = opendir("."); (void) dir_p->DIR_FD_MEMBER_NAME;],
64             dir_fd_found=yes
65           )
66           CFLAGS=$dirfd_save_CFLAGS
67           test "$dir_fd_found" = yes && break
68         done
69         test "$dir_fd_found" = yes || ac_expr=no_such_member
70
71         gl_cv_sys_dir_fd_member_name=$ac_expr
72       ]
73     )
74     if test $gl_cv_sys_dir_fd_member_name != no_such_member; then
75       AC_DEFINE_UNQUOTED(DIR_FD_MEMBER_NAME,
76         $gl_cv_sys_dir_fd_member_name,
77         [the name of the file descriptor member of DIR])
78     fi
79     AH_VERBATIM(DIR_TO_FD,
80                 [#ifdef DIR_FD_MEMBER_NAME
81 # define DIR_TO_FD(Dir_p) ((Dir_p)->DIR_FD_MEMBER_NAME)
82 #else
83 # define DIR_TO_FD(Dir_p) -1
84 #endif
85 ])
86   fi
87 ])