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:
parent
765f400f6b
commit
64c5ad58d2
1 changed files with 11 additions and 0 deletions
11
lib/printf.c
11
lib/printf.c
|
@ -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 *);
|
||||||
|
|
Loading…
Reference in a new issue