X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmultibyte%2Fwcrtomb.c;h=8e34926ed8c5fe7ece77546ea7ae0601098398d8;hb=adfe682eb0d77c6afc751f5e407d9da39623c24e;hp=36180c8f00fa2fa49208ef18e8710c013a2eaba9;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01;p=musl diff --git a/src/multibyte/wcrtomb.c b/src/multibyte/wcrtomb.c index 36180c8f..8e34926e 100644 --- a/src/multibyte/wcrtomb.c +++ b/src/multibyte/wcrtomb.c @@ -1,22 +1,21 @@ -/* - * 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 *s, wchar_t wc, mbstate_t *st) +size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict st) { if (!s) return 1; 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);