kernel - cleanup vfs_cache debugging
[dragonfly.git] / contrib / mdocml / mandoc_aux.c
blobb5376735ceea298bda5a67d9bc642743a47cb916
1 /* $Id: mandoc_aux.c,v 1.3 2014/07/09 08:20:34 schwarze Exp $ */
2 /*
3 * Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
22 #include <sys/types.h>
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
29 #include "mandoc.h"
30 #include "mandoc_aux.h"
32 int
33 mandoc_asprintf(char **dest, const char *fmt, ...)
35 va_list ap;
36 int ret;
38 va_start(ap, fmt);
39 ret = vasprintf(dest, fmt, ap);
40 va_end(ap);
42 if (-1 == ret) {
43 perror(NULL);
44 exit((int)MANDOCLEVEL_SYSERR);
46 return(ret);
49 void *
50 mandoc_calloc(size_t num, size_t size)
52 void *ptr;
54 ptr = calloc(num, size);
55 if (NULL == ptr) {
56 perror(NULL);
57 exit((int)MANDOCLEVEL_SYSERR);
59 return(ptr);
62 void *
63 mandoc_malloc(size_t size)
65 void *ptr;
67 ptr = malloc(size);
68 if (NULL == ptr) {
69 perror(NULL);
70 exit((int)MANDOCLEVEL_SYSERR);
72 return(ptr);
75 void *
76 mandoc_realloc(void *ptr, size_t size)
79 ptr = realloc(ptr, size);
80 if (NULL == ptr) {
81 perror(NULL);
82 exit((int)MANDOCLEVEL_SYSERR);
84 return(ptr);
87 void *
88 mandoc_reallocarray(void *ptr, size_t num, size_t size)
91 ptr = reallocarray(ptr, num, size);
92 if (NULL == ptr) {
93 perror(NULL);
94 exit((int)MANDOCLEVEL_SYSERR);
96 return(ptr);
99 char *
100 mandoc_strdup(const char *ptr)
102 char *p;
104 p = strdup(ptr);
105 if (NULL == p) {
106 perror(NULL);
107 exit((int)MANDOCLEVEL_SYSERR);
109 return(p);
112 char *
113 mandoc_strndup(const char *ptr, size_t sz)
115 char *p;
117 p = mandoc_malloc(sz + 1);
118 memcpy(p, ptr, sz);
119 p[(int)sz] = '\0';
120 return(p);