1 # Check for fnmatch - serial 2.
3 # Copyright (C) 2000-2007, 2009 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 # _AC_FUNC_FNMATCH_IF([STANDARD = GNU | POSIX], [CACHE_VAR], [IF-TRUE], [IF-FALSE])
12 # -------------------------------------------------------------------------
13 # If a STANDARD compliant fnmatch is found, run IF-TRUE, otherwise
14 # IF-FALSE. Use CACHE_VAR.
15 AC_DEFUN([_AC_FUNC_FNMATCH_IF],
17 [for working $1 fnmatch],
19 [dnl Some versions of Solaris, SCO, and the GNU C Library
20 dnl have a broken or incompatible fnmatch.
21 dnl So we run a test program. If we are cross-compiling, take no chance.
22 dnl Thanks to John Oleynick, François Pinard, and Paul Eggert for this test.
25 [[#include <fnmatch.h>
27 y (char const *pattern, char const *string, int flags)
29 return fnmatch (pattern, string, flags) == 0;
32 n (char const *pattern, char const *string, int flags)
34 return fnmatch (pattern, string, flags) == FNM_NOMATCH;
37 [[char const *Apat = 'A' < '\\\\' ? "[A-\\\\\\\\]" : "[\\\\\\\\-A]";
38 char const *apat = 'a' < '\\\\' ? "[a-\\\\\\\\]" : "[\\\\\\\\-a]";
39 static char const A_1[] = { 'A' - 1, 0 };
40 static char const A01[] = { 'A' + 1, 0 };
41 static char const a_1[] = { 'a' - 1, 0 };
42 static char const a01[] = { 'a' + 1, 0 };
43 static char const bs_1[] = { '\\\\' - 1, 0 };
44 static char const bs01[] = { '\\\\' + 1, 0 };
48 && n ("d*/*1", "d/s/1", FNM_PATHNAME)
49 && y ("a\\\\bc", "abc", 0)
50 && n ("a\\\\bc", "abc", FNM_NOESCAPE)
52 && n ("*x", ".x", FNM_PERIOD)
53 && y (Apat, "\\\\", 0) && y (Apat, "A", 0)
54 && y (apat, "\\\\", 0) && y (apat, "a", 0)
55 && n (Apat, A_1, 0) == ('A' < '\\\\')
56 && n (apat, a_1, 0) == ('a' < '\\\\')
57 && y (Apat, A01, 0) == ('A' < '\\\\')
58 && y (apat, a01, 0) == ('a' < '\\\\')
59 && y (Apat, bs_1, 0) == ('A' < '\\\\')
60 && y (apat, bs_1, 0) == ('a' < '\\\\')
61 && n (Apat, bs01, 0) == ('A' < '\\\\')
62 && n (apat, bs01, 0) == ('a' < '\\\\')
63 && ]m4_if([$1], [GNU],
64 [y ("xxXX", "xXxX", FNM_CASEFOLD)
65 && y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH)
66 && n ("d*/*1", "d/s/1", FNM_FILE_NAME)
67 && y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR)
68 && y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR)
69 && y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR)],
74 AS_IF([test $$2 = yes], [$3], [$4])
75 ])# _AC_FUNC_FNMATCH_IF
80 # Prepare the replacement of fnmatch.
81 AC_DEFUN([_AC_LIBOBJ_FNMATCH],
82 [AC_REQUIRE([AC_FUNC_ALLOCA])dnl
83 AC_REQUIRE([AC_TYPE_MBSTATE_T])dnl
84 AC_CHECK_DECLS([isblank], [], [], [#include <ctype.h>])
85 AC_CHECK_FUNCS_ONCE([btowc isblank iswctype mbsrtowcs mempcpy wmemchr wmemcpy wmempcpy])
86 AC_CHECK_HEADERS_ONCE([wctype.h])
89 ])# _AC_LIBOBJ_FNMATCH
92 AC_DEFUN([gl_FUNC_FNMATCH_POSIX],
95 _AC_FUNC_FNMATCH_IF([POSIX], [ac_cv_func_fnmatch_posix],
96 [rm -f lib/fnmatch.h],
98 if test $ac_cv_func_fnmatch_posix != yes; then
99 dnl We must choose a different name for our function, since on ELF systems
100 dnl a broken fnmatch() in libc.so would override our fnmatch() if it is
101 dnl compiled into a shared library.
102 AC_DEFINE([fnmatch], [posix_fnmatch],
103 [Define to a replacement function name for fnmatch().])
105 AC_SUBST([FNMATCH_H])
109 AC_DEFUN([gl_FUNC_FNMATCH_GNU],
111 dnl Persuade glibc <fnmatch.h> to declare FNM_CASEFOLD etc.
112 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
115 _AC_FUNC_FNMATCH_IF([GNU], [ac_cv_func_fnmatch_gnu],
116 [rm -f lib/fnmatch.h],
117 [_AC_LIBOBJ_FNMATCH])
118 if test $ac_cv_func_fnmatch_gnu != yes; then
119 dnl We must choose a different name for our function, since on ELF systems
120 dnl a broken fnmatch() in libc.so would override our fnmatch() if it is
121 dnl compiled into a shared library.
122 AC_DEFINE([fnmatch], [gnu_fnmatch],
123 [Define to a replacement function name for fnmatch().])
125 AC_SUBST([FNMATCH_H])