Initial original import from: fuse-2.4.2-2.fc4
[captive.git] / src / libcaptive / include / reactos / compat.h
1 /* $Id$
2  * Include file for GNU world compatibility with reactos include files for libcaptive
3  * Copyright (C) 2002 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 /* NEVER protect this include file with #ifndef/#define/#endif
21  * wrapper as we need to be included multiple times
22  * Despite this we still #define the symbol to be able to check it
23  */
24 #ifdef _CAPTIVE_REACTOS_COMPAT_H
25 #undef _CAPTIVE_REACTOS_COMPAT_H
26 #define _CAPTIVE_REACTOS_COMPAT_H 2
27 #else
28 #define _CAPTIVE_REACTOS_COMPAT_H 1
29 #endif
30
31 /* NEVER use #include in this file before all the #define-s are done
32  * as we pretend any nested #include "reactos/compat.h" automatically as 'succeeded'.
33  * NEVER use any #include inside !REACTOS_COMPAT condition branches.
34  * We never nest as the include is protected by #ifdef from reactos/?*.h includes.
35  */
36 #ifdef _CAPTIVE_REACTOS_COMPAT_H_INSIDE
37 #error "$(top_srcdir)/src/libcaptive/include/reactos/compat.h MUST NOT NEST!"
38 #endif
39 #define _CAPTIVE_REACTOS_COMPAT_H_INSIDE 1
40
41
42 /* reactos uses __declspec(dllimport) and __declspec(dllexport)
43  * which gets expanded to __attribute__($2) by -D in their Makefile GCC commandline.
44  */
45 #ifdef REACTOS_COMPAT
46 #define __declspec(type)
47 #else
48 #undef __declspec
49 #endif
50
51 /* It gets defined to __attribute__((fastcall)) by "ddk/ntddk.h". */
52 #ifdef REACTOS_COMPAT
53 #define FASTCALL
54 #else
55 #undef FASTCALL
56 #endif
57
58 /* It gets defined to __attribute__((stdcall)) by "base.h" and "ntos/types.h". */
59 #ifdef REACTOS_COMPAT
60 #define STDCALL
61 #else
62 #undef STDCALL
63 #endif
64
65 /* It gets defined to __attribute__((cdecl)) by "base.h" and "ntos/types.h"; should not hurt. */
66 #ifdef REACTOS_COMPAT
67 #define CDECL
68 #else
69 #undef CDECL
70 #endif
71
72 /* Get the system declarations as their original names.
73  * reactos will use the redefined ones below.
74  * If we would include <string.h> later the system declarations would have captive_reactos_*
75  * names and system vs. reactos declarations would conflict again - just named captive_reactos_*.
76  * FIXME: Unfortunately we cannot include <string.h> twice.
77  * If we do "reactos/X.h" include from libcaptive (not reactos)
78  * we already lost the possibility to use the optimized
79  * system macros as they are #define-d and we #undef them here.
80  * Fortunately there should also be a system declarations with the same
81  * name and we are satisfied with their non-inlined (=non-#define-d) versions.
82  */
83 #include <string.h>
84
85 #ifdef REACTOS_COMPAT
86 #define wcscpy captive_reactos_wcscpy
87 #else
88 #undef wcscpy
89 #endif
90
91 #ifdef REACTOS_COMPAT
92 #define wcscat captive_reactos_wcscat
93 #else
94 #undef wcscat
95 #endif
96
97 #ifdef REACTOS_COMPAT
98 #define wcschr captive_reactos_wcschr
99 #else
100 #undef wcschr
101 #endif
102
103 #ifdef REACTOS_COMPAT
104 #define wcsrchr captive_reactos_wcsrchr
105 #else
106 #undef wcsrchr
107 #endif
108
109 #ifdef REACTOS_COMPAT
110 #define wcslen captive_reactos_wcslen
111 #else
112 #undef wcslen
113 #endif
114
115 #ifdef REACTOS_COMPAT
116 #define wcscmp captive_reactos_wcscmp
117 #else
118 #undef wcscmp
119 #endif
120
121 #ifdef REACTOS_COMPAT
122 #define _wcsicmp captive_reactos__wcsicmp
123 #else
124 #undef _wcsicmp
125 #endif
126
127 #ifdef REACTOS_COMPAT
128 #define wcsncmp captive_reactos_wcsncmp
129 #else
130 #undef wcsncmp
131 #endif
132
133 #ifdef REACTOS_COMPAT
134 #undef memchr
135 #define memchr captive_reactos_memchr
136 #else
137 #undef memchr
138 #endif
139
140 #ifdef REACTOS_COMPAT
141 #undef memcpy
142 #define memcpy captive_reactos_memcpy
143 #else
144 #undef memcpy
145 #endif
146
147 #ifdef REACTOS_COMPAT
148 #undef memmove
149 #define memmove captive_reactos_memmove
150 #else
151 #undef memmove
152 #endif
153
154 #ifdef REACTOS_COMPAT
155 #undef memset
156 #define memset captive_reactos_memset
157 #else
158 #undef memset
159 #endif
160
161 #ifdef REACTOS_COMPAT
162 #undef strcat
163 #define strcat captive_reactos_strcat
164 #else
165 #undef strcat
166 #endif
167
168 #ifdef REACTOS_COMPAT
169 #undef strchr
170 #define strchr captive_reactos_strchr
171 #else
172 #undef strchr
173 #endif
174
175 #ifdef REACTOS_COMPAT
176 #undef strcmp
177 #define strcmp captive_reactos_strcmp
178 #else
179 #undef strcmp
180 #endif
181
182 #ifdef REACTOS_COMPAT
183 #undef strcpy
184 #define strcpy captive_reactos_strcpy
185 #else
186 #undef strcpy
187 #endif
188
189 #ifdef REACTOS_COMPAT
190 #undef strlen
191 #define strlen captive_reactos_strlen
192 #else
193 #undef strlen
194 #endif
195
196 #ifdef REACTOS_COMPAT
197 #undef strncat
198 #define strncat captive_reactos_strncat
199 #else
200 #undef strncat
201 #endif
202
203 #ifdef REACTOS_COMPAT
204 #undef strncmp
205 #define strncmp captive_reactos_strncmp
206 #else
207 #undef strncmp
208 #endif
209
210 #ifdef REACTOS_COMPAT
211 #undef strncpy
212 #define strncpy captive_reactos_strncpy
213 #else
214 #undef strncpy
215 #endif
216
217 #ifdef REACTOS_COMPAT
218 #undef strrchr
219 #define strrchr captive_reactos_strrchr
220 #else
221 #undef strrchr
222 #endif
223
224 #ifdef REACTOS_COMPAT
225 #undef strspn
226 #define strspn captive_reactos_strspn
227 #else
228 #undef strspn
229 #endif
230
231 #ifdef REACTOS_COMPAT
232 #undef strstr
233 #define strstr captive_reactos_strstr
234 #else
235 #undef strstr
236 #endif
237
238 #ifdef REACTOS_COMPAT
239 #undef iswdigit
240 #define iswdigit captive_reactos_iswdigit
241 #else
242 #undef iswdigit
243 #endif
244
245 #ifdef REACTOS_COMPAT
246 #undef iswlower
247 #define iswlower captive_reactos_iswlower
248 #else
249 #undef iswlower
250 #endif
251
252 #ifdef REACTOS_COMPAT
253 #undef iswxdigit
254 #define iswxdigit captive_reactos_iswxdigit
255 #else
256 #undef iswxdigit
257 #endif
258
259 #ifdef REACTOS_COMPAT
260 #undef towlower
261 #define towlower captive_reactos_towlower
262 #else
263 #undef towlower
264 #endif
265
266 #ifdef REACTOS_COMPAT
267 #undef towupper
268 #define towupper captive_reactos_towupper
269 #else
270 #undef towupper
271 #endif
272
273 /* Place BEFORE "internal/debug.h" include as there is
274  *      internal/debug.h->internal/ntoskrnl.h->ddk/ntddk.h->REACTOS_UCS2()
275  */
276 #ifdef REACTOS_COMPAT
277 #include <stddef.h>     /* for wchar_t; Prevent <stddef.h> declaration while REACTOS_COMPAT is active */
278 /* You MUST include "captive/unicode_reactos.h" before wchar_t redefinition! */
279 #include "captive/unicode_reactos.h"    /* for captive_ucs4_to_ucs2_const() for crtdll/string.h/REACTOS_UCS2() and captive_ucs2 */
280 #define wchar_t captive_ucs2
281 #define REACTOS_UCS2(string_wchar32) (captive_wchar32_to_ucs2_const((string_wchar32)))
282 #else
283 #undef wchar_t
284 #undef REACTOS_UCS2
285 #endif
286
287 /* for internal/debug.h */
288 #ifdef REACTOS_COMPAT
289 #define DBG 1
290 #else
291 #undef DBG
292 #endif
293
294 /* Defined platform as _WIN32 as it is checked by some reactos include files.
295  * I expect it is set by MingW32 as I didn't find it defined anywhere in reactos distribution.
296  */
297 #ifdef REACTOS_COMPAT
298 #define _WIN32 1
299 /* else _WIN64 1 */
300 #else
301 #undef _WIN32
302 #endif
303
304
305 /* reactos/ntos/security.h/'PACCESS_MODE' does not get defined if !__NT(OSKRNL|HAL)__
306  */
307 #if _CAPTIVE_REACTOS_COMPAT_H == 1
308 #if !defined(__NTOSKRNL__) && !defined(__NTHAL__)
309 typedef /* ULONG: */ unsigned long ACCESS_MODE, *PACCESS_MODE;
310 #endif
311 #endif
312
313
314 /* -------------------------------- #include-s permitted now, #define-s forbidden
315  * See above #define _CAPTIVE_REACTOS_COMPAT_H_INSIDE in this file.
316  */
317
318
319 /* Define CAPTIVE_CDECL and CAPTIVE_STDCALL call types macros.
320  * They do not need to be undefed as they are common to reactos and non-reactos code.
321  * These macros have to be #ifdef-ed inside reactos itself.
322  */
323 #ifdef REACTOS_COMPAT
324 #include "captive/calltype_reactos.h"   /* for CAPTIVE_CDECL and CAPTIVE_STDCALL */
325 #endif
326
327 /* Place AFTER REACTOS_UCS2 definition as there is
328  *      internal/debug.h->internal/ntoskrnl.h->ddk/ntddk.h->REACTOS_UCS2()
329  * Some sources (reactos/ntoskrnl/ldr/loader.c) define NDEBUG themselves!
330  * We have to pre-define all the non-NDEBUG (=debug) macros for such source files.
331  */
332 #ifdef REACTOS_COMPAT
333 #ifdef __NTOSKRNL__     /* Don't pollute the namespace outside ntoskrnl. */
334 #include "reactos/internal/debug.h"
335 #endif
336 #endif
337
338 #ifdef REACTOS_COMPAT
339 /* All invalid reactos definitions go to captive_reactos_* as trash */
340 #define _KPCR            captive_reactos__KPCR
341 #define KPCR             captive_reactos_KPCR
342 #define PKPCR            captive_reactos_PKPCR
343 #define _IKPCR           captive_reactos__IKPCR
344 #define IKPCR            captive_reactos_IKPCR
345 #define PIKPCR           captive_reactos_PIKPCR
346 #define KeGetCurrentKPCR captive_reactos_KeGetCurrentKPCR
347 #include "reactos/internal/i386/ps.h"
348 #undef _KPCR
349 #undef KPCR
350 #undef PKPCR
351 #undef _IKPCR
352 #undef IKPCR
353 #undef PIKPCR
354 #undef KeGetCurrentKPCR
355 /* Usable libcaptive definition for reactos go to captive_*.
356  * Note we don't leave any defintion under its original symbol name
357  * just to make the whole mess a bit more sane.
358  */
359 #include "captive/ps_reactos.h"
360 #define _KPCR            captive__KPCR
361 #define KPCR             captive_KPCR
362 #define PKPCR            captive_PKPCR
363 #define _IKPCR           captive__KPCR
364 #define IKPCR            captive_KPCR
365 #define PIKPCR           captive_PKPCR
366 #define KeGetCurrentKPCR captive_KeGetCurrentKPCR
367 #else
368 #undef _KPCR
369 #undef KPCR
370 #undef PKPCR
371 #undef _IKPCR
372 #undef IKPCR
373 #undef PIKPCR
374 #undef KeGetCurrentKPCR
375 #endif
376
377
378 #undef _CAPTIVE_REACTOS_COMPAT_H_INSIDE