From d45ec1dedfa06155c344f5cce0ac7b2ec331c825 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Thu, 1 Dec 2005 07:35:03 +0000 Subject: - implemented sa_config - uses identification - and host - untested - ts need further tuning --- Source/charon/utils/allocator.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'Source/charon/utils/allocator.c') diff --git a/Source/charon/utils/allocator.c b/Source/charon/utils/allocator.c index 46194e85f..8c314a88a 100644 --- a/Source/charon/utils/allocator.c +++ b/Source/charon/utils/allocator.c @@ -264,6 +264,25 @@ static void * clone_bytes(allocator_t *allocator,void * to_clone, size_t bytes, return new_space; } + +/** + * Implementation of allocator_t.clone_chunk. + */ +static chunk_t clone_chunk(allocator_t *allocator, chunk_t chunk, char * file, int line) +{ + private_allocator_t *this = (private_allocator_t *) allocator; + chunk_t clone = CHUNK_INITIALIZER; + + if (chunk.ptr && chunk.len > 0) + { + clone.ptr = this->allocate_special(this,chunk.len,file,line,TRUE); + clone.len = chunk.len; + memcpy(clone.ptr, chunk.ptr, chunk.len); + } + + return clone; +} + /** * Implementation of allocator_t.allocator_report_memory_leaks. */ @@ -305,6 +324,7 @@ static private_allocator_t allocator = { free_pointer: free_pointer, reallocate: reallocate, clone_bytes : clone_bytes, + clone_chunk : clone_chunk, report_memory_leaks: allocator_report_memory_leaks}, allocations: NULL, allocate_special : allocate_special, @@ -356,6 +376,25 @@ void * allocator_clone_bytes(void * pointer, size_t size) return (data); } + +/** + * Described in header + */ +static chunk_t clone_chunk(chunk_t chunk) +{ + chunk_t clone = CHUNK_INITIALIZER; + + if (chunk.ptr && chunk.len > 0) + { + clone.ptr = malloc(chunk.len); + if (clone.ptr == NULL) {exit(-1)}; + clone.len = chunk.len; + memcpy(clone.ptr, chunk.ptr, chunk.len); + } + + return clone; +} + /* * Described in header */ -- cgit v1.2.3