open.m4 2.5 KB

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