/* vi: set tabstop=4 shiftwidth=4: */ /* * $Id: alloc.c,v 1.3 1996/12/28 22:11:00 schweikh Exp $ */ #include #include #include "alloc.h" #include "error.h" #include "shutup.h" long alloc_free = 0; /* # of allocs - # of frees */ long alloc_max = 0; /* maximum # of allocations */ void * xmalloc (size_t size) { void *ptr = malloc (size); if (ptr == NULL) { err_sys ("malloc (%lu) failed", (unsigned long) size); } if (++alloc_free > alloc_max) { alloc_max = alloc_free; } #if DEBUG_ALLOCATIONS Printf ("%p a %lu %ld\n", (void *) ptr, (unsigned long) size, alloc_free); #endif return ptr; } void * xrealloc (void *ptr, size_t size) { void *new_ptr = realloc (ptr, size); if (new_ptr == NULL) { err_sys ("realloc (%p, %lu) failed", (void *) ptr, (unsigned long) size); } #if DEBUG_ALLOCATIONS Printf ("%p f\n", (void *) ptr); Printf ("%p a %lu\n", (void *) new_ptr, (unsigned long) size); #endif return new_ptr; } void xfree (void *ptr) { free (ptr); --alloc_free; #if DEBUG_ALLOCATIONS Printf ("%p f %ld\n", (void *) ptr, alloc_free); #endif }