From 3d65ea9e8aee32b75f2ed9c3dca45c527837dbda Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 17 Jul 2020 23:58:46 +0300 Subject: [PATCH] Make *printf return count --- src/stdio/_printf.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/stdio/_printf.c b/src/stdio/_printf.c index 59eba8f..d1bd052 100644 --- a/src/stdio/_printf.c +++ b/src/stdio/_printf.c @@ -273,12 +273,14 @@ int __libc_vprintf(const char *format, if (out(ctx, &pad_char, 1) != 0) { return -1; } + ++count; } } if (out(ctx, tmp, l) != 0) { return -1; } + count += l; } else if (ch == 'c') { // TODO: wchar_t pv.value_char = va_arg(ap, int); @@ -287,6 +289,7 @@ int __libc_vprintf(const char *format, if (out(ctx, &pv.value_char, 1) != 0) { return -1; } + ++count; } else if (ch == 's') { // TODO: wchar_t pv.value_str = va_arg(ap, const char *); @@ -302,16 +305,19 @@ int __libc_vprintf(const char *format, if (out(ctx, &pad_char, 1) != 0) { return -1; } + ++count; } } if (out(ctx, pv.value_str, l) != 0) { return -1; } + count += l; } else { // Unknown format or '%' if (out(ctx, &ch, 1) != 0) { return -1; } + ++count; continue; } @@ -322,12 +328,14 @@ int __libc_vprintf(const char *format, if (out(ctx, &pad_char, 1) != 0) { return -1; } + ++count; } } } else { if (out(ctx, &ch, 1) != 0) { return -1; } + ++count; } }