7712 mandoc -Tlint does always exit with error code 0
[unleashed.git] / usr / src / lib / lvm / libmeta / common / meta_mem.c
blobd685f57c0963e82e1bdfa4cce0ba7aff5ddecb03
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
24 * Copyright (c) 1992, 1993, 2000 by Sun Microsystems, Inc.
25 * All rights reserved.
28 #pragma ident "%Z%%M% %I% %E% SMI"
30 #include <meta.h>
33 * free
35 #ifdef _DEBUG_MALLOC_INC
37 void
38 _Free(
39 char *file,
40 int line,
41 void *p
44 debug_free(file, line, p);
47 #else /* ! _DEBUG_MALLOC_INC */
49 void
50 Free(
51 void *p
54 free(p);
57 #endif /* ! _DEBUG_MALLOC_INC */
60 * malloc
62 #ifdef _DEBUG_MALLOC_INC
64 void *
65 _Malloc(
66 char *file,
67 int line,
68 size_t s
71 void *mem;
73 mem = debug_malloc(file, line, s);
74 if (mem == NULL) {
75 md_perror("");
76 md_exit(NULL, 1);
78 return (mem);
81 #else /* ! _DEBUG_MALLOC_INC */
83 void *
84 Malloc(
85 size_t s
88 void *mem;
90 if ((mem = malloc(s)) == NULL) {
91 md_perror("");
92 md_exit(NULL, 1);
94 return (mem);
97 #endif /* ! _DEBUG_MALLOC_INC */
100 * zalloc
102 #ifdef _DEBUG_MALLOC_INC
104 void *
105 _Zalloc(
106 char *file,
107 int line,
108 size_t s
111 return (memset(_Malloc(file, line, s), 0, s));
114 #else /* ! _DEBUG_MALLOC_INC */
116 void *
117 Zalloc(
118 size_t s
121 return (memset(Malloc(s), 0, s));
124 #endif /* ! _DEBUG_MALLOC_INC */
127 * realloc
129 #ifdef _DEBUG_MALLOC_INC
131 void *
132 _Realloc(
133 char *file,
134 int line,
135 void *p,
136 size_t s
139 if (p == NULL)
140 p = debug_malloc(file, line, s);
141 else
142 p = debug_realloc(file, line, p, s);
143 if (p == NULL) {
144 md_perror("");
145 md_exit(NULL, 1);
147 return (p);
150 #else /* ! _DEBUG_MALLOC_INC */
152 void *
153 Realloc(
154 void *p,
155 size_t s
158 if ((p = realloc(p, s)) == NULL) {
159 md_perror("");
160 md_exit(NULL, 1);
162 return (p);
165 #endif /* ! _DEBUG_MALLOC_INC */
168 * calloc
170 #ifdef _DEBUG_MALLOC_INC
172 void *
173 _Calloc(
174 char *file,
175 int line,
176 size_t n,
177 size_t s
180 unsigned long total;
182 if (n == 0 || s == 0) {
183 total = 0;
184 } else {
185 total = (unsigned long)n * s;
186 /* check for overflow */
187 if (total / n != s)
188 return (NULL);
190 return (_Zalloc(file, line, total));
193 #else /* ! _DEBUG_MALLOC_INC */
195 void *
196 Calloc(
197 size_t n,
198 size_t s
201 unsigned long total;
203 if (n == 0 || s == 0) {
204 total = 0;
205 } else {
206 total = (unsigned long)n * s;
207 /* check for overflow */
208 if (total / n != s)
209 return (NULL);
211 return (Zalloc(total));
214 #endif /* ! _DEBUG_MALLOC_INC */
217 * strdup
219 #ifdef _DEBUG_MALLOC_INC
221 char *
222 _Strdup(
223 char *file,
224 int line,
225 char *p
228 p = DBstrdup(file, line, p);
229 if (p == NULL) {
230 md_perror("");
231 md_exit(NULL, 1);
233 return (p);
236 #else /* ! _DEBUG_MALLOC_INC */
238 char *
239 Strdup(
240 char *p
243 if ((p = strdup(p)) == NULL) {
244 md_perror("");
245 md_exit(NULL, 1);
247 return (p);
250 #endif /* ! _DEBUG_MALLOC_INC */