diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2015-10-11 21:12:54 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2015-10-11 21:12:54 +0000 |
commit | 1efc62347acbd0d7c4f4e3e264fc1678f793560f (patch) | |
tree | f768bf7b681587553ac984a5599df4e4506f4f05 /mandoc_aux.c | |
parent | 4888f53396a76dbdeb8fa67b352672a0b231112f (diff) | |
download | mandoc-1efc62347acbd0d7c4f4e3e264fc1678f793560f.tar.gz |
Finally use __progname, err(3) and warn(3).
That's more readable and less error-prone than fumbling around
with argv[0], fprintf(3), strerror(3), perror(3), and exit(3).
It's a bad idea to boycott good interfaces merely because standards
committees ignore them. Instead, let's provide compatibility modules
for archaic systems (like commercial Solaris) that still don't have
them. The compat module has an UCB Copyright (c) 1993...
Diffstat (limited to 'mandoc_aux.c')
-rw-r--r-- | mandoc_aux.c | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/mandoc_aux.c b/mandoc_aux.c index 51dd8dff..30a3bd52 100644 --- a/mandoc_aux.c +++ b/mandoc_aux.c @@ -19,6 +19,7 @@ #include <sys/types.h> +#include <err.h> #include <stdarg.h> #include <stdlib.h> #include <stdio.h> @@ -27,6 +28,10 @@ #include "mandoc.h" #include "mandoc_aux.h" +#if !HAVE_PROGNAME +const char *mandoc_progname; +#endif + int mandoc_asprintf(char **dest, const char *fmt, ...) { @@ -37,10 +42,8 @@ mandoc_asprintf(char **dest, const char *fmt, ...) ret = vasprintf(dest, fmt, ap); va_end(ap); - if (-1 == ret) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + if (ret == -1) + err((int)MANDOCLEVEL_SYSERR, NULL); return ret; } @@ -50,10 +53,8 @@ mandoc_calloc(size_t num, size_t size) void *ptr; ptr = calloc(num, size); - if (NULL == ptr) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + if (ptr == NULL) + err((int)MANDOCLEVEL_SYSERR, NULL); return ptr; } @@ -63,10 +64,8 @@ mandoc_malloc(size_t size) void *ptr; ptr = malloc(size); - if (NULL == ptr) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + if (ptr == NULL) + err((int)MANDOCLEVEL_SYSERR, NULL); return ptr; } @@ -75,10 +74,8 @@ mandoc_realloc(void *ptr, size_t size) { ptr = realloc(ptr, size); - if (NULL == ptr) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + if (ptr == NULL) + err((int)MANDOCLEVEL_SYSERR, NULL); return ptr; } @@ -87,10 +84,8 @@ mandoc_reallocarray(void *ptr, size_t num, size_t size) { ptr = reallocarray(ptr, num, size); - if (NULL == ptr) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + if (ptr == NULL) + err((int)MANDOCLEVEL_SYSERR, NULL); return ptr; } @@ -100,10 +95,8 @@ mandoc_strdup(const char *ptr) char *p; p = strdup(ptr); - if (NULL == p) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + if (ptr == NULL) + err((int)MANDOCLEVEL_SYSERR, NULL); return p; } |