aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mandoc_aux.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-10-11 21:12:54 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-10-11 21:12:54 +0000
commitf9e640f1c0dc5d4fbffde207f2a4b0350d1a0019 (patch)
treeab150c9d46fcd3c701e8245e2f3d5ccbab0db7be /mandoc_aux.c
parentede48977046b65029014a425213d622d938c74c4 (diff)
downloadmandoc-f9e640f1c0dc5d4fbffde207f2a4b0350d1a0019.tar.gz
mandoc-f9e640f1c0dc5d4fbffde207f2a4b0350d1a0019.tar.zst
mandoc-f9e640f1c0dc5d4fbffde207f2a4b0350d1a0019.zip
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.c43
1 files changed, 18 insertions, 25 deletions
diff --git a/mandoc_aux.c b/mandoc_aux.c
index 622c4642..28a6e2f7 100644
--- a/mandoc_aux.c
+++ b/mandoc_aux.c
@@ -1,4 +1,4 @@
-/* $Id: mandoc_aux.c,v 1.5 2015/10/06 18:32:19 schwarze Exp $ */
+/* $Id: mandoc_aux.c,v 1.6 2015/10/11 21:12:54 schwarze Exp $ */
/*
* Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -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;
}