diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2017-02-11 15:30:37 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2017-02-11 15:30:37 +0000 |
commit | b8ede3c284299173f3981aa85dcbd16806a57f55 (patch) | |
tree | 31beb63b99f1840472da304de628e6114ba61f8e /eprintf.c | |
parent | 99778c999c364ad3e5967f7a9a0a3e484c279716 (diff) | |
parent | 0fc0c19e4dc2b4ec2f175744e1ac468643b6da71 (diff) | |
download | hktool-b8ede3c284299173f3981aa85dcbd16806a57f55.tar.gz hktool-b8ede3c284299173f3981aa85dcbd16806a57f55.tar.xz hktool-b8ede3c284299173f3981aa85dcbd16806a57f55.zip |
Merge branch 'halfkay-error-handling'
Diffstat (limited to 'eprintf.c')
-rw-r--r-- | eprintf.c | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -1,9 +1,10 @@ +#include <assert.h> #include <errno.h> #include <stdarg.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <stdint.h> #include "eprintf.h" @@ -15,6 +16,8 @@ void eprintf(const char *fmt, ...) int errnum = errno; va_list va; + assert(fmt); + if (progname() != NULL) fprintf(stderr, "%s: ", progname()); @@ -35,6 +38,8 @@ void weprintf(const char *fmt, ...) int errnum = errno; va_list va; + assert(fmt); + if (progname() != NULL) fprintf(stderr, "%s: ", progname()); @@ -53,6 +58,8 @@ char *estrdup(const char *s) size_t len; char *dup; + assert(s); + len = strlen(s); if (len == SIZE_MAX) eprintf("estrdup(\"%.20s\") failed: Too long", s); @@ -76,6 +83,18 @@ void *emalloc(size_t n) return p; } +/* ecalloc: attempt to allocate memory or exit on error */ +void *ecalloc(size_t nmemb, size_t size) +{ + void *p; + + p = calloc(nmemb, size); + if (p == NULL) + eprintf("ecalloc(%zu, %zu) failed:", nmemb, size); + + return p; +} + /* erealloc: attempt to reallocate memory or exit on error */ void *erealloc(void *p, size_t n) { |