1 /* $Id: alloc.c,v 1.1 2003/05/16 21:48:12 fredette Exp $ */
2
3 /* libtme/alloc.c - memory allocation utility functions: */
4
5 /*
6 * Copyright (c) 2003 Matt Fredette
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Matt Fredette.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 #include <tme/common.h>
37 _TME_RCSID("$Id: alloc.c,v 1.1 2003/05/16 21:48:12 fredette Exp $");
38
39 /* includes: */
40 #include <stdlib.h>
41
42 void *
tme_malloc(unsigned int size)43 tme_malloc(unsigned int size)
44 {
45 void *p;
46 p = malloc(size);
47 if (p == NULL) {
48 abort();
49 }
50 return (p);
51 }
52
53 void *
tme_malloc0(unsigned int size)54 tme_malloc0(unsigned int size)
55 {
56 void *p;
57 p = tme_malloc(size);
58 memset(p, 0, size);
59 return (p);
60 }
61
62 void *
tme_realloc(void * p,unsigned int size)63 tme_realloc(void *p, unsigned int size)
64 {
65 p = realloc(p, size);
66 if (p == NULL) {
67 abort();
68 }
69 return (p);
70 }
71
72 void *
tme_memdup(const void * p1,unsigned int size)73 tme_memdup(const void *p1, unsigned int size)
74 {
75 void *p2;
76 p2 = tme_malloc(size);
77 memcpy(p2, p1, size);
78 return (p2);
79 }
80
81 void
tme_free(void * p)82 tme_free(void *p)
83 {
84 free(p);
85 }
86
87 char *
tme_strdup(const char * s)88 tme_strdup(const char *s)
89 {
90 return (tme_memdup(s, strlen(s) + 1));
91 }
92