mkdir.m4 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # serial 11
  2. # Copyright (C) 2001, 2003-2004, 2006, 2008-2017 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([AC_LANG_PROGRAM([[
  18. # include <sys/types.h>
  19. # include <sys/stat.h>
  20. ]], [return mkdir ("conftest.dir/", 0700);])],
  21. [gl_cv_func_mkdir_trailing_slash_works=yes],
  22. [gl_cv_func_mkdir_trailing_slash_works=no],
  23. [case "$host_os" in
  24. # Guess yes on glibc systems.
  25. *-gnu*) gl_cv_func_mkdir_trailing_slash_works="guessing yes" ;;
  26. # If we don't know, assume the worst.
  27. *) gl_cv_func_mkdir_trailing_slash_works="guessing no" ;;
  28. esac
  29. ])
  30. rm -rf conftest.dir
  31. ]
  32. )
  33. case "$gl_cv_func_mkdir_trailing_slash_works" in
  34. *yes) ;;
  35. *)
  36. REPLACE_MKDIR=1
  37. ;;
  38. esac
  39. AC_CACHE_CHECK([whether mkdir handles trailing dot],
  40. [gl_cv_func_mkdir_trailing_dot_works],
  41. [rm -rf conftest.dir
  42. AC_RUN_IFELSE([AC_LANG_PROGRAM([[
  43. # include <sys/types.h>
  44. # include <sys/stat.h>
  45. ]], [return !mkdir ("conftest.dir/./", 0700);])],
  46. [gl_cv_func_mkdir_trailing_dot_works=yes],
  47. [gl_cv_func_mkdir_trailing_dot_works=no],
  48. [case "$host_os" in
  49. # Guess yes on glibc systems.
  50. *-gnu*) gl_cv_func_mkdir_trailing_dot_works="guessing yes" ;;
  51. # If we don't know, assume the worst.
  52. *) gl_cv_func_mkdir_trailing_dot_works="guessing no" ;;
  53. esac
  54. ])
  55. rm -rf conftest.dir
  56. ]
  57. )
  58. case "$gl_cv_func_mkdir_trailing_dot_works" in
  59. *yes) ;;
  60. *)
  61. REPLACE_MKDIR=1
  62. AC_DEFINE([FUNC_MKDIR_DOT_BUG], [1], [Define to 1 if mkdir mistakenly
  63. creates a directory given with a trailing dot component.])
  64. ;;
  65. esac
  66. ])