vbaprintf.c (520B)
1 /* ISC license. */ 2 3 #include <stdio.h> 4 #include <stdarg.h> 5 #include <skalibs/stralloc.h> 6 #include <skalibs/bufalloc.h> 7 #include <skalibs/lolstdio.h> 8 9 int vbaprintf (bufalloc *ba, char const *format, va_list args) 10 { 11 int r ; 12 { 13 va_list ugly ; 14 va_copy(ugly, args) ; 15 r = vsnprintf(0, 0, format, ugly) ; 16 va_end(ugly) ; 17 } 18 if (r < 0) return r ; 19 if (!stralloc_readyplus(&ba->x, r + 1)) return -1 ; 20 r = vsnprintf(ba->x.s + ba->x.len, r + 1, format, args) ; 21 if (r > 0) ba->x.len += r ; 22 return r ; 23 }