dirfd.m4 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # serial 22 -*- Autoconf -*-
  2. dnl Find out how to get the file descriptor associated with an open DIR*.
  3. # Copyright (C) 2001-2006, 2008-2012 Free Software Foundation, Inc.
  4. # This file is free software; the Free Software Foundation
  5. # gives unlimited permission to copy and/or distribute it,
  6. # with or without modifications, as long as this notice is preserved.
  7. dnl From Jim Meyering
  8. AC_DEFUN([gl_FUNC_DIRFD],
  9. [
  10. AC_REQUIRE([gl_DIRENT_H_DEFAULTS])
  11. dnl Persuade glibc <dirent.h> to declare dirfd().
  12. AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  13. AC_CHECK_FUNCS([dirfd])
  14. AC_CHECK_DECLS([dirfd], , ,
  15. [[#include <sys/types.h>
  16. #include <dirent.h>]])
  17. if test $ac_cv_have_decl_dirfd = no; then
  18. HAVE_DECL_DIRFD=0
  19. fi
  20. AC_CACHE_CHECK([whether dirfd is a macro],
  21. gl_cv_func_dirfd_macro,
  22. [AC_EGREP_CPP([dirent_header_defines_dirfd], [
  23. #include <sys/types.h>
  24. #include <dirent.h>
  25. #ifdef dirfd
  26. dirent_header_defines_dirfd
  27. #endif],
  28. gl_cv_func_dirfd_macro=yes,
  29. gl_cv_func_dirfd_macro=no)])
  30. # Use the replacement only if we have no function or macro with that name.
  31. if test $ac_cv_func_dirfd = no && test $gl_cv_func_dirfd_macro = no; then
  32. if test $ac_cv_have_decl_dirfd = yes; then
  33. # If the system declares dirfd already, let's declare rpl_dirfd instead.
  34. REPLACE_DIRFD=1
  35. fi
  36. fi
  37. ])
  38. dnl Prerequisites of lib/dirfd.c.
  39. AC_DEFUN([gl_PREREQ_DIRFD],
  40. [
  41. AC_CACHE_CHECK([how to get the file descriptor associated with an open DIR*],
  42. [gl_cv_sys_dir_fd_member_name],
  43. [
  44. dirfd_save_CFLAGS=$CFLAGS
  45. for ac_expr in d_fd dd_fd; do
  46. CFLAGS="$CFLAGS -DDIR_FD_MEMBER_NAME=$ac_expr"
  47. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  48. #include <sys/types.h>
  49. #include <dirent.h>]],
  50. [[DIR *dir_p = opendir("."); (void) dir_p->DIR_FD_MEMBER_NAME;]])],
  51. [dir_fd_found=yes]
  52. )
  53. CFLAGS=$dirfd_save_CFLAGS
  54. test "$dir_fd_found" = yes && break
  55. done
  56. test "$dir_fd_found" = yes || ac_expr=no_such_member
  57. gl_cv_sys_dir_fd_member_name=$ac_expr
  58. ]
  59. )
  60. if test $gl_cv_sys_dir_fd_member_name != no_such_member; then
  61. AC_DEFINE_UNQUOTED([DIR_FD_MEMBER_NAME],
  62. [$gl_cv_sys_dir_fd_member_name],
  63. [the name of the file descriptor member of DIR])
  64. fi
  65. AH_VERBATIM([DIR_TO_FD],
  66. [#ifdef DIR_FD_MEMBER_NAME
  67. # define DIR_TO_FD(Dir_p) ((Dir_p)->DIR_FD_MEMBER_NAME)
  68. #else
  69. # define DIR_TO_FD(Dir_p) -1
  70. #endif
  71. ])
  72. ])