Open SCAP Library
|
00001 00015 /* 00016 * Copyright 2009 Red Hat Inc., Durham, North Carolina. 00017 * All Rights Reserved. 00018 * 00019 * This library is free software; you can redistribute it and/or 00020 * modify it under the terms of the GNU Lesser General Public 00021 * License as published by the Free Software Foundation; either 00022 * version 2.1 of the License, or (at your option) any later version. 00023 * 00024 * This library is distributed in the hope that it will be useful, 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00027 * Lesser General Public License for more details. 00028 * 00029 * You should have received a copy of the GNU Lesser General Public 00030 * License along with this library; if not, write to the Free Software 00031 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00032 * 00033 * Authors: 00034 * Lukas Kuklinek <lkuklinek@redhat.com> 00035 */ 00036 00037 #pragma once 00038 #ifndef OSCAP_ALLOC_H 00039 #define OSCAP_ALLOC_H 00040 00041 #include <stdlib.h> 00042 00044 #define __ATTRIB __attribute__ ((unused)) static 00045 00046 00047 #if defined(NDEBUG) 00048 00049 void *__oscap_alloc(size_t s); 00050 __ATTRIB void *oscap_alloc(size_t s) 00051 { 00052 return __oscap_alloc(s); 00053 } 00054 00055 void *__oscap_calloc(size_t n, size_t s); 00056 __ATTRIB void *oscap_calloc(size_t n, size_t s) 00057 { 00058 return __oscap_calloc(n, s); 00059 } 00060 00061 void *__oscap_realloc(void *p, size_t s); 00062 __ATTRIB void *oscap_realloc(void *p, size_t s) 00063 { 00064 return __oscap_realloc(p, s); 00065 } 00066 00067 void *__oscap_reallocf(void *p, size_t s); 00068 __ATTRIB void *oscap_reallocf(void *p, size_t s) 00069 { 00070 return __oscap_reallocf(p, s); 00071 } 00072 00073 void __oscap_free(void *p); 00074 __ATTRIB void oscap_free(void *p) 00075 { 00076 __oscap_free(p); 00077 } 00079 00083 # define oscap_alloc(s) __oscap_alloc (s) 00084 00087 # define oscap_calloc(n, s) __oscap_calloc (n, s); 00088 00091 # define oscap_realloc(p, s) __oscap_realloc ((void *)(p), s) 00092 00095 # define oscap_reallocf(p, s) __oscap_reallocf((void *)(p), s) 00096 00099 # define oscap_free(p) __oscap_free ((void *)(p)) 00100 00101 #else 00102 void *__oscap_alloc_dbg(size_t s, const char *f, size_t l); 00103 __ATTRIB void *oscap_alloc(size_t s) 00104 { 00105 return __oscap_alloc_dbg(s, __FUNCTION__, 0); 00106 } 00107 00108 void *__oscap_calloc_dbg(size_t n, size_t s, const char *f, size_t l); 00109 __ATTRIB void *oscap_calloc(size_t n, size_t s) 00110 { 00111 return __oscap_calloc_dbg(n, s, __FUNCTION__, 0); 00112 } 00113 00114 void *__oscap_realloc_dbg(void *p, size_t s, const char *f, size_t l); 00115 __ATTRIB void *oscap_realloc(void *p, size_t s) 00116 { 00117 return __oscap_realloc_dbg(p, s, __FUNCTION__, 0); 00118 } 00119 00120 void *__oscap_reallocf_dbg(void *p, size_t s, const char *f, size_t l); 00121 __ATTRIB void *oscap_reallocf(void *p, size_t s) 00122 { 00123 return __oscap_reallocf_dbg(p, s, __FUNCTION__, 0); 00124 } 00125 00126 void __oscap_free_dbg(void **p, const char *f, size_t l); 00127 __ATTRIB void oscap_free(void *p) 00128 { 00129 __oscap_free_dbg(&p, __FUNCTION__, 0); 00130 } 00131 00132 00136 # define oscap_alloc(s) __oscap_alloc_dbg (s, __PRETTY_FUNCTION__, __LINE__) 00137 00140 # define oscap_calloc(n, s) __oscap_calloc_dbg (n, s, __PRETTY_FUNCTION__, __LINE__) 00141 00144 # define oscap_realloc(p, s) __oscap_realloc_dbg ((void *)(p), s, __PRETTY_FUNCTION__, __LINE__) 00145 00148 # define oscap_reallocf(p, s) __oscap_reallocf_dbg ((void *)(p), s, __PRETTY_FUNCTION__, __LINE__) 00149 00152 # define oscap_free(p) __oscap_free_dbg ((void **)((void *)&(p)), __PRETTY_FUNCTION__, __LINE__) 00153 #endif 00154 00156 #define oscap_talloc(T) ((T *) oscap_alloc(sizeof(T))) 00157 #define oscap_valloc(v) ((typeof(v) *) oscap_alloc(sizeof v)) 00158 #define OSCAP_SALLOC(TYPE, NAME) struct TYPE* NAME = oscap_calloc(1, sizeof(struct TYPE)) 00159 00160 00161 #endif /* OSCAP_ALLOC_H */