1/*****************************************************************************\ 2* _ _ _ _ ___ * 3* | || | ___ | |_ _ __ | | _ _ __ _ |_ ) * 4* | __ |/ _ \| _|| '_ \| || || |/ _` | / / * 5* |_||_|\___/ \__|| .__/|_| \_,_|\__, |/___| * 6* |_| |___/ * 7\*****************************************************************************/ 8 9#include <stdlib.h> 10#include <stdio.h> 11 12/** 13 * A malloc wrapper. Exits if no memory. 14 * 15 * @1 Ammount of memory to allocate 16 * 17 * Returns: Pointer to freshly allocated memory 18 */ 19inline void *xmalloc(size_t size) { 20 void *ptr; 21 ptr = malloc(size); 22 if (ptr == NULL) { 23 fprintf(stderr, "MALLOC FAILURE!\n"); 24 exit(127); 25 } 26 return ptr; 27} 28 29/** 30 * A realloc wrapper. Exits if no memory. 31 * 32 * @1 Old pointer 33 * @2 Ammount of memory to allocate 34 * 35 * Returns: Pointer to reallocated memory 36 */ 37inline void *xrealloc(void *inptr, size_t size) { 38 void *ptr; 39 ptr = realloc(inptr, size); 40 if (ptr == NULL) { 41 fprintf(stderr, "MALLOC FAILURE!\n"); 42 exit(127); 43 } 44 return ptr; 45} 46