ealloc.c (570B)
1 #include <stdlib.h> 2 #include <string.h> 3 4 #include "../util.h" 5 6 void * 7 ecalloc(size_t nmemb, size_t size) 8 { 9 void *p; 10 11 p = calloc(nmemb, size); 12 if (!p) 13 eprintf("calloc: out of memory\n"); 14 return p; 15 } 16 17 void * 18 emalloc(size_t size) 19 { 20 void *p; 21 22 p = malloc(size); 23 if (!p) 24 eprintf("malloc: out of memory\n"); 25 return p; 26 } 27 28 void * 29 erealloc(void *p, size_t size) 30 { 31 p = realloc(p, size); 32 if (!p) 33 eprintf("realloc: out of memory\n"); 34 return p; 35 } 36 37 char * 38 estrdup(const char *s) 39 { 40 char *p; 41 42 p = strdup(s); 43 if (!p) 44 eprintf("strdup: out of memory\n"); 45 return p; 46 }