source: cpp/common/nonstd.h @ 1156

Last change on this file since 1156 was 1154, checked in by Maciej Komosinski, 3 years ago

Supported another variant of qsort()

  • Property svn:eol-style set to native
File size: 3.3 KB
RevLine 
[286]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
[931]2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
[286]3// See LICENSE.txt for details.
[123]4
[109]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
[886]23/////////////////////////////////////////////////////// path separators and other macros
[109]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>
[123]42 #ifndef __CYGWIN__
43  #define stricmp(a,b) strcasecmp(a,b)
[398]44  #define strnicmp(a,b,c) strncasecmp(a,b,c)
[109]45#endif
[398]46#endif
[109]47
[936]48#if defined(MACOS) || defined(__ANDROID__) || defined(IPHONE)
[109]49 #define stricmp(a,b) strcasecmp(a,b)
[424]50 #define strnicmp(a,b,c) strncasecmp(a,b,c)
[109]51#endif
52
[842]53
[109]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
[936]57//How cool, gcc&clang: qsort_r(a,b), borland: qsort_s(a,b), visual: qsort_s(b,a)
58#ifdef __BORLANDC__
[1154]59#define CALL_QSORT_R(base,nmemb,size,compar,context) qsort_s(base,nmemb,size,compar,context)
[936]60#endif
61
[931]62#ifdef _MSC_VER
[1154]63 #define QSORT_R_THIS_FIRST //qsort_r callers use this macro to adjust argument order in comparator, because microsoft and gcc&clang are incompatible here
64 #define CALL_QSORT_R(base,nmemb,size,compar,context) qsort_s((base),(nmemb),(size),(compar),(context))
[931]65#endif
[842]66
[1154]67#if defined MACOS || defined IPHONE
68//qsort_r(void *__base, size_t __nel, size_t __width, void *, int (* _Nonnull __compar)(void *, const void *, const void *));
69#define QSORT_R_THIS_FIRST
70#define CALL_QSORT_R(base,nmemb,size,compar,context) qsort_r(base,nmemb,size,context,compar)
71#endif
72
73#ifndef CALL_QSORT_R
74#define CALL_QSORT_R(base,nmemb,size,compar,context) qsort_r(base,nmemb,size,compar,context)
75#endif
76
[842]77#ifdef __BORLANDC__
78 #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
79#endif
80
81
[220]82//vsnprintf implementations support different standards, some only return -1 instead of the required number of characters
83//these definitions are used by stl-util.cpp/ssprintf_va and SString::sprintf
84#ifdef LINUX
85#define VSNPRINTF_RETURNS_REQUIRED_SIZE
86#endif
87#if defined _WIN32 && !defined __BORLANDC__
88#define USE_VSCPRINTF
89#endif
[109]90
[220]91
[1016]92
93#if defined(__ANDROID__) && !defined(PRIuPTR)
94#define PRIuPTR "u" //w ktorejs z wersji kompilacji 32 albo 64 bit pewnie brakuje tej definicji w naglowku <inttypes.h>, a w tej drugiej wersji jest. Nie wiem czy "u" jest wlasciwe ale i tak prawdopodobnie naprawili w nowszym ndk...
[109]95#endif
[1016]96
97
98#endif
Note: See TracBrowser for help on using the repository browser.