From 34c0fd8f36269699b75e0aaf841911b5ae06246e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 28 Aug 2018 13:23:45 +0200 Subject: Simplify en* functions, and handle argv0 == NULL correct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- encalloc.c | 9 ++------- enmalloc.c | 9 ++------- enmemdup.c | 9 ++------- enrealloc.c | 9 ++------- enstrdup.c | 9 ++------- enstrndup.c | 9 ++------- envmalloczn.c | 9 ++------- envputenvf.c | 9 ++------- envreallocn.c | 9 ++------- 9 files changed, 18 insertions(+), 63 deletions(-) diff --git a/encalloc.c b/encalloc.c index 1277d7b..de5a2c9 100644 --- a/encalloc.c +++ b/encalloc.c @@ -3,17 +3,12 @@ #ifndef TEST -extern char *argv0; - - void * libsimple_encalloc(int status, size_t n, size_t m) /* TODO test */ { void *ret = calloc(n, m); - if (!ret) { - fprintf(stderr, "%s: calloc: %s\n", argv0, strerror(errno)); - exit(status); - } + if (!ret) + enprintf(status, "calloc:"); return ret; } diff --git a/enmalloc.c b/enmalloc.c index 0a13f03..f981872 100644 --- a/enmalloc.c +++ b/enmalloc.c @@ -3,17 +3,12 @@ #ifndef TEST -extern char *argv0; - - void * libsimple_enmalloc(int status, size_t n) /* TODO test */ { void *ret = malloc(n); - if (!ret) { - fprintf(stderr, "%s: malloc: %s\n", argv0, strerror(errno)); - exit(status); - } + if (!ret) + enprintf(status, "malloc:"); return ret; } diff --git a/enmemdup.c b/enmemdup.c index 8693af6..9050efd 100644 --- a/enmemdup.c +++ b/enmemdup.c @@ -3,17 +3,12 @@ #ifndef TEST -extern char *argv0; - - void * libsimple_enmemdup(int status, const void *s, size_t n) /* TODO test */ { void *ret = memdup(s, n); - if (!ret) { - fprintf(stderr, "%s: memdup: %s\n", argv0, strerror(errno)); - exit(status); - } + if (!ret) + enprintf(status, "memdup:"); return ret; } diff --git a/enrealloc.c b/enrealloc.c index 04feede..92a50db 100644 --- a/enrealloc.c +++ b/enrealloc.c @@ -3,17 +3,12 @@ #ifndef TEST -extern char *argv0; - - void * libsimple_enrealloc(int status, void *ptr, size_t n) /* TODO test */ { char *ret = realloc(ptr, n); - if (!ret) { - fprintf(stderr, "%s: realloc: %s\n", argv0, strerror(errno)); - exit(status); - } + if (!ret) + enprintf(status, "realloc:"); return ret; } diff --git a/enstrdup.c b/enstrdup.c index 2adb309..d8a8c53 100644 --- a/enstrdup.c +++ b/enstrdup.c @@ -3,17 +3,12 @@ #ifndef TEST -extern char *argv0; - - char * libsimple_enstrdup(int status, const char *s) /* TODO test */ { char *ret = strdup(s); - if (!ret) { - fprintf(stderr, "%s: strdup: %s\n", argv0, strerror(errno)); - exit(status); - } + if (!ret) + enprintf(status, "strdup:"); return ret; } diff --git a/enstrndup.c b/enstrndup.c index 7dd6595..8803a99 100644 --- a/enstrndup.c +++ b/enstrndup.c @@ -3,17 +3,12 @@ #ifndef TEST -extern char *argv0; - - char * libsimple_enstrndup(int status, const char *s, size_t n) /* TODO test */ { void *ret = strndup(s, n); - if (!ret) { - fprintf(stderr, "%s: strndup: %s\n", argv0, strerror(errno)); - exit(status); - } + if (!ret) + enprintf(status, "strndup:"); return ret; } diff --git a/envmalloczn.c b/envmalloczn.c index 832ce67..84c0ea7 100644 --- a/envmalloczn.c +++ b/envmalloczn.c @@ -3,17 +3,12 @@ #ifndef TEST -extern char *argv0; - - void * libsimple_envmalloczn(int status, int clear, size_t n, va_list ap) /* TODO test */ { void *ret = libsimple_vmalloczn(clear, n, ap); - if (!ret) { - fprintf(stderr, "%s: %s: %s\n", argv0, clear ? "calloc" : "malloc", strerror(errno)); - exit(status); - } + if (!ret) + enprintf(status, "%s:", clear ? "calloc" : "malloc"); return ret; } diff --git a/envputenvf.c b/envputenvf.c index cf30208..cdcf4f5 100644 --- a/envputenvf.c +++ b/envputenvf.c @@ -3,16 +3,11 @@ #ifndef TEST -extern char *argv0; - - void libsimple_envputenvf(int status, const char *fmt, va_list ap) /* TODO test */ { - if (vputenvf(fmt, ap)) { - fprintf(stderr, "%s: putenvf: %s\n", argv0, strerror(errno)); - exit(status); - } + if (vputenvf(fmt, ap)) + enprintf(status, "putenvf:"); } diff --git a/envreallocn.c b/envreallocn.c index 44b69e3..1956933 100644 --- a/envreallocn.c +++ b/envreallocn.c @@ -3,17 +3,12 @@ #ifndef TEST -extern char *argv0; - - void * libsimple_envreallocn(int status, void *ptr, size_t n, va_list ap) /* TODO test */ { void *ret = libsimple_vreallocn(ptr, n, ap); - if (!ret) { - fprintf(stderr, "%s: realloc: %s\n", argv0, strerror(errno)); - exit(status); - } + if (!ret) + enprintf(status, "realloc:"); return ret; } -- cgit v1.2.3-70-g09d2