| 1 | # Check for fnmatch - serial 9. |
| 2 | |
| 3 | # Copyright (C) 2000-2007, 2009-2012 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 | # Request a POSIX compliant fnmatch function. |
| 12 | AC_DEFUN([gl_FUNC_FNMATCH_POSIX], |
| 13 | [ |
| 14 | m4_divert_text([DEFAULTS], [gl_fnmatch_required=POSIX]) |
| 15 | |
| 16 | dnl Persuade glibc <fnmatch.h> to declare FNM_CASEFOLD etc. |
| 17 | dnl This is only needed if gl_fnmatch_required = GNU. It would be possible |
| 18 | dnl to avoid this dependency for gl_FUNC_FNMATCH_POSIX by putting |
| 19 | dnl gl_FUNC_FNMATCH_GNU into a separate .m4 file. |
| 20 | AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) |
| 21 | |
| 22 | FNMATCH_H= |
| 23 | gl_fnmatch_required_lowercase=` |
| 24 | echo $gl_fnmatch_required | LC_ALL=C tr '[[A-Z]]' '[[a-z]]' |
| 25 | ` |
| 26 | gl_fnmatch_cache_var="gl_cv_func_fnmatch_${gl_fnmatch_required_lowercase}" |
| 27 | AC_CACHE_CHECK([for working $gl_fnmatch_required fnmatch], |
| 28 | [$gl_fnmatch_cache_var], |
| 29 | [dnl Some versions of Solaris, SCO, and the GNU C Library |
| 30 | dnl have a broken or incompatible fnmatch. |
| 31 | dnl So we run a test program. If we are cross-compiling, take no chance. |
| 32 | dnl Thanks to John Oleynick, François Pinard, and Paul Eggert for this |
| 33 | dnl test. |
| 34 | if test $gl_fnmatch_required = GNU; then |
| 35 | gl_fnmatch_gnu_start= |
| 36 | gl_fnmatch_gnu_end= |
| 37 | else |
| 38 | gl_fnmatch_gnu_start='#if 0' |
| 39 | gl_fnmatch_gnu_end='#endif' |
| 40 | fi |
| 41 | AC_RUN_IFELSE( |
| 42 | [AC_LANG_PROGRAM( |
| 43 | [[#include <fnmatch.h> |
| 44 | static int |
| 45 | y (char const *pattern, char const *string, int flags) |
| 46 | { |
| 47 | return fnmatch (pattern, string, flags) == 0; |
| 48 | } |
| 49 | static int |
| 50 | n (char const *pattern, char const *string, int flags) |
| 51 | { |
| 52 | return fnmatch (pattern, string, flags) == FNM_NOMATCH; |
| 53 | } |
| 54 | ]], |
| 55 | [[char const *Apat = 'A' < '\\\\' ? "[A-\\\\\\\\]" : "[\\\\\\\\-A]"; |
| 56 | char const *apat = 'a' < '\\\\' ? "[a-\\\\\\\\]" : "[\\\\\\\\-a]"; |
| 57 | static char const A_1[] = { 'A' - 1, 0 }; |
| 58 | static char const A01[] = { 'A' + 1, 0 }; |
| 59 | static char const a_1[] = { 'a' - 1, 0 }; |
| 60 | static char const a01[] = { 'a' + 1, 0 }; |
| 61 | static char const bs_1[] = { '\\\\' - 1, 0 }; |
| 62 | static char const bs01[] = { '\\\\' + 1, 0 }; |
| 63 | int result = 0; |
| 64 | if (!n ("a*", "", 0)) |
| 65 | return 1; |
| 66 | if (!y ("a*", "abc", 0)) |
| 67 | return 1; |
| 68 | if (!y ("[/b", "[/b", 0)) /*"]]"*/ /* glibc Bugzilla bug 12378 */ |
| 69 | return 1; |
| 70 | if (!n ("d*/*1", "d/s/1", FNM_PATHNAME)) |
| 71 | return 2; |
| 72 | if (!y ("a\\\\bc", "abc", 0)) |
| 73 | return 3; |
| 74 | if (!n ("a\\\\bc", "abc", FNM_NOESCAPE)) |
| 75 | return 3; |
| 76 | if (!y ("*x", ".x", 0)) |
| 77 | return 4; |
| 78 | if (!n ("*x", ".x", FNM_PERIOD)) |
| 79 | return 4; |
| 80 | if (!y (Apat, "\\\\", 0)) |
| 81 | return 5; |
| 82 | if (!y (Apat, "A", 0)) |
| 83 | return 5; |
| 84 | if (!y (apat, "\\\\", 0)) |
| 85 | return 5; |
| 86 | if (!y (apat, "a", 0)) |
| 87 | return 5; |
| 88 | if (!(n (Apat, A_1, 0) == ('A' < '\\\\'))) |
| 89 | return 5; |
| 90 | if (!(n (apat, a_1, 0) == ('a' < '\\\\'))) |
| 91 | return 5; |
| 92 | if (!(y (Apat, A01, 0) == ('A' < '\\\\'))) |
| 93 | return 5; |
| 94 | if (!(y (apat, a01, 0) == ('a' < '\\\\'))) |
| 95 | return 5; |
| 96 | if (!(y (Apat, bs_1, 0) == ('A' < '\\\\'))) |
| 97 | return 5; |
| 98 | if (!(y (apat, bs_1, 0) == ('a' < '\\\\'))) |
| 99 | return 5; |
| 100 | if (!(n (Apat, bs01, 0) == ('A' < '\\\\'))) |
| 101 | return 5; |
| 102 | if (!(n (apat, bs01, 0) == ('a' < '\\\\'))) |
| 103 | return 5; |
| 104 | $gl_fnmatch_gnu_start |
| 105 | if (!y ("xxXX", "xXxX", FNM_CASEFOLD)) |
| 106 | result |= 8; |
| 107 | if (!y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH)) |
| 108 | result |= 16; |
| 109 | if (!n ("d*/*1", "d/s/1", FNM_FILE_NAME)) |
| 110 | result |= 32; |
| 111 | if (!y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR)) |
| 112 | result |= 64; |
| 113 | if (!y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR)) |
| 114 | result |= 64; |
| 115 | if (!y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR)) |
| 116 | result |= 64; |
| 117 | $gl_fnmatch_gnu_end |
| 118 | return result; |
| 119 | ]])], |
| 120 | [eval "$gl_fnmatch_cache_var=yes"], |
| 121 | [eval "$gl_fnmatch_cache_var=no"], |
| 122 | [eval "$gl_fnmatch_cache_var=\"guessing no\""]) |
| 123 | ]) |
| 124 | eval "gl_fnmatch_result=\"\$$gl_fnmatch_cache_var\"" |
| 125 | if test "$gl_fnmatch_result" = yes; then |
| 126 | dnl Not strictly necessary. Only to avoid spurious leftover files if people |
| 127 | dnl don't do "make distclean". |
| 128 | rm -f "$gl_source_base/fnmatch.h" |
| 129 | else |
| 130 | FNMATCH_H=fnmatch.h |
| 131 | fi |
| 132 | AC_SUBST([FNMATCH_H]) |
| 133 | AM_CONDITIONAL([GL_GENERATE_FNMATCH_H], [test -n "$FNMATCH_H"]) |
| 134 | ]) |
| 135 | |
| 136 | # Request a POSIX compliant fnmatch function with GNU extensions. |
| 137 | AC_DEFUN([gl_FUNC_FNMATCH_GNU], |
| 138 | [ |
| 139 | m4_divert_text([INIT_PREPARE], [gl_fnmatch_required=GNU]) |
| 140 | |
| 141 | AC_REQUIRE([gl_FUNC_FNMATCH_POSIX]) |
| 142 | ]) |
| 143 | |
| 144 | AC_DEFUN([gl_PREREQ_FNMATCH], |
| 145 | [ |
| 146 | dnl We must choose a different name for our function, since on ELF systems |
| 147 | dnl a broken fnmatch() in libc.so would override our fnmatch() if it is |
| 148 | dnl compiled into a shared library. |
| 149 | AC_DEFINE_UNQUOTED([fnmatch], [${gl_fnmatch_required_lowercase}_fnmatch], |
| 150 | [Define to a replacement function name for fnmatch().]) |
| 151 | dnl Prerequisites of lib/fnmatch.c. |
| 152 | AC_REQUIRE([AC_TYPE_MBSTATE_T]) |
| 153 | AC_CHECK_DECLS([isblank], [], [], [[#include <ctype.h>]]) |
| 154 | AC_CHECK_FUNCS_ONCE([btowc isblank iswctype mbsrtowcs mempcpy wmemchr wmemcpy wmempcpy]) |
| 155 | AC_CHECK_HEADERS_ONCE([wctype.h]) |
| 156 | ]) |