diff options
Diffstat (limited to 'usr.sbin/makefs/xmalloc.c')
-rw-r--r-- | usr.sbin/makefs/xmalloc.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/usr.sbin/makefs/xmalloc.c b/usr.sbin/makefs/xmalloc.c new file mode 100644 index 00000000000..1a0e22d2094 --- /dev/null +++ b/usr.sbin/makefs/xmalloc.c @@ -0,0 +1,43 @@ +#include <err.h> +#include <stdlib.h> +#include <string.h> + +void * +emalloc(size_t size) +{ + void *v; + + if ((v = malloc(size)) == NULL) + err(1, "malloc"); + return v; +} + +void * +ecalloc(size_t nmemb, size_t size) +{ + void *v; + + if ((v = calloc(nmemb, size)) == NULL) + err(1, "calloc"); + return v; +} + +void * +erealloc(void *ptr, size_t size) +{ + void *v; + + if ((v = realloc(ptr, size)) == NULL) + err(1, "realloc"); + return v; +} + +char * +estrdup(const char *s) +{ + char *s2; + + if ((s2 = strdup(s)) == NULL) + err(1, "strdup"); + return s2; +} |