summaryrefslogtreecommitdiff
path: root/src/stdio
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-08-15 15:47:18 -0400
committerJakob Kaivo <jkk@ung.org>2020-08-15 15:47:18 -0400
commit91d875c5e85ca2d17f4a2c217cd4f83efe9af6dc (patch)
treee1bd4d1124db715f2590c42a591a0a5e3b75deba /src/stdio
parent88eb465b34b8d06d443bf81114cab21d2b2b5f7d (diff)
handle %lc and %ls correctly
Diffstat (limited to 'src/stdio')
-rw-r--r--src/stdio/__printf.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/stdio/__printf.c b/src/stdio/__printf.c
index 3f2b82ad..e82156b9 100644
--- a/src/stdio/__printf.c
+++ b/src/stdio/__printf.c
@@ -6,6 +6,7 @@
#include "wchar.h"
#include "inttypes.h"
#include "unistd.h"
+#include "stdlib.h"
#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199909L
#include "stdint/intmax_t.c"
@@ -273,10 +274,14 @@ int (__printf)(struct io_options *opt, const char * format, va_list arg)
}
nout++;
} else if (length == l) {
- /* wint_t wc = va_arg(arg, wint_t); */
- /* char mb[MB_CUR_MAX + 1] = "WC"; */
- /* wctomb(mb, wc); */
- /* nout = __append(s, mb, nout, n); */
+ #if defined __STDC_VERSION__
+ wint_t wc = va_arg(arg, wint_t);
+ char mb[MB_CUR_MAX + 1] = "WC";
+ wctomb(mb, wc);
+ nout = __append(s, mb, nout, n);
+ #else
+ nout = __append(s, "NOSUP", nout, n);
+ #endif
} else {
nout = -nout;
goto end;
@@ -288,12 +293,15 @@ int (__printf)(struct io_options *opt, const char * format, va_list arg)
char *string = va_arg(arg, char *);
nout = __append(s, string, nout, n);
} else if (length == l) {
- /*wchar_t *ws = va_arg(arg, wchar_t *); */
- /*char *mbs = malloc(wcslen(ws) * MB_CUR_MAX + 1); */
- /*wcstombs(mbs, ws, wcslen(ws) * MB_CUR_MAX + 1); */
- /*nout = __append(s, mbs, nout, n); */
- /*free(mbs); */
- nout = __append(s, "WIDE STRING", nout, n);
+ #if defined __STDC_VERSION__
+ wchar_t *ws = va_arg(arg, wchar_t *);
+ char *mbs = malloc(wcslen(ws) * MB_CUR_MAX + 1);
+ wcstombs(mbs, ws, wcslen(ws) * MB_CUR_MAX + 1);
+ nout = __append(s, mbs, nout, n);
+ free(mbs);
+ #else
+ nout = __append(s, "NOSUP", nout, n);
+ #endif
} else {
nout = -nout;
goto end;