+respected proper function calling types cdecl/stdcall/fastcall
[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 #ifdef REACTOS_COMPAT
73 #define wcscpy captive_reactos_wcscpy
74 #else
75 #undef wcscpy
76 #endif
77
78 #ifdef REACTOS_COMPAT
79 #define wcscat captive_reactos_wcscat
80 #else
81 #undef wcscat
82 #endif
83
84 #ifdef REACTOS_COMPAT
85 #define wcschr captive_reactos_wcschr
86 #else
87 #undef wcschr
88 #endif
89
90 #ifdef REACTOS_COMPAT
91 #define wcsrchr captive_reactos_wcsrchr
92 #else
93 #undef wcsrchr
94 #endif
95
96 #ifdef REACTOS_COMPAT
97 #define wcslen captive_reactos_wcslen
98 #else
99 #undef wcslen
100 #endif
101
102 #ifdef REACTOS_COMPAT
103 #define _wcsicmp captive_reactos__wcsicmp
104 #else
105 #undef _wcsicmp
106 #endif
107
108 /* int iswdigit(wint_t wc); should be safe */
109 /* int iswlower(wint_t wc); should be safe */
110 /* int iswxdigit(wint_t wc); should be safe */
111
112 /* Place BEFORE "internal/debug.h" include as there is
113  *      internal/debug.h->internal/ntoskrnl.h->ddk/ntddk.h->REACTOS_UCS2()
114  */
115 #ifdef REACTOS_COMPAT
116 #include <stddef.h>     /* for wchar_t; Prevent <stddef.h> declaration while REACTOS_COMPAT is active */
117 /* You MUST include "captive/unicode_reactos.h" before wchar_t redefinition! */
118 #include "captive/unicode_reactos.h"    /* for captive_ucs4_to_ucs2_const() for crtdll/string.h/REACTOS_UCS2() and captive_ucs2 */
119 #define wchar_t captive_ucs2
120 #define REACTOS_UCS2(string_wchar32) (captive_wchar32_to_ucs2_const((string_wchar32)))
121 #else
122 #undef wchar_t
123 #undef REACTOS_UCS2
124 #endif
125
126 /* for internal/debug.h */
127 #ifdef REACTOS_COMPAT
128 #define DBG 1
129 #else
130 #undef DBG
131 #endif
132
133
134 /* -------------------------------- #include-s permitted now, #define-s forbidden
135  * See above #define _CAPTIVE_REACTOS_COMPAT_H_INSIDE in this file.
136  */
137
138
139 /* Place AFTER REACTOS_UCS2 definition as there is
140  *      internal/debug.h->internal/ntoskrnl.h->ddk/ntddk.h->REACTOS_UCS2()
141  * Some sources (reactos/ntoskrnl/ldr/loader.c) define NDEBUG themselves!
142  * We have to pre-define all the non-NDEBUG (=debug) macros for such source files.
143  */
144 #ifdef REACTOS_COMPAT
145 #ifdef __NTOSKRNL__     /* Don't pollute the namespace outside ntoskrnl. */
146 #include "reactos/internal/debug.h"
147 #endif
148 #endif
149
150 #ifdef REACTOS_COMPAT
151 /* All invalid reactos definitions go to captive_reactos_* as trash */
152 #define _KPCR            captive_reactos__KPCR
153 #define KPCR             captive_reactos_KPCR
154 #define PKPCR            captive_reactos_PKPCR
155 #define KeGetCurrentKPCR captive_reactos_KeGetCurrentKPCR
156 #include "reactos/internal/i386/ps.h"
157 #undef _KPCR
158 #undef KPCR
159 #undef PKPCR
160 #undef KeGetCurrentKPCR
161 /* Usable libcaptive definition for reactos go to captive_*.
162  * Note we don't leave any defintion under its original symbol name
163  * just to make the whole mess a bit more sane.
164  */
165 #include "captive/ps_reactos.h"
166 #define _KPCR            captive__KPCR
167 #define KPCR             captive_KPCR
168 #define PKPCR            captive_PKPCR
169 #define KeGetCurrentKPCR captive_KeGetCurrentKPCR
170 #else
171 #undef _KPCR
172 #undef KPCR
173 #undef PKPCR
174 #undef KeGetCurrentKPCR
175 #endif
176
177
178 #undef _CAPTIVE_REACTOS_COMPAT_H_INSIDE