1.1 --- a/ucx/string.c Fri Jul 12 20:50:18 2013 +0200 1.2 +++ b/ucx/string.c Sun Jul 14 17:11:34 2013 +0200 1.3 @@ -31,6 +31,7 @@ 1.4 #include <stdarg.h> 1.5 1.6 #include "string.h" 1.7 +#include "allocator.h" 1.8 1.9 sstr_t sstr(char *s) { 1.10 sstr_t string; 1.11 @@ -180,16 +181,30 @@ 1.12 sstr_t sstrdup(sstr_t s) { 1.13 sstr_t newstring; 1.14 newstring.ptr = (char*) malloc(s.length + 1); 1.15 - newstring.length = 0; 1.16 if (newstring.ptr) { 1.17 newstring.length = s.length; 1.18 newstring.ptr[newstring.length] = 0; 1.19 - 1.20 + 1.21 memcpy(newstring.ptr, s.ptr, s.length); 1.22 } else { 1.23 newstring.length = 0; 1.24 } 1.25 + 1.26 + return newstring; 1.27 +} 1.28 1.29 +sstr_t sstrdup_alloc(UcxAllocator *allocator, sstr_t s) { 1.30 + sstr_t newstring; 1.31 + newstring.ptr = (char*)allocator->malloc(allocator->pool, s.length + 1); 1.32 + if (newstring.ptr) { 1.33 + newstring.length = s.length; 1.34 + newstring.ptr[newstring.length] = 0; 1.35 + 1.36 + memcpy(newstring.ptr, s.ptr, s.length); 1.37 + } else { 1.38 + newstring.length = 0; 1.39 + } 1.40 + 1.41 return newstring; 1.42 } 1.43