-
Notifications
You must be signed in to change notification settings - Fork 0
/
portable.h
180 lines (152 loc) · 5.04 KB
/
portable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
Copyright (c) 2018 Robert Lodico
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once
#ifndef H_PORTABLE
#define H_PORTABLE
/* Drown Microsoft's stupid compiler warnings encouraging
the usage of platform-locked fopen_s() instead of fopen(). */
#define _CRT_SECURE_NO_WARNINGS
#ifdef H_PORTABLE_EXPOSE_MATH
#ifndef sqr
#define sqr(n) (n * n)
#endif//sqr
#endif//H_PORTABLE_EXPOSE_MATH
/* BEGIN: Portable Types */
#if defined(__cplusplus)
namespace portable {
#endif
/* 64-bit */
#ifdef _MSC_VER
#define INT64 __int64
#else
#define INT64 long long
#endif
#define FLT64 double
/* Normal */
typedef char int8;
typedef short int16;
typedef int int32;
typedef INT64 int64;
typedef float flt32;
typedef FLT64 flt64;
/* Unsigned */
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned INT64 uint64;
/* Signed */
typedef signed char sint8;
typedef signed short sint16;
typedef signed int sint32;
typedef signed INT64 sint64;
/* Aliases */
typedef unsigned char byte;
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned INT64 ulong;
#if defined(__cplusplus)
}
#endif
/* END: Portable Types */
/* BEGIN: Platform Detection */
/* Operating System Defines */
#define OS_UNKNOWN -1 /* If we legitimately have no clue. */
#define OS_U_UNIX -2 /* If we know it's Unix, but we don't know which. */
#define OS_U_APPLE -3 /* If we know it's Apple, but don't know which. */
#define OS_LINUX 0
#define OS_ANDROID 1
#define OS_WINDOWS 2
#define OS_OSX 3
#define OS_IOS 4
#define OS_BSD 5
/* Define our detected platform as our
default value, unknown. */
/* Unix Children */
#if defined(__unix__)
#define PLATFORM_UNIX
/* Linux */
#if defined(__linux__)
#define PLATFORM_LINUX
#define DETECTED_PLATFORM OS_LINUX
/* Android */
#elif defined(__ANDROID__)
#define PLATFORM_ANDROID
#define DETECTED_PLATFORM OS_ANDROID
/* BSD */
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#define PLATFORM_BSD
#define DETECTED_PLATFORM OS_BSD
/* Unknown/unsupported Unix */
#else
#define DETECTED_PLATFORM OS_U_UNIX
#endif
/* Windows */
#elif defined(_WIN32)
#define PLATFORM_WINDOWS
#define DETECTED_PLATFORM OS_WINDOWS
#ifndef NOMINMAX
#define NOMINMAX
#endif
/* Apple */
#elif defined(__APPLE__) && defined(__MACH__)
#define PLATFORM_APPLE
#include "TargetConditionals.h"
/* iOS */
#if TARGET_OS_IPHONE || TARGET_OS_IPHONE_SIMULATOR
#define PLATFORM_IOS
#define DETECTED_PLATFORM OS_IOS
/* OSX */
#elif TARGET_OS_MAC
#define PLATFORM_OSX
#define DETECTED_PLATFORM OS_OSX
/* Unknown/unsupported Apple-crap */
#else
#define DETECTED_PLATFORM OS_U_APPLE
#endif
/* Unknown */
#else
#define DETECTED_PLATFORM OS_UNKNOWN
#endif
/* END: Platform Detection */
/* BEGIN: Export/Import Macros */
#if !defined(PORTABLE_STATIC)
/* VC needs specific keywords for exporting/importing symbols */
#if defined(PLATFORM_WINDOWS)
#define PORTABLE_EXPORT __declspec(dllexport)
#define PORTABLE_IMPORT __declspec(dllimport)
#if defined(_MSC_VER)
#pragma warning(disable : 4251)
#endif
/* GCC >= 4 has special keywords for exporting/importing symbols */
#elif __GNUC__ >= 4
#define PORTABLE_EXPORT __attribute__ ((__visibility__ ("default")))
#define PORTABLE_IMPORT __attribute__ ((__visibility__ ("default")))
/* Assume GCC < 4, everything is exported by default */
#else
#define PORTABLE_EXPORT
#define PORTABLE_IMPORT
#endif
/* Static libraries do not need exports/imports */
#else
#define PORTABLE_EXPORT
#define PORTABLE_IMPORT
#endif
/* END: Export/Import Macros */
#endif//H_PORTABLE