1d7cb080d8e8b1a00d4bde1597295ca158f7d717
[deliverable/binutils-gdb.git] / gnulib / import / m4 / dirfd.m4
1 # serial 24 -*- Autoconf -*-
2
3 dnl Find out how to get the file descriptor associated with an open DIR*.
4
5 # Copyright (C) 2001-2006, 2008-2016 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 AC_REQUIRE([gl_DIRENT_H_DEFAULTS])
15
16 dnl Persuade glibc <dirent.h> to declare dirfd().
17 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
18
19 AC_CHECK_FUNCS([dirfd])
20 AC_CHECK_DECLS([dirfd], , ,
21 [[#include <sys/types.h>
22 #include <dirent.h>]])
23 if test $ac_cv_have_decl_dirfd = no; then
24 HAVE_DECL_DIRFD=0
25 fi
26
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>
31 #include <dirent.h>
32 #ifdef dirfd
33 dirent_header_defines_dirfd
34 #endif],
35 gl_cv_func_dirfd_macro=yes,
36 gl_cv_func_dirfd_macro=no)])
37
38 # Use the replacement if we have no function or macro with that name,
39 # or if OS/2 kLIBC whose dirfd() does not work.
40 # Replace only if the system declares dirfd already.
41 case $ac_cv_func_dirfd,$gl_cv_func_dirfd_macro,$host_os,$ac_cv_have_decl_dirfd in
42 no,no,*,yes | *,*,os2*,yes)
43 REPLACE_DIRFD=1
44 AC_DEFINE([REPLACE_DIRFD], [1],
45 [Define to 1 if gnulib's dirfd() replacement is used.]);;
46 esac
47 ])
48
49 dnl Prerequisites of lib/dirfd.c.
50 AC_DEFUN([gl_PREREQ_DIRFD],
51 [
52 AC_CACHE_CHECK([how to get the file descriptor associated with an open DIR*],
53 [gl_cv_sys_dir_fd_member_name],
54 [
55 dirfd_save_CFLAGS=$CFLAGS
56 for ac_expr in d_fd dd_fd; do
57
58 CFLAGS="$CFLAGS -DDIR_FD_MEMBER_NAME=$ac_expr"
59 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
60 #include <sys/types.h>
61 #include <dirent.h>]],
62 [[DIR *dir_p = opendir("."); (void) dir_p->DIR_FD_MEMBER_NAME;]])],
63 [dir_fd_found=yes]
64 )
65 CFLAGS=$dirfd_save_CFLAGS
66 test "$dir_fd_found" = yes && break
67 done
68 test "$dir_fd_found" = yes || ac_expr=no_such_member
69
70 gl_cv_sys_dir_fd_member_name=$ac_expr
71 ]
72 )
73 if test $gl_cv_sys_dir_fd_member_name != no_such_member; then
74 AC_DEFINE_UNQUOTED([DIR_FD_MEMBER_NAME],
75 [$gl_cv_sys_dir_fd_member_name],
76 [the name of the file descriptor member of DIR])
77 fi
78 AH_VERBATIM([DIR_TO_FD],
79 [#ifdef DIR_FD_MEMBER_NAME
80 # define DIR_TO_FD(Dir_p) ((Dir_p)->DIR_FD_MEMBER_NAME)
81 #else
82 # define DIR_TO_FD(Dir_p) -1
83 #endif
84 ])
85 ])
This page took 0.030772 seconds and 3 git commands to generate.