aboutsummaryrefslogtreecommitdiff
path: root/contrib/mdocml/mandoc_aux.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/mdocml/mandoc_aux.c')
-rw-r--r--contrib/mdocml/mandoc_aux.c56
1 files changed, 24 insertions, 32 deletions
diff --git a/contrib/mdocml/mandoc_aux.c b/contrib/mdocml/mandoc_aux.c
index 2275bbcf36b9..cc74b7e72058 100644
--- a/contrib/mdocml/mandoc_aux.c
+++ b/contrib/mdocml/mandoc_aux.c
@@ -1,4 +1,4 @@
-/* $Id: mandoc_aux.c,v 1.4 2014/08/10 23:54:41 schwarze Exp $ */
+/* $Id: mandoc_aux.c,v 1.9 2015/11/07 14:22:29 schwarze Exp $ */
/*
* Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -19,6 +19,9 @@
#include <sys/types.h>
+#if HAVE_ERR
+#include <err.h>
+#endif
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
@@ -27,6 +30,7 @@
#include "mandoc.h"
#include "mandoc_aux.h"
+
int
mandoc_asprintf(char **dest, const char *fmt, ...)
{
@@ -37,11 +41,9 @@ mandoc_asprintf(char **dest, const char *fmt, ...)
ret = vasprintf(dest, fmt, ap);
va_end(ap);
- if (-1 == ret) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
- return(ret);
+ if (ret == -1)
+ err((int)MANDOCLEVEL_SYSERR, NULL);
+ return ret;
}
void *
@@ -50,11 +52,9 @@ mandoc_calloc(size_t num, size_t size)
void *ptr;
ptr = calloc(num, size);
- if (NULL == ptr) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
- return(ptr);
+ if (ptr == NULL)
+ err((int)MANDOCLEVEL_SYSERR, NULL);
+ return ptr;
}
void *
@@ -63,11 +63,9 @@ mandoc_malloc(size_t size)
void *ptr;
ptr = malloc(size);
- if (NULL == ptr) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
- return(ptr);
+ if (ptr == NULL)
+ err((int)MANDOCLEVEL_SYSERR, NULL);
+ return ptr;
}
void *
@@ -75,11 +73,9 @@ mandoc_realloc(void *ptr, size_t size)
{
ptr = realloc(ptr, size);
- if (NULL == ptr) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
- return(ptr);
+ if (ptr == NULL)
+ err((int)MANDOCLEVEL_SYSERR, NULL);
+ return ptr;
}
void *
@@ -87,11 +83,9 @@ mandoc_reallocarray(void *ptr, size_t num, size_t size)
{
ptr = reallocarray(ptr, num, size);
- if (NULL == ptr) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
- return(ptr);
+ if (ptr == NULL)
+ err((int)MANDOCLEVEL_SYSERR, NULL);
+ return ptr;
}
char *
@@ -100,11 +94,9 @@ mandoc_strdup(const char *ptr)
char *p;
p = strdup(ptr);
- if (NULL == p) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
- return(p);
+ if (p == NULL)
+ err((int)MANDOCLEVEL_SYSERR, NULL);
+ return p;
}
char *
@@ -115,5 +107,5 @@ mandoc_strndup(const char *ptr, size_t sz)
p = mandoc_malloc(sz + 1);
memcpy(p, ptr, sz);
p[(int)sz] = '\0';
- return(p);
+ return p;
}