1193326Sed/*===---- stddef.h - Basic type definitions --------------------------------===
2193326Sed *
3193326Sed * Copyright (c) 2008 Eli Friedman
4193326Sed *
5193326Sed * Permission is hereby granted, free of charge, to any person obtaining a copy
6193326Sed * of this software and associated documentation files (the "Software"), to deal
7193326Sed * in the Software without restriction, including without limitation the rights
8193326Sed * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9193326Sed * copies of the Software, and to permit persons to whom the Software is
10193326Sed * furnished to do so, subject to the following conditions:
11193326Sed *
12193326Sed * The above copyright notice and this permission notice shall be included in
13193326Sed * all copies or substantial portions of the Software.
14193326Sed *
15193326Sed * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16193326Sed * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17193326Sed * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18193326Sed * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19193326Sed * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20193326Sed * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21193326Sed * THE SOFTWARE.
22193326Sed *
23193326Sed *===-----------------------------------------------------------------------===
24193326Sed */
25193326Sed
26193326Sed#ifndef __STDDEF_H
27193326Sed#define __STDDEF_H
28193326Sed
29249423Sdim#if !defined(_PTRDIFF_T) || __has_feature(modules)
30249423Sdim/* Always define ptrdiff_t when modules are available. */
31249423Sdim#if !__has_feature(modules)
32221345Sdim#define _PTRDIFF_T
33221345Sdim#endif
34249423Sdimtypedef __PTRDIFF_TYPE__ ptrdiff_t;
35249423Sdim#endif
36249423Sdim
37249423Sdim#if !defined(_SIZE_T) || __has_feature(modules)
38249423Sdim/* Always define size_t when modules are available. */
39249423Sdim#if !__has_feature(modules)
40204962Srdivacky#define _SIZE_T
41204962Srdivacky#endif
42249423Sdimtypedef __SIZE_TYPE__ size_t;
43249423Sdim#endif
44249423Sdim
45251662Sdim/* ISO9899:2011 7.20 (C11 Annex K): Define rsize_t if __STDC_WANT_LIB_EXT1__ is
46251662Sdim * enabled. */
47251662Sdim#if (defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 && \
48251662Sdim     !defined(_RSIZE_T)) || __has_feature(modules)
49251662Sdim/* Always define rsize_t when modules are available. */
50251662Sdim#if !__has_feature(modules)
51251662Sdim#define _RSIZE_T
52251662Sdim#endif
53251662Sdimtypedef __SIZE_TYPE__ rsize_t;
54251662Sdim#endif
55251662Sdim
56193326Sed#ifndef __cplusplus
57249423Sdim/* Always define wchar_t when modules are available. */
58249423Sdim#if !defined(_WCHAR_T) || __has_feature(modules)
59249423Sdim#if !__has_feature(modules)
60204962Srdivacky#define _WCHAR_T
61251662Sdim#if defined(_MSC_EXTENSIONS)
62251662Sdim#define _WCHAR_T_DEFINED
63249423Sdim#endif
64251662Sdim#endif
65212904Sdimtypedef __WCHAR_TYPE__ wchar_t;
66193326Sed#endif
67204962Srdivacky#endif
68193326Sed
69204962Srdivacky#undef NULL
70193326Sed#ifdef __cplusplus
71239462Sdim#  if !defined(__MINGW32__) && !defined(_MSC_VER)
72239462Sdim#    define NULL __null
73239462Sdim#  else
74239462Sdim#    define NULL 0
75239462Sdim#  endif
76193326Sed#else
77239462Sdim#  define NULL ((void*)0)
78193326Sed#endif
79193326Sed
80239462Sdim#ifdef __cplusplus
81239462Sdim#if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED)
82239462Sdimnamespace std { typedef decltype(nullptr) nullptr_t; }
83239462Sdimusing ::std::nullptr_t;
84239462Sdim#endif
85239462Sdim#endif
86239462Sdim
87193326Sed#define offsetof(t, d) __builtin_offsetof(t, d)
88193326Sed
89193326Sed#endif /* __STDDEF_H */
90218893Sdim
91218893Sdim/* Some C libraries expect to see a wint_t here. Others (notably MinGW) will use
92221345Sdim__WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */
93218893Sdim#if defined(__need_wint_t)
94249423Sdim/* Always define wint_t when modules are available. */
95249423Sdim#if !defined(_WINT_T) || __has_feature(modules)
96249423Sdim#if !__has_feature(modules)
97218893Sdim#define _WINT_T
98249423Sdim#endif
99218893Sdimtypedef __WINT_TYPE__ wint_t;
100249423Sdim#endif
101218893Sdim#undef __need_wint_t
102218893Sdim#endif /* __need_wint_t */
103