[PATCH 1/2] pbl: console: implement vprintf()
Sascha Hauer
s.hauer at pengutronix.de
Thu Feb 26 03:07:57 PST 2026
vprintf() can be used to implement printf() which is done in this patch,
but will also be usable for panic() in the next patch.
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
pbl/console.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/pbl/console.c b/pbl/console.c
index 6665232014..f2e7b3a20e 100644
--- a/pbl/console.c
+++ b/pbl/console.c
@@ -56,18 +56,32 @@ int console_puts(unsigned int ch, const char *str)
return n;
}
+int vprintf(const char *fmt, va_list args)
+{
+ int i;
+ char printbuffer[CFG_PBSIZE];
+
+ /*
+ * For this to work, printbuffer must be larger than
+ * anything we ever want to print.
+ */
+ i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args);
+
+ /* Print the string */
+ console_puts(CONSOLE_STDOUT, printbuffer);
+
+ return i;
+}
+
int printf(const char *fmt, ...)
{
va_list args;
uint i;
- char printbuffer[CFG_PBSIZE];
va_start(args, fmt);
- i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args);
+ i = vprintf(fmt, args);
va_end(args);
- console_puts(CONSOLE_STDOUT, printbuffer);
-
return i;
}
--
2.47.3
More information about the barebox
mailing list