1 /* xmalloc.c - memory allocation with error checking 2 * 3 * Copyright 1998 Jochen Voss */ 4 5 static const char rcsid[] = "$Id: xmalloc.c 4839 2003-04-13 16:50:02Z voss $"; 6 7 #ifdef HAVE_CONFIG_H 8 #include <config.h> 9 #endif 10 11 #include <stdio.h> 12 #include <stdlib.h> 13 14 #include "moon-buggy.h" 15 16 17 void * xmalloc(size_t size)18xmalloc (size_t size) 19 /* Like `malloc', but check for shortage of memory. `xmalloc' never 20 * returns `NULL'. */ 21 { 22 void *ptr = malloc (size); 23 if (ptr == NULL) fatal ("Memory exhausted"); 24 return ptr; 25 } 26 27 void * xrealloc(void * ptr,size_t size)28xrealloc (void *ptr, size_t size) 29 /* Like `realloc', but check for shortage of memory. `xrealloc' never 30 * returns `NULL'. */ 31 { 32 void *tmp; 33 34 if (ptr) { 35 tmp = realloc (ptr, size); 36 } else { 37 tmp = malloc (size); 38 } 39 if (tmp == NULL) fatal ("Memory exhausted"); 40 return tmp; 41 } 42