OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
PlatformAbstraction.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* All the ifdefs in one place (Hah, I wish) */
19 
20 #ifndef INC_PLATFORMABSTRACTION
21 #define INC_PLATFORMABSTRACTION
22 
23 #include <vector>
24 
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif // HAVE_CONFIG_H
28 
29 #if defined(USE_WIN32_WINDOWS)
30 #define USE_WGL
31 #endif
32 
33 // We need to #define the target Windows version selector macros before we
34 // including any MinGW header.
35 #ifdef _WIN64
36 # define WINVER 0x0501
37 # define _WIN32_WINDOWS 0x0501
38 # define _WIN32_WINNT 0x0501
39 # define _WIN32_IE 0x0501
40 # define _AMD64_ 1
41 #elif defined(_WIN32)
42 # define WINVER 0x0500
43 # define _WIN32_WINDOWS 0x0500
44 # define _WIN32_WINNT 0x0501
45 # define _WIN32_IE 0x0501
46 # define _X86_ 1
47 #endif
48 #ifdef _WIN32
49 #define WIN32_LEAN_AND_MEAN
50 #define UNICODE
51 #define _UNICODE
52 #ifndef NOMINMAX
53 # define NOMINMAX
54 #endif
55 #endif
56 
57 #ifdef _MSC_VER
58 #define DEPRECATED __declspec(deprecated)
59 #elif defined(__GNUC__)
60 #define DEPRECATED __attribute__((deprecated))
61 #else
62 #define DEPRECATED
63 #endif
64 
65 #ifdef _MSC_VER
66 #pragma warning(disable : 4786) // long symbol names
67 #pragma warning(disable: 4706)
68 #pragma warning(disable: 4239)
69 #pragma warning(disable: 4521) // multiple copy constructors specified
70 // Get non-standard <cmath> constants (M_PI etc.)
71 # define _USE_MATH_DEFINES
72 // Use IPv4 functions (inet_ntoa) since we don't support IPv6 yet.
73 #define _WINSOCK_DEPRECATED_NO_WARNINGS
74 #endif
75 
76 
77 // Integer dataypes
78 #include <stdint.h>
79 
80 
81 #ifdef HAVE_UNISTD_H
82 #include <unistd.h>
83 #else
84 typedef ptrdiff_t ssize_t;
85 #endif
86 
87 #if defined(__GNUC__)
88 // Allow checks for correct printf-usage
89 #define GNUC_FORMAT_ATTRIBUTE __attribute__ ((format (printf, 1, 2)))
90 #define GNUC_FORMAT_ATTRIBUTE_O __attribute__ ((format (printf, 2, 3)))
91 #define ALWAYS_INLINE inline __attribute__ ((always_inline))
92 #define NORETURN __attribute__ ((noreturn))
93 #elif defined(_MSC_VER)
94 #define GNUC_FORMAT_ATTRIBUTE
95 #define GNUC_FORMAT_ATTRIBUTE_O
96 #define ALWAYS_INLINE __forceinline
97 #define NORETURN __declspec(noreturn)
98 #else
99 #define GNUC_FORMAT_ATTRIBUTE
100 #define GNUC_FORMAT_ATTRIBUTE_O
101 #define ALWAYS_INLINE inline
102 #define NORETURN
103 #endif
104 
105 
106 
107 #if defined(_DEBUG) && defined(_MSC_VER)
108 // use inline assembler to invoke the "breakpoint exception"
109 # define BREAKPOINT_HERE __debugbreak()
110 #elif defined(_DEBUG) && defined(__GNUC__)
111 # define BREAKPOINT_HERE asm volatile("int $3")
112 #elif defined(_DEBUG) && defined(HAVE_SIGNAL_H)
113 # include <signal.h>
114 # if defined(SIGTRAP)
115 # define BREAKPOINT_HERE raise(SIGTRAP);
116 # else
117 # define BREAKPOINT_HERE ((void)0)
118 # endif
119 #else
120 # define BREAKPOINT_HERE ((void)0)
121 #endif
122 
123 
124 
125 #ifdef _WIN32
126 
127 typedef unsigned long DWORD;
128 typedef unsigned char BYTE;
129 typedef unsigned short WORD;
130 
131 #else
132 
133 // Windows integer types
134 typedef uint32_t DWORD;
135 typedef uint8_t BYTE;
136 typedef uint16_t WORD;
137 
138 #include <strings.h>
139 inline int stricmp(const char *s1, const char *s2)
140 {
141  return strcasecmp(s1, s2);
142 }
143 
144 #endif //_WIN32
145 
146 
147 
148 #ifdef _WIN64
149 #define C4_OS "win-x86_64"
150 #elif defined(_WIN32)
151 #define C4_OS "win-x86"
152 #elif defined(__linux__)
153 #if defined(__x86_64__)
154 #define C4_OS "linux-x86_64"
155 #else
156 #define C4_OS "linux-x86"
157 #endif
158 #elif defined(__APPLE__)
159 #define C4_OS "mac-x86"
160 #else
161 #define C4_OS ""
162 #endif
163 
164 // delete item to the recycle bin
165 bool EraseItemSafe(const char *szFilename);
166 
167 // Check whether the OS is "German"
168 bool IsGermanSystem();
169 
170 // open a weblink in an external browser
171 bool OpenURL(const char* szURL);
172 
173 // reopen the engine with given parameters
174 bool RestartApplication(std::vector<const char *> parameters);
175 
176 #ifdef _WIN32
177 #include <io.h>
178 #define F_OK 0
179 #else
180 #include <dirent.h>
181 #include <limits.h>
182 #define _O_BINARY 0
183 #define _MAX_PATH PATH_MAX
184 #define _MAX_FNAME NAME_MAX
185 
186 bool CopyFile(const char *szSource, const char *szTarget, bool FailIfExists);
187 #endif
188 
189 #include <fcntl.h>
190 #ifndef O_CLOEXEC
191 #define O_CLOEXEC 0
192 #endif
193 
194 #ifdef _WIN32
195 #define DirSep "\\"
196 #define DirectorySeparator '\\'
197 #define AltDirectorySeparator '/'
198 #else
199 #define DirSep "/"
200 #define DirectorySeparator '/'
201 #define AltDirectorySeparator '\\'
202 #endif
203 
204 #endif // INC_PLATFORMABSTRACTION
bool RestartApplication(std::vector< const char * > parameters)
int stricmp(const char *s1, const char *s2)
uint8_t BYTE
bool IsGermanSystem()
Definition: C4AppMac.mm:193
ptrdiff_t ssize_t
bool OpenURL(const char *szURL)
Definition: C4AppMac.mm:199
bool CopyFile(const char *szSource, const char *szTarget, bool FailIfExists)
Definition: StdFile.cpp:531
bool EraseItemSafe(const char *szFilename)
Definition: C4GroupMain.cpp:41
uint32_t DWORD
uint16_t WORD