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_ofs_vprintf(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 (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_ofs_printf(bb_t *bb, uns ofs, char *fmt, ...)
51 char *res = bb_ofs_vprintf(bb, ofs, fmt, args);
62 char *x = bb_ofs_printf(&bb, 0, "<Hello, %s!>", "World");
64 x = bb_ofs_printf(&bb, 5, "<Hello, %50s!>\n", "World");