--- /dev/null
+/*
+ * Sherlock Library -- Memory Pools (String Operations)
+ *
+ * (c) 2004 Martin Mares <mj@ucw.cz>
+ *
+ * This software may be freely distributed and used according to the terms
+ * of the GNU Lesser General Public License.
+ */
+
+#include "lib/lib.h"
+#include "lib/pools.h"
+
+#include <alloca.h>
+#include <string.h>
+
+char *
+mp_strdup(struct mempool *p, char *s)
+{
+ uns l = strlen(s) + 1;
+ char *t = mp_alloc_fast_noalign(p, l);
+ memcpy(t, s, l);
+ return t;
+}
+
+char *
+mp_multicat(struct mempool *p, ...)
+{
+ va_list args, a;
+ va_start(args, p);
+ char *x, *y;
+ uns cnt = 0;
+ a = args;
+ while (x = va_arg(a, char *))
+ cnt++;
+ uns *sizes = alloca(cnt * sizeof(uns));
+ uns len = 1;
+ cnt = 0;
+ a = args;
+ while (x = va_arg(a, char *))
+ len += sizes[cnt++] = strlen(x);
+ char *buf = mp_alloc_fast_noalign(p, len);
+ y = buf;
+ a = args;
+ cnt = 0;
+ while (x = va_arg(a, char *))
+ {
+ memcpy(y, x, sizes[cnt]);
+ y += sizes[cnt++];
+ }
+ *y = 0;
+ return buf;
+}
bzero(x, s);
return x;
}
-
-char *
-mp_strdup(struct mempool *p, char *s)
-{
- uns l = strlen(s) + 1;
- char *t = mp_alloc_fast_noalign(p, l);
- memcpy(t, s, l);
- return t;
-}
void mp_flush(struct mempool *);
void *mp_alloc(struct mempool *, uns);
void *mp_alloc_zero(struct mempool *, uns);
-char *mp_strdup(struct mempool *, char *);
static inline void *mp_alloc_fast(struct mempool *p, uns l)
{
p->free = stop;
}
+/* pool-str.c */
+
+char *mp_strdup(struct mempool *, char *);
+char *mp_multicat(struct mempool *, ...);
+static inline char *
+mp_strcat(struct mempool *mp, char *x, char *y)
+{
+ mp_multicat(mp, x, y, NULL);
+}
+
#endif