finalise NEWS.stable
[gnulib.git] / lib / mbrtowc.c
index 5c2650e..7a8e599 100644 (file)
@@ -1,5 +1,5 @@
 /* Convert multibyte character to wide character.
-   Copyright (C) 1999-2002, 2005-2010 Free Software Foundation, Inc.
+   Copyright (C) 1999-2002, 2005-2011 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2008.
 
    This program is free software: you can redistribute it and/or modify
@@ -40,9 +40,6 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
 {
   char *pstate = (char *)ps;
 
-  if (pstate == NULL)
-    pstate = internal_state;
-
   if (s == NULL)
     {
       pwc = NULL;
@@ -54,6 +51,10 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
     return (size_t)(-2);
 
   /* Here n > 0.  */
+
+  if (pstate == NULL)
+    pstate = internal_state;
+
   {
     size_t nstate = pstate[0];
     char buf[4];
@@ -91,7 +92,7 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
 
     /* Here m > 0.  */
 
-# if __GLIBC__
+# if __GLIBC__ || defined __UCLIBC__
     /* Work around bug <http://sourceware.org/bugzilla/show_bug.cgi?id=9674> */
     mbtowc (NULL, NULL, 0);
 # endif
@@ -321,7 +322,7 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
 size_t
 rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
 {
-# if MBRTOWC_NULL_ARG_BUG || MBRTOWC_RETVAL_BUG
+# if MBRTOWC_NULL_ARG2_BUG || MBRTOWC_RETVAL_BUG
   if (s == NULL)
     {
       pwc = NULL;
@@ -334,7 +335,7 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
   {
     static mbstate_t internal_state;
 
-    /* Override mbrtowc's internal state.  We can not call mbsinit() on the
+    /* Override mbrtowc's internal state.  We cannot call mbsinit() on the
        hidden internal state, but we can call it on our variable.  */
     if (ps == NULL)
       ps = &internal_state;
@@ -379,7 +380,16 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
     return ret;
   }
 # else
-  return mbrtowc (pwc, s, n, ps);
+  {
+#   if MBRTOWC_NULL_ARG1_BUG
+    wchar_t dummy;
+
+    if (pwc == NULL)
+      pwc = &dummy;
+#   endif
+
+    return mbrtowc (pwc, s, n, ps);
+  }
 # endif
 }