From 0f734f0e317996d246fed2b0bdd1550c49d46e5b Mon Sep 17 00:00:00 2001 From: stkhan Date: Sat, 7 May 2022 12:42:36 +0000 Subject: Fixed things, added sfm --- sfm-0.4/util.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 sfm-0.4/util.c (limited to 'sfm-0.4/util.c') diff --git a/sfm-0.4/util.c b/sfm-0.4/util.c new file mode 100644 index 0000000..4aca4e0 --- /dev/null +++ b/sfm-0.4/util.c @@ -0,0 +1,44 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include +#include +#include +#include + +#include "util.h" + +void * +ecalloc(size_t nmemb, size_t size) +{ + void *p; + p = calloc(nmemb, size); + FAIL_IF(p == NULL, "calloc"); + return p; +} + +void * +erealloc(void *p, size_t len) +{ + if ((p = realloc(p, len)) == NULL) + die("realloc: %s\n", strerror(errno)); + return p; +} + +void +die(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + (void)vfprintf(stderr, fmt, ap); + va_end(ap); + + if (fmt[0] != '\0' && fmt[strlen(fmt)-1] == ':') { + (void)fputc(' ', stderr); + perror(NULL); + } else { + (void)fputc('\n', stderr); + } + + exit(EXIT_FAILURE); +} -- cgit v1.2.3