RBBS_FIXEDSIZE should not affect _AdjustBands (found by Mike McCormack
[wine] / include / heap.h
1 /*
2  * Win32 heap definitions
3  *
4  * Copyright 1996 Alexandre Julliard
5  */
6
7 #ifndef __WINE_HEAP_H
8 #define __WINE_HEAP_H
9
10 #include "config.h"
11
12 #include <string.h>
13 #include "winbase.h"
14 #include "winnls.h"
15 #include "wine/unicode.h"
16 #include "wine/windef16.h"  /* for SEGPTR */
17
18 extern SEGPTR HEAP_GetSegptr( HANDLE heap, DWORD flags, LPCVOID ptr );
19
20 /* SEGPTR helper macros */
21
22 #define SEGPTR_ALLOC(size) \
23      (HeapAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, (size) ))
24 #define SEGPTR_NEW(type) \
25      ((type *)HeapAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, sizeof(type) ))
26 #define SEGPTR_STRDUP(str) \
27      (HIWORD(str) ? HEAP_strdupA( GetProcessHeap(), HEAP_WINE_SEGPTR, (str) ) : (LPSTR)(str))
28 #define SEGPTR_STRDUP_WtoA(str) \
29      (HIWORD(str) ? HEAP_strdupWtoA( GetProcessHeap(), HEAP_WINE_SEGPTR, (str) ) : (LPSTR)(str))
30 #define SEGPTR_FREE(ptr) \
31      (HIWORD(ptr) ? HeapFree( GetProcessHeap(), HEAP_WINE_SEGPTR, (ptr) ) : 0)
32 #define SEGPTR_GET(ptr) MapLS(ptr)
33
34
35 /* strdup macros */
36 /* DO NOT USE THEM!!  they will go away soon */
37
38 inline static LPSTR HEAP_strdupA( HANDLE heap, DWORD flags, LPCSTR str )
39 {
40     INT len = strlen(str) + 1;
41     LPSTR p = HeapAlloc( heap, flags, len );
42     if (p) memcpy( p, str, len );
43     return p;
44 }
45
46 inline static LPWSTR HEAP_strdupW( HANDLE heap, DWORD flags, LPCWSTR str )
47 {
48     INT len = strlenW(str) + 1;
49     LPWSTR p = HeapAlloc( heap, flags, len * sizeof(WCHAR) );
50     if (p) memcpy( p, str, len * sizeof(WCHAR) );
51     return p;
52 }
53
54 inline static LPWSTR HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str )
55 {
56     LPWSTR ret;
57     INT len;
58
59     if (!str) return NULL;
60     len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
61     ret = HeapAlloc( heap, flags, len * sizeof(WCHAR) );
62     if (ret) MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
63     return ret;
64 }
65
66 inline static LPSTR HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str )
67 {
68     LPSTR ret;
69     INT len;
70
71     if (!str) return NULL;
72     len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
73     ret = HeapAlloc( heap, flags, len );
74     if(ret) WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
75     return ret;
76 }
77
78 #endif  /* __WINE_HEAP_H */