OSDN Git Service

* libc/stdlib/btowc.c (btowc): Reorganize EOF check. Fix incorrect
authorcorinna <corinna>
Tue, 6 Apr 2010 14:46:29 +0000 (14:46 +0000)
committercorinna <corinna>
Tue, 6 Apr 2010 14:46:29 +0000 (14:46 +0000)
return value if input byte is ASCII NUL.

newlib/ChangeLog
newlib/libc/stdlib/btowc.c

index aa661b9..eeb3edd 100644 (file)
@@ -1,3 +1,8 @@
+2010-04-06  Corinna Vinschen  <corinna@vinschen.de>
+
+       * libc/stdlib/btowc.c (btowc): Reorganize EOF check.  Fix incorrect
+       return value if input byte is ASCII NUL.
+
 2010-04-01  Joel Sherrill <joel.sherrill@oarcorp.com>
 
        * libc/include/sched.h: Include prototypes for
index f5ef462..ec6c291 100644 (file)
@@ -13,6 +13,9 @@ btowc (int c)
   wchar_t pwc;
   unsigned char b;
 
+  if (c == EOF)
+    return WEOF;
+
   b = (unsigned char)c;
 
   /* Put mbs in initial state. */
@@ -22,8 +25,8 @@ btowc (int c)
 
   retval = __mbtowc (_REENT, &pwc, &b, 1, __locale_charset (), &mbs);
 
-  if (c == EOF || retval != 1)
+  if (retval != 0 && retval != 1)
     return WEOF;
-  else
-    return (wint_t)pwc;
+
+  return (wint_t)pwc;
 }