diff options
author | kartofen <mladenovnasko0@gmail.com> | 2023-10-16 23:46:15 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2023-10-16 23:46:15 +0300 |
commit | 5e910c7e41d18dab95e34ceb6e620a8958197ae6 (patch) | |
tree | bf49c8ca6dd123d0765beef63d5858445dcf24aa /src/common.c |
things done
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; +} |