fnmatch.m4 5.9 KB

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