From: David Laight <david.laight.linux@gmail.com>
Simple to do and saves calls to the callback function.
Signed-off-by: David Laight <david.laight.linux@gmail.com>
---
tools/include/nolibc/stdio.h | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h
index 985e10d747db..52cb516ea3db 100644
--- a/tools/include/nolibc/stdio.h
+++ b/tools/include/nolibc/stdio.h
@@ -355,10 +355,12 @@ int __nolibc_printf(__nolibc_printf_cb cb, void *state, const char *fmt, va_list
outstr = fmt;
len = ofs - 1;
flush_str:
- while (width-- > len) {
- if (cb(state, " ", 1) != 0)
+ while (width > len) {
+ unsigned int pad_len = ((width - len - 1) & 15) + 1;
+ width -= pad_len;
+ written += pad_len;
+ if (cb(state, " ", pad_len) != 0)
return -1;
- written += 1;
}
if (cb(state, outstr, len) != 0)
return -1;
--
2.39.5