summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorChristophe Lyon <christophe.lyon@st.com>2018-07-04 18:09:19 +0200
committerWaldemar Brodkorb <wbrodkorb@conet.de>2018-08-10 16:02:45 +0200
commite54692f524c5ada8883afcdd65b2ab998083c3fe (patch)
tree188601181abbfc66c37e6b94b6570d1bb758be6d /libc
parentd53bc3437f941cf01bf709ddd8e9c394db095b7a (diff)
mbtowc: Fix non compliant behavior for end of string
Match glibc behavior. * libc/stdlib/stdlib.c (mbtowc): Fix end of string behavior. Signed-off-by: Mickaël Guêné <mickael.guene@st.com> Signed-off-by: Christophe Lyon <christophe.lyon@st.com>
Diffstat (limited to 'libc')
-rw-r--r--libc/stdlib/stdlib.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/libc/stdlib/stdlib.c b/libc/stdlib/stdlib.c
index 075e6e5d6..f5936630c 100644
--- a/libc/stdlib/stdlib.c
+++ b/libc/stdlib/stdlib.c
@@ -895,9 +895,13 @@ int mbtowc(wchar_t *__restrict pwc, register const char *__restrict s, size_t n)
return is_stateful(ENCODING);
}
- if (*s == '\0')
+ if (*s == '\0') {
/* According to the ISO C 89 standard this is the expected behaviour. */
+ /* Standard not very clear here, so do like glibc. */
+ if (pwc != NULL)
+ *pwc = L'\0';
return 0;
+ }
if ((r = mbrtowc(pwc, s, n, &state)) == (size_t) -2) {
/* TODO: Should we set an error state? */