console: Support a format string for stderr output

Add a console_printf_select_stderr() function so that it is not
necessary for the caller to process the format string.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-04-02 06:29:32 +13:00
parent 9b9647c89c
commit 8ac852ff7f
2 changed files with 33 additions and 0 deletions

View File

@@ -359,6 +359,24 @@ void console_puts_select_stderr(bool serial_only, const char *s)
console_puts_select(stderr, serial_only, s);
}
int console_printf_select_stderr(bool serial_only, const char *fmt, ...)
{
char buf[CONFIG_SYS_PBSIZE];
va_list args;
int ret;
va_start(args, fmt);
/* For this to work, buf must be larger than anything we ever want to
* print.
*/
ret = vscnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
console_puts_select_stderr(serial_only, buf);
return ret;
}
static void console_puts(int file, const char *s)
{
int i;