diff options
-rw-r--r-- | lib/libc/locale/mblen.c | 7 | ||||
-rw-r--r-- | lib/libc/locale/mbtowc.c | 7 |
2 files changed, 6 insertions, 8 deletions
diff --git a/lib/libc/locale/mblen.c b/lib/libc/locale/mblen.c index a54e051..ad5edb3 100644 --- a/lib/libc/locale/mblen.c +++ b/lib/libc/locale/mblen.c @@ -47,13 +47,12 @@ mblen(const char *s, size_t n) { const char *e; - if (s == NULL || *s == '\0') + if (s == NULL) /* No support for state dependent encodings. */ return (0); - if (sgetrune(s, n, &e) == _INVALID_RUNE) { errno = EILSEQ; - return (s - e); + return (-1); } - return (e - s); + return (*s == '\0' ? 0 : e - s); } diff --git a/lib/libc/locale/mbtowc.c b/lib/libc/locale/mbtowc.c index a690bec..27bebcf 100644 --- a/lib/libc/locale/mbtowc.c +++ b/lib/libc/locale/mbtowc.c @@ -48,15 +48,14 @@ mbtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n) const char *e; rune_t r; - if (s == NULL || *s == '\0') + if (s == NULL) /* No support for state dependent encodings. */ return (0); - if ((r = sgetrune(s, n, &e)) == _INVALID_RUNE) { errno = EILSEQ; - return (s - e); + return (-1); } if (pwc != NULL) *pwc = r; - return (e - s); + return (r == 0 ? 0 : e - s); } |