Open SCAP Library
alloc.h
Go to the documentation of this file.
1 
15 /*
16  * Copyright 2009 Red Hat Inc., Durham, North Carolina.
17  * All Rights Reserved.
18  *
19  * This library is free software; you can redistribute it and/or
20  * modify it under the terms of the GNU Lesser General Public
21  * License as published by the Free Software Foundation; either
22  * version 2.1 of the License, or (at your option) any later version.
23  *
24  * This library is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27  * Lesser General Public License for more details.
28  *
29  * You should have received a copy of the GNU Lesser General Public
30  * License along with this library; if not, write to the Free Software
31  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32  *
33  * Authors:
34  * Lukas Kuklinek <lkuklinek@redhat.com>
35  */
36 
37 #pragma once
38 #ifndef OSCAP_ALLOC_H
39 #define OSCAP_ALLOC_H
40 
41 #include <stdlib.h>
42 
44 #define __ATTRIB __attribute__ ((unused)) static
45 
46 
47 #if defined(NDEBUG)
48 
49 void *__oscap_alloc(size_t s);
50 __ATTRIB void *oscap_alloc(size_t s)
51 {
52  return __oscap_alloc(s);
53 }
54 
55 void *__oscap_calloc(size_t n, size_t s);
56 __ATTRIB void *oscap_calloc(size_t n, size_t s)
57 {
58  return __oscap_calloc(n, s);
59 }
60 
61 void *__oscap_realloc(void *p, size_t s);
62 __ATTRIB void *oscap_realloc(void *p, size_t s)
63 {
64  return __oscap_realloc(p, s);
65 }
66 
67 void *__oscap_reallocf(void *p, size_t s);
68 __ATTRIB void *oscap_reallocf(void *p, size_t s)
69 {
70  return __oscap_reallocf(p, s);
71 }
72 
73 void __oscap_free(void *p);
74 __ATTRIB void oscap_free(void *p)
75 {
76  __oscap_free(p);
77 }
79 
83 # define oscap_alloc(s) __oscap_alloc (s)
84 
87 # define oscap_calloc(n, s) __oscap_calloc (n, s);
88 
91 # define oscap_realloc(p, s) __oscap_realloc ((void *)(p), s)
92 
95 # define oscap_reallocf(p, s) __oscap_reallocf((void *)(p), s)
96 
99 # define oscap_free(p) __oscap_free ((void *)(p))
100 
101 #else
102 void *__oscap_alloc_dbg(size_t s, const char *f, size_t l);
103 __ATTRIB void *oscap_alloc(size_t s)
104 {
105  return __oscap_alloc_dbg(s, __FUNCTION__, 0);
106 }
107 
108 void *__oscap_calloc_dbg(size_t n, size_t s, const char *f, size_t l);
109 __ATTRIB void *oscap_calloc(size_t n, size_t s)
110 {
111  return __oscap_calloc_dbg(n, s, __FUNCTION__, 0);
112 }
113 
114 void *__oscap_realloc_dbg(void *p, size_t s, const char *f, size_t l);
115 __ATTRIB void *oscap_realloc(void *p, size_t s)
116 {
117  return __oscap_realloc_dbg(p, s, __FUNCTION__, 0);
118 }
119 
120 void *__oscap_reallocf_dbg(void *p, size_t s, const char *f, size_t l);
121 __ATTRIB void *oscap_reallocf(void *p, size_t s)
122 {
123  return __oscap_reallocf_dbg(p, s, __FUNCTION__, 0);
124 }
125 
126 void __oscap_free_dbg(void **p, const char *f, size_t l);
127 __ATTRIB void oscap_free(void *p)
128 {
129  __oscap_free_dbg(&p, __FUNCTION__, 0);
130 }
131 
132 
136 # define oscap_alloc(s) __oscap_alloc_dbg (s, __PRETTY_FUNCTION__, __LINE__)
137 
140 # define oscap_calloc(n, s) __oscap_calloc_dbg (n, s, __PRETTY_FUNCTION__, __LINE__)
141 
144 # define oscap_realloc(p, s) __oscap_realloc_dbg ((void *)(p), s, __PRETTY_FUNCTION__, __LINE__)
145 
148 # define oscap_reallocf(p, s) __oscap_reallocf_dbg ((void *)(p), s, __PRETTY_FUNCTION__, __LINE__)
149 
152 # define oscap_free(p) __oscap_free_dbg ((void **)((void *)&(p)), __PRETTY_FUNCTION__, __LINE__)
153 #endif
154 
156 #define oscap_talloc(T) ((T *) oscap_alloc(sizeof(T)))
157 #define oscap_valloc(v) ((typeof(v) *) oscap_alloc(sizeof v))
158 #define OSCAP_SALLOC(TYPE, NAME) struct TYPE* NAME = oscap_calloc(1, sizeof(struct TYPE))
159 
160 
161 #endif /* OSCAP_ALLOC_H */
162 
163