This function is missing on some platforms:
mingw, MSVC 14.
@item
+The @code{"?"} pattern character fails to match characters outside the
+single-byte range on some platforms:
+@c Failing test cases:
+@c fnmatch ("x?y", "x\303\274y", 0) == 0
+@c fnmatch ("x?y", "x\303\237y", 0) == 0
+@c fnmatch ("x?y", "x\360\237\230\213y", 0) == 0
+@c fnmatch ("x?y", "x\306\374y", 0) == 0
+@c fnmatch ("x?y", "x\313\334y", 0) == 0
+@c fnmatch ("x?y", "x\270\354y", 0) == 0
+@c fnmatch ("x?y", "x\250\271y", 0) == 0
+@c fnmatch ("x?y", "x\201\060\211\070y", 0) == 0
+@c fnmatch ("x?y", "x\224\071\375\067y", 0) == 0
+NetBSD 9.3,
+@c Failing test cases:
+@c fnmatch ("x?y", "x\303\274y", 0) == 0
+@c fnmatch ("x?y", "x\303\237y", 0) == 0
+@c fnmatch ("x?y", "x\360\237\230\213y", 0) == 0
+Android 13.
+@item
+In the pattern, negated character ranges (such as @code{[!a-z]}) are not
+supported on some platforms:
+@c Failing test cases:
+@c fnmatch ("[!a-z]", "", 0) == FNM_NOMATCH
+Solaris 11.4.
+@item
+In the pattern, character classes (such as @code{[:alnum:]}) inside
+bracket expressions are not supported on some platforms:
+@c Failing test cases:
+@c fnmatch ("[[:alnum:]]", "a", 0) == 0
+@c etc.
+FreeBSD 13.2, NetBSD 9.3, Cygwin 3.4.6.
+@item
+In the pattern, character classes (such as @code{[:alnum:]}) inside
+bracket expressions fail to match characters outside the single-byte
+range on some platforms:
+@c Failing test cases:
+@c fnmatch ("x[[:alnum:]]y", "x\305\201y", 0) == 0
+@c fnmatch ("x[[:alnum:]]y", "x\360\220\214\260y", 0) == 0
+@c fnmatch ("x[[:alpha:]]y", "x\305\201y", 0) == 0
+@c fnmatch ("x[[:alpha:]]y", "x\360\220\214\260y", 0) == 0
+@c fnmatch ("x[[:graph:]]y", "x\302\270y", 0) == 0
+@c fnmatch ("x[[:graph:]]y", "x\360\240\200\200y", 0) == 0
+@c fnmatch ("x[[:lower:]]y", "x\303\277y", 0) == 0
+@c fnmatch ("x[[:lower:]]y", "x\360\220\221\201y", 0) == 0
+@c fnmatch ("x[[:print:]]y", "x\302\270y", 0) == 0
+@c fnmatch ("x[[:print:]]y", "x\360\240\200\200y", 0) == 0
+@c fnmatch ("x[[:punct:]]y", "x\302\277y", 0) == 0
+@c fnmatch ("x[[:space:]]y", "x\343\200\200y", 0) == 0
+@c fnmatch ("x[[:upper:]]y", "x\320\251y", 0) == 0
+@c fnmatch ("x[[:upper:]]y", "x\360\220\220\231y", 0) == 0
+Android 13.
+@item
+The character class @code{[:cntrl:]} matches the empty string
+on some platforms:
+@c Failing test cases:
+@c fnmatch ("[[:cntrl:]]", "", 0) == FNM_NOMATCH
+Solaris 11.4.
+@item
Ranges that start or end with a backslash don't work right on some platforms:
@c https://sourceware.org/bugzilla/show_bug.cgi?id=361
glibc 2.3.3.
@c fnmatch ("[", "[", 0) == 0
@c fnmatch ("[", "]", 0) == FNM_NOMATCH
@c fnmatch ("[/b", "[/b", 0) == 0
-macOS 12.5.
+macOS 12.5,
+@c Failing test cases:
+@c fnmatch ("[", "[", 0) == 0
+@c fnmatch ("[/-/]", "/", 0) == 0
+NetBSD 9.3.
@end itemize
Portability problems fixed by Gnulib module @code{fnmatch-gnu}:
@itemize
@item
The @code{"?"} pattern character fails to match characters outside the
-single-byte range on some platforms:
-@c Failing test cases:
-@c fnmatch ("x?y", "x\303\274y", 0) == 0
-@c fnmatch ("x?y", "x\303\237y", 0) == 0
-@c fnmatch ("x?y", "x\360\237\230\213y", 0) == 0
-@c fnmatch ("x?y", "x\306\374y", 0) == 0
-@c fnmatch ("x?y", "x\313\334y", 0) == 0
-@c fnmatch ("x?y", "x\270\354y", 0) == 0
-@c fnmatch ("x?y", "x\250\271y", 0) == 0
-@c fnmatch ("x?y", "x\201\060\211\070y", 0) == 0
-@c fnmatch ("x?y", "x\224\071\375\067y", 0) == 0
-NetBSD 9.3,
-@c Failing test cases:
-@c fnmatch ("x?y", "x\303\274y", 0) == 0
-@c fnmatch ("x?y", "x\303\237y", 0) == 0
-@c fnmatch ("x?y", "x\360\237\230\213y", 0) == 0
-Android 13.
-@item
-The @code{"?"} pattern character fails to match characters outside the
Unicode BMP on some platforms:
@c Failing test cases:
@c fnmatch ("x?y", "x\360\237\230\213y", 0) == 0
@c fnmatch ("x[[:print:]]y", "x\360\240\200\200y", 0) == 0
@c fnmatch ("x[[:upper:]]y", "x\360\220\220\231y", 0) == 0
32-bit AIX.
-@item
-In the pattern, negated character ranges (such as @code{[!a-z]}) are not
-supported on some platforms:
-@c Failing test cases:
-@c fnmatch ("[!a-z]", "", 0) == FNM_NOMATCH
-Solaris 11.4.
-@item
-In the pattern, character classes (such as @code{[:alnum:]}) inside
-bracket expressions are not supported on some platforms:
-@c Failing test cases:
-@c fnmatch ("[[:alnum:]]", "a", 0) == 0
-@c etc.
-FreeBSD 13.2, NetBSD 9.3, Cygwin 2.9.0.
-@item
-In the pattern, character classes (such as @code{[:alnum:]}) inside
-bracket expressions fail to match characters outside the single-byte
-range on some platforms:
-@c Failing test cases:
-@c fnmatch ("x[[:alnum:]]y", "x\305\201y", 0) == 0
-@c fnmatch ("x[[:alnum:]]y", "x\360\220\214\260y", 0) == 0
-@c fnmatch ("x[[:alpha:]]y", "x\305\201y", 0) == 0
-@c fnmatch ("x[[:alpha:]]y", "x\360\220\214\260y", 0) == 0
-@c fnmatch ("x[[:graph:]]y", "x\302\270y", 0) == 0
-@c fnmatch ("x[[:graph:]]y", "x\360\240\200\200y", 0) == 0
-@c fnmatch ("x[[:lower:]]y", "x\303\277y", 0) == 0
-@c fnmatch ("x[[:lower:]]y", "x\360\220\221\201y", 0) == 0
-@c fnmatch ("x[[:print:]]y", "x\302\270y", 0) == 0
-@c fnmatch ("x[[:print:]]y", "x\360\240\200\200y", 0) == 0
-@c fnmatch ("x[[:punct:]]y", "x\302\277y", 0) == 0
-@c fnmatch ("x[[:space:]]y", "x\343\200\200y", 0) == 0
-@c fnmatch ("x[[:upper:]]y", "x\320\251y", 0) == 0
-@c fnmatch ("x[[:upper:]]y", "x\360\220\220\231y", 0) == 0
-Android 13.
-@item
-The character class @code{[:cntrl:]} matches the empty string
-on some platforms:
-@c Failing test cases:
-@c fnmatch ("[[:cntrl:]]", "", 0) == FNM_NOMATCH
-Solaris 11.4.
-@item
-In the pattern, an opening bracket without closing bracket does not match
-a literal @code{'['} on some platforms:
-@c Failing test cases:
-@c fnmatch ("[", "[", 0) == 0
-@c fnmatch ("[/-/]", "/", 0) == 0
-NetBSD 9.3.
@end itemize
Note: Gnulib's replacement function has some limitations:
-# Check for fnmatch - serial 16. -*- coding: utf-8 -*-
+# Check for fnmatch - serial 17 -*- coding: utf-8 -*-
# Copyright (C) 2000-2007, 2009-2023 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
[[#include <fnmatch.h>
+ #include <locale.h>
+ #include <stddef.h>
static int
y (char const *pattern, char const *string, int flags)
{
static char const bs_1[] = { '\\\\' - 1, 0 };
static char const bs01[] = { '\\\\' + 1, 0 };
int result = 0;
+ /* ==== Start of tests in the "C" locale ==== */
+ /* These are sanity checks. They all succeed on current platforms. */
if (!n ("a*", "", 0))
return 1;
if (!y ("a*", "abc", 0))
return 1;
- if (!y ("[/b", "[/b", 0)) /*"]]"*/ /* glibc Bugzilla bug 12378 */
- return 1;
if (!n ("d*/*1", "d/s/1", FNM_PATHNAME))
- return 2;
+ return 1;
if (!y ("a\\\\bc", "abc", 0))
- return 3;
+ return 1;
if (!n ("a\\\\bc", "abc", FNM_NOESCAPE))
- return 3;
+ return 1;
if (!y ("*x", ".x", 0))
- return 4;
+ return 1;
if (!n ("*x", ".x", FNM_PERIOD))
- return 4;
+ return 1;
+ /* glibc bug <https://sourceware.org/bugzilla/show_bug.cgi?id=361>
+ exists in glibc 2.3.3, fixed in glibc 2.5. */
if (!y (Apat, "\\\\", 0))
- return 5;
+ result |= 2;
if (!y (Apat, "A", 0))
- return 5;
+ result |= 2;
if (!y (apat, "\\\\", 0))
- return 5;
+ result |= 2;
if (!y (apat, "a", 0))
- return 5;
+ result |= 2;
if (!(n (Apat, A_1, 0) == ('A' < '\\\\')))
- return 5;
+ result |= 2;
if (!(n (apat, a_1, 0) == ('a' < '\\\\')))
- return 5;
+ result |= 2;
if (!(y (Apat, A01, 0) == ('A' < '\\\\')))
- return 5;
+ result |= 2;
if (!(y (apat, a01, 0) == ('a' < '\\\\')))
- return 5;
+ result |= 2;
if (!(y (Apat, bs_1, 0) == ('A' < '\\\\')))
- return 5;
+ result |= 2;
if (!(y (apat, bs_1, 0) == ('a' < '\\\\')))
- return 5;
+ result |= 2;
if (!(n (Apat, bs01, 0) == ('A' < '\\\\')))
- return 5;
+ result |= 2;
if (!(n (apat, bs01, 0) == ('a' < '\\\\')))
- return 5;
- $gl_fnmatch_gnu_start
- if (!y ("xxXX", "xXxX", FNM_CASEFOLD))
+ result |= 2;
+ /* glibc bug <https://sourceware.org/bugzilla/show_bug.cgi?id=12378>
+ exists in glibc 2.12, fixed in glibc 2.13. */
+ if (!y ("[/b", "[/b", 0)) /*"]]"*/
+ result |= 4;
+ /* This test fails on FreeBSD 13.2, NetBSD 9.3, Cygwin 3.4.6. */
+ if (!y ("[[:alnum:]]", "a", 0))
result |= 8;
+ $gl_fnmatch_gnu_start /* ==== Start of GNU extensions tests ==== */
+ /* Sanity checks, mainly to check the presence of the FNM_* macros. */
+ if (!y ("xxXX", "xXxX", FNM_CASEFOLD))
+ result |= 64;
if (!y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH))
- result |= 16;
+ result |= 64;
if (!n ("d*/*1", "d/s/1", FNM_FILE_NAME))
- result |= 32;
+ result |= 64;
if (!y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR))
result |= 64;
if (!y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR))
result |= 64;
if (!y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR))
result |= 64;
- $gl_fnmatch_gnu_end
+ $gl_fnmatch_gnu_end /* ==== End of GNU extensions tests ==== */
+ /* ==== End of tests in the "C" locale ==== */
+ /* ==== Start of tests that require a specific locale ==== */
+ /* This test fails on Solaris 11.4. */
+ if (setlocale (LC_ALL, "en_US.UTF-8") != NULL)
+ {
+ if (!n ("[!a-z]", "", 0))
+ result |= 16;
+ }
+ /* This test fails on NetBSD 9.3, Android 13. */
+ if (setlocale (LC_ALL, "C.UTF-8") != NULL)
+ {
+ if (!y ("x?y", "x\\303\\274y", 0))
+ result |= 32;
+ }
+ /* ==== End of tests that require a specific locale ==== */
return result;
]])],
[eval "$gl_fnmatch_cache_var=yes"],
static char const a01[] = { 'a' + 1, 0 };
static char const bs_1[] = { '\\' - 1, 0 };
static char const bs01[] = { '\\' + 1, 0 };
+ /* These are sanity checks. They all succeed on current platforms. */
ASSERT (fnmatch ("a*", "", 0) == FNM_NOMATCH);
ASSERT (fnmatch ("a*", "abc", 0) == 0);
- /* <https://sourceware.org/bugzilla/show_bug.cgi?id=12378> */
- ASSERT (fnmatch ("[/b", "[/b", 0) == 0);
ASSERT (fnmatch ("d*/*1", "d/s/1", FNM_PATHNAME) == FNM_NOMATCH);
ASSERT (fnmatch ("a\\bc", "abc", 0) == 0);
ASSERT (fnmatch ("a\\bc", "abc", FNM_NOESCAPE) == FNM_NOMATCH);
ASSERT (fnmatch ("*x", ".x", FNM_PERIOD) == FNM_NOMATCH);
if (argc == 1 || strcmp (argv[1], "1") == 0)
{
+ /* glibc bug <https://sourceware.org/bugzilla/show_bug.cgi?id=361>
+ exists in glibc 2.3.3, fixed in glibc 2.5. */
ASSERT (fnmatch (Apat, "\\", 0) == 0);
ASSERT (fnmatch (Apat, "A", 0) == 0);
ASSERT (fnmatch (apat, "\\", 0) == 0);
ASSERT (fnmatch (Apat, bs01, 0) == ('A' < '\\' ? FNM_NOMATCH : 0));
ASSERT (fnmatch (apat, bs01, 0) == ('a' < '\\' ? FNM_NOMATCH : 0));
}
+ /* glibc bug <https://sourceware.org/bugzilla/show_bug.cgi?id=12378>
+ exists in glibc 2.12, fixed in glibc 2.13. */
+ ASSERT (fnmatch ("[/b", "[/b", 0) == 0);
+ /* This test fails on FreeBSD 13.2, NetBSD 9.3, Cygwin 3.4.6. */
+ ASSERT (fnmatch ("[[:alnum:]]", "a", 0) == 0);
#if GNULIB_FNMATCH_GNU && defined FNM_CASEFOLD
ASSERT (fnmatch ("xxXX", "xXxX", FNM_CASEFOLD) == 0);
#endif