2 * Sherlock Library -- Character Conversion with Allocation on a Memory Pool
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.
11 #include "lib/mempool.h"
12 #include "charset/mp-charconv.h"
17 mp_conv(struct mempool *mp, byte *s, uns in_cs, uns out_cs)
20 return mp_strdup(mp, s);
22 struct conv_context c;
24 uns bs[32], n = 0, sum = 0;
25 uns l = strlen(s) + 1;
28 conv_set_charset(&c, in_cs, out_cs);
35 c.dest_start = c.dest = b[n] = alloca(l);
36 c.dest_end = c.dest_start+ l;
38 sum += bs[n++] = c.dest - c.dest_start;
39 if (r & CONV_SOURCE_END)
41 c.dest_start = c.dest = mp_alloc(mp, sum);
42 for (uns i = 0; i < n; i++)
44 memcpy(c.dest, b[i], bs[i]);