[INCLUDE/WINE] Import heap.h from Wine Staging 3.3. CORE-14434
[reactos.git] / sdk / include / reactos / wine / heap.h
1 /*
2 * Wine heap memory allocation wrappers
3 *
4 * Copyright 2006 Jacek Caban for CodeWeavers
5 * Copyright 2013, 2018 Michael Stefaniuc
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #ifndef __WINE_WINE_HEAP_H
23 #define __WINE_WINE_HEAP_H
24
25 #include <winbase.h>
26
27 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(SIZE_T len)
28 {
29 return HeapAlloc(GetProcessHeap(), 0, len);
30 }
31
32 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(SIZE_T len)
33 {
34 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
35 }
36
37 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, SIZE_T len)
38 {
39 if (!mem)
40 return HeapAlloc(GetProcessHeap(), 0, len);
41 return HeapReAlloc(GetProcessHeap(), 0, mem, len);
42 }
43
44 static inline void heap_free(void *mem)
45 {
46 HeapFree(GetProcessHeap(), 0, mem);
47 }
48
49 static inline void *heap_calloc(SIZE_T count, SIZE_T size)
50 {
51 SIZE_T len = count * size;
52
53 if (size && len / size != count)
54 return NULL;
55 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
56 }
57
58 #endif /* __WINE_WINE_HEAP_H */