From 20c83ba605183e1a597bf790be1d1d0f06d2651f Mon Sep 17 00:00:00 2001 From: axel Date: Sat, 11 Feb 2006 10:13:17 +1000 Subject: 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 --- halloc_util.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'halloc_util.c') 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 #include +#include #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; +} -- cgit v1.2.3