aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libc/stdlib')
-rw-r--r--newlib/libc/stdlib/wcstombs_r.c7
-rw-r--r--newlib/libc/stdlib/wctomb_r.c4
2 files changed, 6 insertions, 5 deletions
diff --git a/newlib/libc/stdlib/wcstombs_r.c b/newlib/libc/stdlib/wcstombs_r.c
index c6a06a3..2c82a2c 100644
--- a/newlib/libc/stdlib/wcstombs_r.c
+++ b/newlib/libc/stdlib/wcstombs_r.c
@@ -17,14 +17,15 @@ _wcstombs_r (struct _reent *r,
if (s == NULL)
{
size_t num_bytes = 0;
- while (*pwcs != 0)
+ do
{
- bytes = __WCTOMB (r, buff, *pwcs++, state);
+ bytes = __WCTOMB (r, buff, *pwcs, state);
if (bytes == -1)
return -1;
num_bytes += bytes;
}
- return num_bytes;
+ while (*pwcs++ != 0x00);
+ return num_bytes - 1;
}
else
{
diff --git a/newlib/libc/stdlib/wctomb_r.c b/newlib/libc/stdlib/wctomb_r.c
index 5ea1e13..ec6adfa 100644
--- a/newlib/libc/stdlib/wctomb_r.c
+++ b/newlib/libc/stdlib/wctomb_r.c
@@ -62,8 +62,8 @@ __utf8_wctomb (struct _reent *r,
of the surrogate and proceed to convert the given character. Note
to return extra 3 bytes. */
wchar_t tmp;
- tmp = (state->__value.__wchb[0] << 16 | state->__value.__wchb[1] << 8)
- - (0x10000 >> 10 | 0xd80d);
+ tmp = (((state->__value.__wchb[0] << 16 | state->__value.__wchb[1] << 8)
+ - 0x10000) >> 10) | 0xd800;
*s++ = 0xe0 | ((tmp & 0xf000) >> 12);
*s++ = 0x80 | ((tmp & 0xfc0) >> 6);
*s++ = 0x80 | (tmp & 0x3f);