1 /*
2 This file is part of Warzone 2100.
3 Copyright (C) 1992-2007 Trolltech ASA.
4 Copyright (C) 2005-2020 Warzone 2100 Project
5
6 Warzone 2100 is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 Warzone 2100 is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Warzone 2100; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 /*! \file wzglobal.h
21 * \brief Platform detection, workarounds and compat fixes
22 *
23 * OS and CC detection code shamelessly stolen from Qt4 (Qt/qglobal.h) by Dennis.
24 * This has been stripped down, feel free to add checks as you need them.
25 */
26
27 #ifndef WZGLOBAL_H
28 #define WZGLOBAL_H
29
30 #ifndef __STDC_FORMAT_MACROS
31 #define __STDC_FORMAT_MACROS
32 #endif
33 #ifndef __STDC_LIMIT_MACROS
34 #define __STDC_LIMIT_MACROS
35 #endif
36
37 #if defined(HAVE_CONFIG_H)
38 # undef _XOPEN_SOURCE
39 # include "config.h"
40 #elif !defined(HAVE_CONFIG_H)
41 # define PACKAGE "warzone2100"
42 # define PACKAGE_BUGREPORT "http://wz2100.net/"
43 # define PACKAGE_NAME "Warzone 2100"
44 # define PACKAGE_TARNAME "warzone2100"
45 #endif
46
47
48 /* ---- Platform detection ---- */
49
50
51 /*
52 The operating system, must be one of: (WZ_OS_x)
53
54 DARWIN - Darwin OS (synonym for WZ_OS_MAC)
55 OS2 - OS/2
56 OS2EMX - XFree86 on OS/2 (not PM)
57 WIN32 - Win32 (Windows 95/98/ME and Windows NT/2000/XP)
58 CYGWIN - Cygwin
59 SOLARIS - Sun Solaris
60 HPUX - HP-UX
61 ULTRIX - DEC Ultrix
62 LINUX - Linux
63 FREEBSD - FreeBSD
64 GNU_kFREEBSD - GNU/kFreeBSD
65 NETBSD - NetBSD
66 OPENBSD - OpenBSD
67 BSDI - BSD/OS
68 IRIX - SGI Irix
69 OSF - HP Tru64 UNIX
70 SCO - SCO OpenServer 5
71 UNIXWARE - UnixWare 7, Open UNIX 8
72 AIX - AIX
73 HURD - GNU Hurd
74 DGUX - DG/UX
75 RELIANT - Reliant UNIX
76 DYNIX - DYNIX/ptx
77 QNX - QNX
78 QNX6 - QNX RTP 6.1
79 LYNX - LynxOS
80 BSD4 - Any BSD 4.4 system
81 UNIX - Any UNIX BSD/SYSV system
82 */
83
84 #if defined(__APPLE__) && (defined(__GNUC__) || defined(__xlC__) || defined(__xlc__))
85 # define WZ_OS_DARWIN
86 # define WZ_OS_BSD4
87 # ifdef __LP64__
88 # define WZ_OS_DARWIN64
89 # else
90 # define WZ_OS_DARWIN32
91 # endif
92 #elif defined(__CYGWIN__)
93 # define WZ_OS_CYGWIN
94 #elif defined(__OS2__)
95 # if defined(__EMX__)
96 # define WZ_OS_OS2EMX
97 # else
98 # define WZ_OS_OS2
99 # endif
100 #elif !defined(SAG_COM) && (defined(WIN64) || defined(_WIN64) || defined(__WIN64__))
101 # define WZ_OS_WIN32
102 # define WZ_OS_WIN64
103 #elif !defined(SAG_COM) && (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__))
104 # define WZ_OS_WIN32
105 #elif defined(__MWERKS__) && defined(__INTEL__)
106 # define WZ_OS_WIN32
107 #elif defined(__sun) || defined(sun)
108 # define WZ_OS_SOLARIS
109 #elif defined(hpux) || defined(__hpux)
110 # define WZ_OS_HPUX
111 #elif defined(__ultrix) || defined(ultrix)
112 # define WZ_OS_ULTRIX
113 #elif defined(sinix)
114 # define WZ_OS_RELIANT
115 #elif defined(__linux__) || defined(__linux)
116 # define WZ_OS_LINUX
117 #elif defined(__FreeBSD__) || defined(__DragonFly__)
118 # define WZ_OS_FREEBSD
119 # define WZ_OS_BSD4
120 #elif defined(__FreeBSD_kernel__) && !defined(__FreeBSD__)
121 /* We're running a non-FreeBSD system with a FreeBSD kernel. Find out what C
122 * library we're using to detect the system we're running on. */
123 # include <stdlib.h>
124 # if defined(__GLIBC__)
125 /* We're running GNU/kFreeBSD */
126 # define WZ_OS_GNU_kFREEBSD
127 # endif
128 #elif defined(__NetBSD__)
129 # define WZ_OS_NETBSD
130 # define WZ_OS_BSD4
131 #elif defined(__OpenBSD__)
132 # define WZ_OS_OPENBSD
133 # define WZ_OS_BSD4
134 #elif defined(__bsdi__)
135 # define WZ_OS_BSDI
136 # define WZ_OS_BSD4
137 #elif defined(__sgi)
138 # define WZ_OS_IRIX
139 #elif defined(__osf__)
140 # define WZ_OS_OSF
141 #elif defined(_AIX)
142 # define WZ_OS_AIX
143 #elif defined(__Lynx__)
144 # define WZ_OS_LYNX
145 #elif defined(__GNU__)
146 # define WZ_OS_HURD
147 #elif defined(__DGUX__)
148 # define WZ_OS_DGUX
149 #elif defined(__QNXNTO__)
150 # define WZ_OS_QNX6
151 #elif defined(__QNX__)
152 # define WZ_OS_QNX
153 #elif defined(_SEQUENT_)
154 # define WZ_OS_DYNIX
155 #elif defined(_SCO_DS) /* SCO OpenServer 5 + GCC */
156 # define WZ_OS_SCO
157 #elif defined(__USLC__) /* all SCO platforms + UDK or OUDK */
158 # define WZ_OS_UNIXWARE
159 #elif defined(__svr4__) && defined(i386) /* Open UNIX 8 + GCC */
160 # define WZ_OS_UNIXWARE
161 #elif defined(__INTEGRITY)
162 # define WZ_OS_INTEGRITY
163 #elif defined(__MAKEDEPEND__)
164 #else
165 # error "Warzone has not been tested on this OS. Please contact warzone2100-project@lists.sourceforge.net"
166 #endif /* WZ_OS_x */
167
168 #if defined(WZ_OS_WIN32) || defined(WZ_OS_WIN64)
169 # define WZ_OS_WIN
170 #endif /* WZ_OS_WIN32 */
171
172 #if defined(WZ_OS_DARWIN)
173 # define WZ_OS_MAC /* WZ_OS_MAC is mostly for compatibility, but also more clear */
174 # define WZ_OS_MACX /* WZ_OS_MACX is only for compatibility.*/
175 # if defined(WZ_OS_DARWIN64)
176 # define WZ_OS_MAC64
177 # elif defined(WZ_OS_DARWIN32)
178 # define WZ_OS_MAC32
179 # endif
180 #endif /* WZ_OS_DARWIN */
181
182 #if defined(WZ_OS_MSDOS) || defined(WZ_OS_OS2) || defined(WZ_OS_WIN)
183 # undef WZ_OS_UNIX
184 #elif !defined(WZ_OS_UNIX)
185 # define WZ_OS_UNIX
186 #endif /* WZ_OS_* */
187
188
189 /*
190 The compiler, must be one of: (WZ_CC_x)
191
192 MSVC - Microsoft Visual C/C++, Intel C++ for Windows
193 GNU - GNU C++
194 CLANG - Clang LLVM
195 INTEL - Intel C++ for Linux, Intel C++ for Windows
196 TINYC - Fabrice Bellard's Tiny C Compiler
197
198 Should be sorted most to least authoritative.
199 */
200
201 #if defined(_MSC_VER)
202 # define WZ_CC_MSVC
203 /* All ISO C89 compliant compilers _should_ define the macro __STDC__, MSVC
204 * however is known _not_ to do this, so work around that here. */
205 # if !defined(__STDC__)
206 # define __STDC__ 1
207 # endif
208
209 /* Intel C++ disguising as Visual C++: the `using' keyword avoids warnings */
210 # if defined(__INTEL_COMPILER)
211 # define WZ_CC_INTEL
212 # endif
213 /* x64 does not support mmx intrinsics on windows */
214 # if (defined(ZS_OS_WIN64) && defined(_M_X64))
215 # undef ZS_HAVE_SSE
216 # undef ZS_HAVE_SSE2
217 # undef ZS_HAVE_MMX
218 # undef ZS_HAVE_3DNOW
219 # endif
220
221 #elif defined(__GNUC__)
222 # define WZ_CC_GNU
223 # if defined(__MINGW32__) || defined(__MINGW64__)
224 # define WZ_CC_MINGW
225 # endif
226 # if defined(__INTEL_COMPILER)
227 /* Intel C++ also masquerades as GCC 3.2.0 */
228 # define WZ_CC_INTEL
229 # endif
230
231 # if defined(__llvm__)
232 # define WZ_CC_LLVM
233 # endif
234 # if defined(__clang__)
235 # define WZ_CC_CLANG
236 # endif
237 /* Clang may not always masquerade as gcc */
238 #elif defined(__clang__)
239 # define WZ_CC_CLANG
240 # define WZ_CC_LLVM
241
242 #elif defined(__TINYC__)
243 # define WZ_CC_TINYC
244
245 #else
246 # error "Warzone has not been tested on this compiler. Please contact warzone2100-project@lists.sourceforge.net"
247 #endif /* WZ_CC_x */
248
249
250 /*
251 The window system, must be one of: (WZ_WS_x)
252
253 MACX - Mac OS X
254 WIN32 - Windows
255 X11 - X Window System
256 QNX - QNX
257 */
258
259 #if defined(_WIN32_X11_)
260 # define WZ_WS_X11
261
262 #elif defined(WZ_OS_WIN32)
263 # define WZ_WS_WIN32
264 # if defined(WZ_OS_WIN64)
265 # define WZ_WS_WIN64
266 # endif
267
268 #elif defined(WZ_OS_MAC)
269 # define WZ_WS_MAC
270 # define WZ_WS_MACX
271 # if defined(WZ_OS_MAC64)
272 # define WZ_WS_MAC64
273 # elif defined(WZ_OS_MAC32)
274 # define WZ_WS_MAC32
275 # endif
276
277 #elif defined(WZ_OS_QNX)
278 # define WZ_WS_QNX
279
280 #elif defined(WZ_OS_UNIX)
281 # define WZ_WS_X11
282
283 #else
284 # error "Warzone has not been tested on this window system. Please contact warzone2100-project@lists.sourceforge.net"
285 #endif /* WZ_WS_x */
286
287 #if defined(WZ_WS_WIN16) || defined(WZ_WS_WIN32)
288 # define WZ_WS_WIN
289 #endif
290
291
292 /*
293 The supported C standard, must be one of: (WZ_Cxx)
294
295 99 - ISO/IEC 9899:1999 / C99
296 */
297 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
298 # define WZ_C99
299 #endif /* WZ_Cxx */
300
301 /*
302 The supported C++ standard, must be one of: (WZ_CXXxx)
303
304 98 - ISO/IEC 14882:1998 / C++98
305 */
306 // VS 2013 aka _MSC_VER == 1800 still has __cplusplus == 199711L for some odd reason.
307 #if defined(__cplusplus)
308 # define WZ_CXX98
309 # if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || (_MSC_VER >= 1800)
310 # define WZ_CXX11
311 # endif
312 #endif /* WZ_CXXxx */
313
314
315 /*
316 Convenience macros to test the versions of gcc.
317 Copied from glibc's features.h.
318 */
319 #if defined(WZ_CC_GNU) && defined __GNUC__ && defined __GNUC_MINOR__
320 # define WZ_CC_GNU_PREREQ(maj, min) \
321 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
322 #else
323 # define WZ_CC_GNU_PREREQ(maj, min) 0
324 #endif
325
326
327 /*
328 Convenience macros to test the versions of icc.
329 */
330 #if defined(WZ_CC_INTEL) && defined __ICC
331 # define WZ_CC_INTEL_PREREQ(maj, min) \
332 ((__ICC) >= ((maj) * 100) + (min))
333 #else
334 # define WZ_CC_INTEL_PREREQ(maj, min) 0
335 #endif
336
337
338
339
340 /* ---- Declaration attributes ---- */
341
342
343 /*!
344 * \def WZ_DECL_DEPRECATED
345 *
346 * The WZ_DECL_DEPRECATED macro can be used to trigger compile-time warnings
347 * with newer compilers when deprecated functions are used.
348 *
349 * For non-inline functions, the macro gets inserted at front of the
350 * function declaration, right before the return type:
351 *
352 * \code
353 * WZ_DECL_DEPRECATED void deprecatedFunctionA();
354 * WZ_DECL_DEPRECATED int deprecatedFunctionB() const;
355 * \endcode
356 *
357 * For functions which are implemented inline,
358 * the WZ_DECL_DEPRECATED macro is inserted at the front, right before the return
359 * type, but after "static", "inline" or "virtual":
360 *
361 * \code
362 * WZ_DECL_DEPRECATED void deprecatedInlineFunctionA() { .. }
363 * virtual WZ_DECL_DEPRECATED int deprecatedInlineFunctionB() { .. }
364 * static WZ_DECL_DEPRECATED bool deprecatedInlineFunctionC() { .. }
365 * inline WZ_DECL_DEPRECATED bool deprecatedInlineFunctionD() { .. }
366 * \endcode
367 *
368 * You can also mark whole structs or classes as deprecated, by inserting the
369 * WZ_DECL_DEPRECATED macro after the struct/class keyword, but before the
370 * name of the struct/class:
371 *
372 * \code
373 * class WZ_DECL_DEPRECATED DeprecatedClass { };
374 * struct WZ_DECL_DEPRECATED DeprecatedStruct { };
375 * \endcode
376 *
377 * \note
378 * Description copied from KDE4, code copied from Qt4.
379 *
380 */
381 #if WZ_CC_GNU_PREREQ(3,2) || WZ_CC_INTEL_PREREQ(10,0)
382 # define WZ_DECL_DEPRECATED __attribute__((__deprecated__))
383 #elif defined(WZ_CC_MSVC)
384 # define WZ_DECL_DEPRECATED __declspec(deprecated)
385 #else
386 # define WZ_DECL_DEPRECATED
387 #endif
388
389
390 /*! \def WZ_DECL_FORMAT
391 * GCC: "The format attribute specifies that a function takes printf, scanf, strftime or strfmon
392 * style arguments which should be type-checked against a format string."
393 */
394 #if WZ_CC_GNU_PREREQ(2,5) && !defined(WZ_CC_INTEL)
395 # define WZ_DECL_FORMAT(archetype, string_index, first_to_check) \
396 __attribute__((__format__(archetype, string_index, first_to_check)))
397 #else
398 # define WZ_DECL_FORMAT(archetype, string_index, first_to_check)
399 #endif
400
401 #if WZ_CC_GNU_PREREQ(4,9)
402 # define WZ_DECL_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
403 # define WZ_DECL_RETURNS_NONNULL __attribute__((returns_nonnull))
404 # define WZ_DECL_ALLOCATION __attribute__((returns_nonnull, malloc, warn_unused_result))
405 #else
406 # define WZ_DECL_ALLOCATION
407 # define WZ_DECL_NONNULL(...)
408 # define WZ_DECL_RETURNS_NONNULL
409 #endif
410
411 /*!
412 * \def WZ_DECL_NORETURN
413 * "A few standard library functions, such as abort and exit, cannot return. GCC knows this
414 * automatically. Some programs define their own functions that never return.
415 * You can declare them noreturn to tell the compiler this fact."
416 */
417 #if WZ_CC_GNU_PREREQ(2,5) && !defined(WZ_CC_INTEL)
418 # define WZ_DECL_NORETURN __attribute__((__noreturn__))
419 #elif defined(WZ_CC_MSVC)
420 # define WZ_DECL_NORETURN __declspec(noreturn)
421 #else
422 # define WZ_DECL_NORETURN
423 #endif
424
425
426 /*!
427 * \def WZ_DECL_CONST
428 * GCC: "Many functions do not examine any values except their arguments, and have no effects
429 * except the return value. Basically this is just slightly more strict class than
430 * the pure attribute below, since function is not allowed to read global memory."
431 *
432 * Note that __attribute__((__const__)) doesn't work with some versions of gcc, in C++, at least
433 * for functions returning structures, and may silently return random results instead. So use
434 * constexpr instead, which seems to work (although can't be added to all types of function).
435 */
436 #if WZ_CC_GNU_PREREQ(2,5) && !defined(WZ_CC_INTEL)
437 # define WZ_DECL_CONST constexpr __attribute__((__warn_unused_result__))
438 #else
439 # define WZ_DECL_CONST
440 #endif
441
442
443 /*!
444 * \def WZ_DECL_ALWAYS_INLINE
445 * GCC: "Generally, functions are not inlined unless optimization is specified. For functions
446 * declared inline, this attribute inlines the function even if no optimization level
447 * was specified."
448 */
449 #if WZ_CC_GNU_PREREQ(2,5)
450 # define WZ_DECL_ALWAYS_INLINE __attribute__((__always_inline__))
451 #else
452 # define WZ_DECL_ALWAYS_INLINE
453 #endif
454
455
456 /*!
457 * \def WZ_DECL_PURE
458 * GCC: "Many functions have no effects except the return value and their return value depends
459 * only on the parameters and/or global variables. Such a function can be subject to
460 * common subexpression elimination and loop optimization just as an arithmetic operator
461 * would be."
462 */
463 #if WZ_CC_GNU_PREREQ(2,96) && !defined(WZ_CC_INTEL)
464 # define WZ_DECL_PURE __attribute__((__pure__))
465 #else
466 # define WZ_DECL_PURE
467 #endif
468
469
470 /*!
471 * \def WZ_DECL_UNUSED
472 * GCC: "This attribute, attached to a function, means that the function is meant to be possibly
473 * unused. GCC will not produce a warning for this function."
474 */
475 #if WZ_CC_GNU_PREREQ(3,2) || WZ_CC_INTEL_PREREQ(10,0)
476 # define WZ_DECL_UNUSED __attribute__((__unused__))
477 #else
478 # define WZ_DECL_UNUSED
479 #endif
480
481
482 /*!
483 * \def WZ_DECL_WARN_UNUSED_RESULT
484 * GCC: "The warn_unused_result attribute causes a warning to be emitted if a caller of the
485 * function with this attribute does not use its return value. This is useful for
486 * functions where not checking the result is either a security problem or always a bug,
487 * such as realloc."
488 */
489 #if defined(WZ_CC_GNU) && !defined(WZ_CC_INTEL)
490 # define WZ_DECL_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
491 #else
492 # define WZ_DECL_WARN_UNUSED_RESULT
493 #endif
494
495
496 /*! \def WZ_DECL_MAY_ALIAS
497 * GCC: "Accesses to objects with types with this attribute are not subjected to type-based alias
498 * analysis, but are instead assumed to be able to alias any other type of objects,
499 * just like the char type. See -fstrict-aliasing for more information on aliasing issues."
500 */
501 #if WZ_CC_GNU_PREREQ(3,3) && !defined(WZ_CC_INTEL)
502 # define WZ_DECL_MAY_ALIAS __attribute__((__may_alias__))
503 #else
504 # define WZ_DECL_MAY_ALIAS
505 #endif
506
507
508 /*!
509 * \def WZ_DECL_RESTRICT
510 * Apply the "restrict" keyword found in the C99 revision of the standard.
511 * The compiler may assume that the memory referenced by a "restrict" pointer is not aliased
512 * by any other pointer. Thus this forms the opposite of WZ_DECL_MAY_ALIAS.
513 */
514 #if defined(WZ_C99) && WZ_CC_GNU_PREREQ(4,1) && !defined(WZ_CC_INTEL)
515 # define WZ_DECL_RESTRICT restrict
516 #elif defined(WZ_CC_MSVC)
517 # define WZ_DECL_RESTRICT __restrict
518 #else
519 # define WZ_DECL_RESTRICT
520 #endif
521
522
523 /*! \def WZ_DECL_THREAD
524 * Declares a variable to be local to the running thread, and not shared between threads.
525 */
526 #if defined(__MACOSX__)
527 # define WZ_DECL_THREAD // nothing, MacOSX does not yet support this
528 #elif defined(WZ_CC_GNU) || defined(WZ_CC_INTEL)
529 # define WZ_DECL_THREAD __thread
530 #elif defined(WZ_CC_MSVC)
531 # define WZ_DECL_THREAD __declspec(thread)
532 #else
533 # error "Thread local storage attribute required"
534 #endif
535
536 /* ---- Platform specific setup ---- */
537
538 #if defined(WZ_OS_WIN)
539 # if defined(WZ_CC_MINGW)
540 // NOTE: For mingw-w64, we must define _GDI32_ otherwise we would be making WINGDIAPI DECLSPEC_IMPORT
541 // which we do not want (that is for shared libs, aka dlls). See wingdi.h to see where the check is.
542 // refs: http://sourceforge.net/p/mingw-w64/patches/41/
543 # define _GDI32_
544 # include <unistd.h>
545 # include <sys/param.h>
546 # include <w32api.h>
547 # define _WIN32_IE IE5
548 // Required for alloca
549 # include <malloc.h>
550
551 # elif defined(WZ_CC_MSVC)
552 # if defined(_DEBUG)
553 # define DEBUG
554 # define _CRTDBG_MAP_ALLOC
555 # include <stdlib.h>
556 # include <crtdbg.h>
557 # endif /* _DEBUG */
558 // Required for alloca
559 # include <malloc.h>
560 # endif /* WZ_CC_* */
561
562 # define WIN32_LEAN_AND_MEAN
563 # define WIN32_EXTRA_LEAN
564 # undef NOMINMAX
565 # define NOMINMAX 1 // disable the min / max macros
566 # include <windows.h>
567
568 # if defined(WZ_CC_MSVC)
569 // notify people we are disabling these warning messages.
570 # pragma message (" *** Warnings 4018,4127,4389 have been squelched. ***")
571 # pragma warning (disable : 4018) // Shut up: '>' : signed/unsigned mismatch
572 # pragma warning (disable : 4127) // Shut up: conditional expression is constant (eg. "while(0)")
573 # pragma warning (disable : 4389) // Shut up: '==' : signed/unsigned mismatch
574
575 # define strcasecmp _stricmp
576 # define strncasecmp _strnicmp
577 # if !defined(inline) && !defined(__cplusplus)
578 # define inline __inline
579 # endif
580 # define alloca _alloca
581 # define fileno _fileno
582
583 # define PATH_MAX MAX_PATH
584
585 // These are useless for MSVC builds, since we don't populate them / use them at this time.
586 #ifndef PACKAGE_DISTRIBUTOR
587 # define PACKAGE_DISTRIBUTOR "UNKNOWN"
588 #endif
589 #ifndef PACKAGE_VERSION
590 # define PACKAGE_VERSION "UNKNOWN"
591 #endif
592 #ifndef PACKAGE
593 # define PACKAGE "Warzone"
594 #endif
595
596
597 # endif /* WZ_CC_MSVC */
598
599 /* Make sure that PATH_MAX is large enough to use as the size for return
600 * buffers for Windows API calls
601 */
602 # if (PATH_MAX < MAX_PATH)
603 # undef PATH_MAX
604 # define PATH_MAX MAX_PATH
605 # endif
606
607 #elif defined(WZ_OS_UNIX)
608 # include <unistd.h>
609 # if defined(HAVE_ALLOCA_H)
610 # include <alloca.h>
611 # endif
612 #endif /* WZ_OS_* */
613
614 // Define PATH_MAX for systems that don't have it, like Hurd
615 #ifndef PATH_MAX
616 #define PATH_MAX 4096
617 #endif
618
619
620 #if !defined(WZ_C99) && !defined(va_copy)
621 /**
622 * Implements the interface of the C99 macro va_copy such that we can use it on
623 * non-C99 systems as well.
624 *
625 * This implementation assumes that va_list is just a pointer to the stack
626 * frame of the variadic function. This is by far the most common setup, though
627 * it might not always work.
628 */
629 # define va_copy(dest, src) (void)((dest) = (src))
630 #endif // !WZ_C99 && !va_copy
631
632 /*! \def WZ_ASSERT_STATIC_STRING
633 * Asserts that the given string is statically allocated.
634 */
635 #if defined(__cplusplus)
636 template <int N>
_WZ_ASSERT_STATIC_STRING_FUNCTION(char const (&)[N])637 static inline char _WZ_ASSERT_STATIC_STRING_FUNCTION(char const(&)[N])
638 {
639 return '\0'; // Regular array.
640 }
_WZ_ASSERT_STATIC_STRING_FUNCTION(char const * &)641 static inline char *_WZ_ASSERT_STATIC_STRING_FUNCTION(char const *&)
642 {
643 return nullptr; // Eeek, it's a pointer!
644 }
_WZ_ASSERT_STATIC_STRING_FUNCTION(char * &)645 static inline char *_WZ_ASSERT_STATIC_STRING_FUNCTION(char *&)
646 {
647 return nullptr; // Eeek, it's a pointer!
648 }
649 # define WZ_ASSERT_STATIC_STRING(_var) STATIC_ASSERT(sizeof(_WZ_ASSERT_STATIC_STRING_FUNCTION(_var)) == sizeof(char))
650 #elif defined(WZ_CC_GNU) || defined(WZ_CC_INTEL)
651 # define WZ_ASSERT_STATIC_STRING(_var) STATIC_ASSERT(__builtin_types_compatible_p(typeof(_var), char[]))
652 #else
653 # define WZ_ASSERT_STATIC_STRING(_var) (void)(_var)
654 #endif
655
656 /*! \def WZ_ASSERT_ARRAY
657 * Asserts that the given variable is a (statically sized) array, not just a pointer.
658 */
659 #if defined(__cplusplus)
660 template <typename T, int N>
_WZ_ASSERT_ARRAY_EXPR_FUNCTION(T (&)[N])661 static inline char _WZ_ASSERT_ARRAY_EXPR_FUNCTION(T(&)[N])
662 {
663 return '\0'; // Regular array.
664 }
_WZ_ASSERT_ARRAY_EXPR_FUNCTION(void const *)665 static inline char _WZ_ASSERT_ARRAY_EXPR_FUNCTION(void const *)
666 {
667 return '\0'; // Catch static arrays of unnamed structs.
668 }
669 template <typename T>
_WZ_ASSERT_ARRAY_EXPR_FUNCTION(T * &)670 static inline char *_WZ_ASSERT_ARRAY_EXPR_FUNCTION(T *&)
671 {
672 return nullptr; // Eeek, it's a pointer!
673 }
674 # define WZ_ASSERT_ARRAY_EXPR(_var) STATIC_ASSERT_EXPR(sizeof(_WZ_ASSERT_ARRAY_EXPR_FUNCTION(_var)) == sizeof(char))
675 #elif defined(WZ_CC_GNU) || defined(WZ_CC_INTEL)
676 /* &a[0] degrades to a pointer: a different type from an array */
677 # define WZ_ASSERT_ARRAY_EXPR(a) STATIC_ASSERT_EXPR(!__builtin_types_compatible_p(typeof(a), typeof(&(a)[0])))
678 #else
679 # define WZ_ASSERT_ARRAY_EXPR(a) 0
680 #endif
681 #define WZ_ASSERT_ARRAY(a) (void)WZ_ASSERT_ARRAY_EXPR(a)
682
683 #ifdef HAVE___BUILTIN_EXPECT
684 # define unlikely(expr) __builtin_expect(!!(expr),0)
685 # define likely(expr) __builtin_expect(!!(expr),1)
686 #else
687 # define unlikely(expr) (expr)
688 # define likely(expr) (expr)
689 #endif
690
691 // Compiler-specific #pragma support
692 #if defined( _MSC_VER )
693 #define MSVC_PRAGMA(x) __pragma(x)
694 #else
695 #define MSVC_PRAGMA(x)
696 #endif
697
698 // Gfx backend option support
699 #if defined(WZ_OS_WIN)
700 # define WZ_BACKEND_DIRECTX
701 #endif
702
703 #endif /* WZGLOBAL_H */
704