[SHELL32] SHChangeNotify: Add drive, remove drive (#6782)
[reactos.git] / sdk / include / host / typedefs.h
1 /*
2 * PROJECT: ReactOS Host Headers
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Type definitions and useful macros for host tools
5 * COPYRIGHT: Copyright 2007 Hervé Poussineau (hpoussin@reactos.org)
6 * Copyright 2007 Colin Finck (colin@reactos.org)
7 */
8
9 #ifndef _TYPEDEFS_HOST_H
10 #define _TYPEDEFS_HOST_H
11
12 #include <assert.h>
13 #include <stdlib.h>
14 #include <limits.h>
15 #include <stdint.h>
16
17 /* Function attributes for GCC */
18 #if !defined(_MSC_VER) && !defined(__fastcall)
19 #define __fastcall __attribute__((fastcall))
20 #endif
21 #if !defined(_MSC_VER) && !defined(__cdecl)
22 #define __cdecl __attribute__((cdecl))
23 #endif
24 #if !defined(_MSC_VER) && !defined(__stdcall)
25 #define __stdcall __attribute__((stdcall))
26 #endif
27
28 /* Basic definitions */
29 #define UNIMPLEMENTED { printf("%s unimplemented\n", __FUNCTION__); exit(1); }
30 #define UNIMPLEMENTED_ONCE { printf("%s unimplemented\n", __FUNCTION__); exit(1); }
31 #define ASSERT(x) assert(x)
32 #define ASSERTMSG(m, x) assert(x)
33 #define DPRINT if (0) printf
34 #define DPRINT1 printf
35
36 #define NTAPI
37 #define WINAPI
38
39 #define IN
40 #define OUT
41 #define OPTIONAL
42
43 #define FALSE 0
44 #define TRUE 1
45
46 #define ANYSIZE_ARRAY 1
47
48 /* Basic types
49 Emulate a LLP64 memory model using a LP64 compiler */
50 typedef void VOID, *PVOID, *LPVOID;
51 typedef char CHAR, CCHAR, *PCHAR, *PSTR, *LPSTR;
52 typedef const char *PCSTR, *LPCSTR;
53 typedef unsigned char UCHAR, *PUCHAR, BYTE, *LPBYTE, BOOLEAN, *PBOOLEAN;
54 typedef int16_t SHORT, *PSHORT;
55 typedef uint16_t USHORT, *PUSHORT, WORD, *PWORD, *LPWORD, WCHAR, *PWCHAR, *PWSTR, *LPWSTR, UINT16;
56 typedef const uint16_t *PCWSTR, *LPCWSTR;
57 typedef int32_t INT, LONG, *PLONG, *LPLONG, BOOL, WINBOOL;
58 typedef uint32_t UINT, *PUINT, *LPUINT, ULONG, *PULONG, DWORD, *PDWORD, *LPDWORD, UINT32;
59 #if defined(_LP64) || defined(_WIN64)
60 typedef int64_t LONG_PTR, *PLONG_PTR, INT_PTR, *PINT_PTR;
61 typedef uint64_t ULONG_PTR, DWORD_PTR, *PULONG_PTR, UINT_PTR, *PUINT_PTR;
62 #else
63 typedef int32_t LONG_PTR, *PLONG_PTR, INT_PTR, *PINT_PTR;
64 typedef uint32_t ULONG_PTR, DWORD_PTR, *PULONG_PTR, UINT_PTR, *PUINT_PTR;
65 #endif
66 typedef uint64_t ULONG64, DWORD64, *PDWORD64, UINT64, ULONGLONG;
67 typedef int64_t LONGLONG, LONG64;
68 typedef float FLOAT;
69 typedef double DOUBLE;
70
71 /* Derived types */
72 typedef PVOID HANDLE;
73 #ifndef _HAVE_HKEY
74 typedef HANDLE HKEY, *PHKEY;
75 #endif
76 typedef HANDLE HMODULE, HINSTANCE;
77 typedef INT NTSTATUS, POOL_TYPE;
78 typedef LONG HRESULT;
79 typedef ULONG_PTR SIZE_T, *PSIZE_T;
80 typedef WORD LANGID;
81
82 #define MAXUSHORT USHRT_MAX
83
84 /* Widely used structures */
85
86 #ifndef _HAVE_RTL_BITMAP
87 typedef struct _RTL_BITMAP
88 {
89 ULONG SizeOfBitMap;
90 PULONG Buffer;
91 } RTL_BITMAP, *PRTL_BITMAP;
92
93 typedef struct _RTL_BITMAP_RUN
94 {
95 ULONG StartingIndex;
96 ULONG NumberOfBits;
97 } RTL_BITMAP_RUN, *PRTL_BITMAP_RUN;
98 #endif
99
100 #ifndef _HAVE_LARGE_INTEGER
101 typedef union _LARGE_INTEGER
102 {
103 struct
104 {
105 ULONG LowPart;
106 LONG HighPart;
107 };
108 struct
109 {
110 ULONG LowPart;
111 LONG HighPart;
112 } u;
113 LONGLONG QuadPart;
114 } LARGE_INTEGER, *PLARGE_INTEGER;
115 #endif
116
117 #ifndef _HAVE_LIST_ENTRY
118 typedef struct _LIST_ENTRY
119 {
120 struct _LIST_ENTRY *Flink;
121 struct _LIST_ENTRY *Blink;
122 } LIST_ENTRY,*PLIST_ENTRY;
123 #endif
124
125 #ifndef _HAVE_ANSI_STRING
126 typedef struct _ANSI_STRING
127 {
128 USHORT Length;
129 USHORT MaximumLength;
130 PSTR Buffer;
131 } ANSI_STRING, *PANSI_STRING;
132
133 typedef struct _UNICODE_STRING
134 {
135 USHORT Length;
136 USHORT MaximumLength;
137 PWSTR Buffer;
138 } UNICODE_STRING, *PUNICODE_STRING;
139 #endif
140
141
142 #ifndef _HAVE_LIST_ENTRY
143 /* List Functions */
144 static __inline
145 VOID
146 InitializeListHead(
147 IN PLIST_ENTRY ListHead
148 )
149 {
150 ListHead->Flink = ListHead->Blink = ListHead;
151 }
152
153 static __inline
154 VOID
155 InsertHeadList(
156 IN PLIST_ENTRY ListHead,
157 IN PLIST_ENTRY Entry
158 )
159 {
160 PLIST_ENTRY OldFlink;
161 OldFlink = ListHead->Flink;
162 Entry->Flink = OldFlink;
163 Entry->Blink = ListHead;
164 OldFlink->Blink = Entry;
165 ListHead->Flink = Entry;
166 }
167
168 static __inline
169 VOID
170 InsertTailList(
171 IN PLIST_ENTRY ListHead,
172 IN PLIST_ENTRY Entry
173 )
174 {
175 PLIST_ENTRY OldBlink;
176 OldBlink = ListHead->Blink;
177 Entry->Flink = ListHead;
178 Entry->Blink = OldBlink;
179 OldBlink->Flink = Entry;
180 ListHead->Blink = Entry;
181 }
182
183 static __inline
184 BOOLEAN
185 IsListEmpty(
186 IN const LIST_ENTRY * ListHead
187 )
188 {
189 return (BOOLEAN)(ListHead->Flink == ListHead);
190 }
191
192 static __inline
193 BOOLEAN
194 RemoveEntryList(
195 IN PLIST_ENTRY Entry)
196 {
197 PLIST_ENTRY OldFlink;
198 PLIST_ENTRY OldBlink;
199
200 OldFlink = Entry->Flink;
201 OldBlink = Entry->Blink;
202 OldFlink->Blink = OldBlink;
203 OldBlink->Flink = OldFlink;
204 return (BOOLEAN)(OldFlink == OldBlink);
205 }
206
207 static __inline
208 PLIST_ENTRY
209 RemoveHeadList(
210 IN PLIST_ENTRY ListHead)
211 {
212 PLIST_ENTRY Flink;
213 PLIST_ENTRY Entry;
214
215 Entry = ListHead->Flink;
216 Flink = Entry->Flink;
217 ListHead->Flink = Flink;
218 Flink->Blink = ListHead;
219 return Entry;
220 }
221
222 static __inline
223 PLIST_ENTRY
224 RemoveTailList(
225 IN PLIST_ENTRY ListHead)
226 {
227 PLIST_ENTRY Blink;
228 PLIST_ENTRY Entry;
229
230 Entry = ListHead->Blink;
231 Blink = Entry->Blink;
232 ListHead->Blink = Blink;
233 Blink->Flink = ListHead;
234 return Entry;
235 }
236 #endif
237
238 #ifndef _HAVE_ANSI_STRING
239 typedef const UNICODE_STRING *PCUNICODE_STRING;
240 #endif
241
242 /* Widely used macros */
243 #define LOBYTE(w) ((BYTE)(w))
244 #define HIBYTE(w) ((BYTE)(((WORD)(w)>>8)&0xFF))
245 #define LOWORD(l) ((WORD)((DWORD_PTR)(l)))
246 #define HIWORD(l) ((WORD)(((DWORD_PTR)(l)>>16)&0xFFFF))
247 #define MAKEWORD(a,b) ((WORD)(((BYTE)(a))|(((WORD)((BYTE)(b)))<<8)))
248 #define MAKELONG(a,b) ((LONG)(((WORD)(a))|(((DWORD)((WORD)(b)))<<16)))
249
250 #define MAXULONG 0xFFFFFFFF
251
252 #define NT_SUCCESS(x) ((x)>=0)
253 #if !defined(__GNUC__)
254 #define FIELD_OFFSET(t,f) ((LONG)(LONG_PTR)&(((t*) 0)->f))
255 #else
256 #define FIELD_OFFSET(t,f) ((LONG)__builtin_offsetof(t,f))
257 #endif
258 #define RTL_CONSTANT_STRING(s) { sizeof(s)-sizeof((s)[0]), sizeof(s), s }
259 #define CONTAINING_RECORD(address, type, field) ((type *)(((ULONG_PTR)address) - (ULONG_PTR)(&(((type *)0)->field))))
260
261 #define RtlZeroMemory(Destination, Length) memset(Destination, 0, Length)
262 #define RtlCopyMemory(Destination, Source, Length) memcpy(Destination, Source, Length)
263 #define RtlMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
264
265 #define MAKELANGID(p,s) ((((WORD)(s))<<10)|(WORD)(p))
266 #define PRIMARYLANGID(l) ((WORD)(l)&0x3ff)
267 #define SUBLANGID(l) ((WORD)(l)>>10)
268 #define SUBLANG_NEUTRAL 0x00
269
270 /* Prevent inclusion of some other headers */
271 #define __INTERNAL_DEBUG
272 #define RTL_H
273
274 #endif
275