| 1 |
# fnmatch.m4 |
| 2 |
# serial 21 |
| 3 |
dnl Copyright (C) 2000-2007, 2009-2024 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
# Check for fnmatch |
| 10 |
|
| 11 |
# Autoconf defines AC_FUNC_FNMATCH, but that is obsolescent. |
| 12 |
# New applications should use the macros below instead. |
| 13 |
|
| 14 |
# Request a POSIX compliant fnmatch function. |
| 15 |
AC_DEFUN([gl_FUNC_FNMATCH_POSIX], |
| 16 |
[ |
| 17 |
m4_divert_text([DEFAULTS], [gl_fnmatch_required=POSIX]) |
| 18 |
|
| 19 |
AC_REQUIRE([gl_FNMATCH_H]) |
| 20 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 21 |
gl_fnmatch_required_lowercase=` |
| 22 |
echo $gl_fnmatch_required | LC_ALL=C tr '[[A-Z]]' '[[a-z]]' |
| 23 |
` |
| 24 |
AC_CHECK_FUNCS_ONCE([fnmatch]) |
| 25 |
if test $ac_cv_func_fnmatch = no; then |
| 26 |
HAVE_FNMATCH=0 |
| 27 |
else |
| 28 |
gl_fnmatch_cache_var="gl_cv_func_fnmatch_${gl_fnmatch_required_lowercase}" |
| 29 |
AC_CACHE_CHECK([for working $gl_fnmatch_required fnmatch], |
| 30 |
[$gl_fnmatch_cache_var], |
| 31 |
[dnl Some versions of Solaris, SCO, and the GNU C Library |
| 32 |
dnl have a broken or incompatible fnmatch. |
| 33 |
dnl So we run a test program. If we are cross-compiling, take no chance. |
| 34 |
dnl Thanks to John Oleynick, François Pinard, and Paul Eggert for this |
| 35 |
dnl test. |
| 36 |
if test $gl_fnmatch_required = GNU; then |
| 37 |
gl_fnmatch_gnu_start= |
| 38 |
gl_fnmatch_gnu_end= |
| 39 |
else |
| 40 |
gl_fnmatch_gnu_start='#if 0' |
| 41 |
gl_fnmatch_gnu_end='#endif' |
| 42 |
fi |
| 43 |
AC_RUN_IFELSE( |
| 44 |
[AC_LANG_PROGRAM( |
| 45 |
[[#include <fnmatch.h> |
| 46 |
#include <locale.h> |
| 47 |
#include <stddef.h> |
| 48 |
static int |
| 49 |
y (char const *pattern, char const *string, int flags) |
| 50 |
{ |
| 51 |
return fnmatch (pattern, string, flags) == 0; |
| 52 |
} |
| 53 |
static int |
| 54 |
n (char const *pattern, char const *string, int flags) |
| 55 |
{ |
| 56 |
return fnmatch (pattern, string, flags) == FNM_NOMATCH; |
| 57 |
} |
| 58 |
]], |
| 59 |
[[char const *Apat = 'A' < '\\\\' ? "[A-\\\\\\\\]" : "[\\\\\\\\-A]"; |
| 60 |
char const *apat = 'a' < '\\\\' ? "[a-\\\\\\\\]" : "[\\\\\\\\-a]"; |
| 61 |
static char const A_1[] = { 'A' - 1, 0 }; |
| 62 |
static char const A01[] = { 'A' + 1, 0 }; |
| 63 |
static char const a_1[] = { 'a' - 1, 0 }; |
| 64 |
static char const a01[] = { 'a' + 1, 0 }; |
| 65 |
static char const bs_1[] = { '\\\\' - 1, 0 }; |
| 66 |
static char const bs01[] = { '\\\\' + 1, 0 }; |
| 67 |
int result = 0; |
| 68 |
/* ==== Start of tests in the "C" locale ==== */ |
| 69 |
/* These are sanity checks. They all succeed on current platforms. */ |
| 70 |
if (!n ("a*", "", 0)) |
| 71 |
return 1; |
| 72 |
if (!y ("a*", "abc", 0)) |
| 73 |
return 1; |
| 74 |
if (!n ("d*/*1", "d/s/1", FNM_PATHNAME)) |
| 75 |
return 1; |
| 76 |
if (!y ("a\\\\bc", "abc", 0)) |
| 77 |
return 1; |
| 78 |
if (!n ("a\\\\bc", "abc", FNM_NOESCAPE)) |
| 79 |
return 1; |
| 80 |
if (!y ("*x", ".x", 0)) |
| 81 |
return 1; |
| 82 |
if (!n ("*x", ".x", FNM_PERIOD)) |
| 83 |
return 1; |
| 84 |
/* glibc bug <https://sourceware.org/bugzilla/show_bug.cgi?id=361> |
| 85 |
exists in glibc 2.3.3, fixed in glibc 2.5. */ |
| 86 |
if (!y (Apat, "\\\\", 0)) |
| 87 |
result |= 2; |
| 88 |
if (!y (Apat, "A", 0)) |
| 89 |
result |= 2; |
| 90 |
if (!y (apat, "\\\\", 0)) |
| 91 |
result |= 2; |
| 92 |
if (!y (apat, "a", 0)) |
| 93 |
result |= 2; |
| 94 |
if (!(n (Apat, A_1, 0) == ('A' < '\\\\'))) |
| 95 |
result |= 2; |
| 96 |
if (!(n (apat, a_1, 0) == ('a' < '\\\\'))) |
| 97 |
result |= 2; |
| 98 |
if (!(y (Apat, A01, 0) == ('A' < '\\\\'))) |
| 99 |
result |= 2; |
| 100 |
if (!(y (apat, a01, 0) == ('a' < '\\\\'))) |
| 101 |
result |= 2; |
| 102 |
if (!(y (Apat, bs_1, 0) == ('A' < '\\\\'))) |
| 103 |
result |= 2; |
| 104 |
if (!(y (apat, bs_1, 0) == ('a' < '\\\\'))) |
| 105 |
result |= 2; |
| 106 |
if (!(n (Apat, bs01, 0) == ('A' < '\\\\'))) |
| 107 |
result |= 2; |
| 108 |
if (!(n (apat, bs01, 0) == ('a' < '\\\\'))) |
| 109 |
result |= 2; |
| 110 |
/* glibc bug <https://sourceware.org/bugzilla/show_bug.cgi?id=12378> |
| 111 |
exists in glibc 2.12, fixed in glibc 2.13. */ |
| 112 |
if (!y ("[/b", "[/b", 0)) /*"]]"*/ |
| 113 |
result |= 4; |
| 114 |
/* glibc bug <https://sourceware.org/bugzilla/show_bug.cgi?id=17062> |
| 115 |
is fixed in glibc 2.20. |
| 116 |
glibc bugs <https://sourceware.org/bugzilla/show_bug.cgi?id=18032> |
| 117 |
<https://sourceware.org/bugzilla/show_bug.cgi?id=18036> |
| 118 |
are fixed in glibc 2.22. |
| 119 |
These bugs are not easy to test for reliably (without mmap), |
| 120 |
therefore test the glibc version. */ |
| 121 |
#if defined __GLIBC__ |
| 122 |
if (__GLIBC__ == 2 && __GLIBC_MINOR__ < 22) |
| 123 |
result |= 4; |
| 124 |
#endif |
| 125 |
/* This test fails on FreeBSD 13.2, NetBSD 10.0, Cygwin 3.4.6. */ |
| 126 |
if (!y ("[[:alnum:]]", "a", 0)) |
| 127 |
result |= 8; |
| 128 |
$gl_fnmatch_gnu_start /* ==== Start of GNU extensions tests ==== */ |
| 129 |
/* Sanity checks, mainly to check the presence of the FNM_* macros. */ |
| 130 |
if (!y ("xxXX", "xXxX", FNM_CASEFOLD)) |
| 131 |
result |= 64; |
| 132 |
if (!y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH)) |
| 133 |
result |= 64; |
| 134 |
if (!n ("d*/*1", "d/s/1", FNM_FILE_NAME)) |
| 135 |
result |= 64; |
| 136 |
if (!y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR)) |
| 137 |
result |= 64; |
| 138 |
if (!y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR)) |
| 139 |
result |= 64; |
| 140 |
if (!y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR)) |
| 141 |
result |= 64; |
| 142 |
$gl_fnmatch_gnu_end /* ==== End of GNU extensions tests ==== */ |
| 143 |
/* ==== End of tests in the "C" locale ==== */ |
| 144 |
/* ==== Start of tests that require a specific locale ==== */ |
| 145 |
/* This test fails on Solaris 11.4. */ |
| 146 |
if (setlocale (LC_ALL, "en_US.UTF-8") != NULL) |
| 147 |
{ |
| 148 |
if (!n ("[!a-z]", "", 0)) |
| 149 |
result |= 16; |
| 150 |
} |
| 151 |
/* This test fails on NetBSD 10.0, Android 13. */ |
| 152 |
if (setlocale (LC_ALL, "C.UTF-8") != NULL) |
| 153 |
{ |
| 154 |
if (!y ("x?y", "x\\303\\274y", 0)) |
| 155 |
result |= 32; |
| 156 |
} |
| 157 |
/* ==== End of tests that require a specific locale ==== */ |
| 158 |
return result; |
| 159 |
]])], |
| 160 |
[eval "$gl_fnmatch_cache_var=yes"], |
| 161 |
[eval "$gl_fnmatch_cache_var=no"], |
| 162 |
[case "$host_os" in |
| 163 |
# Guess yes on musl systems. |
| 164 |
*-musl* | midipix*) eval "$gl_fnmatch_cache_var=\"guessing yes\"" ;; |
| 165 |
# Guess no otherwise, even on glibc systems. |
| 166 |
*) eval "$gl_fnmatch_cache_var=\"guessing no\"" ;; |
| 167 |
esac |
| 168 |
]) |
| 169 |
]) |
| 170 |
eval "gl_fnmatch_result=\"\$$gl_fnmatch_cache_var\"" |
| 171 |
case "$gl_fnmatch_result" in |
| 172 |
*yes) ;; |
| 173 |
*) REPLACE_FNMATCH=1 ;; |
| 174 |
esac |
| 175 |
dnl On AIX 7.2 in 32-bit mode, fnmatch()'s only POSIX compliance problem is |
| 176 |
dnl that is does not support characters outside the Unicode BMP correctly. |
| 177 |
dnl Test case: fnmatch ("x?y", "x\360\237\230\213y", 0) == 0 |
| 178 |
dnl This is due to wchar_t being only 16 bits wide. |
| 179 |
AC_REQUIRE([gl_UCHAR_H]) |
| 180 |
if test $SMALL_WCHAR_T = 1; then |
| 181 |
case "$host_os" in |
| 182 |
cygwin*) |
| 183 |
dnl On Cygwin < 3.5.0, the above $gl_fnmatch_result came out as 'no', |
| 184 |
dnl On Cygwin >= 3.5.0, fnmatch supports all Unicode characters, |
| 185 |
dnl despite wchar_t being only 16 bits wide (because internally it |
| 186 |
dnl works on wint_t values). |
| 187 |
;; |
| 188 |
*) |
| 189 |
REPLACE_FNMATCH=1 |
| 190 |
;; |
| 191 |
esac |
| 192 |
fi |
| 193 |
fi |
| 194 |
if test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1; then |
| 195 |
gl_REPLACE_FNMATCH_H |
| 196 |
fi |
| 197 |
]) |
| 198 |
|
| 199 |
# Request a POSIX compliant fnmatch function with GNU extensions. |
| 200 |
AC_DEFUN([gl_FUNC_FNMATCH_GNU], |
| 201 |
[ |
| 202 |
m4_divert_text([INIT_PREPARE], [gl_fnmatch_required=GNU]) |
| 203 |
|
| 204 |
AC_REQUIRE([gl_FUNC_FNMATCH_POSIX]) |
| 205 |
]) |
| 206 |
|
| 207 |
AC_DEFUN([gl_PREREQ_FNMATCH], |
| 208 |
[ |
| 209 |
dnl Prerequisites of lib/fnmatch.c. |
| 210 |
AC_REQUIRE([AC_TYPE_MBSTATE_T]) |
| 211 |
AC_CHECK_FUNCS_ONCE([mbsrtowcs]) |
| 212 |
]) |