diff options
| author | stkhan <personal@slickd.xyz> | 2022-05-07 12:42:36 +0000 |
|---|---|---|
| committer | stkhan <personal@slickd.xyz> | 2022-05-07 12:42:36 +0000 |
| commit | 0f734f0e317996d246fed2b0bdd1550c49d46e5b (patch) | |
| tree | db0f535dcb02dc1959508a1e94570db74ea3bbb2 /sfm-0.4/util.c | |
| parent | 42966e3e531b8e46e4ab31480d45aa7a141f19ce (diff) | |
Fixed things, added sfm
Diffstat (limited to 'sfm-0.4/util.c')
| -rw-r--r-- | sfm-0.4/util.c | 44 |
1 files changed, 44 insertions, 0 deletions
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 <errno.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#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); +} |