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