1 /*-------------------------------------------------------------------------
\r
3 * wrappers around malloc/realloc/free
\r
5 * Copyright (c) 2007-2015, glyn@8kb.co.uk
\r
6 * Author: Glyn Astill <glyn@8kb.co.uk>
\r
8 *-------------------------------------------------------------------------
\r
17 * Wrappers around malloc/realloc/free
\r
19 void * wmalloc(unsigned int size) {
\r
22 if ((result = malloc(size)) == NULL) {
\r
23 fprintf(stderr, "Failed to malloc %d bytes\n", size);
\r
29 void * wrealloc(void *iptr, unsigned int size) {
\r
32 assert(iptr != NULL);
\r
34 if ((result = realloc(iptr, size)) == NULL) {
\r
35 fprintf(stderr, "Failed to realloc %d bytes\n", size);
\r
41 void wfree(void *iptr){
\r
42 assert(iptr != NULL);
\r
51 * Reallocate memory block pointed to by iptr in chunks of chunk_size when
\r
52 * required_size is greater than value pointed to be allocated_size.
\r
53 * Sets value of allocated_size to current allocation.
\r
55 void * reallocate_block(void *iptr, int *allocated_size, int required_size, int chunk_size) {
\r
58 if (*allocated_size >= required_size)
\r
61 *allocated_size += (((required_size-*allocated_size)/chunk_size)+1)*chunk_size;
\r
63 result = wrealloc(iptr, *allocated_size);
\r