forked from pool/glibc
35b77f97b8
Copy from Base:System/glibc based on submit request 24314 from user pbaudis OBS-URL: https://build.opensuse.org/request/show/24314 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/glibc?expand=0&rev=13
59 lines
2.0 KiB
Diff
59 lines
2.0 KiB
Diff
When fnmatch detects an invalid multibyte character it should fall back to
|
|
single byte matching, so that "*" has a chance to match such a string.
|
|
|
|
Andreas.
|
|
|
|
2005-04-12 Andreas Schwab <schwab@suse.de>
|
|
|
|
* posix/fnmatch.c (fnmatch): If conversion to wide character
|
|
fails fall back to single byte matching.
|
|
|
|
Index: posix/fnmatch.c
|
|
===================================================================
|
|
--- posix/fnmatch.c.orig
|
|
+++ posix/fnmatch.c
|
|
@@ -327,6 +327,7 @@ fnmatch (pattern, string, flags)
|
|
# if HANDLE_MULTIBYTE
|
|
if (__builtin_expect (MB_CUR_MAX, 1) != 1)
|
|
{
|
|
+ const char *orig_pattern = pattern;
|
|
mbstate_t ps;
|
|
size_t n;
|
|
const char *p;
|
|
@@ -382,10 +383,8 @@ fnmatch (pattern, string, flags)
|
|
wstring = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
|
|
n = mbsrtowcs (wstring, &p, n + 1, &ps);
|
|
if (__builtin_expect (n == (size_t) -1, 0))
|
|
- /* Something wrong.
|
|
- XXX Do we have to set `errno' to something which mbsrtows hasn't
|
|
- already done? */
|
|
- return -1;
|
|
+ /* Something wrong. Fall back to single byte matching. */
|
|
+ goto try_singlebyte;
|
|
if (p)
|
|
{
|
|
memset (&ps, '\0', sizeof (ps));
|
|
@@ -397,10 +396,8 @@ fnmatch (pattern, string, flags)
|
|
prepare_wstring:
|
|
n = mbsrtowcs (NULL, &string, 0, &ps);
|
|
if (__builtin_expect (n == (size_t) -1, 0))
|
|
- /* Something wrong.
|
|
- XXX Do we have to set `errno' to something which mbsrtows hasn't
|
|
- already done? */
|
|
- return -1;
|
|
+ /* Something wrong. Fall back to single byte matching. */
|
|
+ goto try_singlebyte;
|
|
wstring = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
|
|
assert (mbsinit (&ps));
|
|
(void) mbsrtowcs (wstring, &string, n + 1, &ps);
|
|
@@ -408,6 +405,9 @@ fnmatch (pattern, string, flags)
|
|
|
|
return internal_fnwmatch (wpattern, wstring, wstring + n,
|
|
flags & FNM_PERIOD, flags, NULL);
|
|
+
|
|
+ try_singlebyte:
|
|
+ pattern = orig_pattern;
|
|
}
|
|
# endif /* mbstate_t and mbsrtowcs or _LIBC. */
|
|
|