Work around problems on Solaris if config.h is not included.
[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 "winbase.h"
13 #include "winnls.h"
14 #include "wine/unicode.h"
15 #include "wine/windef16.h"  /* for SEGPTR */
16
17 extern HANDLE SystemHeap;
18
19 extern SEGPTR HEAP_GetSegptr( HANDLE heap, DWORD flags, LPCVOID ptr );
20 extern BOOL HEAP_CreateSystemHeap(void);
21
22 /* SEGPTR helper macros */
23
24 #define SEGPTR_ALLOC(size) \
25      (HeapAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, (size) ))
26 #define SEGPTR_NEW(type) \
27      ((type *)HeapAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, sizeof(type) ))
28 #define SEGPTR_STRDUP(str) \
29      (HIWORD(str) ? HEAP_strdupA( GetProcessHeap(), HEAP_WINE_SEGPTR, (str) ) : (LPSTR)(str))
30 #define SEGPTR_STRDUP_WtoA(str) \
31      (HIWORD(str) ? HEAP_strdupWtoA( GetProcessHeap(), HEAP_WINE_SEGPTR, (str) ) : (LPSTR)(str))
32 #define SEGPTR_FREE(ptr) \
33      (HIWORD(ptr) ? HeapFree( GetProcessHeap(), HEAP_WINE_SEGPTR, (ptr) ) : 0)
34 #define SEGPTR_GET(ptr) MapLS(ptr)
35
36
37 /* strdup macros */
38 /* DO NOT USE THEM!!  they will go away soon */
39
40 inline static LPSTR HEAP_strdupA( HANDLE heap, DWORD flags, LPCSTR str )
41 {
42     INT len = strlen(str) + 1;
43     LPSTR p = HeapAlloc( heap, flags, len );
44     if (p) memcpy( p, str, len );
45     return p;
46 }
47
48 inline static LPWSTR HEAP_strdupW( HANDLE heap, DWORD flags, LPCWSTR str )
49 {
50     INT len = strlenW(str) + 1;
51     LPWSTR p = HeapAlloc( heap, flags, len * sizeof(WCHAR) );
52     if (p) memcpy( p, str, len * sizeof(WCHAR) );
53     return p;
54 }
55
56 inline static LPWSTR HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str )
57 {
58     LPWSTR ret;
59     INT len;
60
61     if (!str) return NULL;
62     len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
63     ret = HeapAlloc( heap, flags, len * sizeof(WCHAR) );
64     if (ret) MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
65     return ret;
66 }
67
68 inline static LPSTR HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str )
69 {
70     LPSTR ret;
71     INT len;
72
73     if (!str) return NULL;
74     len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
75     ret = HeapAlloc( heap, flags, len );
76     if(ret) WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
77     return ret;
78 }
79
80 /* system heap private data */
81 /* you must lock the system heap before using this structure */
82 typedef struct
83 {
84     void     *gdi;        /* GDI heap */
85     void     *user;       /* USER handle table */
86     void     *cursor;     /* cursor information */
87     void     *queue;      /* message queues descriptor */
88     void     *win;        /* windows descriptor */
89     void     *root;       /* X11 root window */
90 } SYSTEM_HEAP_DESCR;
91
92 extern SYSTEM_HEAP_DESCR *SystemHeapDescr;
93
94 #endif  /* __WINE_HEAP_H */