2 * UCW Library -- Memory Pools (String Operations)
4 * (c) 2004 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"
17 mp_strdup(struct mempool *p, char *s)
19 uns l = strlen(s) + 1;
20 char *t = mp_alloc_fast_noalign(p, l);
26 mp_memdup(struct mempool *p, void *s, uns len)
28 void *t = mp_alloc_fast(p, len);
34 mp_multicat(struct mempool *p, ...)
41 while (x = va_arg(a, char *))
43 uns *sizes = alloca(cnt * sizeof(uns));
48 while (x = va_arg(a, char *))
49 len += sizes[cnt++] = strlen(x);
50 char *buf = mp_alloc_fast_noalign(p, len);
54 while (x = va_arg(args, char *))
56 memcpy(y, x, sizes[cnt]);
70 struct mempool *p = mp_new(64);
71 char *s = mp_strdup(p, "12345");
72 char *c = mp_multicat(p, "<<", s, ">>", NULL);