fcntl.m4 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # fcntl.m4 serial 3
  2. dnl Copyright (C) 2009, 2010 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. # For now, this module ensures that fcntl()
  7. # - supports F_DUPFD correctly
  8. # - supports or emulates F_DUPFD_CLOEXEC
  9. # - supports F_GETFD
  10. # Still to be ported to mingw:
  11. # - F_SETFD
  12. # - F_GETFL, F_SETFL
  13. # - F_GETOWN, F_SETOWN
  14. # - F_GETLK, F_SETLK, F_SETLKW
  15. AC_DEFUN([gl_FUNC_FCNTL],
  16. [
  17. dnl Persuade glibc to expose F_DUPFD_CLOEXEC.
  18. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
  19. AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
  20. AC_REQUIRE([AC_CANONICAL_HOST])
  21. AC_CHECK_FUNCS_ONCE([fcntl])
  22. if test $ac_cv_func_fcntl = no; then
  23. gl_REPLACE_FCNTL
  24. else
  25. dnl cygwin 1.5.x F_DUPFD has wrong errno, and allows negative target
  26. AC_CACHE_CHECK([whether fcntl handles F_DUPFD correctly],
  27. [gl_cv_func_fcntl_f_dupfd_works],
  28. [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
  29. #include <fcntl.h>
  30. ]], [[return fcntl (0, F_DUPFD, -1) != -1;
  31. ]])],
  32. [gl_cv_func_fcntl_f_dupfd_works=yes],
  33. [gl_cv_func_fcntl_f_dupfd_works=no],
  34. [# Guess that it works on glibc systems
  35. case $host_os in #((
  36. *-gnu*) gl_cv_func_fcntl_f_dupfd_works="guessing yes";;
  37. *) gl_cv_func_fcntl_f_dupfd_works="guessing no";;
  38. esac])])
  39. case $gl_cv_func_fcntl_f_dupfd_works in
  40. *yes) ;;
  41. *) gl_REPLACE_FCNTL
  42. AC_DEFINE([FCNTL_DUPFD_BUGGY], [1], [Define this to 1 if F_DUPFD
  43. behavior does not match POSIX]) ;;
  44. esac
  45. dnl Many systems lack F_DUPFD_CLOEXEC
  46. AC_CACHE_CHECK([whether fcntl understands F_DUPFD_CLOEXEC],
  47. [gl_cv_func_fcntl_f_dupfd_cloexec],
  48. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  49. #include <fcntl.h>
  50. #ifndef F_DUPFD_CLOEXEC
  51. choke me
  52. #endif
  53. ]])],
  54. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  55. #ifdef __linux__
  56. /* The Linux kernel only added F_DUPFD_CLOEXEC in 2.6.24, so we always replace
  57. it to support the semantics on older kernels that failed with EINVAL. */
  58. choke me
  59. #endif
  60. ]])],
  61. [gl_cv_func_fcntl_f_dupfd_cloexec=yes],
  62. [gl_cv_func_fcntl_f_dupfd_cloexec="needs runtime check"])],
  63. [gl_cv_func_fcntl_f_dupfd_cloexec=no])])
  64. if test "$gl_cv_func_fcntl_f_dupfd_cloexec" != yes; then
  65. gl_REPLACE_FCNTL
  66. dnl No witness macro needed for this bug.
  67. fi
  68. fi
  69. ])
  70. AC_DEFUN([gl_REPLACE_FCNTL],
  71. [
  72. AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
  73. AC_CHECK_FUNCS_ONCE([fcntl])
  74. if test $ac_cv_func_fcntl = no; then
  75. HAVE_FCNTL=0
  76. else
  77. REPLACE_FCNTL=1
  78. fi
  79. AC_LIBOBJ([fcntl])
  80. ])