From: Simon South Date: Wed, 2 Oct 2019 14:55:07 +0000 (-0400) Subject: tiny-printf: Support vsnprintf() X-Git-Tag: v2020.01-rc2~28^2~8 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=9b3fbb2b439a717dda0eaa34cb455a9ce38532ef;p=oweals%2Fu-boot.git tiny-printf: Support vsnprintf() Add a simple implementation of this function, to allow logging to be enabled in the SPL or TPL for systems that rely on the tiny printf() implementation. To keep the code size small, - The function is built only when logging is enabled, as it (currently) is not needed otherwise; and - Like the existing implementation of snprintf(), its buffer-size parameter is ignored. Signed-off-by: Simon South --- diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c index ebef92fc9f..62e6381961 100644 --- a/lib/tiny-printf.c +++ b/lib/tiny-printf.c @@ -366,6 +366,22 @@ int sprintf(char *buf, const char *fmt, ...) return ret; } +#if CONFIG_IS_ENABLED(LOG) +/* Note that size is ignored */ +int vsnprintf(char *buf, size_t size, const char *fmt, va_list va) +{ + struct printf_info info; + int ret; + + info.outstr = buf; + info.putc = putc_outstr; + ret = _vprintf(&info, fmt, va); + *info.outstr = '\0'; + + return ret; +} +#endif + /* Note that size is ignored */ int snprintf(char *buf, size_t size, const char *fmt, ...) {