diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2018-10-02 12:45:19 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2018-10-08 08:36:58 +0200 |
commit | e8909590f73932f944d92ab6f23cd4d32ed0c838 (patch) | |
tree | 1a1545b04bda678cbaf7899089c6410051539949 /lib | |
parent | ca079cf77f7b231b961eb557ccbe154d774967be (diff) | |
download | barebox-e8909590f73932f944d92ab6f23cd4d32ed0c838.tar.gz barebox-e8909590f73932f944d92ab6f23cd4d32ed0c838.tar.xz |
vsprintf: implement %pV
%pV allows to pass in a struct va_format as a pointer. UBIFS uses this
for its logging functions, but it may be useful in other places aswell.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/vsprintf.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index fa9fb75800..6fe0283e84 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -302,6 +302,11 @@ char *address_val(char *buf, char *end, const void *addr, * [0][1][2][3]-[4][5]-[6][7]-[8][9]-[10][11][12][13][14][15] * little endian output byte order is: * [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15] + * - 'V' For a struct va_format which contains a format string * and va_list *, + * call vsnprintf(->format, *->va_list). + * Implements a "recursive vsnprintf". + * Do not use this feature without some mechanism to verify the + * correctness of the format string and va_list arguments. * - 'a[pd]' For address types [p] phys_addr_t, [d] dma_addr_t and derivatives * (default assumed to be phys_addr_t, passed by reference) * @@ -318,6 +323,16 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field if (IS_ENABLED(CONFIG_PRINTF_UUID)) return uuid_string(buf, end, ptr, field_width, precision, flags, fmt); break; + case 'V': + { + va_list va; + + va_copy(va, *((struct va_format *)ptr)->va); + buf += vsnprintf(buf, end > buf ? end - buf : 0, + ((struct va_format *)ptr)->fmt, va); + va_end(va); + return buf; + } case 'a': return address_val(buf, end, ptr, field_width, precision, flags, fmt); case 'I': |