3 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
5 # This file is free software; the Free Software Foundation
6 # gives unlimited permission to copy and/or distribute it,
7 # with or without modifications, as long as this notice is preserved.
9 # Autoconf defines AC_FUNC_FNMATCH, but that is obsolescent.
10 # New applications should use the macros below instead.
12 # _AC_FUNC_FNMATCH_IF(STANDARD = GNU | POSIX, CACHE_VAR, IF-TRUE, IF-FALSE)
13 # -------------------------------------------------------------------------
14 # If a STANDARD compliant fnmatch is found, run IF-TRUE, otherwise
15 # IF-FALSE. Use CACHE_VAR.
16 AC_DEFUN([_AC_FUNC_FNMATCH_IF],
18 [for working $1 fnmatch],
20 [dnl Some versions of Solaris, SCO, and the GNU C Library
21 dnl have a broken or incompatible fnmatch.
22 dnl So we run a test program. If we are cross-compiling, take no chance.
23 dnl Thanks to John Oleynick, François Pinard, and Paul Eggert for this test.
26 [[#include <fnmatch.h>
28 y (char const *pattern, char const *string, int flags)
30 return fnmatch (pattern, string, flags) == 0;
33 n (char const *pattern, char const *string, int flags)
35 return fnmatch (pattern, string, flags) == FNM_NOMATCH;
38 [[char const *Apat = 'A' < '\\\\' ? "[A-\\\\\\\\]" : "[\\\\\\\\-A]";
39 char const *apat = 'a' < '\\\\' ? "[a-\\\\\\\\]" : "[\\\\\\\\-a]";
40 static char const A_1[] = { 'A' - 1, 0 };
41 static char const A01[] = { 'A' + 1, 0 };
42 static char const a_1[] = { 'a' - 1, 0 };
43 static char const a01[] = { 'a' + 1, 0 };
44 static char const bs_1[] = { '\\\\' - 1, 0 };
45 static char const bs01[] = { '\\\\' + 1, 0 };
49 && n ("d*/*1", "d/s/1", FNM_PATHNAME)
50 && y ("a\\\\bc", "abc", 0)
51 && n ("a\\\\bc", "abc", FNM_NOESCAPE)
53 && n ("*x", ".x", FNM_PERIOD)
54 && y (Apat, "\\\\", 0) && y (Apat, "A", 0)
55 && y (apat, "\\\\", 0) && y (apat, "a", 0)
56 && n (Apat, A_1, 0) == ('A' < '\\\\')
57 && n (apat, a_1, 0) == ('a' < '\\\\')
58 && y (Apat, A01, 0) == ('A' < '\\\\')
59 && y (apat, a01, 0) == ('a' < '\\\\')
60 && y (Apat, bs_1, 0) == ('A' < '\\\\')
61 && y (apat, bs_1, 0) == ('a' < '\\\\')
62 && n (Apat, bs01, 0) == ('A' < '\\\\')
63 && n (apat, bs01, 0) == ('a' < '\\\\')
64 && ]m4_if([$1], [GNU],
65 [y ("xxXX", "xXxX", FNM_CASEFOLD)
66 && y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH)
67 && n ("d*/*1", "d/s/1", FNM_FILE_NAME)
68 && y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR)
69 && y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR)
70 && y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR)],
75 AS_IF([test $$2 = yes], [$3], [$4])
76 ])# _AC_FUNC_FNMATCH_IF
81 # Prepare the replacement of fnmatch.
82 AC_DEFUN([_AC_LIBOBJ_FNMATCH],
83 [AC_REQUIRE([AC_FUNC_ALLOCA])dnl
84 AC_REQUIRE([AC_TYPE_MBSTATE_T])dnl
85 AC_CHECK_DECLS([isblank], [], [], [#include <ctype.h>])
86 AC_CHECK_FUNCS([btowc iswctype mbsrtowcs mempcpy wmemchr wmemcpy wmempcpy])
87 AC_CHECK_HEADERS([wctype.h])
90 ])# _AC_LIBOBJ_FNMATCH
93 AC_DEFUN([gl_FUNC_FNMATCH_POSIX],
96 _AC_FUNC_FNMATCH_IF([POSIX], [ac_cv_func_fnmatch_posix],
97 [rm -f lib/fnmatch.h],
99 if test $ac_cv_func_fnmatch_posix != yes; then
100 dnl We must choose a different name for our function, since on ELF systems
101 dnl a broken fnmatch() in libc.so would override our fnmatch() if it is
102 dnl compiled into a shared library.
103 AC_DEFINE([fnmatch], [posix_fnmatch],
104 [Define to a replacement function name for fnmatch().])
106 AC_SUBST([FNMATCH_H])
110 AC_DEFUN([gl_FUNC_FNMATCH_GNU],
112 dnl Persuade glibc <fnmatch.h> to declare FNM_CASEFOLD etc.
113 AC_REQUIRE([AC_GNU_SOURCE])
116 _AC_FUNC_FNMATCH_IF([GNU], [ac_cv_func_fnmatch_gnu],
117 [rm -f lib/fnmatch.h],
118 [_AC_LIBOBJ_FNMATCH])
119 if test $ac_cv_func_fnmatch_gnu != yes; then
120 dnl We must choose a different name for our function, since on ELF systems
121 dnl a broken fnmatch() in libc.so would override our fnmatch() if it is
122 dnl compiled into a shared library.
123 AC_DEFINE([fnmatch], [gnu_fnmatch],
124 [Define to a replacement function name for fnmatch().])
126 AC_SUBST([FNMATCH_H])