OSDN Git Service

Declare the nanosleep() function where POSIX expects it.
[mingw/mingw-org-wsl.git] / mingwrt / include / _mingw.h
1 #ifndef __MINGW_H
2 /*
3  * _mingw.h
4  *
5  * MinGW specific macros included by ALL mingwrt include files; (this file
6  * is part of the MinGW32 runtime library package).
7  *
8  * $Id$
9  *
10  * Written by Mumit Khan  <khan@xraylith.wisc.edu>
11  * Copyright (C) 1999, 2001-2011, 2014, 2015, MinGW.org Project
12  *
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a
15  * copy of this software and associated documentation files (the "Software"),
16  * to deal in the Software without restriction, including without limitation
17  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18  * and/or sell copies of the Software, and to permit persons to whom the
19  * Software is furnished to do so, subject to the following conditions:
20  *
21  * The above copyright notice and this permission notice (including the next
22  * paragraph) shall be included in all copies or substantial portions of the
23  * Software.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31  * DEALINGS IN THE SOFTWARE.
32  *
33  */
34 #define __MINGW_H
35
36 /* In previous versions, __MINGW32_VERSION was expressed as a dotted
37  * numeric pair, representing major.minor; unfortunately, this doesn't
38  * adapt well to the inclusion of a patch-level component, since the
39  * major.minor.patch dotted triplet representation is not valid as a
40  * numeric entity.  Thus, for this version, we adopt a representation
41  * which encodes the version as a long integer value, expressing:
42  *
43  *   __MINGW32_VERSION = 1,000,000 * major + 1,000 * minor + patch
44  */
45 #define __MINGW32_VERSION           3021001L
46 #define __MINGW32_MAJOR_VERSION           3
47 #define __MINGW32_MINOR_VERSION          21
48 #define __MINGW32_PATCHLEVEL              1
49
50 #if __GNUC__ >= 3 && ! defined __PCC__
51 #pragma GCC system_header
52 #endif
53
54 #ifndef _MSVCRTVER_H
55 /* Legacy versions of mingwrt use the macro __MSVCRT_VERSION__ to
56  * enable evolving features of different MSVCRT.DLL versions.  This
57  * usage is no longer recommended, but the __MSVCRT_VERSION__ macro
58  * remains useful when a non-freely distributable MSVCRxx.DLL is to
59  * be substituted for MSVCRT.DLL; for such usage, the substitute
60  * MSVCRxx.DLL may be identified as specified in...
61  */
62 # include <msvcrtver.h>
63 #endif
64
65 /* A better inference than __MSVCRT_VERSION__, of the capabilities
66  * supported by the operating system default MSVCRT.DLL, is provided
67  * by the Windows API version identification macros.
68  */
69 #include <w32api.h>
70
71 /* The following are defined by the user (or by the compiler), to specify how
72  * identifiers are imported from a DLL.  All headers should include this first,
73  * and then use __DECLSPEC_SUPPORTED to choose between the old ``__imp__name''
74  * style or the __MINGW_IMPORT style for declarations.
75  *
76  * __DECLSPEC_SUPPORTED            Defined if dllimport attribute is supported.
77  * __MINGW_IMPORT                  The attribute definition to specify imported
78  *                                 variables/functions.
79  * _CRTIMP                         As above.  For MS compatibility.
80  *
81  * Macros to enable MinGW features which deviate from standard MSVC
82  * compatible behaviour; these may be specified directly in user code,
83  * activated implicitly, (e.g. by specifying _POSIX_C_SOURCE or such),
84  * or by inclusion in __MINGW_FEATURES__:
85  *
86  * __USE_MINGW_ANSI_STDIO          Select a more ANSI C99 compatible
87  *                                 implementation of printf() and friends.
88  *
89  * Other macros:
90  *
91  * __int64                         define to be long long.  Using a typedef
92  *                                 doesn't work for "unsigned __int64"
93  *
94  *
95  * Manifest definitions for flags to control globbing of the command line
96  * during application start up, (before main() is called).  The first pair,
97  * when assigned as bit flags within _CRT_glob, select the globbing algorithm
98  * to be used; (the MINGW algorithm overrides MSCVRT, if both are specified).
99  * Prior to mingwrt-3.21, only the MSVCRT option was supported; this choice
100  * may produce different results, depending on which particular version of
101  * MSVCRT.DLL is in use; (in recent versions, it seems to have become
102  * definitively broken, when globbing within double quotes).
103  */
104 #define __CRT_GLOB_USE_MSVCRT__         0x0001
105
106 /* From mingwrt-3.21 onward, this should be the preferred choice; it will
107  * produce consistent results, regardless of the MSVCRT.DLL version in use.
108  */
109 #define __CRT_GLOB_USE_MINGW__          0x0002
110
111 /* When the __CRT_GLOB_USE_MINGW__ flag is set, within _CRT_glob, the
112  * following additional options are also available; they are not enabled
113  * by default, but the user may elect to enable any combination of them,
114  * by setting _CRT_glob to the boolean sum (i.e. logical OR combination)
115  * of __CRT_GLOB_USE_MINGW__ and the desired options.
116  *
117  *    __CRT_GLOB_USE_SINGLE_QUOTE__     allows use of single (apostrophe)
118  *                                      quoting characters, analogously to
119  *                                      POSIX usage, as an alternative to
120  *                                      double quotes, for collection of
121  *                                      arguments separated by white space
122  *                                      into a single logical argument.
123  *
124  *    __CRT_GLOB_BRACKET_GROUPS__       enable interpretation of bracketed
125  *                                      character groups as POSIX compatible
126  *                                      globbing patterns, matching any one
127  *                                      character which is either included
128  *                                      in, or excluded from the group.
129  *
130  *    __CRT_GLOB_CASE_SENSITIVE__       enable case sensitive matching for
131  *                                      globbing patterns; this is default
132  *                                      behaviour for POSIX, but because of
133  *                                      the case insensitive nature of the
134  *                                      MS-Windows file system, it is more
135  *                                      appropriate to use case insensitive
136  *                                      globbing as the MinGW default.
137  *
138  */
139 #define __CRT_GLOB_USE_SINGLE_QUOTE__   0x0010
140 #define __CRT_GLOB_BRACKET_GROUPS__     0x0020
141 #define __CRT_GLOB_CASE_SENSITIVE__     0x0040
142
143 /* The MinGW globbing algorithm uses the ASCII DEL control code as a marker
144  * for globbing characters which were embedded within quoted arguments; (the
145  * quotes are stripped away BEFORE the argument is globbed; the globbing code
146  * treats the marked character as immutable, and strips out the DEL markers,
147  * before storing the resultant argument).  The DEL code is mapped to this
148  * function here; DO NOT change it, without rebuilding the runtime.
149  */
150 #define __CRT_GLOB_ESCAPE_CHAR__        (char)(127)
151
152
153 /* Manifest definitions identifying the flag bits, controlling activation
154  * of MinGW features, as specified by the user in __MINGW_FEATURES__.
155  */
156 #define __MINGW_ANSI_STDIO__            0x0000000000000001ULL
157 /*
158  * The following three are not yet formally supported; they are
159  * included here, to document anticipated future usage.
160  */
161 #define __MINGW_LC_EXTENSIONS__         0x0000000000000050ULL
162 #define __MINGW_LC_MESSAGES__           0x0000000000000010ULL
163 #define __MINGW_LC_ENVVARS__            0x0000000000000040ULL
164
165
166 /* Try to avoid problems with outdated checks for GCC __attribute__ support.
167  */
168 #undef __attribute__
169
170 #if defined (__PCC__)
171 #  undef __DECLSPEC_SUPPORTED
172 # ifndef __MINGW_IMPORT
173 #  define __MINGW_IMPORT extern
174 # endif
175 # ifndef _CRTIMP
176 #  define _CRTIMP
177 # endif
178 # ifndef __cdecl
179 #  define __cdecl  _Pragma("cdecl")
180 # endif
181 # ifndef __stdcall
182 #  define __stdcall _Pragma("stdcall")
183 # endif
184 # ifndef __int64
185 #  define __int64 long long
186 # endif
187 # ifndef __int32
188 #  define __int32 long
189 # endif
190 # ifndef __int16
191 #  define __int16 short
192 # endif
193 # ifndef __int8
194 #  define __int8 char
195 # endif
196 # ifndef __small
197 #  define __small char
198 # endif
199 # ifndef __hyper
200 #  define __hyper long long
201 # endif
202 # ifndef __volatile__
203 #  define __volatile__ volatile
204 # endif
205 # ifndef __restrict__
206 #  define __restrict__ restrict
207 # endif
208 # define NONAMELESSUNION
209 #elif defined(__GNUC__)
210 # ifdef __declspec
211 #  ifndef __MINGW_IMPORT
212    /* Note the extern. This is needed to work around GCC's
213       limitations in handling dllimport attribute.  */
214 #   define __MINGW_IMPORT  extern __attribute__ ((__dllimport__))
215 #  endif
216 #  ifndef _CRTIMP
217 #   ifdef __USE_CRTIMP
218 #    define _CRTIMP  __attribute__ ((dllimport))
219 #   else
220 #    define _CRTIMP
221 #   endif
222 #  endif
223 #  define __DECLSPEC_SUPPORTED
224 # else /* __declspec */
225 #  undef __DECLSPEC_SUPPORTED
226 #  undef __MINGW_IMPORT
227 #  ifndef _CRTIMP
228 #   define _CRTIMP
229 #  endif
230 # endif /* __declspec */
231 /*
232  * The next two defines can cause problems if user code adds the
233  * __cdecl attribute like so:
234  * void __attribute__ ((__cdecl)) foo(void);
235  */
236 # ifndef __cdecl
237 #  define __cdecl  __attribute__ ((__cdecl__))
238 # endif
239 # ifndef __stdcall
240 #  define __stdcall __attribute__ ((__stdcall__))
241 # endif
242 # ifndef __int64
243 #  define __int64 long long
244 # endif
245 # ifndef __int32
246 #  define __int32 long
247 # endif
248 # ifndef __int16
249 #  define __int16 short
250 # endif
251 # ifndef __int8
252 #  define __int8 char
253 # endif
254 # ifndef __small
255 #  define __small char
256 # endif
257 # ifndef __hyper
258 #  define __hyper long long
259 # endif
260 #else /* ! __GNUC__ && ! __PCC__ */
261 # ifndef __MINGW_IMPORT
262 #  define __MINGW_IMPORT  __declspec(dllimport)
263 # endif
264 # ifndef _CRTIMP
265 #  define _CRTIMP  __declspec(dllimport)
266 # endif
267 # define __DECLSPEC_SUPPORTED
268 # define __attribute__(x) /* nothing */
269 #endif
270
271 #if defined (__GNUC__) && defined (__GNUC_MINOR__)
272 #define __MINGW_GNUC_PREREQ(major, minor) \
273   (__GNUC__ > (major) \
274    || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
275 #else
276 #define __MINGW_GNUC_PREREQ(major, minor)  0
277 #endif
278
279 #ifdef __cplusplus
280 # define __CRT_INLINE    inline
281 #else
282 # if __GNUC_STDC_INLINE__
283 #  define __CRT_INLINE   extern inline __attribute__((__gnu_inline__))
284 # else
285 #  define __CRT_INLINE   extern __inline__
286 # endif
287 #endif
288
289 # ifdef __GNUC__
290   /* A special form of __CRT_INLINE is provided; it will ALWAYS request
291    * inlining when possible.  Originally specified as _CRTALIAS, this is
292    * now deprecated in favour of __CRT_ALIAS, for syntactic consistency
293    * with __CRT_INLINE itself.
294    */
295 #  define  _CRTALIAS   __CRT_INLINE __attribute__((__always_inline__))
296 #  define __CRT_ALIAS  __CRT_INLINE __attribute__((__always_inline__))
297 # else
298 #  define  _CRTALIAS   __CRT_INLINE     /* deprecated form */
299 #  define __CRT_ALIAS  __CRT_INLINE     /* preferred form */
300 # endif
301 /*
302  * Each function which is implemented as a __CRT_ALIAS should also be
303  * accompanied by an externally visible interface.  The following pair
304  * of macros provide a mechanism for implementing this, either as a stub
305  * redirecting to an alternative external function, or by compilation of
306  * the normally inlined code into free standing object code; each macro
307  * provides a way for us to offer arbitrary hints for use by the build
308  * system, while remaining transparent to the compiler.
309  */
310 #define __JMPSTUB__(__BUILD_HINT__)
311 #define __LIBIMPL__(__BUILD_HINT__)
312
313 #ifdef __cplusplus
314 # define __UNUSED_PARAM(x)
315 #else
316 # ifdef __GNUC__
317 #  define __UNUSED_PARAM(x) x __attribute__ ((__unused__))
318 # else
319 #  define __UNUSED_PARAM(x) x
320 # endif
321 #endif
322
323 #ifdef __GNUC__
324 #define __MINGW_ATTRIB_NORETURN __attribute__ ((__noreturn__))
325 #define __MINGW_ATTRIB_CONST __attribute__ ((__const__))
326 #else
327 #define __MINGW_ATTRIB_NORETURN
328 #define __MINGW_ATTRIB_CONST
329 #endif
330
331 #if __MINGW_GNUC_PREREQ (3, 0)
332 #define __MINGW_ATTRIB_MALLOC __attribute__ ((__malloc__))
333 #define __MINGW_ATTRIB_PURE __attribute__ ((__pure__))
334 #else
335 #define __MINGW_ATTRIB_MALLOC
336 #define __MINGW_ATTRIB_PURE
337 #endif
338
339 /* Attribute `nonnull' was valid as of gcc 3.3.  We don't use GCC's
340    variadiac macro facility, because variadic macros cause syntax
341    errors with  --traditional-cpp.  */
342 #if  __MINGW_GNUC_PREREQ (3, 3)
343 #define __MINGW_ATTRIB_NONNULL(arg) __attribute__ ((__nonnull__ (arg)))
344 #else
345 #define __MINGW_ATTRIB_NONNULL(arg)
346 #endif /* GNUC >= 3.3 */
347
348 #if  __MINGW_GNUC_PREREQ (3, 1)
349 #define __MINGW_ATTRIB_DEPRECATED __attribute__ ((__deprecated__))
350 #else
351 #define __MINGW_ATTRIB_DEPRECATED
352 #endif /* GNUC >= 3.1 */
353
354 #if  __MINGW_GNUC_PREREQ (3, 3)
355 #define __MINGW_NOTHROW __attribute__ ((__nothrow__))
356 #else
357 #define __MINGW_NOTHROW
358 #endif /* GNUC >= 3.3 */
359
360
361 /* TODO: Mark (almost) all CRT functions as __MINGW_NOTHROW.  This will
362 allow GCC to optimize away some EH unwind code, at least in DW2 case.  */
363
364 /* Activation of MinGW specific extended features:
365  */
366 #ifndef __USE_MINGW_ANSI_STDIO
367 /*
368  * We must check this BEFORE we specifiy any implicit _POSIX_C_SOURCE,
369  * otherwise we would always implicitly choose __USE_MINGW_ANSI_STDIO;
370  * if user didn't specify it explicitly...
371  */
372 # if   defined __STRICT_ANSI__  ||  defined _ISOC99_SOURCE \
373    ||  defined _POSIX_SOURCE    ||  defined _POSIX_C_SOURCE \
374    ||  defined _XOPEN_SOURCE    ||  defined _XOPEN_SOURCE_EXTENDED \
375    ||  defined _GNU_SOURCE      ||  defined _BSD_SOURCE \
376    ||  defined _SVID_SOURCE
377    /*
378     * but where any of these source code qualifiers are specified,
379     * then assume ANSI I/O standards are preferred over Microsoft's...
380     */
381 #  define __USE_MINGW_ANSI_STDIO    1
382 # else
383    /* otherwise use whatever __MINGW_FEATURES__ specifies...
384     */
385 #  define __USE_MINGW_ANSI_STDIO    (__MINGW_FEATURES__ & __MINGW_ANSI_STDIO__)
386 # endif
387 #endif
388
389 #ifndef _POSIX_C_SOURCE
390  /* Users may define this, either directly or indirectly, to explicitly
391   * enable a particular level of visibility for the subset of those POSIX
392   * features which are supported by MinGW; (notice that this offers no
393   * guarantee that any particular POSIX feature will be supported).
394   */
395 # if defined _XOPEN_SOURCE
396   /* Specifying this is the preferred method for setting _POSIX_C_SOURCE;
397    * (POSIX defines an explicit relationship to _XOPEN_SOURCE).  Note that
398    * any such explicit setting will augment the set of features which are
399    * available to any compilation unit, even if it seeks to be strictly
400    * ANSI-C compliant.
401    */
402 #  if _XOPEN_SOURCE < 500
403 #   define _POSIX_C_SOURCE  1L          /* POSIX.1-1990 / SUSv1 */
404
405 #  elif _XOPEN_SOURCE < 600
406 #   define _POSIX_C_SOURCE  199506L     /* POSIX.1-1996 / SUSv2 */
407
408 #  elif _XOPEN_SOURCE < 700
409 #   define _POSIX_C_SOURCE  200112L     /* POSIX.1-2001 / SUSv3 */
410
411 #  else
412 #   define _POSIX_C_SOURCE  200809L     /* POSIX.1-2008 / SUSv4 */
413 #  endif
414
415 # elif defined _GNU_SOURCE || defined _BSD_SOURCE || ! defined __STRICT_ANSI__
416   /*
417    * No explicit level of support has been specified; implicitly grant
418    * the most comprehensive level to any compilation unit which requests
419    * either GNU or BSD feature support, or does not seek to be strictly
420    * ANSI-C compliant.
421    */
422 #  define _POSIX_C_SOURCE  200809L
423
424 # elif defined _POSIX_SOURCE
425   /* Now formally deprecated by POSIX, some old code may specify this;
426    * it will enable a minimal level of POSIX support, in addition to the
427    * limited feature set enabled for strict ANSI-C conformity.
428    */
429 #  define _POSIX_C_SOURCE  1L
430 # endif
431 #endif
432
433 #ifndef _ISOC99_SOURCE
434  /* libmingwex.a provides free-standing implementations for many of the
435   * functions which were introduced in C99; MinGW headers do not expose
436   * prototypes for these, unless this feature test macro is defined, by
437   * the user, or implied by other standards...
438   */
439 # if __STDC_VERSION__ >= 199901L || _POSIX_C_SOURCE >= 200112L
440 #  define _ISOC99_SOURCE  1
441 # endif
442 #endif
443
444 #if ! defined _MINGW32_EXTENDED_SOURCE && ! defined __STRICT_ANSI__
445 /*
446  * Enable mingw32 extensions by default, except when __STRICT_ANSI__
447  * conformity mode has been enabled.
448  */
449 # define _MINGW32_EXTENDED_SOURCE  1
450 #endif
451
452 #endif /* __MINGW_H: $RCSfile$: end of file */