vbprintf.c (487B)
1 /* ISC license. */ 2 3 #include <stdio.h> 4 #include <stdarg.h> 5 #include <skalibs/buffer.h> 6 #include <skalibs/lolstdio.h> 7 8 int vbprintf (buffer *b, char const *format, va_list args) 9 { 10 int r ; 11 { 12 va_list ugly ; 13 va_copy(ugly, args) ; 14 r = vsnprintf(0, 0, format, ugly) ; 15 va_end(ugly) ; 16 } 17 if (r < 0) return r ; 18 { 19 char buf[r+1] ; 20 r = vsnprintf(buf, r + 1, format, args) ; 21 if (r < 0) return r ; 22 if (buffer_put(b, buf, r) < r) return -1 ; 23 } 24 return r ; 25 }