]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/mempool-str.c
Opt: Introduced contexts
[libucw.git] / ucw / mempool-str.c
index cb2466304a902147f7be3b52fd028257ba06a2d1..9391cbb6eb1db3b8739d74ed364a5a619c7c71bb 100644 (file)
@@ -7,8 +7,8 @@
  *     of the GNU Lesser General Public License.
  */
 
-#include "ucw/lib.h"
-#include "ucw/mempool.h"
+#include <ucw/lib.h>
+#include <ucw/mempool.h>
 
 #include <alloca.h>
 #include <string.h>
@@ -85,6 +85,15 @@ mp_strjoin(struct mempool *p, char **a, uns n, uns sep)
   return dest;
 }
 
+char *
+mp_str_from_mem(struct mempool *a, const void *mem, uns len)
+{
+  char *str = mp_alloc_noalign(a, len+1);
+  memcpy(str, mem, len);
+  str[len] = 0;
+  return str;
+}
+
 #ifdef TEST
 
 #include <stdio.h>
@@ -98,6 +107,7 @@ int main(void)
   char *a[] = { "bugs", "gnats", "insects" };
   puts(mp_strjoin(p, a, 3, '.'));
   puts(mp_strjoin(p, a, 3, 0));
+  puts(mp_str_from_mem(p, s+1, 2));
   return 0;
 }