summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--util.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/util.c b/util.c
index 51acd1a..6b703e9 100644
--- a/util.c
+++ b/util.c
@@ -2,16 +2,32 @@
2#include <stdarg.h> 2#include <stdarg.h>
3#include <stdio.h> 3#include <stdio.h>
4#include <stdlib.h> 4#include <stdlib.h>
5#include <string.h>
5 6
6#include "util.h" 7#include "util.h"
7 8
9void *
10ecalloc(size_t nmemb, size_t size)
11{
12 void *p;
13
14 if (!(p = calloc(nmemb, size)))
15 perror(NULL);
16 return p;
17}
18
8void 19void
9die(const char *errstr, ...) { 20die(const char *fmt, ...) {
10 va_list ap; 21 va_list ap;
11 22
12 va_start(ap, errstr); 23 va_start(ap, fmt);
13 vfprintf(stderr, errstr, ap); 24 vfprintf(stderr, fmt, ap);
14 va_end(ap); 25 va_end(ap);
15 exit(EXIT_FAILURE);
16}
17 26
27 if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
28 fputc(' ', stderr);
29 perror(NULL);
30 }
31
32 exit(1);
33}