summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Laight <david.laight.linux@gmail.com>2026-03-08 14:37:30 +0300
committerThomas Weißschuh <linux@weissschuh.net>2026-03-20 19:46:09 +0300
commita2fa5a752ce67c11a9d6d6535165195073ce0c46 (patch)
tree7251c0e949974e825b46ca8c368adab8d887f9c8
parentc0a08eb87f60daec1c1549c067945abfee711f86 (diff)
downloadlinux-a2fa5a752ce67c11a9d6d6535165195073ce0c46.tar.xz
tools/nolibc/printf: Output pad characters in 16 byte chunks
Simple to do and saves calls to the callback function. Change variables written, width and len to 'signed int' to get better code. Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-6-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
-rw-r--r--tools/include/nolibc/stdio.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h
index 985e7f0834bf..bdecc703511c 100644
--- a/tools/include/nolibc/stdio.h
+++ b/tools/include/nolibc/stdio.h
@@ -312,8 +312,8 @@ int __nolibc_printf(__nolibc_printf_cb cb, void *state, const char *fmt, va_list
{
char escape, lpref, ch;
unsigned long long v;
- unsigned int written, width;
- size_t len, ofs;
+ int written, width, len;
+ size_t ofs;
char outbuf[21];
const char *outstr;
@@ -415,10 +415,14 @@ 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)
+ width -= len;
+ while (width > 0) {
+ /* Output pad in 16 byte blocks with the small block first. */
+ int pad_len = ((width - 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;