]> pd.if.org Git - pdclib/blob - internals/_PDCLIB_aux.h
PDCLIB-19: Remove gets() when >=C11. Deprecated it universally.
[pdclib] / internals / _PDCLIB_aux.h
1 #ifndef _PDCLIB_AUX_H
2 #define _PDCLIB_AUX_H
3
4 /* Auxiliary PDCLib code <_PDCLIB_aux.h>
5
6    This file is part of the Public Domain C Library (PDCLib).
7    Permission is granted to use, modify, and / or redistribute at will.
8 */
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 #if _PDCLIB_C_VERSION >= 1999 || defined(__cplusplus)
55     #ifndef __cplusplus
56         #define _PDCLIB_restrict restrict
57     #endif
58     #define _PDCLIB_inline   inline
59 #endif
60
61 #if _PDCLIB_CXX_VERSION >= 2011
62   #define _PDCLIB_nothrow     noexcept
63   #define _PDCLIB_noexcept(x) noexcept(x)
64 #elif _PDCLIB_CXX_VERSION
65   #define _PDCLIB_nothrow     throw()
66   #define _PDCLIB_noexcept
67 #endif
68
69 #if _PDCLIB_CXX_VERSION >= 2011
70   // Hold off on C++ attribute syntax for now
71   // #define _PDCLIB_noreturn [[noreturn]]
72 #elif _PDCLIB_C_VERSION >= 2011
73     #define _PDCLIB_noreturn _Noreturn
74 #endif
75
76 #ifdef _WIN32
77    #define _PDCLIB_EXPORT __declspec(dllexport)
78    #define _PDCLIB_IMPORT __declspec(dllimport)
79 #endif
80
81 #ifdef __GNUC__
82     #ifndef _PDCLIB_EXPORT
83         #define _PDCLIB_EXPORT __attribute__((__visibility__("protected")))
84     #endif
85
86     #ifndef _PDCLIB_IMPORT
87         #define _PDCLIB_IMPORT
88     #endif
89
90     #ifndef _PDCLIB_HIDDEN
91         #define _PDCLIB_HIDDEN __attribute__((__visibility__("hidden")))
92     #endif
93
94     #ifndef _PDCLIB_nothrow
95       #define _PDCLIB_nothrow __attribute__((__nothrow__))
96       #define _PDCLIB_noexcept
97     #endif
98
99     #ifndef _PDCLIB_restrict
100         #define _PDCLIB_restrict __restrict
101     #endif
102
103     #ifndef _PDCLIB_inline
104         #define _PDCLIB_inline __inline
105     #endif
106
107     #ifndef _PDCLIB_noreturn
108     /* If you don't use __noreturn__, then stdnoreturn.h will break things! */
109         #define _PDCLIB_noreturn __attribute__((__noreturn__))
110     #endif
111
112     #ifndef _PDCLIB_DEPRECATED
113         #define _PDCLIB_DEPRECATED __attribute__ ((deprecated))
114     #endif
115 #endif
116
117 #ifndef _PDCLIB_nothrow
118   #define _PDCLIB_nothrow
119   #define _PDCLIB_noexcept
120 #endif
121
122 #ifndef _PDCLIB_EXPORT
123     #define _PDCLIB_EXPORT
124 #endif
125 #ifndef _PDCLIB_IMPORT
126     #define _PDCLIB_IMPORT
127 #endif
128 #ifndef _PDCLIB_HIDDEN
129     #define _PDCLIB_HIDDEN
130 #endif
131
132 #if defined(_PDCLIB_SHARED) 
133     #if defined(_PDCLIB_BUILD)
134         #define _PDCLIB_API _PDCLIB_EXPORT
135     #else
136         #define _PDCLIB_API _PDCLIB_IMPORT
137     #endif
138 #else
139     #define _PDCLIB_API
140 #endif
141
142 #ifndef _PDCLIB_restrict
143       #define _PDCLIB_restrict
144 #endif
145
146 #ifndef _PDCLIB_inline
147       #define _PDCLIB_inline
148 #endif
149
150 #ifndef _PDCLIB_noreturn
151       #define _PDCLIB_noreturn
152 #endif
153
154 #ifndef _PDCLIB_DEPRECATED
155     #define _PDCLIB_DEPRECATED
156 #endif
157
158 #ifndef __STDC_HOSTED__
159 #error Compiler does not define _ _STDC_HOSTED_ _ (not standard-compliant)!
160 #elif __STDC_HOSTED__ == 0
161 #define _PDCLIB_HOSTED 0
162 #elif __STDC_HOSTED__ == 1
163 #define _PDCLIB_HOSTED 1
164 #else
165 #error Compiler does not define _ _STDC_HOSTED_ _ to 0 or 1 (not standard-compliant)!
166 #endif
167
168 #ifdef __cplusplus
169     #define _PDCLIB_BEGIN_EXTERN_C extern "C" {
170     #define _PDCLIB_END_EXTERN_C }
171   typedef bool _PDCLIB_bool;
172 #else
173   #define _PDCLIB_BEGIN_EXTERN_C
174   #define _PDCLIB_END_EXTERN_C
175   typedef _Bool _PDCLIB_bool;
176 #endif
177
178 /*#if _PDCLIB_C_VERSION != 1999
179 #error PDCLib might not be fully conforming to either C89 or C95 prior to v2.x.
180 #endif*/
181
182 /* -------------------------------------------------------------------------- */
183 /* Helper macros:                                                             */
184 /* _PDCLIB_cc( x, y ) concatenates two preprocessor tokens without extending  */
185 /* _PDCLIB_concat( x, y ) concatenates two preprocessor tokens with extending */
186 /* -------------------------------------------------------------------------- */
187
188 #define _PDCLIB_cc( x, y )     x ## y
189 #define _PDCLIB_concat( x, y ) _PDCLIB_cc( x, y )
190 #define _PDCLIB_concat3( x, y, z ) _PDCLIB_concat( _PDCLIB_concat( x, y ), z )
191
192 #define _PDCLIB_symbol2value( x ) #x
193 #define _PDCLIB_symbol2string( x ) _PDCLIB_symbol2value( x )
194
195 /* Feature test macros
196  *
197  * All of the feature test macros come in the following forms
198  *   _PDCLIB_*_MIN(min):            Available in versions >= min
199  *   _PDCLIB_*_MINMAX(min, max):    Available in versions >= min <= max
200  *   _PDCLIB_*_MAX(max):            Availabel in versions <= max
201  *
202  * The defined tests are:
203  *   C:     C standard versions 
204  *              1990, 1995, 1999, 2011
205  *   CXX:   C++ standard versions 
206  *              1997, 2011
207  *   POSIX: POSIX extension versions.
208  *              1 (POSIX.2), 2 (POSIX.2), 199309L (POSIX.1b), 
209  *              199506L (POSIX.1c), 200112L (2001), 200809L (2008)
210  *   XOPEN: X/Open System Interface (XSI)/Single Unix Specification
211  *              0 (XPG4), 500 (SUSv2/UNIX98), 600 (SUSv3/UNIX03), 700 (SUSv4)
212  *
213  *   Additionally, the macros
214  *     _BSD_SOURCE, _SVID_SOURCE and _GNU_SOURCE
215  *   are adhered to. If _GNU_SOURCE is defined, _XOPEN_SOURCE and 
216  *   _POSIX_C_SOURCE are defined to their most recent values to match glibc 
217  *   behaviour
218  *
219  *   The intention of supporting these feature test macros is to ease 
220  *   application portability from these systems to PDCLib systems; in addition,
221  *   it eases support for these standards by systems supporting them which are 
222  *   using PDCLib as their default C library.
223  *
224  *   Applications targetting purely PDClib/PDCLib based platforms may define 
225  *   just _PDCLIB_EXTENSIONS, which will enable all supported extensions, plus
226  *   all features from all supported versions of C and C++.
227  *
228  */
229 #define _PDCLIB_C_MIN(min)         _PDCLIB_C_MINMAX(min, 3000)
230 #define _PDCLIB_CXX_MIN(min)     _PDCLIB_CXX_MINMAX(min, 3000)
231 #define _PDCLIB_XOPEN_MIN(min) _PDCLIB_XOPEN_MINMAX(min, 30000000)
232 #define _PDCLIB_POSIX_MIN(min) _PDCLIB_POSIX_MINMAX(min, 30000000)
233 #define _PDCLIB_C_MAX(max)         _PDCLIB_C_MINMAX(0, max)
234 #define _PDCLIB_CXX_MAX(max)     _PDCLIB_CXX_MINMAX(0, max)
235 #define _PDCLIB_XOPEN_MAX(max) _PDCLIB_XOPEN_MINMAX(0, max)
236 #define _PDCLIB_POSIX_MAX(max) _PDCLIB_POSIX_MINMAX(0, max)
237 #if defined(_PDCLIB_EXTENSIONS) || defined(_PDCLIB_BUILD)
238     #define _PDCLIB_C_MINMAX(min, max) 1
239     #define _PDCLIB_CXX_MINMAX(min, max) 1
240     #define _PDCLIB_POSIX_MINMAX(min, max) 1
241     #define _PDCLIB_XOPEN_MINMAX(min, max) 1
242
243     #undef _PDCLIB_EXTENSIONS
244     #undef _PDCLIB_BSD_SOURCE 
245     #undef _PDCLIB_SVID_SOURCE
246     #undef _PDCLIB_GNU_SOURCE
247
248     #define _PDCLIB_EXTENSIONS 1
249     #define _PDCLIB_BSD_SOURCE 1
250     #define _PDCLIB_SVID_SOURCE 1
251     #define _PDCLIB_GNU_SOURCE 1
252 #else
253     #define _PDCLIB_C_MINMAX(min, max) \
254         (_PDCLIB_C_VERSION >= (min) && _PDCLIB_C_VERSION <= (max))
255     #define _PDCLIB_CXX_MINMAX(min, max) \
256         (_PDCLIB_CXX_VERSION >= (min) && _PDCLIB_CXX_VERSION <= (max))
257     #define _PDCLIB_XOPEN_MINMAX(min, max) \
258         (defined(_XOPEN_SOURCE) \
259             && _XOPEN_SOURCE >= (min) && _XOPEN_SOURCE <= (max))
260     #define _PDCLIB_POSIX_MINMAX(min, max) \
261         (defined(_POSIX_C_SOURCE) \
262             && _POSIX_C_SOURCE >= (min) && _POSIX_C_SOURCE <= (max))
263
264     #if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE-1 == -1)
265         /* If _XOPEN_SOURCE is defined as empty, redefine here as zero */
266         #undef _XOPEN_SOURCE
267         #define _XOPEN_SOURCE 0
268     #endif
269
270     #if defined(_GNU_SOURCE)
271         #define _PDCLIB_GNU_SOURCE 1
272         #define _PDCLIB_SVID_SOURCE 1
273         #define _PDCLIB_BSD_SOURCE 1
274         #undef _XOPEN_SOURCE
275         #define _XOPEN_SOURCE 700
276     #else
277         #define _PDCLIB_GNU_SOURCE 0
278     #endif
279
280     #if defined(_PDCLIB_BSD_SOURCE)
281         // pass
282     #elif defined(_BSD_SOURCE)
283         #define _PDCLIB_BSD_SOURCE 1
284     #else
285         #define _PDCLIB_BSD_SOURCE 0
286     #endif
287
288     #if defined(_PDCLIB_SVID_SOURCE)
289         // pass
290     #elif defined(_SVID_SOURCE)
291         #define _PDCLIB_SVID_SOURCE 1
292     #else
293         #define _PDCLIB_SVID_SOURCE 0
294     #endif
295
296     #if _PDCLIB_XOPEN_MIN(700) && !_PDCLIB_POSIX_MIN(200809L)
297         #undef _POSIX_C_SOURCE
298         #define _POSIX_C_SOURCE 2008098L    
299     #elif _PDCLIB_XOPEN_MIN(600) && !_PDCLIB_POSIX_MIN(200112L)
300         #undef _POSIX_C_SOURCE
301         #define _POSIX_C_SOURCE 200112L
302     #elif _PDCLIB_XOPEN_MIN(0) && !_PDCLIB_POSIX_MIN(2)
303         #undef _POSIX_C_SOURCE
304         #define _POSIX_C_SOURCE 2
305     #endif
306
307     #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
308         #define _POSIX_C_SOURCE 1
309     #endif
310 #endif
311
312 #endif