open-slash.m4 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # open-slash.m4 serial 2
  2. dnl Copyright (C) 2007-2023 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. dnl Tests whether open() and creat() recognize a trailing slash.
  7. dnl Sets gl_cv_func_open_slash.
  8. AC_DEFUN([gl_OPEN_TRAILING_SLASH_BUG],
  9. [
  10. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  11. dnl open("foo/") should not create a file when the file name has a
  12. dnl trailing slash. FreeBSD only has the problem on symlinks.
  13. AC_CHECK_FUNCS_ONCE([lstat])
  14. AC_CACHE_CHECK([whether open recognizes a trailing slash],
  15. [gl_cv_func_open_slash],
  16. [# Assume that if we have lstat, we can also check symlinks.
  17. if test $ac_cv_func_lstat = yes; then
  18. touch conftest.tmp
  19. ln -s conftest.tmp conftest.lnk
  20. fi
  21. AC_RUN_IFELSE(
  22. [AC_LANG_SOURCE([[
  23. #include <fcntl.h>
  24. #if HAVE_UNISTD_H
  25. # include <unistd.h>
  26. #endif
  27. ]GL_MDA_DEFINES[
  28. int main ()
  29. {
  30. int result = 0;
  31. #if HAVE_LSTAT
  32. if (open ("conftest.lnk/", O_RDONLY) != -1)
  33. result |= 1;
  34. #endif
  35. if (open ("conftest.sl/", O_CREAT, 0600) >= 0)
  36. result |= 2;
  37. return result;
  38. }]])],
  39. [gl_cv_func_open_slash=yes],
  40. [gl_cv_func_open_slash=no],
  41. [
  42. changequote(,)dnl
  43. case "$host_os" in
  44. freebsd* | aix* | hpux* | solaris2.[0-9] | solaris2.[0-9].*)
  45. gl_cv_func_open_slash="guessing no" ;;
  46. *)
  47. gl_cv_func_open_slash="guessing yes" ;;
  48. esac
  49. changequote([,])dnl
  50. ])
  51. rm -f conftest.sl conftest.tmp conftest.lnk
  52. ])
  53. case "$gl_cv_func_open_slash" in
  54. *no)
  55. AC_DEFINE([OPEN_TRAILING_SLASH_BUG], [1],
  56. [Define to 1 if open() fails to recognize a trailing slash.])
  57. ;;
  58. esac
  59. ])