"Das U-Boot" Source Tree
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Simon Glass and committed by
Tom Rini
fe2d4d4c 4ca87fd1

+33
+18
common/console.c
··· 359 359 console_puts_select(stderr, serial_only, s); 360 360 } 361 361 362 + int console_printf_select_stderr(bool serial_only, const char *fmt, ...) 363 + { 364 + char buf[CONFIG_SYS_PBSIZE]; 365 + va_list args; 366 + int ret; 367 + 368 + va_start(args, fmt); 369 + 370 + /* For this to work, buf must be larger than anything we ever want to 371 + * print. 372 + */ 373 + ret = vscnprintf(buf, sizeof(buf), fmt, args); 374 + va_end(args); 375 + console_puts_select_stderr(serial_only, buf); 376 + 377 + return ret; 378 + } 379 + 362 380 static void console_puts(int file, const char *s) 363 381 { 364 382 int i;
+15
include/console.h
··· 170 170 void console_puts_select_stderr(bool serial_only, const char *s); 171 171 172 172 /** 173 + * console_printf_select_stderr() - Output a formatted string to selected devs 174 + * 175 + * This writes to stderr only. It is useful for outputting errors. Note that it 176 + * uses its own buffer, separate from the print buffer, to allow printing 177 + * messages within console/stdio code 178 + * 179 + * @serial_only: true to output only to serial, false to output to everything 180 + * else 181 + * @fmt: Printf format string, followed by format arguments 182 + * Return: number of characters written 183 + */ 184 + int console_printf_select_stderr(bool serial_only, const char *fmt, ...) 185 + __attribute__ ((format (__printf__, 2, 3))); 186 + 187 + /** 173 188 * console_clear() - Clear the console 174 189 * 175 190 * Uses an ANSI sequence to clear the display, failing back to clearing the