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);
  ...
}
This commit is contained in:
Jan Maria Matejka 2018-08-22 14:58:53 +02:00
parent 765f400f6b
commit 64c5ad58d2

View file

@ -270,6 +270,17 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
*str++ = ' '; *str++ = ' ';
continue; 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': case 'p':
if (field_width == -1) { if (field_width == -1) {
field_width = 2*sizeof(void *); field_width = 2*sizeof(void *);