]> git.ipfire.org Git - people/ms/suricata.git/blame - src/util-mem.h
core: Remove unneeded consts
[people/ms/suricata.git] / src / util-mem.h
CommitLineData
3b877929 1/* Copyright (C) 2007-2020 Open Information Security Foundation
ce019275
WM
2 *
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
5 * Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
25a3a5c6 18/**
ce019275 19 * \file
25a3a5c6
PR
20 *
21 * \author Pablo Rincon Crespo <pablo.rincon.crespo@gmail.com>
d1525c6f 22 * \author Bill Meeks <billmeeks8@gmail.com>
25a3a5c6 23 *
ce019275
WM
24 * Utility Macros for memory management
25 *
26 * \todo Add wrappers for functions that allocate/free memory here.
d1525c6f
BM
27 * Currently we have malloc, calloc, realloc, strdup, strndup and
28 * free, but there are more.
25a3a5c6
PR
29 */
30
692eb935
VJ
31#ifndef __UTIL_MEM_H__
32#define __UTIL_MEM_H__
25a3a5c6 33
8aab6016 34#if CPPCHECK==1 || defined(__clang_analyzer__)
fe46c26e
VJ
35#define SCMalloc malloc
36#define SCCalloc calloc
37#define SCRealloc realloc
38#define SCFree free
39#define SCStrdup strdup
d1525c6f 40#define SCStrndup strndup
fe46c26e
VJ
41#define SCMallocAligned _mm_malloc
42#define SCFreeAligned _mm_free
43#else /* CPPCHECK */
44
45
3b877929
VJ
46void *SCMallocFunc(const size_t sz);
47#define SCMalloc(sz) SCMallocFunc((sz))
d1525c6f 48
3b877929
VJ
49void *SCReallocFunc(void *ptr, const size_t size);
50#define SCRealloc(ptr, sz) SCReallocFunc((ptr), (sz))
55da9787 51
3b877929
VJ
52void *SCCallocFunc(const size_t nm, const size_t sz);
53#define SCCalloc(nm, sz) SCCallocFunc((nm), (sz))
55da9787 54
3b877929
VJ
55char *SCStrdupFunc(const char *s);
56#define SCStrdup(s) SCStrdupFunc((s))
8f43670b 57
3b877929
VJ
58char *SCStrndupFunc(const char *s, size_t n);
59#define SCStrndup(s, n) SCStrndupFunc((s), (n))
55da9787 60
3b877929 61#define SCFree(p) free((p))
55da9787
VJ
62
63/** \brief wrapper for allocing aligned mem
64 * \param a size
65 * \param b alignement
66 */
3b877929
VJ
67void *SCMallocAlignedFunc(const size_t size, const size_t align);
68#define SCMallocAligned(size, align) SCMallocAlignedFunc((size), (align))
692eb935 69
8f43670b
VJ
70/** \brief Free aligned memory
71 *
72 * Not needed for mem alloc'd by posix_memalign,
73 * but for possible future use of _mm_malloc needing
74 * _mm_free.
75 */
3b877929
VJ
76void SCFreeAlignedFunc(void *ptr);
77#define SCFreeAligned(p) SCFreeAlignedFunc((p))
8f43670b 78
fe46c26e
VJ
79#endif /* CPPCHECK */
80
692eb935 81#endif /* __UTIL_MEM_H__ */
25a3a5c6 82