Branch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
@node fnmatch
@subsection @code{fnmatch}
@findex fnmatch
POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/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
@mindex fnmatch
@mindex 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 10.0,
@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 10.0, 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/PR361
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/PR12378
@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 10.0.
@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, 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 10.0.
@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 10.0, OpenBSD 7.2, Minix 3.3, AIX 7.2, HP-UX 11.31, 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 10.0, AIX 7.2, HP-UX 11.31, 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