mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2025-08-06 15:26:58 +02:00
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> Reviewed-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
This commit is contained in:
parent
4ca87fd18c
commit
fe2d4d4cef
@ -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;
|
||||
|
@ -169,6 +169,21 @@ int console_announce_r(void);
|
||||
*/
|
||||
void console_puts_select_stderr(bool serial_only, const char *s);
|
||||
|
||||
/**
|
||||
* console_printf_select_stderr() - Output a formatted string to selected devs
|
||||
*
|
||||
* This writes to stderr only. It is useful for outputting errors. Note that it
|
||||
* uses its own buffer, separate from the print buffer, to allow printing
|
||||
* messages within console/stdio code
|
||||
*
|
||||
* @serial_only: true to output only to serial, false to output to everything
|
||||
* else
|
||||
* @fmt: Printf format string, followed by format arguments
|
||||
* Return: number of characters written
|
||||
*/
|
||||
int console_printf_select_stderr(bool serial_only, const char *fmt, ...)
|
||||
__attribute__ ((format (__printf__, 2, 3)));
|
||||
|
||||
/**
|
||||
* console_clear() - Clear the console
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user