Open SCAP Library: sm_alloc.h Source File

Open SCAP Library

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

sm_alloc.h
1 /*
2 * Copyright 2009 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Authors:
20 * "Daniel Kopecek" <dkopecek@redhat.com>
21 */
22
23 #pragma once
24 #ifndef SM_ALLOC_H
25 #define SM_ALLOC_H
26
27 #include "config.h"
28 #include "src/common/debug_priv.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #define __ATTRIB __attribute__ ((unused)) static
35
36 #if !defined(HAVE_POSIX_MEMALIGN)
37 # if defined (HAVE_MEMALIGN)
38 extern int posix_memalign (void ** __memptr, size_t __alignment, size_t __size);
39
40 # endif /* HAVE_MEMALIGN */
41 #endif /* HAVE_POSIX_MEMALIGN */
42
43 #if defined(NDEBUG)
44 void *sm_alloc (size_t s);
45 void *sm_calloc (size_t n, size_t s);
46 void *sm_realloc (void *p, size_t s);
47 void *sm_reallocf (void *p, size_t s);
48 int sm_memalign (void **p, size_t a, size_t s);
49 void sm_free (void *p);
50 #else
51 void * __sm_alloc_dbg (size_t s, const char *f, size_t l);
52 __ATTRIB void *sm_alloc (size_t s) { return __sm_alloc_dbg (s, __FUNCTION__, 0); }
53
54 void * __sm_calloc_dbg (size_t n, size_t s, const char *f, size_t l);
55 __ATTRIB void *sm_calloc (size_t n, size_t s) { return __sm_calloc_dbg (n, s, __FUNCTION__, 0); }
56
57 void * __sm_realloc_dbg (void *p, size_t s, const char *f, size_t l);
58 __ATTRIB void *sm_realloc (void *p, size_t s) { return __sm_realloc_dbg (p, s, __FUNCTION__, 0); }
59
60 void * __sm_reallocf_dbg (void *p, size_t s, const char *f, size_t l);
61 __ATTRIB void *sm_reallocf (void *p, size_t s) { return __sm_reallocf_dbg (p, s, __FUNCTION__, 0); }
62
63 int __sm_memalign_dbg (void **p, size_t a, size_t s, const char *f, size_t l);
64 __ATTRIB int __sm_memalign (void **p, size_t a, size_t s) { return __sm_memalign_dbg (p, a, s, __FUNCTION__, 0); }
65
66 void __sm_free_dbg (void *p, const char *f, size_t l);
67 __ATTRIB void sm_free (void *p) { __sm_free_dbg (p, __FUNCTION__, 0); }
68
69 # define sm_alloc(s) __sm_alloc_dbg (s, __PRETTY_FUNCTION__, __LINE__)
70 # define sm_calloc(n, s) __sm_calloc_dbg (n, s, __PRETTY_FUNCTION__, __LINE__)
71 # define sm_realloc(p, s) __sm_realloc_dbg ((void *)(p), s, __PRETTY_FUNCTION__, __LINE__)
72 # define sm_reallocf(p, s) __sm_reallocf_dbg ((void *)(p), s, __PRETTY_FUNCTION__, __LINE__)
73 # define sm_memalign(p, a, s) __sm_memalign_dbg (p, a, s, __PRETTY_FUNCTION__, __LINE__)
74 # define sm_free(p) __sm_free_dbg ((void *)(p), __PRETTY_FUNCTION__, __LINE__)
75 #endif
76
77 #define sm_talloc(T) ((T *) sm_alloc(sizeof(T)))
78 #define sm_valloc(v) ((typeof(v) *) sm_alloc(sizeof v))
79
80 #include <assert.h>
81
82 #ifdef __cplusplus
83 }
84 #endif
85
86 #endif /* SM_ALLOC_H */
debug_priv.h
oscap debug helpers private header