aboutsummaryrefslogtreecommitdiffhomepage
path: root/halloc_util.c
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-02-11 10:13:17 +1000
committerGravatar axel <axel@liljencrantz.se>2006-02-11 10:13:17 +1000
commit20c83ba605183e1a597bf790be1d1d0f06d2651f (patch)
tree09e989c55d6bdf40dbe5d8cbcb4694cbbcf2a3c7 /halloc_util.c
parente9e32f980bb906994ed8bc1aa26f97fb3df19eec (diff)
Optimize the halloc implementation so that mutiple calls to halloc can be satisfied by a single malloc, also add wcsdup and wcsndup workalikes using halloc
darcs-hash:20060211001317-ac50b-c9cf234c334b4d697fe1251c21013c8ec7f7b0a1.gz
Diffstat (limited to 'halloc_util.c')
-rw-r--r--halloc_util.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/halloc_util.c b/halloc_util.c
index bc575f7e..f2eae06a 100644
--- a/halloc_util.c
+++ b/halloc_util.c
@@ -10,6 +10,7 @@
#include <stdlib.h>
#include <unistd.h>
+#include <string.h>
#include "util.h"
#include "common.h"
@@ -33,7 +34,7 @@ array_list_t *al_halloc( void *context )
if( !res )
die_mem();
al_init( res );
- halloc_register_function( res, (void (*)(void *)) &al_destroy, res );
+ halloc_register_function( context, (void (*)(void *)) &al_destroy, res );
return res;
}
@@ -43,7 +44,7 @@ string_buffer_t *sb_halloc( void *context )
if( !res )
die_mem();
sb_init( res );
- halloc_register_function( res, (void (*)(void *)) &sb_destroy, res );
+ halloc_register_function( context, (void (*)(void *)) &sb_destroy, res );
return res;
}
@@ -67,3 +68,27 @@ void *halloc_register( void *context, void *data )
return data;
}
+wchar_t *halloc_wcsdup( void *context, wchar_t *in )
+{
+ size_t len=wcslen(in);
+ wchar_t *out = halloc( context, sizeof( wchar_t)*(len+1));
+
+ if( out == 0 )
+ {
+ die_mem();
+ }
+ memcpy( out, in, sizeof( wchar_t)*(len+1));
+ return out;
+}
+
+wchar_t *halloc_wcsndup( void * context, const wchar_t *in, int c )
+{
+ wchar_t *res = halloc( context, sizeof(wchar_t)*(c+1) );
+ if( res == 0 )
+ {
+ die_mem();
+ }
+ wcslcpy( res, in, c );
+ res[c] = L'\0';
+ return res;
+}