X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmultibyte%2Fwcrtomb.c;h=8e34926ed8c5fe7ece77546ea7ae0601098398d8;hb=2e5fff43dd7fc808197744c67cca7908ac19bb4f;hp=59f733db6e33dac743c89a8927fd2cbdb9f87c31;hpb=571744447c23f91feb6439948f3a619aca850dfb;p=musl diff --git a/src/multibyte/wcrtomb.c b/src/multibyte/wcrtomb.c index 59f733db..8e34926e 100644 --- a/src/multibyte/wcrtomb.c +++ b/src/multibyte/wcrtomb.c @@ -1,11 +1,7 @@ -/* - * 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 "internal.h" size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict st) { @@ -13,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);