X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmultibyte%2Fwcrtomb.c;h=8e34926ed8c5fe7ece77546ea7ae0601098398d8;hb=2e5fff43dd7fc808197744c67cca7908ac19bb4f;hp=250649f55b4fb707b4216b96f9d9e2dba96968a7;hpb=400c5e5c8307a2ebe44ef1f203f5a15669f20347;p=musl diff --git a/src/multibyte/wcrtomb.c b/src/multibyte/wcrtomb.c index 250649f5..8e34926e 100644 --- a/src/multibyte/wcrtomb.c +++ b/src/multibyte/wcrtomb.c @@ -1,14 +1,6 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - #include -#include #include #include - #include "internal.h" size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict st) @@ -17,6 +9,13 @@ size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict st) if ((unsigned)wc < 0x80) { *s = wc; return 1; + } else if (MB_CUR_MAX == 1) { + if (!IS_CODEUNIT(wc)) { + errno = EILSEQ; + return -1; + } + *s = wc; + return 1; } else if ((unsigned)wc < 0x800) { *s++ = 0xc0 | (wc>>6); *s = 0x80 | (wc&0x3f);