xref: /titanic_41/usr/src/cmd/lvm/rpc.metamhd/mhd_mem.c (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
1 /*
2  * CDDL HEADER START
3  *
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.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright (c) 1994, 2000 by Sun Microsystems, Inc.
25  * All rights reserved.
26  */
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 #include "mhd_local.h"
31 
32 void
33 Free(
34 	void	*p
35 )
36 {
37 	free(p);
38 }
39 
40 void *
41 Malloc(
42 	size_t	s
43 )
44 {
45 	void *mem;
46 
47 	if ((mem = malloc(s)) == NULL) {
48 		mhd_perror("");
49 		mhd_exit(1);
50 	}
51 	return (mem);
52 }
53 
54 void *
55 Zalloc(
56 	size_t	s
57 )
58 {
59 	return (memset(Malloc(s), 0, s));
60 }
61 
62 void *
63 Realloc(
64 	void	*p,
65 	size_t	s
66 )
67 {
68 	if (p == NULL)
69 		p = malloc(s);
70 	else
71 		p = realloc(p, s);
72 	if (p == NULL) {
73 		mhd_perror("");
74 		mhd_exit(1);
75 	}
76 	return (p);
77 }
78 
79 void *
80 Calloc(
81 	size_t	n,
82 	size_t	s
83 )
84 {
85 	unsigned long total;
86 
87 	if (n == 0 || s == 0) {
88 		total = 0;
89 	} else {
90 		total = (unsigned long)n * s;
91 		/* check for overflow */
92 		if (total / n != s)
93 			return (NULL);
94 	}
95 	return (Zalloc(total));
96 }
97 
98 char *
99 Strdup(
100 	const char	*p
101 )
102 {
103 	char		*n;
104 
105 	if ((n = strdup(p)) == NULL) {
106 		mhd_perror("");
107 		mhd_exit(1);
108 	}
109 	return (n);
110 }
111