util.c (527B)
1 /* See LICENSE file for copyright and license details. */ 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <string.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 perror("calloc"); 14 exit(EXIT_FAILURE); 15 } 16 return p; 17 } 18 19 void * 20 emalloc(size_t size) 21 { 22 void *p; 23 24 p = malloc(size); 25 if (!p) { 26 perror("malloc"); 27 exit(EXIT_FAILURE); 28 } 29 return p; 30 } 31 32 char * 33 estrdup(const char *s) 34 { 35 char *r; 36 37 r = strdup(s); 38 if (!r) { 39 perror("strdup"); 40 exit(EXIT_FAILURE); 41 } 42 return r; 43 }