@node fnmatch
@section @code{fnmatch}
@findex fnmatch

POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/fnmatch.html}

LSB specification:@* @url{https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/baselib-fnmatch-3.html}

Documentation:
@itemize
@item
@ifinfo
@ref{Wildcard Matching,,Wildcard Matching,libc},
@end ifinfo
@ifnotinfo
@url{https://www.gnu.org/software/libc/manual/html_node/Wildcard-Matching.html},
@end ifnotinfo
@item
@uref{https://www.kernel.org/doc/man-pages/online/pages/man3/fnmatch.3.html,,man fnmatch}.
@end itemize

Gnulib module: fnmatch or fnmatch-gnu

Portability problems fixed by either Gnulib module @code{fnmatch} or @code{fnmatch-gnu}:
@itemize
@item
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
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
Solaris 10, Cygwin 3.4.6,
@c Failing test cases:
@c fnmatch ("x?y", "x\360\237\230\213y", 0) == 0
@c fnmatch ("x[[:alnum:]]y", "x\360\220\214\260y", 0) == 0
@c fnmatch ("x[[:alpha:]]y", "x\360\220\214\260y", 0) == 0
@c fnmatch ("x[[:graph:]]y", "x\360\240\200\200y", 0) == 0
@c fnmatch ("x[[:lower:]]y", "x\360\220\221\201y", 0) == 0
@c fnmatch ("x[[:print:]]y", "x\360\240\200\200y", 0) == 0
@c fnmatch ("x[[:punct:]]y", "x\360\235\204\200y", 0) == 0
@c fnmatch ("x[[:upper:]]y", "x\360\220\220\231y", 0) == 0
MSVC,
@c Failing test cases:
@c fnmatch ("x?y", "x\360\237\230\213y", 0) == 0
@c fnmatch ("x[[:alnum:]]y", "x\360\220\214\260y", 0) == 0
@c fnmatch ("x[[:alpha:]]y", "x\360\220\214\260y", 0) == 0
@c fnmatch ("x[[:graph:]]y", "x\360\240\200\200y", 0) == 0
@c fnmatch ("x[[:lower:]]y", "x\360\220\221\201y", 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.
@c https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=57911
FreeBSD 13.2,
NetBSD 9.3, Solaris 11 OpenIndiana, 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.
@item
In the pattern, an opening bracket without closing bracket does not match
a literal @code{'['} on some platforms:
@c https://sourceware.org/bugzilla/show_bug.cgi?id=12378
@c Failing test cases:
@c fnmatch ("[[:alpha:]'[:alpha:]\0]", "a", 0) == FNM_NOMATCH
@c fnmatch ("[a[.\0.]]", "a", 0) == FNM_NOMATCH
@c fnmatch ("[", "[", 0) == 0
@c fnmatch ("[/b", "[/b", 0) == 0
glibc 2.12,
@c Failing test cases:
@c fnmatch ("[[:alpha:]'[:alpha:]\0]", "a", 0) == FNM_NOMATCH
@c fnmatch ("[a[.\0.]]", "a", 0) == FNM_NOMATCH
@c fnmatch ("[", "[", 0) == 0
@c fnmatch ("[", "]", 0) == FNM_NOMATCH
@c fnmatch ("[/b", "[/b", 0) == 0
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
This function does not support the flags @code{FNM_LEADING_DIR} and
@code{FNM_CASEFOLD} on some platforms:
AIX 7.2, HP-UX 11.31, IRIX 6.5, Solaris 10.
@item
The flag @code{FNM_CASEFOLD} does not work in many situations on some platforms:
@c Failing test cases:
@c fnmatch ("H\366hle", "H\326hLe", FNM_CASEFOLD) == 0
@c etc.
@c fnmatch ("\303\266zg\303\274r", "\303\226ZG\303\234R", FNM_CASEFOLD) == 0
@c etc.
@c fnmatch ("xy", "Xy", FNM_CASEFOLD) == 0
@c etc.
@c fnmatch ("\201\060\213\062zg\250\271r", "\201\060\211\060ZG\201\060\211\065R", FNM_CASEFOLD) == 0
@c etc.
NetBSD 9.3.
@item
The flag @code{FNM_CASEFOLD} does not work for multibyte characters
consisting of more than one byte on some platforms:
@c Failing test cases:
@c fnmatch ("\303\266zg\303\274r", "\303\226ZG\303\234R", FNM_CASEFOLD) == 0
@c etc.
Android 13.
@item
This function does not support the flag @code{FNM_EXTMATCH}
on all non-glibc platforms:
musl libc, macOS 12.5, FreeBSD 13.2, NetBSD 9.3, OpenBSD 7.2, Minix 3.3, AIX 7.2, HP-UX 11.31, IRIX 6.5, Solaris 11.4, Cygwin 3.4.6, Android 13.
@item
This function does not support the flag @code{FNM_FILE_NAME} as an
alias of @code{FNM_PATHNAME} on some platforms:
NetBSD 9.3, AIX 7.2, HP-UX 11.31, IRIX 6.5, Solaris 10.
@end itemize

Portability problems not fixed by Gnulib:
@itemize
@end itemize

Note: Gnulib's replacement function has some limitations:
@itemize
@item
It does not implement patterns with
collating elements (such as @code{"[[.ch.]]"}) or
equivalence classes (such as @code{"[[=a=]]"}).
@end itemize
