summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJan Maria Matejka <mq@ucw.cz>2018-08-22 14:58:53 +0200
committerJan Maria Matejka <mq@ucw.cz>2018-08-22 15:14:06 +0200
commit64c5ad58d276d8a0463aa9ad2b34f75b7d1f4108 (patch)
tree522a2ae0f16d4606d1f81021d42f9644060f5277 /lib
parent765f400f6b7ac054ddb4fcc4f5bec58f94d1bdd4 (diff)
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); ... }
Diffstat (limited to 'lib')
-rw-r--r--lib/printf.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/printf.c b/lib/printf.c
index 533a1300..cafeeb93 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 *);