2 * UCW Library -- A simple growing buffers for byte-sized items
4 * (c) 2006 Pavel Charvat <pchar@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
16 bb_vprintf_at(bb_t *bb, uns ofs, char *fmt, va_list args)
21 int cnt = vsnprintf(bb->ptr + ofs, bb->len - ofs, fmt, args2);
25 /* Our C library doesn't support C99 return value of vsnprintf, so we need to iterate */
28 bb_do_grow(bb, bb->len + 1);
30 cnt = vsnprintf(bb->ptr + ofs, bb->len - ofs, fmt, args2);
35 else if ((uns)cnt >= bb->len - ofs)
37 bb_do_grow(bb, ofs + cnt + 1);
39 int cnt2 = vsnprintf(bb->ptr + ofs, bb->len - ofs, fmt, args2);
47 bb_printf_at(bb_t *bb, uns ofs, char *fmt, ...)
51 char *res = bb_vprintf_at(bb, ofs, fmt, args);
57 bb_vprintf(bb_t *bb, char *fmt, va_list args)
59 return bb_vprintf_at(bb, 0, fmt, args);
63 bb_printf(bb_t *bb, char *fmt, ...)
67 char *res = bb_vprintf_at(bb, 0, fmt, args);
78 char *x = bb_printf(&bb, "<Hello, %s!>", "World");
80 x = bb_printf_at(&bb, 5, "<Hello, %50s!>\n", "World");