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;
27 int cnt = vsnprintf(ret, free, fmt, args);
30 /* Our C library doesn't support C99 return value of vsnprintf, so we need to iterate */
37 cnt = vsnprintf(buf, len, fmt, args);
40 ret = mp_alloc(p, cnt+1);
41 memcpy(ret, buf, cnt+1);
47 ret = mp_alloc(p, cnt+1);
48 int cnt2 = vsnprintf(ret, cnt+1, fmt, args);
55 mp_printf(struct mempool *p, char *fmt, ...)
59 char *res = mp_vprintf(p, fmt, args);
68 struct mempool *mp = mp_new(64);
69 char *x = mp_printf(mp, "<Hello, %s!>", "World");
71 x = mp_printf(mp, "<Hello, %50s!>\n", "World");