diff options
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/common.c b/src/common.c new file mode 100644 index 0000000..084c584 --- /dev/null +++ b/src/common.c @@ -0,0 +1,33 @@ +#include <string.h> +#include <errno.h> +#include "common.h" + +void *xmalloc(size_t size) +{ + void *ret; + if(!(ret = malloc(size))) { + die("malloc: %s", strerror(errno)); + } + + return ret; +} + +void *xcalloc(size_t nmemb, size_t size) +{ + void *ret; + if(!(ret = calloc(nmemb, size))) { + die("calloc: %s", strerror(errno)); + } + + return ret; +} + +void *xrealloc(void *ptr, size_t size) +{ + void *ret; + if(!(ret = realloc(ptr, size))) { + die("realloc: %s", strerror(errno)); + } + + return ret; +} |