ScummVM API documentation
sdl-sys.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef BACKEND_SDL_SYS_H
23#define BACKEND_SDL_SYS_H
24
25// The purpose of this header is to include the SDL headers in a uniform
26// fashion.
27// Moreover, it contains a workaround for the fact that SDL_rwops.h uses
28// a FILE pointer in one place, which conflicts with common/forbidden.h.
29// The SDL 1.3 headers also include strings.h
30
31#include "common/scummsys.h"
32
33#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_FILE)
34#undef FILE
35#endif
36
37#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strcasecmp)
38#undef strcasecmp
39#define strcasecmp FAKE_strcasecmp
40#endif
41
42#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strncasecmp)
43#undef strncasecmp
44#define strncasecmp FAKE_strncasecmp
45#endif
46
47#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_exit)
48#undef exit
49#define exit FAKE_exit
50#endif
51
52#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_abort)
53#undef abort
54#define abort FAKE_abort
55#endif
56
57#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_system)
58#undef system
59#define system FAKE_system
60#endif
61
62#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_mkdir)
63#undef mkdir
64#define mkdir FAKE_mkdir
65#endif
66
67#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strcpy)
68#undef strcpy
69#define strcpy FAKE_strcpy
70#endif
71
72#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strcat)
73#undef strcat
74#define strcat FAKE_strcat
75#endif
76
77#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_vsprintf)
78#undef vsprintf
79#define vsprintf FAKE_vsprintf
80#endif
81
82#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_sprintf)
83#undef sprintf
84#define sprintf FAKE_sprintf
85#endif
86
87// Fix compilation with MacPorts SDL 2
88// It needs various (usually forbidden) symbols from time.h
89#ifndef FORBIDDEN_SYMBOL_EXCEPTION_time_h
90
91 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_asctime)
92 #undef asctime
93 #define asctime FAKE_asctime
94 #endif
95
96 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_clock)
97 #undef clock
98 #define clock FAKE_clock
99 #endif
100
101 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_ctime)
102 #undef ctime
103 #define ctime FAKE_ctime
104 #endif
105
106 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_difftime)
107 #undef difftime
108 #define difftime FAKE_difftime
109 #endif
110
111 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getdate)
112 #undef getdate
113 #define getdate FAKE_getdate
114 #endif
115
116 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_gmtime)
117 #undef gmtime
118 #define gmtime FAKE_gmtime
119 #endif
120
121 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_localtime)
122 #undef localtime
123 #define localtime FAKE_localtime
124 #endif
125
126 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_mktime)
127 #undef mktime
128 #define mktime FAKE_mktime
129 #endif
130
131 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_time)
132 #undef time
133 #define time FAKE_time
134 #endif
135
136#endif // FORBIDDEN_SYMBOL_EXCEPTION_time_h
137
138// Fix compilation on non-x86 architectures
139// It needs various (usually forbidden) symbols from unistd.h
140#ifndef FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
141
142 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_chdir)
143 #undef chdir
144 #define chdir FAKE_chdir
145 #endif
146
147 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getcwd)
148 #undef getcwd
149 #define getcwd FAKE_getcwd
150 #endif
151
152 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getwd)
153 #undef getwd
154 #define getwd FAKE_getwd
155 #endif
156
157 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_unlink)
158 #undef unlink
159 #define unlink FAKE_unlink
160 #endif
161
162#endif // FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
163
164// HACK: SDL might include windows.h which defines its own ARRAYSIZE.
165// However, we want to use the version from common/util.h. Thus, we make sure
166// that we actually have this definition after including the SDL headers.
167#if defined(ARRAYSIZE) && defined(COMMON_UTIL_H)
168#define HACK_REDEFINE_ARRAYSIZE
169#undef ARRAYSIZE
170#endif
171
172// HACK to fix compilation with SDL 2.0 in MSVC.
173// In SDL 2.0, intrin.h is now included in SDL_cpuinfo.h, which includes
174// setjmp.h. SDL_cpuinfo.h is included from SDL.h and SDL_syswm.h.
175// Thus, we remove the exceptions for setjmp and longjmp before these two
176// includes.
177#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && defined(_MSC_VER) && defined(USE_SDL2)
178// We unset any fake definitions of setjmp/longjmp here
179
180#ifndef FORBIDDEN_SYMBOL_EXCEPTION_setjmp
181#undef setjmp
182#endif
183
184#ifndef FORBIDDEN_SYMBOL_EXCEPTION_longjmp
185#undef longjmp
186#endif
187
188#endif
189
190#ifdef USE_SDL3
191#include <SDL3/SDL.h>
192#else
193#include <SDL.h>
194#endif
195
196// Ignore warnings from system headers pulled by SDL
197#pragma warning(push)
198#pragma warning(disable:4121) // alignment of a member was sensitive to packing
199#if !SDL_VERSION_ATLEAST(3, 0, 0)
200#include <SDL_syswm.h>
201#endif
202#pragma warning(pop)
203
204// Restore the forbidden exceptions from the hack above
205#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && defined(_MSC_VER)
206
207#ifndef FORBIDDEN_SYMBOL_EXCEPTION_setjmp
208#undef setjmp
209#define setjmp(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
210#endif
211
212#ifndef FORBIDDEN_SYMBOL_EXCEPTION_longjmp
213#undef longjmp
214#define longjmp(a,b) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
215#endif
216
217#endif
218
219// SDL_syswm.h will include windows.h on Win32. We need to undefine its
220// ARRAYSIZE definition because we supply our own.
221#undef ARRAYSIZE
222
223#ifdef HACK_REDEFINE_ARRAYSIZE
224#undef HACK_REDEFINE_ARRAYSIZE
225#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
226#endif
227
228// In a moment of brilliance Xlib.h included by SDL_syswm.h #defines the
229// following names. In a moment of mental breakdown, which occurred upon
230// gazing at Xlib.h, LordHoto decided to undefine them to prevent havoc.
231#ifdef Status
232#undef Status
233#endif
234
235#ifdef Bool
236#undef Bool
237#endif
238
239#ifdef True
240#undef True
241#endif
242
243#ifdef False
244#undef False
245#endif
246
247#ifdef Complex
248#undef Complex
249#endif
250
251// Finally forbid FILE again (if it was forbidden to start with)
252#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_FILE)
253#undef FILE
254#define FILE FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
255#endif
256
257#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strcasecmp)
258#undef strcasecmp
259#define strcasecmp FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
260#endif
261
262#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strncasecmp)
263#undef strncasecmp
264#define strncasecmp FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
265#endif
266
267#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_exit)
268#undef exit
269#define exit(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
270#endif
271
272#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_abort)
273#undef abort
274#define abort() FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
275#endif
276
277#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_system)
278#undef system
279#define system(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
280#endif
281
282#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_mkdir)
283#undef mkdir
284#define mkdir(a,b) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
285#endif
286
287#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strcpy)
288#undef strcpy
289#define strcpy(a,b) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
290#endif
291
292#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strcat)
293#undef strcat
294#define strcat(a,b) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
295#endif
296
297#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_vsprintf)
298#undef vsprintf
299#define vsprintf(a,b,c) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
300#endif
301
302#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_sprintf)
303#undef sprintf
304#define sprintf(a,b,...) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
305#endif
306
307// re-forbid all those time.h symbols again (if they were forbidden)
308#ifndef FORBIDDEN_SYMBOL_EXCEPTION_time_h
309
310 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_asctime)
311 #undef asctime
312 #define asctime(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
313 #endif
314
315 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_clock)
316 #undef clock
317 #define clock() FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
318 #endif
319
320 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_ctime)
321 #undef ctime
322 #define ctime(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
323 #endif
324
325 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_difftime)
326 #undef difftime
327 #define difftime(a,b) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
328 #endif
329
330 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getdate)
331 #undef getdate
332 #define getdate(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
333 #endif
334
335 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_gmtime)
336 #undef gmtime
337 #define gmtime(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
338 #endif
339
340 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_localtime)
341 #undef localtime
342 #define localtime(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
343 #endif
344
345 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_mktime)
346 #undef mktime
347 #define mktime(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
348 #endif
349
350 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_time)
351 #undef time
352 #define time(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
353 #endif
354
355#endif // FORBIDDEN_SYMBOL_EXCEPTION_time_h
356
357// re-forbid all those unistd.h symbols again (if they were forbidden)
358#ifndef FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
359
360 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_chdir)
361 #undef chdir
362 #define chdir(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
363 #endif
364
365 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getcwd)
366 #undef getcwd
367 #define getcwd(a,b) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
368 #endif
369
370 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getwd)
371 #undef getwd
372 #define getwd(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
373 #endif
374
375 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_unlink)
376 #undef unlink
377 #define unlink(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
378 #endif
379
380#endif // FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
381
382#endif