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 "charset/mp-charconv.h"
16 mp_strconv(struct mempool *mp, const byte *s, uns in_cs, uns out_cs)
19 return mp_strdup(mp, s);
21 struct conv_context c;
23 uns bs[32], n = 0, sum = 0;
24 uns l = strlen(s) + 1;
27 conv_set_charset(&c, in_cs, out_cs);
34 c.dest_start = c.dest = b[n] = alloca(l);
35 c.dest_end = c.dest_start+ l;
37 sum += bs[n++] = c.dest - c.dest_start;
38 if (r & CONV_SOURCE_END)
40 c.dest_start = c.dest = mp_alloc(mp, sum);
41 for (uns i = 0; i < n; i++)
43 memcpy(c.dest, b[i], bs[i]);