open.m4 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # open.m4 serial 8
  2. dnl Copyright (C) 2007-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. AC_DEFUN([gl_FUNC_OPEN],
  7. [
  8. AC_REQUIRE([AC_CANONICAL_HOST])
  9. case "$host_os" in
  10. mingw* | pw*)
  11. gl_REPLACE_OPEN
  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_TRY_RUN([
  25. #include <fcntl.h>
  26. #if HAVE_UNISTD_H
  27. # include <unistd.h>
  28. #endif
  29. int main ()
  30. {
  31. #if HAVE_LSTAT
  32. if (open ("conftest.lnk/", O_RDONLY) != -1) return 2;
  33. #endif
  34. return open ("conftest.sl/", O_CREAT, 0600) >= 0;
  35. }], [gl_cv_func_open_slash=yes], [gl_cv_func_open_slash=no],
  36. [
  37. changequote(,)dnl
  38. case "$host_os" in
  39. freebsd*) gl_cv_func_open_slash="guessing no" ;;
  40. solaris2.[0-9]*) gl_cv_func_open_slash="guessing no" ;;
  41. hpux*) gl_cv_func_open_slash="guessing no" ;;
  42. *) gl_cv_func_open_slash="guessing yes" ;;
  43. esac
  44. changequote([,])dnl
  45. ])
  46. rm -f conftest.sl conftest.tmp conftest.lnk
  47. ])
  48. case "$gl_cv_func_open_slash" in
  49. *no)
  50. AC_DEFINE([OPEN_TRAILING_SLASH_BUG], [1],
  51. [Define to 1 if open() fails to recognize a trailing slash.])
  52. gl_REPLACE_OPEN
  53. ;;
  54. esac
  55. ;;
  56. esac
  57. ])
  58. AC_DEFUN([gl_REPLACE_OPEN],
  59. [
  60. AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
  61. REPLACE_OPEN=1
  62. AC_LIBOBJ([open])
  63. gl_PREREQ_OPEN
  64. ])
  65. # Prerequisites of lib/open.c.
  66. AC_DEFUN([gl_PREREQ_OPEN],
  67. [
  68. AC_REQUIRE([AC_C_INLINE])
  69. AC_REQUIRE([gl_PROMOTED_TYPE_MODE_T])
  70. :
  71. ])