15 #if defined(__APPLE__)
19 #if defined(__BEOS__) || defined(__HAIKU__)
20 #include <SupportDefs.h>
25 #elif defined(__NDS__)
26 #include <nds/jtypes.h>
34 #if !defined(__APPLE__) && (!defined(_MSC_VER) || _MSC_VER >= 1600) && !defined(__MORPHOS__)
40 #define __STDC_LIMIT_MACROS
46 #if !defined(UINT64_MAX)
47 #define UINT64_MAX (18446744073709551615ULL)
49 #if !defined(INT64_MAX)
50 #define INT64_MAX (9223372036854775807LL)
52 #if !defined(INT64_MIN)
53 #define INT64_MIN (-INT64_MAX - 1)
55 #if !defined(UINT32_MAX)
56 #define UINT32_MAX (4294967295U)
58 #if !defined(INT32_MAX)
59 #define INT32_MAX (2147483647)
61 #if !defined(INT32_MIN)
62 #define INT32_MIN (-INT32_MAX - 1)
64 #if !defined(UINT16_MAX)
65 #define UINT16_MAX (65535U)
67 #if !defined(INT16_MAX)
68 #define INT16_MAX (32767)
70 #if !defined(INT16_MIN)
71 #define INT16_MIN (-INT16_MAX - 1)
73 #if !defined(UINT8_MAX)
74 #define UINT8_MAX (255)
76 #if !defined(INT8_MAX)
77 #define INT8_MAX (127)
79 #if !defined(INT8_MIN)
80 #define INT8_MIN (-INT8_MAX - 1)
91 #define SIZE_MAX ((size_t)-1)
94 #if defined(UNIX) || defined(__MINGW32__)
95 #include <sys/types.h>
100 #define strcasecmp stricmp
104 #include <psptypes.h>
105 #include <pspdebug.h>
106 #include <pspthreadman.h>
109 #if defined(SUNOS) || defined(HPUX)
113 #if defined(__MORPHOS__)
120 #if defined(__amigaos__)
123 #if defined(__AMIGA__)
134 #define CLIB_USERGROUP_PROTOS_H
141 #define LIMITED_FDS 8
142 #define printf pspDebugScreenPrintf
146 #if defined(__GNUC__)
147 #define NORETURN __attribute__ ((noreturn))
149 #define __int64 long long
150 #define GCC_PACK __attribute__((packed))
153 #define WARN_FORMAT(string, args) __attribute__ ((format (printf, string, args)))
154 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
161 #if defined(__WATCOMC__)
165 #define WARN_FORMAT(string, args)
170 #if defined(__MINGW32__) || defined(__CYGWIN__)
175 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
179 #if defined(_MSC_VER)
183 #define NTDDI_VERSION NTDDI_WINXP // Windows XP
184 #define _WIN32_WINNT 0x501 // Windows XP
185 #define _WIN32_WINDOWS 0x501 // Windows XP
186 #define WINVER 0x0501 // Windows XP
187 #define _WIN32_IE_ 0x0600 // 6.0 (XP+)
191 #define NTDDI_VERSION NTDDI_WIN2K // Windows 2000
192 #define _WIN32_WINNT 0x0500 // Windows 2000
193 #define _WIN32_WINDOWS 0x400 // Windows 95
195 #define WINVER 0x0400 // Windows NT 4.0 / Windows 95
197 #define _WIN32_IE_ 0x0401 // 4.01 (win98 and NT4SP5+)
199 #define NOMINMAX // Disable min/max macros in windows.h.
201 #pragma warning(disable: 4244) // 'conversion' conversion from 'type1' to 'type2', possible loss of data
202 #pragma warning(disable: 4761) // integral size mismatch in argument : conversion supplied
203 #pragma warning(disable: 4200) // nonstandard extension used : zero-sized array in struct/union
204 #pragma warning(disable: 4355) // 'this' : used in base member initializer list
206 #if (_MSC_VER < 1400) // MSVC 2005 safety checks
207 #error "Only MSVC 2005 or higher are supported. MSVC 2003 and earlier are not! Upgrade your compiler."
209 #pragma warning(disable: 4291) // no matching operator delete found; memory will not be freed if initialization throws an exception (reason: our overloaded functions never throw an exception)
210 #pragma warning(disable: 4996) // 'function': was declared deprecated
211 #define _CRT_SECURE_NO_DEPRECATE // all deprecated 'unsafe string functions
212 #pragma warning(disable: 6308) // code analyzer: 'realloc' might return null pointer: assigning null pointer to 't_ptr', which is passed as an argument to 'realloc', will cause the original memory block to be leaked
213 #pragma warning(disable: 6011) // code analyzer: Dereferencing NULL pointer 'pfGetAddrInfo': Lines: 995, 996, 998, 999, 1001
214 #pragma warning(disable: 6326) // code analyzer: potential comparison of a constant with another constant
215 #pragma warning(disable: 6031) // code analyzer: Return value ignored: 'ReadFile'
216 #pragma warning(disable: 6255) // code analyzer: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead
217 #pragma warning(disable: 6246) // code analyzer: Local declaration of 'statspec' hides declaration of the same name in outer scope. For additional information, see previous declaration at ...
219 #if (_MSC_VER == 1500) // Addresses item #13 on http://blogs.msdn.com/b/vcblog/archive/2008/08/11/tr1-fixes-in-vc9-sp1.aspx, for Visual Studio 2008
220 #define _DO_NOT_DECLARE_INTERLOCKED_INTRINSICS_IN_MEMORY
225 #define NORETURN __declspec(noreturn)
226 #define inline __forceinline
233 #define WARN_FORMAT(string, args)
237 int CDECL vsnprintf(
char *str,
size_t size,
const char *format, va_list ap);
240 #if defined(WIN32) && !defined(_WIN64) && !defined(WIN64)
245 typedef _W64
int INT_PTR, *PINT_PTR;
246 typedef _W64
unsigned int UINT_PTR, *PUINT_PTR;
249 #if defined(_WIN64) || defined(WIN64)
250 #define fseek _fseeki64
254 #if defined(WITH_ZLIB) || defined(WITH_PNG)
255 #if !defined(ZLIB_WINAPI)
261 #define strcasecmp _stricmp
262 #define strncasecmp _strnicmp
265 #define strcasecmp stricmp
266 #define strncasecmp strnicmp
270 #define S_ISDIR(mode) (mode & S_IFDIR)
271 #define S_ISREG(mode) (mode & S_IFREG)
277 #define strsignal(sig) ""
281 #define SIGBUS SIGNOFP
285 #define stredup _stredup
290 #if !defined(STRGEN) && !defined(SETTINGSGEN)
291 #if defined(WIN32) || defined(WIN64)
292 char *getcwd(
char *buf,
size_t size);
298 namespace std { using ::_tfopen; }
299 #define fopen(file, mode) _tfopen(OTTD2FS(file), _T(mode))
300 #define unlink(file) _tunlink(OTTD2FS(file))
303 const char *
FS2OTTD(
const TCHAR *name);
304 const TCHAR *
OTTD2FS(
const char *name,
bool console_cp =
false);
306 #define fopen(file, mode) fopen(OTTD2FS(file), mode)
307 const char *
FS2OTTD(
const char *name);
308 const char *
OTTD2FS(
const char *name);
312 #if defined(WIN32) || defined(WIN64) || defined(__OS2__) && !defined(__INNOTEK_LIBC__)
314 #define PATHSEPCHAR '\\'
317 #define PATHSEPCHAR '/'
321 #if defined(_MSC_VER) || defined(__MINGW32__)
322 #define OTTD_PRINTF64 "%I64d"
323 #define OTTD_PRINTFHEX64 "%I64x"
324 #define PRINTF_SIZE "%Iu"
326 #define OTTD_PRINTF64 "%lld"
327 #define OTTD_PRINTFHEX64 "%llx"
328 #define PRINTF_SIZE "%zu"
331 typedef unsigned char byte;
334 #if (!defined(UNIX) && !defined(__CYGWIN__) && !defined(__BEOS__) && !defined(__HAIKU__) && !defined(__MORPHOS__)) || defined(__QNXNTO__)
335 typedef unsigned int uint;
338 #if defined(TROUBLED_INTS)
341 #define uint32 uint32_ugly_hack
342 #define int32 int32_ugly_hack
343 typedef unsigned int uint32_ugly_hack;
344 typedef signed int int32_ugly_hack;
346 typedef unsigned char uint8;
347 typedef signed char int8;
348 typedef unsigned short uint16;
349 typedef signed short int16;
350 typedef unsigned int uint32;
351 typedef signed int int32;
352 typedef unsigned __int64 uint64;
353 typedef signed __int64 int64;
356 #if !defined(WITH_PERSONAL_DIR)
357 #define PERSONAL_DIR ""
363 #if defined(__STDCXX_VERSION__) || defined(__GXX_EXPERIMENTAL_CXX0X__) || defined(__GXX_EXPERIMENTAL_CPP0X__) || defined(static_assert)
365 #define assert_compile(expr) static_assert(expr, #expr )
366 #define assert_tcompile(expr) assert_compile(expr)
367 #elif defined(__OS2__)
369 #define assert_compile(expr)
370 #define assert_tcompile(expr) assert_compile(expr)
372 #define assert_compile(expr) typedef int __ct_assert__[1 - 2 * !(expr)]
373 #define assert_tcompile(expr) assert(expr)
377 assert_compile(
sizeof(uint64) == 8);
378 assert_compile(
sizeof(uint32) == 4);
379 assert_compile(
sizeof(uint16) == 2);
380 assert_compile(
sizeof(uint8) == 1);
381 assert_compile(SIZE_MAX >= UINT32_MAX);
384 #define M_PI_2 1.57079632679489661923
385 #define M_PI 3.14159265358979323846
396 #define lengthof(x) (sizeof(x) / sizeof(x[0]))
404 #define endof(x) (&x[lengthof(x)])
412 #define lastof(x) (&x[lengthof(x) - 1])
414 #define cpp_offsetof(s, m) (((size_t)&reinterpret_cast<const volatile char&>((((s*)(char*)8)->m))) - 8)
415 #if !defined(offsetof)
416 #define offsetof(s, m) cpp_offsetof(s, m)
425 #define cpp_sizeof(base, variable) (sizeof(((base*)8)->variable))
433 #define cpp_lengthof(base, variable) (cpp_sizeof(base, variable) / cpp_sizeof(base, variable[0]))
437 #if defined(__APPLE__)
438 #define GetString OTTD_GetString
439 #define DrawString OTTD_DrawString
440 #define CloseConnection OTTD_CloseConnection
443 void NORETURN CDECL
usererror(
const char *str, ...) WARN_FORMAT(1, 2);
444 void NORETURN CDECL
error(const
char *str, ...) WARN_FORMAT(1, 2);
445 #define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
451 #if (defined(_MSC_VER) && defined(NDEBUG) && defined(WITH_ASSERT)) || (!defined(_MSC_VER) && !defined(NDEBUG) && !defined(_DEBUG))
453 #define assert(expression) if (!(expression)) error("Assertion failed at line %i of %s: %s", __LINE__, __FILE__, #expression);
457 #if !defined(NDEBUG) || (defined(_MSC_VER) && defined(WITH_ASSERT))
461 #if defined(MORPHOS) || defined(__NDS__) || defined(__DJGPP__)
463 #define _stricmp stricmp
464 #elif defined(OPENBSD)
466 #define _stricmp strcasecmp
469 #if defined(MAX_PATH)
471 #elif defined(PATH_MAX) && PATH_MAX > 0
473 #define MAX_PATH PATH_MAX
483 static inline void free(
const void *ptr)
485 free(const_cast<void *>(ptr));
492 #define MAX_UVALUE(type) ((type)~(type)0)
494 #if defined(_MSC_VER) && !defined(_DEBUG)
495 #define IGNORE_UNINITIALIZED_WARNING_START __pragma(warning(push)) __pragma(warning(disable:4700))
496 #define IGNORE_UNINITIALIZED_WARNING_STOP __pragma(warning(pop))
497 #elif defined(__GNUC__) && !defined(_DEBUG)
498 #define HELPER0(x) #x
499 #define HELPER1(x) HELPER0(GCC diagnostic ignored x)
500 #define HELPER2(y) HELPER1(#y)
501 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
502 #define IGNORE_UNINITIALIZED_WARNING_START \
503 _Pragma("GCC diagnostic push") \
504 _Pragma(HELPER2(-Wuninitialized)) \
505 _Pragma(HELPER2(-Wmaybe-uninitialized))
506 #define IGNORE_UNINITIALIZED_WARNING_STOP _Pragma("GCC diagnostic pop")
510 #ifndef IGNORE_UNINITIALIZED_WARNING_START
511 #define IGNORE_UNINITIALIZED_WARNING_START
512 #define IGNORE_UNINITIALIZED_WARNING_STOP