diff options
Diffstat (limited to 'util.c')
| -rw-r--r-- | util.c | 26 |
1 files changed, 21 insertions, 5 deletions
| @@ -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 | ||
| 9 | void * | ||
| 10 | ecalloc(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 | |||
| 8 | void | 19 | void |
| 9 | die(const char *errstr, ...) { | 20 | die(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 | } | ||
