Print this page
9718 update mandoc to 1.14.4
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/mandoc/mandoc_aux.c
+++ new/usr/src/cmd/mandoc/mandoc_aux.c
1 -/* $Id: mandoc_aux.c,v 1.10 2017/06/12 19:05:47 schwarze Exp $ */
1 +/* $Id: mandoc_aux.c,v 1.11 2018/02/07 20:04:57 schwarze Exp $ */
2 2 /*
3 3 * Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 4 * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
5 5 *
6 6 * Permission to use, copy, modify, and distribute this software for any
7 7 * purpose with or without fee is hereby granted, provided that the above
8 8 * copyright notice and this permission notice appear in all copies.
9 9 *
10 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
13 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 17 */
18 18 #include "config.h"
19 19
20 20 #include <sys/types.h>
21 21
22 22 #if HAVE_ERR
23 23 #include <err.h>
24 24 #endif
25 25 #include <stdarg.h>
26 26 #include <stdlib.h>
27 27 #include <stdio.h>
28 28 #include <string.h>
29 29
30 30 #include "mandoc.h"
31 31 #include "mandoc_aux.h"
32 32
33 33
34 34 int
35 35 mandoc_asprintf(char **dest, const char *fmt, ...)
36 36 {
37 37 va_list ap;
38 38 int ret;
39 39
40 40 va_start(ap, fmt);
41 41 ret = vasprintf(dest, fmt, ap);
42 42 va_end(ap);
43 43
44 44 if (ret == -1)
45 45 err((int)MANDOCLEVEL_SYSERR, NULL);
46 46 return ret;
47 47 }
48 48
49 49 void *
50 50 mandoc_calloc(size_t num, size_t size)
51 51 {
52 52 void *ptr;
53 53
54 54 ptr = calloc(num, size);
55 55 if (ptr == NULL)
56 56 err((int)MANDOCLEVEL_SYSERR, NULL);
57 57 return ptr;
58 58 }
59 59
60 60 void *
61 61 mandoc_malloc(size_t size)
62 62 {
63 63 void *ptr;
64 64
65 65 ptr = malloc(size);
66 66 if (ptr == NULL)
67 67 err((int)MANDOCLEVEL_SYSERR, NULL);
68 68 return ptr;
69 69 }
70 70
71 71 void *
72 72 mandoc_realloc(void *ptr, size_t size)
73 73 {
74 74 ptr = realloc(ptr, size);
75 75 if (ptr == NULL)
76 76 err((int)MANDOCLEVEL_SYSERR, NULL);
77 77 return ptr;
78 78 }
79 79
80 80 void *
81 81 mandoc_reallocarray(void *ptr, size_t num, size_t size)
82 82 {
83 83 ptr = reallocarray(ptr, num, size);
84 84 if (ptr == NULL)
85 85 err((int)MANDOCLEVEL_SYSERR, NULL);
86 86 return ptr;
87 87 }
88 88
89 89 void *
90 90 mandoc_recallocarray(void *ptr, size_t oldnum, size_t num, size_t size)
91 91 {
92 92 ptr = recallocarray(ptr, oldnum, num, size);
93 93 if (ptr == NULL)
94 94 err((int)MANDOCLEVEL_SYSERR, NULL);
95 95 return ptr;
96 96 }
97 97
98 98 char *
99 99 mandoc_strdup(const char *ptr)
100 100 {
101 101 char *p;
102 102
103 103 p = strdup(ptr);
↓ open down ↓ |
92 lines elided |
↑ open up ↑ |
104 104 if (p == NULL)
105 105 err((int)MANDOCLEVEL_SYSERR, NULL);
106 106 return p;
107 107 }
108 108
109 109 char *
110 110 mandoc_strndup(const char *ptr, size_t sz)
111 111 {
112 112 char *p;
113 113
114 - p = mandoc_malloc(sz + 1);
115 - memcpy(p, ptr, sz);
116 - p[(int)sz] = '\0';
114 + p = strndup(ptr, sz);
115 + if (p == NULL)
116 + err((int)MANDOCLEVEL_SYSERR, NULL);
117 117 return p;
118 118 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX