fnmatch.m4 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # Check for fnmatch - serial 15. -*- coding: utf-8 -*-
  2. # Copyright (C) 2000-2007, 2009-2021 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. AC_REQUIRE([gl_FNMATCH_H])
  13. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  14. gl_fnmatch_required_lowercase=`
  15. echo $gl_fnmatch_required | LC_ALL=C tr '[[A-Z]]' '[[a-z]]'
  16. `
  17. AC_CHECK_FUNCS_ONCE([fnmatch])
  18. if test $ac_cv_func_fnmatch = no; then
  19. HAVE_FNMATCH=0
  20. else
  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. [case "$host_os" in
  118. # Guess yes on musl systems.
  119. *-musl*) eval "$gl_fnmatch_cache_var=\"guessing yes\"" ;;
  120. # Guess no otherwise, even on glibc systems.
  121. *) eval "$gl_fnmatch_cache_var=\"guessing no\"" ;;
  122. esac
  123. ])
  124. ])
  125. eval "gl_fnmatch_result=\"\$$gl_fnmatch_cache_var\""
  126. case "$gl_fnmatch_result" in
  127. *yes) ;;
  128. *) REPLACE_FNMATCH=1 ;;
  129. esac
  130. fi
  131. if test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1; then
  132. gl_REPLACE_FNMATCH_H
  133. fi
  134. ])
  135. # Request a POSIX compliant fnmatch function with GNU extensions.
  136. AC_DEFUN([gl_FUNC_FNMATCH_GNU],
  137. [
  138. m4_divert_text([INIT_PREPARE], [gl_fnmatch_required=GNU])
  139. AC_REQUIRE([gl_FUNC_FNMATCH_POSIX])
  140. ])
  141. AC_DEFUN([gl_PREREQ_FNMATCH],
  142. [
  143. dnl Prerequisites of lib/fnmatch.c.
  144. AC_REQUIRE([AC_TYPE_MBSTATE_T])
  145. AC_CHECK_FUNCS_ONCE([mbsrtowcs])
  146. ])