1 http://sourceware.org/ml/libc-hacker/2002-11/msg00071.html
3 When fnmatch detects an invalid multibyte character it should fall back to
4 single byte matching, so that "*" has a chance to match such a string.
8 2005-04-12 Andreas Schwab <schwab@suse.de>
10 * posix/fnmatch.c (fnmatch): If conversion to wide character
11 fails fall back to single byte matching.
13 Index: posix/fnmatch.c
14 ===================================================================
16 diff -durN glibc-2.10.1.orig/posix/fnmatch.c glibc-2.10.1/posix/fnmatch.c
17 --- glibc-2.10.1.orig/posix/fnmatch.c 2007-07-28 22:35:00.000000000 +0200
18 +++ glibc-2.10.1/posix/fnmatch.c 2009-11-13 00:50:39.000000000 +0100
21 if (__builtin_expect (MB_CUR_MAX, 1) != 1)
23 + const char *orig_pattern = pattern;
28 wstring = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
29 n = mbsrtowcs (wstring, &p, n + 1, &ps);
30 if (__builtin_expect (n == (size_t) -1, 0))
32 - XXX Do we have to set `errno' to something which mbsrtows hasn't
35 + /* Something wrong. Fall back to single byte matching. */
36 + goto try_singlebyte;
39 memset (&ps, '\0', sizeof (ps));
42 n = mbsrtowcs (NULL, &string, 0, &ps);
43 if (__builtin_expect (n == (size_t) -1, 0))
45 - XXX Do we have to set `errno' to something which mbsrtows hasn't
48 + /* Something wrong. Fall back to single byte matching. */
49 + goto try_singlebyte;
50 wstring = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
51 assert (mbsinit (&ps));
52 (void) mbsrtowcs (wstring, &string, n + 1, &ps);
55 return internal_fnwmatch (wpattern, wstring, wstring + n,
56 flags & FNM_PERIOD, flags, NULL);
59 + pattern = orig_pattern;
61 # endif /* mbstate_t and mbsrtowcs or _LIBC. */