Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/waterbox/libc/internals/_PDCLIB_aux.h
2 views
1
/* Auxiliary PDCLib code <_PDCLIB_aux.h>
2
3
This file is part of the Public Domain C Library (PDCLib).
4
Permission is granted to use, modify, and / or redistribute at will.
5
*/
6
7
#ifndef __PDCLIB_AUX_H
8
#define __PDCLIB_AUX_H __PDCLIB_AUX_H
9
10
/* -------------------------------------------------------------------------- */
11
/* You should not have to edit anything in this file; if you DO have to, it */
12
/* would be considered a bug / missing feature: notify the author(s). */
13
/* -------------------------------------------------------------------------- */
14
15
/* -------------------------------------------------------------------------- */
16
/* Standard Version */
17
/* -------------------------------------------------------------------------- */
18
19
/* Many a compiler gets this wrong, so you might have to hardcode it instead. */
20
21
#if __STDC__ != 1
22
#error Compiler does not define _ _STDC_ _ to 1 (not standard-compliant)!
23
#endif
24
25
#if defined(_PDCLIB_C_VERSION)
26
/* Pass - conditional simplification case */
27
#elif !defined(__STDC_VERSION__)
28
#define _PDCLIB_C_VERSION 1990
29
#elif __STDC_VERSION__ == 199409L
30
#define _PDCLIB_C_VERSION 1995
31
#elif __STDC_VERSION__ == 199901L
32
#define _PDCLIB_C_VERSION 1999
33
#elif __STDC_VERSION__ == 201112L
34
#define _PDCLIB_C_VERSION 2011
35
#else
36
#error Unsupported _ _STDC_VERSION_ _ (__STDC_VERSION__) (supported: ISO/IEC 9899:1990, 9899/AMD1:1995, 9899:1999, 9899:2011).
37
#endif
38
39
#if !defined(__cplusplus) || defined(_PDCLIB_CXX_VERSION)
40
#define _PDCLIB_CXX_VERSION 0
41
#elif __cplusplus == 201103L
42
#define _PDCLIB_CXX_VERSION 2011
43
/* TODO: Do we want this? */
44
#if _PDCLIB_C_VERSION < 2011
45
#undef _PDCLIB_C_VERSION
46
#define _PDCLIB_C_VERSION 2011
47
#endif
48
#elif __cplusplus == 199711L
49
#define _PDCLIB_CXX_VERSION 1997
50
#else
51
#error Unsupported _ _cplusplus (__cplusplus) (supported: ISO/IEC 14882:1997, ISO/IEC 14882:2011).
52
#endif
53
54
#ifndef __STDC_HOSTED__
55
#error Compiler does not define _ _STDC_HOSTED_ _ (not standard-compliant)!
56
#elif __STDC_HOSTED__ == 0
57
#define _PDCLIB_HOSTED 0
58
#elif __STDC_HOSTED__ == 1
59
#define _PDCLIB_HOSTED 1
60
#else
61
#error Compiler does not define _ _STDC_HOSTED_ _ to 0 or 1 (not standard-compliant)!
62
#endif
63
64
#ifdef __cplusplus
65
typedef bool _PDCLIB_bool;
66
#else
67
typedef _Bool _PDCLIB_bool;
68
#endif
69
70
/* Clang style feature detection macros
71
* Note: It is common to #define __has_feature(0) if undefined so the presence
72
* of this macro does not guarantee it to be working
73
*/
74
75
#ifdef __has_feature
76
#define _PDCLIB_HAS_FEATURE(x) __has_feature(x)
77
#else
78
#define _PDCLIB_HAS_FEATURE(x) (0)
79
#endif
80
81
#ifdef __has_extension
82
#define _PDCLIB_HAS_EXTENSION(x) __has_extension(x)
83
#else
84
// Older versions of Clang use __has_feature instead
85
#define _PDCLIB_HAS_EXTENSION(x) _PDCLIB_HAS_FEATURE(x)
86
#endif
87
88
#ifdef __has_builtin
89
#define _PDCLIB_HAS_BUILTIN(x) __has_builtin(x)
90
#else
91
#define _PDCLIB_HAS_BUILTIN(x) (0)
92
#endif
93
94
#ifdef __has_attribute
95
#define _PDCLIB_HAS_ATTRIBUTE(x) __has_attribute(x)
96
#else
97
#define _PDCLIB_HAS_ATTRIBUTE(x) (0)
98
#endif
99
100
/* GCC feature detection macros */
101
102
#if defined(__GNUC__)
103
#define _PDCLIB_GCC_MIN(maj, min) \
104
((__GNUC__ > maj) || (__GNUC__ == maj && __GNUC_MINOR__ >= min))
105
#else
106
#define _PDCLIB_GCC_MIN(maj, min) (0)
107
#endif
108
109
/* Hybrid GCC/Clang feature detection macros */
110
#define _PDCLIB_GCC_FEATURE(x, gccmaj, gccmin) \
111
(_PDCLIB_HAS_FEATURE(x) || _PDCLIB_GCC_MIN(gccmin, gccmaj))
112
113
#define _PDCLIB_GCC_EXTENSION(x, gccmaj, gccmin) \
114
(_PDCLIB_HAS_EXTENSION(x) || _PDCLIB_GCC_MIN(gccmin, gccmaj))
115
116
#define _PDCLIB_GCC_BUILTIN(x, gccmaj, gccmin) \
117
(_PDCLIB_HAS_BUILTIN(x) || _PDCLIB_GCC_MIN(gccmin, gccmaj))
118
119
#define _PDCLIB_GCC_ATTRIBUTE(x, gccmaj, gccmin) \
120
(_PDCLIB_HAS_ATTRIBUTE(x) || _PDCLIB_GCC_MIN(gccmin, gccmaj))
121
122
/* Extension & Language feature detection */
123
124
#if _PDCLIB_C_VERSION >= 1999 || defined(__cplusplus)
125
#ifndef __cplusplus
126
#define _PDCLIB_restrict restrict
127
#endif
128
#define _PDCLIB_inline inline
129
#endif
130
131
#if _PDCLIB_CXX_VERSION >= 2011
132
#define _PDCLIB_nothrow noexcept
133
#define _PDCLIB_noexcept(x) noexcept(x)
134
#elif _PDCLIB_CXX_VERSION
135
#define _PDCLIB_nothrow throw()
136
#define _PDCLIB_noexcept
137
#endif
138
139
#if _PDCLIB_CXX_VERSION >= 2011 && _PDCLIB_GCC_FEATURE(cxx_attributes, 4, 8)
140
#define _PDCLIB_noreturn [[noreturn]]
141
#elif _PDCLIB_C_VERSION >= 2011 && _PDCLIB_GCC_FEATURE(c_noreturn, 4, 7)
142
#define _PDCLIB_noreturn _Noreturn
143
#endif
144
145
#ifdef _WIN32
146
#define _PDCLIB_EXPORT __declspec(dllexport)
147
#define _PDCLIB_IMPORT __declspec(dllimport)
148
#endif
149
150
#if !defined(_PDCLIB_EXPORT) && _PDCLIB_GCC_ATTRIBUTE(__visibility__, 4, 0)
151
#define _PDCLIB_EXPORT __attribute__((__visibility__("protected")))
152
#endif
153
154
#if !defined(_PDCLIB_HIDDEN) && _PDCLIB_GCC_ATTRIBUTE(__visibility__, 4, 0)
155
#define _PDCLIB_HIDDEN __attribute__((__visibility__("hidden")))
156
#endif
157
158
#if !defined(_PDCLIB_nothrow) && _PDCLIB_GCC_ATTRIBUTE(__nothrow__, 4, 0)
159
#define _PDCLIB_nothrow __attribute__((__nothrow__))
160
#define _PDCLIB_noexcept
161
#endif
162
163
#if !defined(_PDCLIB_restrict) && _PDCLIB_GCC_MIN(3, 0)
164
#define _PDCLIB_restrict __restrict
165
#endif
166
167
#if !defined(_PDCLIB_inline) && _PDCLIB_GCC_MIN(3, 0)
168
#define _PDCLIB_inline __inline
169
#endif
170
171
#if !defined(_PDCLIB_noreturn) && _PDCLIB_GCC_ATTRIBUTE(__noreturn__, 3, 0)
172
/* If you don't use __noreturn__, then stdnoreturn.h will break things! */
173
#define _PDCLIB_noreturn __attribute__((__noreturn__))
174
#endif
175
176
#if !defined(_PDCLIB_DEPRECATED) && _PDCLIB_GCC_ATTRIBUTE(__deprecated__, 3, 0)
177
#define _PDCLIB_DEPRECATED __attribute__ ((__deprecated__))
178
#endif
179
180
#if !defined(_PDCLIB_UNREACHABLE) && _PDCLIB_GCC_BUILTIN(__builtin_unreachable, 4, 0)
181
#define _PDCLIB_UNREACHABLE __builtin_unreachable()
182
#endif
183
184
#if !defined(_PDCLIB_UNDEFINED) && defined(__GNUC__)
185
#define _PDCLIB_UNDEFINED(_var) \
186
do { __asm__("" : "=X"(_var)); } while(0)
187
#endif
188
189
/* No-op fallbacks */
190
191
#ifndef _PDCLIB_nothrow
192
#define _PDCLIB_nothrow
193
#define _PDCLIB_noexcept
194
#endif
195
196
#ifndef _PDCLIB_EXPORT
197
#define _PDCLIB_EXPORT
198
#endif
199
#ifndef _PDCLIB_IMPORT
200
#define _PDCLIB_IMPORT
201
#endif
202
#ifndef _PDCLIB_HIDDEN
203
#define _PDCLIB_HIDDEN
204
#endif
205
206
#if defined(_PDCLIB_SHARED)
207
#if defined(_PDCLIB_BUILD)
208
#define _PDCLIB_API _PDCLIB_EXPORT
209
#else
210
#define _PDCLIB_API _PDCLIB_IMPORT
211
#endif
212
#else
213
#define _PDCLIB_API
214
#endif
215
216
#ifndef _PDCLIB_restrict
217
#define _PDCLIB_restrict
218
#endif
219
220
#ifndef _PDCLIB_inline
221
#define _PDCLIB_inline
222
#endif
223
224
#ifndef _PDCLIB_noreturn
225
#define _PDCLIB_noreturn
226
#endif
227
228
#ifndef _PDCLIB_DEPRECATED
229
#define _PDCLIB_DEPRECATED
230
#endif
231
232
#ifndef _PDCLIB_UNREACHABLE
233
#define _PDCLIB_UNREACHABLE do {} while(0)
234
#endif
235
236
#ifndef _PDCLIB_UNDEFINED
237
#define _PDCLIB_UNDEFINED(_var) do {} while(0)
238
#endif
239
240
/*#if _PDCLIB_C_VERSION != 1999
241
#error PDCLib might not be fully conforming to either C89 or C95 prior to v2.x.
242
#endif*/
243
244
/* -------------------------------------------------------------------------- */
245
/* Helper macros: */
246
/* _PDCLIB_cc( x, y ) concatenates two preprocessor tokens without extending */
247
/* _PDCLIB_concat( x, y ) concatenates two preprocessor tokens with extending */
248
/* _PDCLIB_concat3( x, y, z ) is the same for three tokens */
249
/* _PDCLIB_static_assert( x ) provides a compile-time check mechanism */
250
/* -------------------------------------------------------------------------- */
251
252
#define _PDCLIB_cc( x, y ) x ## y
253
#define _PDCLIB_concat( x, y ) _PDCLIB_cc( x, y )
254
#define _PDCLIB_concat3( x, y, z ) _PDCLIB_concat( _PDCLIB_concat( x, y ), z )
255
#if _PDCLIB_C_VERSION >= 2011
256
#define _PDCLIB_static_assert _Static_assert
257
#else
258
#define _PDCLIB_static_assert( e, m ) ;enum { _PDCLIB_concat( _PDCLIB_assert_, __LINE__ ) = 1 / ( !!( e ) ) }
259
#endif
260
261
#define _PDCLIB_symbol2value( x ) #x
262
#define _PDCLIB_symbol2string( x ) _PDCLIB_symbol2value( x )
263
264
/* Feature test macros
265
*
266
* All of the feature test macros come in the following forms
267
* _PDCLIB_*_MIN(min): Available in versions >= min
268
* _PDCLIB_*_MINMAX(min, max): Available in versions >= min <= max
269
* _PDCLIB_*_MAX(max): Availabel in versions <= max
270
*
271
* The defined tests are:
272
* C: C standard versions
273
* 1990, 1995, 1999, 2011
274
* CXX: C++ standard versions
275
* 1997, 2011
276
* POSIX: POSIX extension versions.
277
* 1 (POSIX.2), 2 (POSIX.2), 199309L (POSIX.1b),
278
* 199506L (POSIX.1c), 200112L (2001), 200809L (2008)
279
* XOPEN: X/Open System Interface (XSI)/Single Unix Specification
280
* 0 (XPG4), 500 (SUSv2/UNIX98), 600 (SUSv3/UNIX03), 700 (SUSv4)
281
*
282
* Additionally, the macros
283
* _BSD_SOURCE, _SVID_SOURCE and _GNU_SOURCE
284
* are adhered to. If _GNU_SOURCE is defined, _XOPEN_SOURCE and
285
* _POSIX_C_SOURCE are defined to their most recent values to match glibc
286
* behaviour
287
*
288
* The intention of supporting these feature test macros is to ease
289
* application portability from these systems to PDCLib systems; in addition,
290
* it eases support for these standards by systems supporting them which are
291
* using PDCLib as their default C library.
292
*
293
* Applications targetting purely PDClib/PDCLib based platforms may define
294
* just _PDCLIB_EXTENSIONS, which will enable all supported extensions, plus
295
* all features from all supported versions of C and C++.
296
*
297
*/
298
#define _PDCLIB_C_MIN(min) _PDCLIB_C_MINMAX(min, 3000)
299
#define _PDCLIB_CXX_MIN(min) _PDCLIB_CXX_MINMAX(min, 3000)
300
#define _PDCLIB_XOPEN_MIN(min) _PDCLIB_XOPEN_MINMAX(min, 30000000)
301
#define _PDCLIB_POSIX_MIN(min) _PDCLIB_POSIX_MINMAX(min, 30000000)
302
#define _PDCLIB_C_MAX(max) _PDCLIB_C_MINMAX(0, max)
303
#define _PDCLIB_CXX_MAX(max) _PDCLIB_CXX_MINMAX(0, max)
304
#define _PDCLIB_XOPEN_MAX(max) _PDCLIB_XOPEN_MINMAX(0, max)
305
#define _PDCLIB_POSIX_MAX(max) _PDCLIB_POSIX_MINMAX(0, max)
306
#if defined(_PDCLIB_EXTENSIONS) || defined(_PDCLIB_BUILD)
307
#define _PDCLIB_C_MINMAX(min, max) 1
308
#define _PDCLIB_CXX_MINMAX(min, max) 1
309
#define _PDCLIB_POSIX_MINMAX(min, max) 1
310
#define _PDCLIB_XOPEN_MINMAX(min, max) 1
311
312
#undef _PDCLIB_EXTENSIONS
313
#undef _PDCLIB_BSD_SOURCE
314
#undef _PDCLIB_SVID_SOURCE
315
#undef _PDCLIB_GNU_SOURCE
316
317
#define _PDCLIB_EXTENSIONS 1
318
#define _PDCLIB_BSD_SOURCE 1
319
#define _PDCLIB_SVID_SOURCE 1
320
#define _PDCLIB_GNU_SOURCE 1
321
#else
322
#define _PDCLIB_C_MINMAX(min, max) \
323
(_PDCLIB_C_VERSION >= (min) && _PDCLIB_C_VERSION <= (max))
324
#define _PDCLIB_CXX_MINMAX(min, max) \
325
(_PDCLIB_CXX_VERSION >= (min) && _PDCLIB_CXX_VERSION <= (max))
326
#define _PDCLIB_XOPEN_MINMAX(min, max) \
327
(defined(_XOPEN_SOURCE) \
328
&& _XOPEN_SOURCE >= (min) && _XOPEN_SOURCE <= (max))
329
#define _PDCLIB_POSIX_MINMAX(min, max) \
330
(defined(_POSIX_C_SOURCE) \
331
&& _POSIX_C_SOURCE >= (min) && _POSIX_C_SOURCE <= (max))
332
333
#if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE-1 == -1)
334
/* If _XOPEN_SOURCE is defined as empty, redefine here as zero */
335
#undef _XOPEN_SOURCE
336
#define _XOPEN_SOURCE 0
337
#endif
338
339
#if defined(_GNU_SOURCE)
340
#define _PDCLIB_GNU_SOURCE 1
341
#define _PDCLIB_SVID_SOURCE 1
342
#define _PDCLIB_BSD_SOURCE 1
343
#undef _XOPEN_SOURCE
344
#define _XOPEN_SOURCE 700
345
#else
346
#define _PDCLIB_GNU_SOURCE 0
347
#endif
348
349
#if defined(_PDCLIB_BSD_SOURCE)
350
// pass
351
#elif defined(_BSD_SOURCE)
352
#define _PDCLIB_BSD_SOURCE 1
353
#else
354
#define _PDCLIB_BSD_SOURCE 0
355
#endif
356
357
#if defined(_PDCLIB_SVID_SOURCE)
358
// pass
359
#elif defined(_SVID_SOURCE)
360
#define _PDCLIB_SVID_SOURCE 1
361
#else
362
#define _PDCLIB_SVID_SOURCE 0
363
#endif
364
365
#if _PDCLIB_XOPEN_MIN(700) && !_PDCLIB_POSIX_MIN(200809L)
366
#undef _POSIX_C_SOURCE
367
#define _POSIX_C_SOURCE 2008098L
368
#elif _PDCLIB_XOPEN_MIN(600) && !_PDCLIB_POSIX_MIN(200112L)
369
#undef _POSIX_C_SOURCE
370
#define _POSIX_C_SOURCE 200112L
371
#elif _PDCLIB_XOPEN_MIN(0) && !_PDCLIB_POSIX_MIN(2)
372
#undef _POSIX_C_SOURCE
373
#define _POSIX_C_SOURCE 2
374
#endif
375
376
#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
377
#define _POSIX_C_SOURCE 1
378
#endif
379
#endif
380
381
#endif
382
383