From ba9a7343ad22d507cfaed6b7bb8618a99c2f2976 Mon Sep 17 00:00:00 2001 From: jvech Date: Wed, 16 Aug 2023 08:31:33 -0500 Subject: add: Cli defined --- src/util.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/util.c (limited to 'src/util.c') diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..4a8c3ef --- /dev/null +++ b/src/util.c @@ -0,0 +1,33 @@ +/* See LICENSE file for copyright and license details. */ +#include + +#include "util.h" + +void +die(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + + if (fmt[0] && fmt[strlen(fmt)-1] == ':') { + fputc(' ', stderr); + perror(NULL); + } else { + fputc('\n', stderr); + } + + exit(1); +} + +void * +ecalloc(size_t nmemb, size_t size) +{ + void *p; + + if (!(p = calloc(nmemb, size))) + die("calloc:"); + return p; +} -- cgit v1.2.3-70-g09d2