diff options
| author | Matthias-Christian Ott <ott@enolink.de> | 2008-06-10 17:56:57 +0200 |
|---|---|---|
| committer | Matthias-Christian Ott <ott@enolink.de> | 2008-06-10 17:56:57 +0200 |
| commit | 5f287254715dd91f2c508a2a6b9853f0ef4ed785 (patch) | |
| tree | d9c93f4d89197a5339f6e979b0cbd67519f37f0b /util.c | |
| parent | add copyright comment (diff) | |
| download | st-5f287254715dd91f2c508a2a6b9853f0ef4ed785.tar.gz st-5f287254715dd91f2c508a2a6b9853f0ef4ed785.zip | |
source utility functions out to util.c
Diffstat (limited to '')
| -rw-r--r-- | util.c | 37 |
1 files changed, 37 insertions, 0 deletions
| @@ -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 | |||
| 9 | void * | ||
| 10 | emallocz(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 | |||
| 18 | void | ||
| 19 | eprint(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 | |||
| 28 | void | ||
| 29 | eprintn(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 | } | ||
