200aeb
diff -Nrup a/posix/fnmatch.c b/posix/fnmatch.c
200aeb
--- a/posix/fnmatch.c	2012-01-01 07:16:32.000000000 -0500
200aeb
+++ b/posix/fnmatch.c	2012-05-23 14:14:29.099461189 -0400
200aeb
@@ -333,6 +333,7 @@ fnmatch (pattern, string, flags)
200aeb
 # if HANDLE_MULTIBYTE
200aeb
   if (__builtin_expect (MB_CUR_MAX, 1) != 1)
200aeb
     {
200aeb
+      const char *orig_pattern = pattern;
200aeb
       mbstate_t ps;
200aeb
       size_t n;
200aeb
       const char *p;
200aeb
@@ -356,10 +357,8 @@ fnmatch (pattern, string, flags)
200aeb
 						 alloca_used);
200aeb
 	  n = mbsrtowcs (wpattern, &p, n + 1, &ps);
Siddhesh Poyarekar 372014
 	  if (__glibc_unlikely (n == (size_t) -1))
200aeb
-	    /* Something wrong.
200aeb
-	       XXX Do we have to set `errno' to something which mbsrtows hasn't
200aeb
-	       already done?  */
200aeb
-	    return -1;
200aeb
+	    /* Something wrong: Fall back to single byte matching. */
200aeb
+	    goto try_singlebyte;
200aeb
 	  if (p)
200aeb
 	    {
200aeb
 	      memset (&ps, '\0', sizeof (ps));
200aeb
@@ -371,10 +370,8 @@ fnmatch (pattern, string, flags)
200aeb
 	prepare_wpattern:
200aeb
 	  n = mbsrtowcs (NULL, &pattern, 0, &ps);
Siddhesh Poyarekar 372014
 	  if (__glibc_unlikely (n == (size_t) -1))
200aeb
-	    /* Something wrong.
200aeb
-	       XXX Do we have to set `errno' to something which mbsrtows hasn't
200aeb
-	       already done?  */
200aeb
-	    return -1;
200aeb
+	    /*Something wrong: Fall back to single byte matching. */
200aeb
+	    goto try_singlebyte;
Siddhesh Poyarekar 372014
 	  if (__glibc_unlikely (n >= (size_t) -1 / sizeof (wchar_t)))
200aeb
 	    {
200aeb
 	      __set_errno (ENOMEM);
200aeb
@@ -401,14 +398,8 @@ fnmatch (pattern, string, flags)
200aeb
 						alloca_used);
200aeb
 	  n = mbsrtowcs (wstring, &p, n + 1, &ps);
Siddhesh Poyarekar 372014
 	  if (__glibc_unlikely (n == (size_t) -1))
200aeb
-	    {
200aeb
-	      /* Something wrong.
200aeb
-		 XXX Do we have to set `errno' to something which
200aeb
-		 mbsrtows hasn't already done?  */
200aeb
-	    free_return:
200aeb
-	      free (wpattern_malloc);
200aeb
-	      return -1;
200aeb
-	    }
200aeb
+	    /* Something wrong: Fall back to single byte matching. */
200aeb
+	    goto free_and_try_singlebyte;
200aeb
 	  if (p)
200aeb
 	    {
200aeb
 	      memset (&ps, '\0', sizeof (ps));
200aeb
@@ -420,10 +411,8 @@ fnmatch (pattern, string, flags)
200aeb
 	prepare_wstring:
200aeb
 	  n = mbsrtowcs (NULL, &string, 0, &ps);
Siddhesh Poyarekar 372014
 	  if (__glibc_unlikely (n == (size_t) -1))
200aeb
-	    /* Something wrong.
200aeb
-	       XXX Do we have to set `errno' to something which mbsrtows hasn't
200aeb
-	       already done?  */
200aeb
-	    goto free_return;
200aeb
+	    /* Something wrong: Fall back to singlebyte matching. */
200aeb
+	    goto free_and_try_singlebyte;
Siddhesh Poyarekar 372014
 	  if (__glibc_unlikely (n >= (size_t) -1 / sizeof (wchar_t)))
200aeb
 	    {
200aeb
 	      free (wpattern_malloc);
200aeb
@@ -450,6 +439,10 @@ fnmatch (pattern, string, flags)
200aeb
       free (wpattern_malloc);
200aeb
 
200aeb
       return res;
200aeb
+      free_and_try_singlebyte:
200aeb
+	free(wpattern_malloc);
200aeb
+      try_singlebyte:
200aeb
+	pattern = orig_pattern;
200aeb
     }
200aeb
 # endif  /* mbstate_t and mbsrtowcs or _LIBC.  */
200aeb