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