2 * UCW Library -- Memory Pools (Formatting)
4 * (c) 2005 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include "lib/mempool.h"
18 mp_vprintf(struct mempool *p, char *fmt, va_list args)
21 int free = p->last - p->free;
25 free = p->last - p->free;
29 int cnt = vsnprintf(ret, free, fmt, args2);
33 /* Our C library doesn't support C99 return value of vsnprintf, so we need to iterate */
41 cnt = vsnprintf(buf, len, fmt, args2);
45 ret = mp_alloc(p, cnt+1);
46 memcpy(ret, buf, cnt+1);
52 ret = mp_alloc(p, cnt+1);
54 int cnt2 = vsnprintf(ret, cnt+1, fmt, args2);
62 mp_printf(struct mempool *p, char *fmt, ...)
66 char *res = mp_vprintf(p, fmt, args);
75 struct mempool *mp = mp_new(64);
76 char *x = mp_printf(mp, "<Hello, %s!>", "World");
78 x = mp_printf(mp, "<Hello, %50s!>\n", "World");