aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mandoc_aux.c
diff options
context:
space:
mode:
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;
}