summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Mustacchi <rm@fingolfin.org>2020-03-02 05:43:38 +0000
committerRobert Mustacchi <rm@fingolfin.org>2020-03-26 07:42:53 +0000
commit0ac311bae7f6f50d9ba506b52bd8860f2d68d4ce (patch)
tree88ae565ae009c9abbf4e976e7d2f71a0990515bd
parentd726994754c938f91b6fd7e96b5cab3829615c58 (diff)
downloadillumos-joyent-0ac311bae7f6f50d9ba506b52bd8860f2d68d4ce.tar.gz
12358 Need mbrtowc variant that indicates consumed zero bytes
Reviewed by: John Levon <john.levon@joyent.com> Reviewed by: Yuri Pankov <ypankov@fastmail.com> Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r--usr/src/lib/libc/inc/libc.h8
-rw-r--r--usr/src/lib/libc/port/locale/big5.c10
-rw-r--r--usr/src/lib/libc/port/locale/euc.c42
-rw-r--r--usr/src/lib/libc/port/locale/fgetwc.c2
-rw-r--r--usr/src/lib/libc/port/locale/gb18030.c10
-rw-r--r--usr/src/lib/libc/port/locale/gb2312.c10
-rw-r--r--usr/src/lib/libc/port/locale/gbk.c10
-rw-r--r--usr/src/lib/libc/port/locale/lctype.h6
-rw-r--r--usr/src/lib/libc/port/locale/mblocal.h2
-rw-r--r--usr/src/lib/libc/port/locale/mbrtowc.c20
-rw-r--r--usr/src/lib/libc/port/locale/mbsnrtowcs.c8
-rw-r--r--usr/src/lib/libc/port/locale/mskanji.c10
-rw-r--r--usr/src/lib/libc/port/locale/none.c8
-rw-r--r--usr/src/lib/libc/port/locale/utf8.c27
14 files changed, 123 insertions, 50 deletions
diff --git a/usr/src/lib/libc/inc/libc.h b/usr/src/lib/libc/inc/libc.h
index 448523df01..90a2859b33 100644
--- a/usr/src/lib/libc/inc/libc.h
+++ b/usr/src/lib/libc/inc/libc.h
@@ -333,6 +333,14 @@ extern void __throw_constraint_handler_s(const char *_RESTRICT_KYWD, int);
*/
extern void common_panic(const char *, const char *);
+/*
+ * defined in mbrtowc.c.
+ */
+extern size_t mbrtowc_nz_l(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
+ size_t, mbstate_t *_RESTRICT_KYWD, locale_t);
+extern size_t mbrtowc_nz(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
+ size_t, mbstate_t *_RESTRICT_KYWD);
+
#ifdef __cplusplus
}
#endif
diff --git a/usr/src/lib/libc/port/locale/big5.c b/usr/src/lib/libc/port/locale/big5.c
index 2729ab0289..889b182de5 100644
--- a/usr/src/lib/libc/port/locale/big5.c
+++ b/usr/src/lib/libc/port/locale/big5.c
@@ -44,7 +44,7 @@
static size_t _BIG5_mbrtowc(wchar_t *_RESTRICT_KYWD,
const char *_RESTRICT_KYWD,
- size_t, mbstate_t *RESTRICT_KYWD);
+ size_t, mbstate_t *RESTRICT_KYWD, boolean_t);
static int _BIG5_mbsinit(const mbstate_t *);
static size_t _BIG5_wcrtomb(char *_RESTRICT_KYWD, wchar_t,
mbstate_t *_RESTRICT_KYWD);
@@ -88,7 +88,7 @@ _big5_check(uint_t c)
static size_t
_BIG5_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
- size_t n, mbstate_t *_RESTRICT_KYWD ps)
+ size_t n, mbstate_t *_RESTRICT_KYWD ps, boolean_t zero)
{
_BIG5State *bs;
wchar_t wc;
@@ -143,7 +143,11 @@ _BIG5_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
} else {
if (pwc != NULL)
*pwc = wc;
- return (wc == L'\0' ? 0 : 1);
+ if (zero || wc != L'\0') {
+ return (1);
+ } else {
+ return (0);
+ }
}
}
diff --git a/usr/src/lib/libc/port/locale/euc.c b/usr/src/lib/libc/port/locale/euc.c
index a99cdf8689..1d1d25b17b 100644
--- a/usr/src/lib/libc/port/locale/euc.c
+++ b/usr/src/lib/libc/port/locale/euc.c
@@ -46,22 +46,23 @@
static size_t _EUC_mbrtowc_impl(wchar_t *_RESTRICT_KYWD,
const char *_RESTRICT_KYWD,
- size_t, mbstate_t *_RESTRICT_KYWD, uint8_t, uint8_t, uint8_t, uint8_t);
+ size_t, mbstate_t *_RESTRICT_KYWD, uint8_t, uint8_t, uint8_t, uint8_t,
+ boolean_t);
static size_t _EUC_wcrtomb_impl(char *_RESTRICT_KYWD, wchar_t,
mbstate_t *_RESTRICT_KYWD, uint8_t, uint8_t, uint8_t, uint8_t);
static size_t _EUC_CN_mbrtowc(wchar_t *_RESTRICT_KYWD,
const char *_RESTRICT_KYWD,
- size_t, mbstate_t *_RESTRICT_KYWD);
+ size_t, mbstate_t *_RESTRICT_KYWD, boolean_t);
static size_t _EUC_JP_mbrtowc(wchar_t *_RESTRICT_KYWD,
const char *_RESTRICT_KYWD,
- size_t, mbstate_t *_RESTRICT_KYWD);
+ size_t, mbstate_t *_RESTRICT_KYWD, boolean_t);
static size_t _EUC_KR_mbrtowc(wchar_t *_RESTRICT_KYWD,
const char *_RESTRICT_KYWD,
- size_t, mbstate_t *_RESTRICT_KYWD);
+ size_t, mbstate_t *_RESTRICT_KYWD, boolean_t);
static size_t _EUC_TW_mbrtowc(wchar_t *_RESTRICT_KYWD,
const char *_RESTRICT_KYWD,
- size_t, mbstate_t *_RESTRICT_KYWD);
+ size_t, mbstate_t *_RESTRICT_KYWD, boolean_t);
static size_t _EUC_CN_wcrtomb(char *_RESTRICT_KYWD, wchar_t,
mbstate_t *_RESTRICT_KYWD);
@@ -131,9 +132,9 @@ _EUC_CN_init(struct lc_ctype *lct)
static size_t
_EUC_CN_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
- size_t n, mbstate_t *_RESTRICT_KYWD ps)
+ size_t n, mbstate_t *_RESTRICT_KYWD ps, boolean_t zero)
{
- return (_EUC_mbrtowc_impl(pwc, s, n, ps, SS2, 4, 0, 0));
+ return (_EUC_mbrtowc_impl(pwc, s, n, ps, SS2, 4, 0, 0, zero));
}
static size_t
@@ -176,9 +177,9 @@ _EUC_KR_init(struct lc_ctype *lct)
static size_t
_EUC_KR_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
- size_t n, mbstate_t *_RESTRICT_KYWD ps)
+ size_t n, mbstate_t *_RESTRICT_KYWD ps, boolean_t zero)
{
- return (_EUC_mbrtowc_impl(pwc, s, n, ps, 0, 0, 0, 0));
+ return (_EUC_mbrtowc_impl(pwc, s, n, ps, 0, 0, 0, 0, zero));
}
static size_t
@@ -221,9 +222,9 @@ _EUC_JP_init(struct lc_ctype *lct)
static size_t
_EUC_JP_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
- size_t n, mbstate_t *_RESTRICT_KYWD ps)
+ size_t n, mbstate_t *_RESTRICT_KYWD ps, boolean_t zero)
{
- return (_EUC_mbrtowc_impl(pwc, s, n, ps, SS2, 2, SS3, 3));
+ return (_EUC_mbrtowc_impl(pwc, s, n, ps, SS2, 2, SS3, 3, zero));
}
static size_t
@@ -266,9 +267,9 @@ _EUC_TW_init(struct lc_ctype *lct)
static size_t
_EUC_TW_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
- size_t n, mbstate_t *_RESTRICT_KYWD ps)
+ size_t n, mbstate_t *_RESTRICT_KYWD ps, boolean_t zero)
{
- return (_EUC_mbrtowc_impl(pwc, s, n, ps, SS2, 4, 0, 0));
+ return (_EUC_mbrtowc_impl(pwc, s, n, ps, SS2, 4, 0, 0, zero));
}
static size_t
@@ -300,7 +301,8 @@ _EUC_TW_wcsnrtombs(char *_RESTRICT_KYWD dst, const wchar_t **_RESTRICT_KYWD src,
static size_t
_EUC_mbrtowc_impl(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
size_t n, mbstate_t *_RESTRICT_KYWD ps,
- uint8_t cs2, uint8_t cs2width, uint8_t cs3, uint8_t cs3width)
+ uint8_t cs2, uint8_t cs2width, uint8_t cs3, uint8_t cs3width,
+ boolean_t zero)
{
_EucState *es;
int i, want;
@@ -329,7 +331,11 @@ _EUC_mbrtowc_impl(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
if (((ch = (unsigned char)*s) & 0x80) == 0) {
if (pwc != NULL)
*pwc = ch;
- return (ch != '\0' ? 1 : 0);
+ if (zero || ch != '\0') {
+ return (1);
+ } else {
+ return (0);
+ }
}
if (ch >= 0xa1) {
@@ -367,7 +373,11 @@ _EUC_mbrtowc_impl(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
if (pwc != NULL)
*pwc = wc;
es->want = 0;
- return (wc == L'\0' ? 0 : want);
+ if (zero || wc != L'\0') {
+ return (want);
+ } else {
+ return (0);
+ }
}
static size_t
diff --git a/usr/src/lib/libc/port/locale/fgetwc.c b/usr/src/lib/libc/port/locale/fgetwc.c
index 282b65cebc..254a785891 100644
--- a/usr/src/lib/libc/port/locale/fgetwc.c
+++ b/usr/src/lib/libc/port/locale/fgetwc.c
@@ -66,7 +66,7 @@ _fgetwc_unlocked_l(FILE *fp, locale_t loc)
}
do {
char x = (char)c;
- nconv = lct->lc_mbrtowc(&wc, &x, 1, statep);
+ nconv = lct->lc_mbrtowc(&wc, &x, 1, statep, B_FALSE);
if (nconv == (size_t)-1) {
break;
} else if (nconv == (size_t)-2) {
diff --git a/usr/src/lib/libc/port/locale/gb18030.c b/usr/src/lib/libc/port/locale/gb18030.c
index 232daade50..36c48c5cc5 100644
--- a/usr/src/lib/libc/port/locale/gb18030.c
+++ b/usr/src/lib/libc/port/locale/gb18030.c
@@ -44,7 +44,7 @@
static size_t _GB18030_mbrtowc(wchar_t *_RESTRICT_KYWD,
const char *_RESTRICT_KYWD,
- size_t, mbstate_t *_RESTRICT_KYWD);
+ size_t, mbstate_t *_RESTRICT_KYWD, boolean_t);
static int _GB18030_mbsinit(const mbstate_t *);
static size_t _GB18030_wcrtomb(char *_RESTRICT_KYWD, wchar_t,
mbstate_t *_RESTRICT_KYWD);
@@ -83,7 +83,7 @@ _GB18030_mbsinit(const mbstate_t *ps)
static size_t
_GB18030_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
- size_t n, mbstate_t *_RESTRICT_KYWD ps)
+ size_t n, mbstate_t *_RESTRICT_KYWD ps, boolean_t zero)
{
_GB18030State *gs;
wchar_t wch;
@@ -159,7 +159,11 @@ _GB18030_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
if (pwc != NULL)
*pwc = wch;
gs->count = 0;
- return (wch == L'\0' ? 0 : len - ocount);
+ if (zero || wch != L'\0') {
+ return (len - ocount);
+ } else {
+ return (0);
+ }
ilseq:
errno = EILSEQ;
return ((size_t)-1);
diff --git a/usr/src/lib/libc/port/locale/gb2312.c b/usr/src/lib/libc/port/locale/gb2312.c
index a25af781b4..bfb6c0177b 100644
--- a/usr/src/lib/libc/port/locale/gb2312.c
+++ b/usr/src/lib/libc/port/locale/gb2312.c
@@ -39,7 +39,7 @@
static size_t _GB2312_mbrtowc(wchar_t *_RESTRICT_KYWD,
const char *_RESTRICT_KYWD,
- size_t, mbstate_t *_RESTRICT_KYWD);
+ size_t, mbstate_t *_RESTRICT_KYWD, boolean_t);
static int _GB2312_mbsinit(const mbstate_t *);
static size_t _GB2312_wcrtomb(char *_RESTRICT_KYWD, wchar_t,
mbstate_t *_RESTRICT_KYWD);
@@ -101,7 +101,7 @@ _GB2312_check(const char *str, size_t n)
static size_t
_GB2312_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
- size_t n, mbstate_t *_RESTRICT_KYWD ps)
+ size_t n, mbstate_t *_RESTRICT_KYWD ps, boolean_t zero)
{
_GB2312State *gs;
wchar_t wc;
@@ -137,7 +137,11 @@ _GB2312_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
if (pwc != NULL)
*pwc = wc;
gs->count = 0;
- return (wc == L'\0' ? 0 : len - ocount);
+ if (zero || wc != L'\0') {
+ return (len - ocount);
+ } else {
+ return (0);
+ }
}
static size_t
diff --git a/usr/src/lib/libc/port/locale/gbk.c b/usr/src/lib/libc/port/locale/gbk.c
index 5c94b9954b..f422ce8fb5 100644
--- a/usr/src/lib/libc/port/locale/gbk.c
+++ b/usr/src/lib/libc/port/locale/gbk.c
@@ -44,7 +44,7 @@
static size_t _GBK_mbrtowc(wchar_t *_RESTRICT_KYWD,
const char *_RESTRICT_KYWD,
- size_t, mbstate_t *_RESTRICT_KYWD);
+ size_t, mbstate_t *_RESTRICT_KYWD, boolean_t);
static int _GBK_mbsinit(const mbstate_t *);
static size_t _GBK_wcrtomb(char *_RESTRICT_KYWD, wchar_t,
mbstate_t *_RESTRICT_KYWD);
@@ -88,7 +88,7 @@ _gbk_check(uint_t c)
static size_t
_GBK_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
- size_t n, mbstate_t *_RESTRICT_KYWD ps)
+ size_t n, mbstate_t *_RESTRICT_KYWD ps, boolean_t zero)
{
_GBKState *gs;
wchar_t wc;
@@ -143,7 +143,11 @@ _GBK_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
} else {
if (pwc != NULL)
*pwc = wc;
- return (wc == L'\0' ? 0 : 1);
+ if (zero || wc != L'\0') {
+ return (1);
+ } else {
+ return (0);
+ }
}
}
diff --git a/usr/src/lib/libc/port/locale/lctype.h b/usr/src/lib/libc/port/locale/lctype.h
index 25652da1d4..0a9e1335bf 100644
--- a/usr/src/lib/libc/port/locale/lctype.h
+++ b/usr/src/lib/libc/port/locale/lctype.h
@@ -17,6 +17,7 @@
#define _LCTYPE_H_
#include <wchar.h>
+#include <sys/types.h>
/* private LC_CTYPE related structures */
@@ -24,7 +25,8 @@
struct lc_ctype {
size_t (*lc_mbrtowc)(wchar_t *_RESTRICT_KYWD,
- const char *_RESTRICT_KYWD, size_t, mbstate_t *_RESTRICT_KYWD);
+ const char *_RESTRICT_KYWD, size_t, mbstate_t *_RESTRICT_KYWD,
+ boolean_t);
int (*lc_mbsinit)(const mbstate_t *);
@@ -51,7 +53,7 @@ struct lc_ctype {
* Default implementation (C locale, i.e. ASCII).
*/
size_t __mbrtowc_ascii(wchar_t *_RESTRICT_KYWD,
- const char *_RESTRICT_KYWD, size_t, mbstate_t *_RESTRICT_KYWD);
+ const char *_RESTRICT_KYWD, size_t, mbstate_t *_RESTRICT_KYWD, boolean_t);
int __mbsinit_ascii(const mbstate_t *);
size_t __mbsnrtowcs_ascii(wchar_t *_RESTRICT_KYWD dst,
const char **_RESTRICT_KYWD src, size_t nms, size_t len,
diff --git a/usr/src/lib/libc/port/locale/mblocal.h b/usr/src/lib/libc/port/locale/mblocal.h
index 4412bec7cb..3d958e364e 100644
--- a/usr/src/lib/libc/port/locale/mblocal.h
+++ b/usr/src/lib/libc/port/locale/mblocal.h
@@ -48,7 +48,7 @@ void _BIG5_init(struct lc_ctype *);
void _MSKanji_init(struct lc_ctype *);
typedef size_t (*mbrtowc_pfn_t)(wchar_t *_RESTRICT_KYWD,
- const char *_RESTRICT_KYWD, size_t, mbstate_t *_RESTRICT_KYWD);
+ const char *_RESTRICT_KYWD, size_t, mbstate_t *_RESTRICT_KYWD, boolean_t);
typedef size_t (*wcrtomb_pfn_t)(char *_RESTRICT_KYWD, wchar_t,
mbstate_t *_RESTRICT_KYWD);
size_t __mbsnrtowcs_std(wchar_t *_RESTRICT_KYWD, const char **_RESTRICT_KYWD,
diff --git a/usr/src/lib/libc/port/locale/mbrtowc.c b/usr/src/lib/libc/port/locale/mbrtowc.c
index cd1e7b064f..c0934c88d1 100644
--- a/usr/src/lib/libc/port/locale/mbrtowc.c
+++ b/usr/src/lib/libc/port/locale/mbrtowc.c
@@ -40,7 +40,7 @@ mbrtowc_l(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
if (ps == NULL)
ps = &mbs;
- return (loc->ctype->lc_mbrtowc(pwc, s, n, ps));
+ return (loc->ctype->lc_mbrtowc(pwc, s, n, ps, B_FALSE));
}
size_t
@@ -49,3 +49,21 @@ mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
{
return (mbrtowc_l(pwc, s, n, ps, uselocale(NULL)));
}
+
+size_t
+mbrtowc_nz_l(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
+ size_t n, mbstate_t *_RESTRICT_KYWD ps, locale_t loc)
+{
+ static mbstate_t mbs;
+
+ if (ps == NULL)
+ ps = &mbs;
+ return (loc->ctype->lc_mbrtowc(pwc, s, n, ps, B_TRUE));
+}
+
+size_t
+mbrtowc_nz(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
+ size_t n, mbstate_t *_RESTRICT_KYWD ps)
+{
+ return (mbrtowc_nz_l(pwc, s, n, ps, uselocale(NULL)));
+}
diff --git a/usr/src/lib/libc/port/locale/mbsnrtowcs.c b/usr/src/lib/libc/port/locale/mbsnrtowcs.c
index 533b7776e0..6411cfcb74 100644
--- a/usr/src/lib/libc/port/locale/mbsnrtowcs.c
+++ b/usr/src/lib/libc/port/locale/mbsnrtowcs.c
@@ -68,11 +68,13 @@ __mbsnrtowcs_std(wchar_t *_RESTRICT_KYWD dst, const char **_RESTRICT_KYWD src,
if (dst == NULL) {
for (;;) {
- if ((nb = pmbrtowc(&wc, s, nms, ps)) == (size_t)-1)
+ if ((nb = pmbrtowc(&wc, s, nms, ps, B_FALSE)) ==
+ (size_t)-1) {
/* Invalid sequence - mbrtowc() sets errno. */
return ((size_t)-1);
- else if (nb == 0 || nb == (size_t)-2)
+ } else if (nb == 0 || nb == (size_t)-2) {
return (nchr);
+ }
s += nb;
nms -= nb;
nchr++;
@@ -81,7 +83,7 @@ __mbsnrtowcs_std(wchar_t *_RESTRICT_KYWD dst, const char **_RESTRICT_KYWD src,
}
while (len-- > 0) {
- if ((nb = pmbrtowc(dst, s, nms, ps)) == (size_t)-1) {
+ if ((nb = pmbrtowc(dst, s, nms, ps, B_FALSE)) == (size_t)-1) {
*src = s;
return ((size_t)-1);
} else if (nb == (size_t)-2) {
diff --git a/usr/src/lib/libc/port/locale/mskanji.c b/usr/src/lib/libc/port/locale/mskanji.c
index 5d9b899aae..69955e5afa 100644
--- a/usr/src/lib/libc/port/locale/mskanji.c
+++ b/usr/src/lib/libc/port/locale/mskanji.c
@@ -46,7 +46,7 @@
static size_t _MSKanji_mbrtowc(wchar_t *_RESTRICT_KYWD,
const char *_RESTRICT_KYWD,
- size_t, mbstate_t *_RESTRICT_KYWD);
+ size_t, mbstate_t *_RESTRICT_KYWD, boolean_t);
static int _MSKanji_mbsinit(const mbstate_t *);
static size_t _MSKanji_wcrtomb(char *_RESTRICT_KYWD, wchar_t,
mbstate_t *_RESTRICT_KYWD);
@@ -83,7 +83,7 @@ _MSKanji_mbsinit(const mbstate_t *ps)
static size_t
_MSKanji_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
- size_t n, mbstate_t *_RESTRICT_KYWD ps)
+ size_t n, mbstate_t *_RESTRICT_KYWD ps, boolean_t zero)
{
_MSKanjiState *ms;
wchar_t wc;
@@ -135,7 +135,11 @@ _MSKanji_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
} else {
if (pwc != NULL)
*pwc = wc;
- return (wc == L'\0' ? 0 : 1);
+ if (zero || wc != L'\0') {
+ return (1);
+ } else {
+ return (0);
+ }
}
}
diff --git a/usr/src/lib/libc/port/locale/none.c b/usr/src/lib/libc/port/locale/none.c
index 0511563cb1..5eefc746aa 100644
--- a/usr/src/lib/libc/port/locale/none.c
+++ b/usr/src/lib/libc/port/locale/none.c
@@ -73,7 +73,7 @@ __mbsinit_ascii(const mbstate_t *unused)
size_t
__mbrtowc_ascii(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
- size_t n, mbstate_t *_RESTRICT_KYWD unused)
+ size_t n, mbstate_t *_RESTRICT_KYWD unused, boolean_t zero)
{
_NOTE(ARGUNUSED(unused));
@@ -85,7 +85,11 @@ __mbrtowc_ascii(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
return ((size_t)-2);
if (pwc != NULL)
*pwc = (unsigned char)*s;
- return (*s == '\0' ? 0 : 1);
+ if (zero || *s != '\0') {
+ return (1);
+ } else {
+ return (0);
+ }
}
size_t
diff --git a/usr/src/lib/libc/port/locale/utf8.c b/usr/src/lib/libc/port/locale/utf8.c
index e919b9dd4a..a6e037d94e 100644
--- a/usr/src/lib/libc/port/locale/utf8.c
+++ b/usr/src/lib/libc/port/locale/utf8.c
@@ -37,7 +37,7 @@
static size_t _UTF8_mbrtowc(wchar_t *_RESTRICT_KYWD,
const char *_RESTRICT_KYWD,
- size_t, mbstate_t *_RESTRICT_KYWD);
+ size_t, mbstate_t *_RESTRICT_KYWD, boolean_t);
static int _UTF8_mbsinit(const mbstate_t *);
static size_t _UTF8_mbsnrtowcs(wchar_t *_RESTRICT_KYWD,
const char **_RESTRICT_KYWD, size_t, size_t,
@@ -75,7 +75,7 @@ _UTF8_mbsinit(const mbstate_t *ps)
static size_t
_UTF8_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
- size_t n, mbstate_t *_RESTRICT_KYWD ps)
+ size_t n, mbstate_t *_RESTRICT_KYWD ps, boolean_t zero)
{
_UTF8State *us;
int ch, i, mask, want;
@@ -116,7 +116,11 @@ _UTF8_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
/* Fast path for plain ASCII characters. */
if (pwc != NULL)
*pwc = ch;
- return (ch != '\0' ? 1 : 0);
+ if (zero || ch != '\0') {
+ return (1);
+ } else {
+ return (0);
+ }
}
if ((ch & 0xe0) == 0xc0) {
mask = 0x1f;
@@ -192,7 +196,11 @@ _UTF8_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
if (pwc != NULL)
*pwc = wch;
us->want = 0;
- return (wch == L'\0' ? 0 : want);
+ if (zero || wch != L'\0') {
+ return (want);
+ } else {
+ return (0);
+ }
}
static size_t
@@ -221,18 +229,19 @@ _UTF8_mbsnrtowcs(wchar_t *_RESTRICT_KYWD dst, const char **_RESTRICT_KYWD src,
return ((size_t)-1);
}
for (;;) {
- if (nms > 0 && (signed char)*s > 0)
+ if (nms > 0 && (signed char)*s > 0) {
/*
* Fast path for plain ASCII characters
* excluding NUL.
*/
nb = 1;
- else if ((nb = _UTF8_mbrtowc(&wc, s, nms, ps)) ==
- (size_t)-1)
+ } else if ((nb = _UTF8_mbrtowc(&wc, s, nms, ps,
+ B_FALSE)) == (size_t)-1) {
/* Invalid sequence - mbrtowc() sets errno. */
return ((size_t)-1);
- else if (nb == 0 || nb == (size_t)-2)
+ } else if (nb == 0 || nb == (size_t)-2) {
return (nchr);
+ }
s += nb;
nms -= nb;
nchr++;
@@ -257,7 +266,7 @@ _UTF8_mbsnrtowcs(wchar_t *_RESTRICT_KYWD dst, const char **_RESTRICT_KYWD src,
*/
*dst = (wchar_t)*s;
nb = 1;
- } else if ((nb = _UTF8_mbrtowc(dst, s, nms, ps)) ==
+ } else if ((nb = _UTF8_mbrtowc(dst, s, nms, ps, B_FALSE)) ==
(size_t)-1) {
*src = s;
return ((size_t)-1);