scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 6e7751100b041448d70c6825b41139fd8a41e872
parent 9a9bc0e6e69c2aafa59e13d2300736be512a6855
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  7 Nov 2022 14:30:23 +0100

libc/stdio: Enable printing wide character strings

Diffstat:
Msrc/libc/stdio/vfprintf.c | 23+++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/src/libc/stdio/vfprintf.c b/src/libc/stdio/vfprintf.c @@ -123,28 +123,31 @@ wstrout(wchar_t *ws, size_t len, int width, int fill, FILE *restrict fp) int left = 0, adjust; size_t cnt = 0; wchar_t wc; -#if 0 if (width < 0) { left = 1; width = -width; } - len *= sizeof(wchar_t); - adjust = (len < width) ? width - len : 0; - cnt = adjust + len; + adjust = len < width ? width - len : 0; if (left) adjust = -adjust; - for ( ; adjust > 0; adjust++) - putc(fill, fp); + for ( ; adjust > 0; adjust--) { + putwc(fill, fp); + ++cnt; + } - while (wc = *ws++) + for ( ; len-- > 0 && (wc = *ws) != '\0'; ++ws) { putwc(wc, fp); + ++cnt; + } + + for ( ; adjust < 0; adjust++) { + putwc(' ', fp); + ++cnt; + } - for ( ; adjust < 0; adjust--) - putc(' ', fp); -#endif return cnt; }