source: cpp/common/nonstd.h @ 999

Last change on this file since 999 was 936, checked in by Maciej Komosinski, 5 years ago

Supported qsort_r()/qsort_s() in Borland/Embarcadero? compiler

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
4
5#ifndef _NONSTD_H_
6#define _NONSTD_H_
7
8#define SAFEDELETE(p) {if (p) {delete p; p=NULL;}}
9#define SAFEDELETEARRAY(p) {if (p) {delete[] p; p=NULL;}}
10
11#define roundToInt(x) ((int)(floor((x)+0.5)))
12
13
14#define CPP_STR(s) CPP_XSTR(s)
15#define CPP_XSTR(s) #s
16
17
18#define DB(x) //output debug info. If needed, use #define DB(x) x
19//#define DB(x) x
20
21
22
23/////////////////////////////////////////////////////// path separators and other macros
24#ifdef _WIN32
25        #define PATH_SEPARATOR_CHAR '\\'
26        #define PATH_SEPARATOR_STRING "\\"
27        #define FPU_THROWS_EXCEPTIONS
28#else
29        #define PATH_SEPARATOR_CHAR '/'
30        #define PATH_SEPARATOR_STRING "/"
31#endif
32
33#define FOPEN_READ_BINARY "rb"
34// no FOPEN_READ_TEXT
35#define FOPEN_WRITE_BINARY "wb"
36#define FOPEN_APPEND_BINARY "ab"
37#define FOPEN_WRITE_TEXT "wt"
38#define FOPEN_APPEND_TEXT "at"
39
40#ifdef LINUX
41 #include <strings.h>
42 #ifndef __CYGWIN__
43  #define stricmp(a,b) strcasecmp(a,b)
44  #define strnicmp(a,b,c) strncasecmp(a,b,c)
45#endif
46#endif
47
48#if defined(MACOS) || defined(__ANDROID__) || defined(IPHONE)
49 #define stricmp(a,b) strcasecmp(a,b)
50 #define strnicmp(a,b,c) strncasecmp(a,b,c)
51#endif
52
53
54//typedef unsigned char boolean; //niestety nie mozna uzyc 'bool' bo VC w rpcndr.h wlasnie tak definiuje booleana, jako unsigned char
55//typedef char byte; //rozne srodowiska c++ definiuja byte jako unsigned char! w javie jest inaczej -> trzeba i tak zmienic w portowanych zrodlach byte na char.
56
57//How cool, gcc&clang: qsort_r(a,b), borland: qsort_s(a,b), visual: qsort_s(b,a)
58#ifdef __BORLANDC__
59 #define qsort_r qsort_s
60#endif
61
62#ifdef _MSC_VER
63 #define QSORT_R_USING_QSORT_S //qsort_r callers use this macro to adjust argument order in comparator, because microsoft and gcc&clang are incompatible here
64 #define qsort_r(base,nmemb,size,compar,context) qsort_s((base),(nmemb),(size),(compar),(context))
65#endif
66
67#ifdef __BORLANDC__
68 #define va_copy(to,from) ((to)=(from)) //borland's implementation of va_copy (the _Vacopy() function) copies from="" to to=NULL, and this behavior crashes our ssprintf_va(), so we prefer our simple macro since va_list is just a char* pointer in borland
69#endif
70
71
72//vsnprintf implementations support different standards, some only return -1 instead of the required number of characters
73//these definitions are used by stl-util.cpp/ssprintf_va and SString::sprintf
74#ifdef LINUX
75#define VSNPRINTF_RETURNS_REQUIRED_SIZE
76#endif
77#if defined _WIN32 && !defined __BORLANDC__
78#define USE_VSCPRINTF
79#endif
80
81
82#endif
Note: See TracBrowser for help on using the repository browser.