aboutsummaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'util.c')
-rw-r--r--util.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/util.c b/util.c
new file mode 100644
index 0000000..f8b9eee
--- /dev/null
+++ b/util.c
@@ -0,0 +1,37 @@
1/* See LICENSE file for copyright and license details. */
2#include "util.h"
3#include <errno.h>
4#include <stdarg.h>
5#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8
9void *
10emallocz(unsigned int size) {
11 void *res = calloc(1, size);
12
13 if(!res)
14 eprint("fatal: could not malloc() %u bytes\n", size);
15 return res;
16}
17
18void
19eprint(const char *errstr, ...) {
20 va_list ap;
21
22 va_start(ap, errstr);
23 vfprintf(stderr, errstr, ap);
24 va_end(ap);
25 exit(EXIT_FAILURE);
26}
27
28void
29eprintn(const char *errstr, ...) {
30 va_list ap;
31
32 va_start(ap, errstr);
33 vfprintf(stderr, errstr, ap);
34 va_end(ap);
35 fprintf(stderr, ": %s\n", strerror(errno));
36 exit(EXIT_FAILURE);
37}