From: Jan Maria Matejka Date: Wed, 22 Aug 2018 12:58:53 +0000 (+0200) Subject: Lib: recursive printf X-Git-Tag: v2.0.3~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=64c5ad58d276d8a0463aa9ad2b34f75b7d1f4108;p=thirdparty%2Fbird.git Lib: recursive printf Use like this: void func(const char *msg, va_list args) { ... bvsnprintf(buf, len, "file %s, line %d: %V (foo %d, bar %d)", file, line, msg, &args, foo, bar); ... } --- diff --git a/lib/printf.c b/lib/printf.c index 533a1300b..cafeeb931 100644 --- a/lib/printf.c +++ b/lib/printf.c @@ -270,6 +270,17 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args) *str++ = ' '; continue; + case 'V': { + const char *vfmt = va_arg(args, const char *); + va_list *vargs = va_arg(args, va_list *); + int res = bvsnprintf(str, size, vfmt, *vargs); + if (res < 0) + return -1; + str += res; + size -= res; + continue; + } + case 'p': if (field_width == -1) { field_width = 2*sizeof(void *);