1 # Check for fnmatch - serial 15. -*- coding: utf-8 -*-
3 # Copyright (C) 2000-2007, 2009-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 # Autoconf defines AC_FUNC_FNMATCH, but that is obsolescent.
9 # New applications should use the macros below instead.
11 # Request a POSIX compliant fnmatch function.
12 AC_DEFUN([gl_FUNC_FNMATCH_POSIX],
14 m4_divert_text([DEFAULTS], [gl_fnmatch_required=POSIX])
16 AC_REQUIRE([gl_FNMATCH_H])
17 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
18 gl_fnmatch_required_lowercase=`
19 echo $gl_fnmatch_required | LC_ALL=C tr '[[A-Z]]' '[[a-z]]'
21 AC_CHECK_FUNCS_ONCE([fnmatch])
22 if test $ac_cv_func_fnmatch = no; then
25 gl_fnmatch_cache_var="gl_cv_func_fnmatch_${gl_fnmatch_required_lowercase}"
26 AC_CACHE_CHECK([for working $gl_fnmatch_required fnmatch],
27 [$gl_fnmatch_cache_var],
28 [dnl Some versions of Solaris, SCO, and the GNU C Library
29 dnl have a broken or incompatible fnmatch.
30 dnl So we run a test program. If we are cross-compiling, take no chance.
31 dnl Thanks to John Oleynick, François Pinard, and Paul Eggert for this
33 if test $gl_fnmatch_required = GNU; then
37 gl_fnmatch_gnu_start='#if 0'
38 gl_fnmatch_gnu_end='#endif'
42 [[#include <fnmatch.h>
44 y (char const *pattern, char const *string, int flags)
46 return fnmatch (pattern, string, flags) == 0;
49 n (char const *pattern, char const *string, int flags)
51 return fnmatch (pattern, string, flags) == FNM_NOMATCH;
54 [[char const *Apat = 'A' < '\\\\' ? "[A-\\\\\\\\]" : "[\\\\\\\\-A]";
55 char const *apat = 'a' < '\\\\' ? "[a-\\\\\\\\]" : "[\\\\\\\\-a]";
56 static char const A_1[] = { 'A' - 1, 0 };
57 static char const A01[] = { 'A' + 1, 0 };
58 static char const a_1[] = { 'a' - 1, 0 };
59 static char const a01[] = { 'a' + 1, 0 };
60 static char const bs_1[] = { '\\\\' - 1, 0 };
61 static char const bs01[] = { '\\\\' + 1, 0 };
65 if (!y ("a*", "abc", 0))
67 if (!y ("[/b", "[/b", 0)) /*"]]"*/ /* glibc Bugzilla bug 12378 */
69 if (!n ("d*/*1", "d/s/1", FNM_PATHNAME))
71 if (!y ("a\\\\bc", "abc", 0))
73 if (!n ("a\\\\bc", "abc", FNM_NOESCAPE))
75 if (!y ("*x", ".x", 0))
77 if (!n ("*x", ".x", FNM_PERIOD))
79 if (!y (Apat, "\\\\", 0))
81 if (!y (Apat, "A", 0))
83 if (!y (apat, "\\\\", 0))
85 if (!y (apat, "a", 0))
87 if (!(n (Apat, A_1, 0) == ('A' < '\\\\')))
89 if (!(n (apat, a_1, 0) == ('a' < '\\\\')))
91 if (!(y (Apat, A01, 0) == ('A' < '\\\\')))
93 if (!(y (apat, a01, 0) == ('a' < '\\\\')))
95 if (!(y (Apat, bs_1, 0) == ('A' < '\\\\')))
97 if (!(y (apat, bs_1, 0) == ('a' < '\\\\')))
99 if (!(n (Apat, bs01, 0) == ('A' < '\\\\')))
101 if (!(n (apat, bs01, 0) == ('a' < '\\\\')))
103 $gl_fnmatch_gnu_start
104 if (!y ("xxXX", "xXxX", FNM_CASEFOLD))
106 if (!y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH))
108 if (!n ("d*/*1", "d/s/1", FNM_FILE_NAME))
110 if (!y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR))
112 if (!y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR))
114 if (!y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR))
119 [eval "$gl_fnmatch_cache_var=yes"],
120 [eval "$gl_fnmatch_cache_var=no"],
122 # Guess yes on musl systems.
123 *-musl*) eval "$gl_fnmatch_cache_var=\"guessing yes\"" ;;
124 # Guess no otherwise, even on glibc systems.
125 *) eval "$gl_fnmatch_cache_var=\"guessing no\"" ;;
129 eval "gl_fnmatch_result=\"\$$gl_fnmatch_cache_var\""
130 case "$gl_fnmatch_result" in
132 *) REPLACE_FNMATCH=1 ;;
135 if test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1; then
140 # Request a POSIX compliant fnmatch function with GNU extensions.
141 AC_DEFUN([gl_FUNC_FNMATCH_GNU],
143 m4_divert_text([INIT_PREPARE], [gl_fnmatch_required=GNU])
145 AC_REQUIRE([gl_FUNC_FNMATCH_POSIX])
148 AC_DEFUN([gl_PREREQ_FNMATCH],
150 dnl Prerequisites of lib/fnmatch.c.
151 AC_REQUIRE([AC_TYPE_MBSTATE_T])
152 AC_CHECK_FUNCS_ONCE([mbsrtowcs])