mkdir.m4 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # serial 17
  2. # Copyright (C) 2001, 2003-2004, 2006, 2008-2023 Free Software Foundation, Inc.
  3. # This file is free software; the Free Software Foundation
  4. # gives unlimited permission to copy and/or distribute it,
  5. # with or without modifications, as long as this notice is preserved.
  6. # On some systems, mkdir ("foo/", 0700) fails because of the trailing slash.
  7. # On others, mkdir ("foo/./", 0700) mistakenly succeeds.
  8. # On such systems, arrange to use a wrapper function.
  9. AC_DEFUN([gl_FUNC_MKDIR],
  10. [dnl
  11. AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
  12. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  13. AC_CHECK_HEADERS_ONCE([unistd.h])
  14. AC_CACHE_CHECK([whether mkdir handles trailing slash],
  15. [gl_cv_func_mkdir_trailing_slash_works],
  16. [rm -rf conftest.dir
  17. AC_RUN_IFELSE(
  18. [AC_LANG_PROGRAM([[
  19. #include <sys/types.h>
  20. #include <sys/stat.h>
  21. ]GL_MDA_DEFINES],
  22. [[return mkdir ("conftest.dir/", 0700);]])],
  23. [gl_cv_func_mkdir_trailing_slash_works=yes],
  24. [gl_cv_func_mkdir_trailing_slash_works=no],
  25. [case "$host_os" in
  26. # Guess yes on Linux systems.
  27. linux-* | linux) gl_cv_func_mkdir_trailing_slash_works="guessing yes" ;;
  28. # Guess yes on glibc systems.
  29. *-gnu* | gnu*) gl_cv_func_mkdir_trailing_slash_works="guessing yes" ;;
  30. # Guess yes on MSVC, no on mingw.
  31. mingw*) AC_EGREP_CPP([Known], [
  32. #ifdef _MSC_VER
  33. Known
  34. #endif
  35. ],
  36. [gl_cv_func_mkdir_trailing_slash_works="guessing yes"],
  37. [gl_cv_func_mkdir_trailing_slash_works="guessing no"])
  38. ;;
  39. # If we don't know, obey --enable-cross-guesses.
  40. *) gl_cv_func_mkdir_trailing_slash_works="$gl_cross_guess_normal" ;;
  41. esac
  42. ])
  43. rm -rf conftest.dir
  44. ])
  45. case "$gl_cv_func_mkdir_trailing_slash_works" in
  46. *yes) ;;
  47. *)
  48. REPLACE_MKDIR=1
  49. ;;
  50. esac
  51. AC_CACHE_CHECK([whether mkdir handles trailing dot],
  52. [gl_cv_func_mkdir_trailing_dot_works],
  53. [rm -rf conftest.dir
  54. AC_RUN_IFELSE(
  55. [AC_LANG_PROGRAM([[
  56. #include <sys/types.h>
  57. #include <sys/stat.h>
  58. ]GL_MDA_DEFINES],
  59. [[return !mkdir ("conftest.dir/./", 0700);]])],
  60. [gl_cv_func_mkdir_trailing_dot_works=yes],
  61. [gl_cv_func_mkdir_trailing_dot_works=no],
  62. [case "$host_os" in
  63. # Guess yes on glibc systems.
  64. *-gnu* | gnu*) gl_cv_func_mkdir_trailing_dot_works="guessing yes" ;;
  65. # Guess yes on musl systems.
  66. *-musl*) gl_cv_func_mkdir_trailing_dot_works="guessing yes" ;;
  67. # Guess no on native Windows.
  68. mingw*) gl_cv_func_mkdir_trailing_dot_works="guessing no" ;;
  69. # If we don't know, obey --enable-cross-guesses.
  70. *) gl_cv_func_mkdir_trailing_dot_works="$gl_cross_guess_normal" ;;
  71. esac
  72. ])
  73. rm -rf conftest.dir
  74. ]
  75. )
  76. case "$gl_cv_func_mkdir_trailing_dot_works" in
  77. *yes) ;;
  78. *)
  79. REPLACE_MKDIR=1
  80. AC_DEFINE([FUNC_MKDIR_DOT_BUG], [1], [Define to 1 if mkdir mistakenly
  81. creates a directory given with a trailing dot component.])
  82. ;;
  83. esac
  84. ])