open.m4 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # open.m4 serial 15
  2. dnl Copyright (C) 2007-2017 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. AC_DEFUN([gl_FUNC_OPEN],
  7. [
  8. AC_REQUIRE([AC_CANONICAL_HOST])
  9. AC_REQUIRE([gl_PREPROC_O_CLOEXEC])
  10. case "$host_os" in
  11. mingw* | pw*)
  12. REPLACE_OPEN=1
  13. ;;
  14. *)
  15. dnl open("foo/") should not create a file when the file name has a
  16. dnl trailing slash. FreeBSD only has the problem on symlinks.
  17. AC_CHECK_FUNCS_ONCE([lstat])
  18. if test "$gl_cv_macro_O_CLOEXEC" != yes; then
  19. REPLACE_OPEN=1
  20. fi
  21. AC_CACHE_CHECK([whether open recognizes a trailing slash],
  22. [gl_cv_func_open_slash],
  23. [# Assume that if we have lstat, we can also check symlinks.
  24. if test $ac_cv_func_lstat = yes; then
  25. touch conftest.tmp
  26. ln -s conftest.tmp conftest.lnk
  27. fi
  28. AC_RUN_IFELSE(
  29. [AC_LANG_SOURCE([[
  30. #include <fcntl.h>
  31. #if HAVE_UNISTD_H
  32. # include <unistd.h>
  33. #endif
  34. int main ()
  35. {
  36. int result = 0;
  37. #if HAVE_LSTAT
  38. if (open ("conftest.lnk/", O_RDONLY) != -1)
  39. result |= 1;
  40. #endif
  41. if (open ("conftest.sl/", O_CREAT, 0600) >= 0)
  42. result |= 2;
  43. return result;
  44. }]])],
  45. [gl_cv_func_open_slash=yes],
  46. [gl_cv_func_open_slash=no],
  47. [
  48. changequote(,)dnl
  49. case "$host_os" in
  50. freebsd* | aix* | hpux* | solaris2.[0-9] | solaris2.[0-9].*)
  51. gl_cv_func_open_slash="guessing no" ;;
  52. *)
  53. gl_cv_func_open_slash="guessing yes" ;;
  54. esac
  55. changequote([,])dnl
  56. ])
  57. rm -f conftest.sl conftest.tmp conftest.lnk
  58. ])
  59. case "$gl_cv_func_open_slash" in
  60. *no)
  61. AC_DEFINE([OPEN_TRAILING_SLASH_BUG], [1],
  62. [Define to 1 if open() fails to recognize a trailing slash.])
  63. REPLACE_OPEN=1
  64. ;;
  65. esac
  66. ;;
  67. esac
  68. dnl Replace open() for supporting the gnulib-defined fchdir() function,
  69. dnl to keep fchdir's bookkeeping up-to-date.
  70. m4_ifdef([gl_FUNC_FCHDIR], [
  71. if test $REPLACE_OPEN = 0; then
  72. gl_TEST_FCHDIR
  73. if test $HAVE_FCHDIR = 0; then
  74. REPLACE_OPEN=1
  75. fi
  76. fi
  77. ])
  78. dnl Replace open() for supporting the gnulib-defined O_NONBLOCK flag.
  79. m4_ifdef([gl_NONBLOCKING_IO], [
  80. if test $REPLACE_OPEN = 0; then
  81. gl_NONBLOCKING_IO
  82. if test $gl_cv_have_open_O_NONBLOCK != yes; then
  83. REPLACE_OPEN=1
  84. fi
  85. fi
  86. ])
  87. ])
  88. # Prerequisites of lib/open.c.
  89. AC_DEFUN([gl_PREREQ_OPEN],
  90. [
  91. AC_REQUIRE([gl_PROMOTED_TYPE_MODE_T])
  92. :
  93. ])