1 # Check for fnmatch - serial 13. -*- coding: utf-8 -*-
3 # Copyright (C) 2000-2007, 2009-2019 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 gl_fnmatch_required_lowercase=`
18 echo $gl_fnmatch_required | LC_ALL=C tr '[[A-Z]]' '[[a-z]]'
20 AC_CHECK_FUNCS_ONCE([fnmatch])
21 if test $ac_cv_func_fnmatch = no; then
24 gl_fnmatch_cache_var="gl_cv_func_fnmatch_${gl_fnmatch_required_lowercase}"
25 AC_CACHE_CHECK([for working $gl_fnmatch_required fnmatch],
26 [$gl_fnmatch_cache_var],
27 [dnl Some versions of Solaris, SCO, and the GNU C Library
28 dnl have a broken or incompatible fnmatch.
29 dnl So we run a test program. If we are cross-compiling, take no chance.
30 dnl Thanks to John Oleynick, François Pinard, and Paul Eggert for this
32 if test $gl_fnmatch_required = GNU; then
36 gl_fnmatch_gnu_start='#if 0'
37 gl_fnmatch_gnu_end='#endif'
41 [[#include <fnmatch.h>
43 y (char const *pattern, char const *string, int flags)
45 return fnmatch (pattern, string, flags) == 0;
48 n (char const *pattern, char const *string, int flags)
50 return fnmatch (pattern, string, flags) == FNM_NOMATCH;
53 [[char const *Apat = 'A' < '\\\\' ? "[A-\\\\\\\\]" : "[\\\\\\\\-A]";
54 char const *apat = 'a' < '\\\\' ? "[a-\\\\\\\\]" : "[\\\\\\\\-a]";
55 static char const A_1[] = { 'A' - 1, 0 };
56 static char const A01[] = { 'A' + 1, 0 };
57 static char const a_1[] = { 'a' - 1, 0 };
58 static char const a01[] = { 'a' + 1, 0 };
59 static char const bs_1[] = { '\\\\' - 1, 0 };
60 static char const bs01[] = { '\\\\' + 1, 0 };
64 if (!y ("a*", "abc", 0))
66 if (!y ("[/b", "[/b", 0)) /*"]]"*/ /* glibc Bugzilla bug 12378 */
68 if (!n ("d*/*1", "d/s/1", FNM_PATHNAME))
70 if (!y ("a\\\\bc", "abc", 0))
72 if (!n ("a\\\\bc", "abc", FNM_NOESCAPE))
74 if (!y ("*x", ".x", 0))
76 if (!n ("*x", ".x", FNM_PERIOD))
78 if (!y (Apat, "\\\\", 0))
80 if (!y (Apat, "A", 0))
82 if (!y (apat, "\\\\", 0))
84 if (!y (apat, "a", 0))
86 if (!(n (Apat, A_1, 0) == ('A' < '\\\\')))
88 if (!(n (apat, a_1, 0) == ('a' < '\\\\')))
90 if (!(y (Apat, A01, 0) == ('A' < '\\\\')))
92 if (!(y (apat, a01, 0) == ('a' < '\\\\')))
94 if (!(y (Apat, bs_1, 0) == ('A' < '\\\\')))
96 if (!(y (apat, bs_1, 0) == ('a' < '\\\\')))
98 if (!(n (Apat, bs01, 0) == ('A' < '\\\\')))
100 if (!(n (apat, bs01, 0) == ('a' < '\\\\')))
102 $gl_fnmatch_gnu_start
103 if (!y ("xxXX", "xXxX", FNM_CASEFOLD))
105 if (!y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH))
107 if (!n ("d*/*1", "d/s/1", FNM_FILE_NAME))
109 if (!y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR))
111 if (!y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR))
113 if (!y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR))
118 [eval "$gl_fnmatch_cache_var=yes"],
119 [eval "$gl_fnmatch_cache_var=no"],
120 [eval "$gl_fnmatch_cache_var=\"guessing no\""])
122 eval "gl_fnmatch_result=\"\$$gl_fnmatch_cache_var\""
123 if test "$gl_fnmatch_result" != yes; then
127 if test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1; then
132 # Request a POSIX compliant fnmatch function with GNU extensions.
133 AC_DEFUN([gl_FUNC_FNMATCH_GNU],
135 m4_divert_text([INIT_PREPARE], [gl_fnmatch_required=GNU])
137 AC_REQUIRE([gl_FUNC_FNMATCH_POSIX])
140 AC_DEFUN([gl_PREREQ_FNMATCH],
142 dnl Prerequisites of lib/fnmatch.c.
143 AC_REQUIRE([AC_TYPE_MBSTATE_T])
144 AC_CHECK_DECLS([isblank], [], [], [[#include <ctype.h>]])
145 AC_CHECK_FUNCS_ONCE([btowc isblank iswctype mbsrtowcs mempcpy wmemchr wmemcpy wmempcpy])
146 AC_CHECK_HEADERS_ONCE([wctype.h])