From 154874afda4a8df885e51c01f7681f04fb0b8e61 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Sat, 9 Apr 2022 09:43:53 +0200 Subject: neue Verzeichnisstruktur --- allocator.c | 79 ------------------------------------------------------------- 1 file changed, 79 deletions(-) delete mode 100644 allocator.c (limited to 'allocator.c') diff --git a/allocator.c b/allocator.c deleted file mode 100644 index 98fa69f..0000000 --- a/allocator.c +++ /dev/null @@ -1,79 +0,0 @@ -#include "allocator.h" - -#include /* malloc */ - -/* Interface Code */ -static void * -default_allocate(struct allocator *allocator, size_t n) -{ - (void) allocator; - return malloc(n); -} - -static void -default_deallocate(struct allocator *allocator, void *ptr) -{ - (void) allocator; - free(ptr); -} - -struct allocator allocator_default_allocator = { - .allocate = &default_allocate, - .deallocate = &default_deallocate -}; - -/* Libary Code */ -#include - -void * -allocator_malloc(struct allocator *allocator, size_t n) -{ - if ( !allocator ) { - allocator = &allocator_default_allocator; - } - - return allocator->allocate(allocator, n); -} - -void -allocator_free(struct allocator *allocator, void *ptr) -{ - if ( !allocator ) { - allocator = &allocator_default_allocator; - } - - allocator->deallocate(allocator, ptr); -} - -char * -allocator_strdup(struct allocator *allocator, const char *str) -{ - size_t n; - char * dest; - - n = strlen(str) + 1; - dest = allocator_malloc(allocator, n); - if ( dest ) { - memcpy(dest, str, n); - } - - return dest; -} - -void * -allocator_malloc_zero(struct allocator *allocator, size_t n) -{ - void *ptr; - - ptr = allocator_malloc(allocator, n); - if ( ptr ) { - memset(ptr, 0, n); - } - - return ptr; -} - -int -main() -{ -} -- cgit v1.3