]> git.cworth.org Git - tar/blob - m4/fnmatch.m4
Imported Upstream version 1.22
[tar] / m4 / fnmatch.m4
1 # Check for fnmatch - serial 2.
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.
7
8 # Autoconf defines AC_FUNC_FNMATCH, but that is obsolescent.
9 # New applications should use the macros below instead.
10
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],
16 [AC_CACHE_CHECK(
17    [for working $1 fnmatch],
18    [$2],
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.
23    AC_RUN_IFELSE(
24       [AC_LANG_PROGRAM(
25          [[#include <fnmatch.h>
26            static int
27            y (char const *pattern, char const *string, int flags)
28            {
29              return fnmatch (pattern, string, flags) == 0;
30            }
31            static int
32            n (char const *pattern, char const *string, int flags)
33            {
34              return fnmatch (pattern, string, flags) == FNM_NOMATCH;
35            }
36          ]],
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 };
45            return
46             !(n ("a*", "", 0)
47               && y ("a*", "abc", 0)
48               && n ("d*/*1", "d/s/1", FNM_PATHNAME)
49               && y ("a\\\\bc", "abc", 0)
50               && n ("a\\\\bc", "abc", FNM_NOESCAPE)
51               && y ("*x", ".x", 0)
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)],
70                    1))[;]])],
71       [$2=yes],
72       [$2=no],
73       [$2=cross])])
74 AS_IF([test $$2 = yes], [$3], [$4])
75 ])# _AC_FUNC_FNMATCH_IF
76
77
78 # _AC_LIBOBJ_FNMATCH
79 # ------------------
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])
87 AC_LIBOBJ([fnmatch])
88 FNMATCH_H=fnmatch.h
89 ])# _AC_LIBOBJ_FNMATCH
90
91
92 AC_DEFUN([gl_FUNC_FNMATCH_POSIX],
93 [
94   FNMATCH_H=
95   _AC_FUNC_FNMATCH_IF([POSIX], [ac_cv_func_fnmatch_posix],
96                       [rm -f lib/fnmatch.h],
97                       [_AC_LIBOBJ_FNMATCH])
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().])
104   fi
105   AC_SUBST([FNMATCH_H])
106 ])
107
108
109 AC_DEFUN([gl_FUNC_FNMATCH_GNU],
110 [
111   dnl Persuade glibc <fnmatch.h> to declare FNM_CASEFOLD etc.
112   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
113
114   FNMATCH_H=
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().])
124   fi
125   AC_SUBST([FNMATCH_H])
126 ])