source: cpp/common/nonstd.h @ 932

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

Supported all platforms using either qsort_r() or qsort_s()

  • Property svn:eol-style set to native
File size: 2.4 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#ifdef _MSC_VER
58#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
59#define qsort_r(base,nmemb,size,compar,context) qsort_s((base),(nmemb),(size),(compar),(context))
60#endif
61
62#ifdef __BORLANDC__
63 #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
64#endif
65
66
67//vsnprintf implementations support different standards, some only return -1 instead of the required number of characters
68//these definitions are used by stl-util.cpp/ssprintf_va and SString::sprintf
69#ifdef LINUX
70#define VSNPRINTF_RETURNS_REQUIRED_SIZE
71#endif
72#if defined _WIN32 && !defined __BORLANDC__
73#define USE_VSCPRINTF
74#endif
75
76
77#endif
Note: See TracBrowser for help on using the repository browser.