yann@1625: http://sourceware.org/ml/libc-hacker/2002-11/msg00071.html yann@1625: yann@1625: When fnmatch detects an invalid multibyte character it should fall back to yann@1625: single byte matching, so that "*" has a chance to match such a string. yann@1625: yann@1625: Andreas. yann@1625: yann@1625: 2005-04-12 Andreas Schwab yann@1625: yann@1625: * posix/fnmatch.c (fnmatch): If conversion to wide character yann@1625: fails fall back to single byte matching. yann@1625: yann@1625: Index: posix/fnmatch.c yann@1625: =================================================================== yann@1625: yann@1625: diff -durN glibc-2.10.1.orig/posix/fnmatch.c glibc-2.10.1/posix/fnmatch.c yann@1625: --- glibc-2.10.1.orig/posix/fnmatch.c 2007-07-28 22:35:00.000000000 +0200 yann@1625: +++ glibc-2.10.1/posix/fnmatch.c 2009-11-13 00:50:39.000000000 +0100 yann@1625: @@ -327,6 +327,7 @@ yann@1625: # if HANDLE_MULTIBYTE yann@1625: if (__builtin_expect (MB_CUR_MAX, 1) != 1) yann@1625: { yann@1625: + const char *orig_pattern = pattern; yann@1625: mbstate_t ps; yann@1625: size_t n; yann@1625: const char *p; yann@1625: @@ -382,10 +383,8 @@ yann@1625: wstring = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t)); yann@1625: n = mbsrtowcs (wstring, &p, n + 1, &ps); yann@1625: if (__builtin_expect (n == (size_t) -1, 0)) yann@1625: - /* Something wrong. yann@1625: - XXX Do we have to set `errno' to something which mbsrtows hasn't yann@1625: - already done? */ yann@1625: - return -1; yann@1625: + /* Something wrong. Fall back to single byte matching. */ yann@1625: + goto try_singlebyte; yann@1625: if (p) yann@1625: { yann@1625: memset (&ps, '\0', sizeof (ps)); yann@1625: @@ -397,10 +396,8 @@ yann@1625: prepare_wstring: yann@1625: n = mbsrtowcs (NULL, &string, 0, &ps); yann@1625: if (__builtin_expect (n == (size_t) -1, 0)) yann@1625: - /* Something wrong. yann@1625: - XXX Do we have to set `errno' to something which mbsrtows hasn't yann@1625: - already done? */ yann@1625: - return -1; yann@1625: + /* Something wrong. Fall back to single byte matching. */ yann@1625: + goto try_singlebyte; yann@1625: wstring = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t)); yann@1625: assert (mbsinit (&ps)); yann@1625: (void) mbsrtowcs (wstring, &string, n + 1, &ps); yann@1625: @@ -408,6 +405,9 @@ yann@1625: yann@1625: return internal_fnwmatch (wpattern, wstring, wstring + n, yann@1625: flags & FNM_PERIOD, flags, NULL); yann@1625: + yann@1625: + try_singlebyte: yann@1625: + pattern = orig_pattern; yann@1625: } yann@1625: # endif /* mbstate_t and mbsrtowcs or _LIBC. */ yann@1625: