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