]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000-2010 Apple Inc. | |
3 | * All rights reserved. | |
4 | */ | |
5 | ||
6 | #ifndef _KERNEL_STDINT_H_ | |
7 | #define _KERNEL_STDINT_H_ | |
8 | ||
9 | #ifndef KERNEL | |
10 | /* For user-space code that may include this header */ | |
11 | #include_next <stdint.h> | |
12 | #else /* KERNEL */ | |
13 | ||
14 | #include <machine/types.h> | |
15 | ||
16 | #if __LP64__ | |
17 | #define __WORDSIZE 64 | |
18 | #else | |
19 | #define __WORDSIZE 32 | |
20 | #endif | |
21 | ||
22 | /* from ISO/IEC 988:1999 spec */ | |
23 | ||
24 | /* 7.18.1.1 Exact-width integer types */ | |
25 | /* int8_t is defined in <machine/types.h> */ | |
26 | /* int16_t is defined in <machine/types.h> */ | |
27 | /* int32_t is defined in <machine/types.h> */ | |
28 | /* int64_t is defined in <machine/types.h> */ | |
29 | typedef u_int8_t uint8_t; /* u_int8_t is defined in <machine/types.h> */ | |
30 | typedef u_int16_t uint16_t; /* u_int16_t is defined in <machine/types.h> */ | |
31 | typedef u_int32_t uint32_t; /* u_int32_t is defined in <machine/types.h> */ | |
32 | typedef u_int64_t uint64_t; /* u_int64_t is defined in <machine/types.h> */ | |
33 | ||
34 | ||
35 | /* 7.18.1.2 Minimum-width integer types */ | |
36 | typedef int8_t int_least8_t; | |
37 | typedef int16_t int_least16_t; | |
38 | typedef int32_t int_least32_t; | |
39 | typedef int64_t int_least64_t; | |
40 | typedef uint8_t uint_least8_t; | |
41 | typedef uint16_t uint_least16_t; | |
42 | typedef uint32_t uint_least32_t; | |
43 | typedef uint64_t uint_least64_t; | |
44 | ||
45 | ||
46 | /* 7.18.1.3 Fastest-width integer types */ | |
47 | typedef int8_t int_fast8_t; | |
48 | typedef int16_t int_fast16_t; | |
49 | typedef int32_t int_fast32_t; | |
50 | typedef int64_t int_fast64_t; | |
51 | typedef uint8_t uint_fast8_t; | |
52 | typedef uint16_t uint_fast16_t; | |
53 | typedef uint32_t uint_fast32_t; | |
54 | typedef uint64_t uint_fast64_t; | |
55 | ||
56 | ||
57 | /* 7.18.1.4 Integer types capable of holding object pointers */ | |
58 | /* intptr_t is defined in <machine/types.h> */ | |
59 | /* uintptr_t is defined in <machine/types.h> */ | |
60 | ||
61 | ||
62 | /* 7.18.1.5 Greatest-width integer types */ | |
63 | #ifdef __INTMAX_TYPE__ | |
64 | typedef __INTMAX_TYPE__ intmax_t; | |
65 | #else | |
66 | #ifdef __LP64__ | |
67 | typedef long int intmax_t; | |
68 | #else | |
69 | typedef long long int intmax_t; | |
70 | #endif /* __LP64__ */ | |
71 | #endif /* __INTMAX_TYPE__ */ | |
72 | #ifdef __UINTMAX_TYPE__ | |
73 | typedef __UINTMAX_TYPE__ uintmax_t; | |
74 | #else | |
75 | #ifdef __LP64__ | |
76 | typedef long unsigned int uintmax_t; | |
77 | #else | |
78 | typedef long long unsigned int uintmax_t; | |
79 | #endif /* __LP64__ */ | |
80 | #endif /* __UINTMAX_TYPE__ */ | |
81 | ||
82 | /* 7.18.4 Macros for integer constants */ | |
83 | #define INT8_C(v) (v) | |
84 | #define INT16_C(v) (v) | |
85 | #define INT32_C(v) (v) | |
86 | #define INT64_C(v) (v ## LL) | |
87 | ||
88 | #define UINT8_C(v) (v) | |
89 | #define UINT16_C(v) (v) | |
90 | #define UINT32_C(v) (v ## U) | |
91 | #define UINT64_C(v) (v ## ULL) | |
92 | ||
93 | #ifdef __LP64__ | |
94 | #define INTMAX_C(v) (v ## L) | |
95 | #define UINTMAX_C(v) (v ## UL) | |
96 | #else | |
97 | #define INTMAX_C(v) (v ## LL) | |
98 | #define UINTMAX_C(v) (v ## ULL) | |
99 | #endif | |
100 | ||
101 | /* 7.18.2 Limits of specified-width integer types: | |
102 | * These #defines specify the minimum and maximum limits | |
103 | * of each of the types declared above. | |
104 | * | |
105 | * They must have "the same type as would an expression that is an | |
106 | * object of the corresponding type converted according to the integer | |
107 | * promotion". | |
108 | */ | |
109 | ||
110 | ||
111 | /* 7.18.2.1 Limits of exact-width integer types */ | |
112 | #define INT8_MAX 127 | |
113 | #define INT16_MAX 32767 | |
114 | #define INT32_MAX 2147483647 | |
115 | #define INT64_MAX 9223372036854775807LL | |
116 | ||
117 | #define INT8_MIN -128 | |
118 | #define INT16_MIN -32768 | |
119 | /* | |
120 | Note: the literal "most negative int" cannot be written in C -- | |
121 | the rules in the standard (section 6.4.4.1 in C99) will give it | |
122 | an unsigned type, so INT32_MIN (and the most negative member of | |
123 | any larger signed type) must be written via a constant expression. | |
124 | */ | |
125 | #define INT32_MIN (-INT32_MAX-1) | |
126 | #define INT64_MIN (-INT64_MAX-1) | |
127 | ||
128 | #define UINT8_MAX 255 | |
129 | #define UINT16_MAX 65535 | |
130 | #define UINT32_MAX 4294967295U | |
131 | #define UINT64_MAX 18446744073709551615ULL | |
132 | ||
133 | /* 7.18.2.2 Limits of minimum-width integer types */ | |
134 | #define INT_LEAST8_MIN INT8_MIN | |
135 | #define INT_LEAST16_MIN INT16_MIN | |
136 | #define INT_LEAST32_MIN INT32_MIN | |
137 | #define INT_LEAST64_MIN INT64_MIN | |
138 | ||
139 | #define INT_LEAST8_MAX INT8_MAX | |
140 | #define INT_LEAST16_MAX INT16_MAX | |
141 | #define INT_LEAST32_MAX INT32_MAX | |
142 | #define INT_LEAST64_MAX INT64_MAX | |
143 | ||
144 | #define UINT_LEAST8_MAX UINT8_MAX | |
145 | #define UINT_LEAST16_MAX UINT16_MAX | |
146 | #define UINT_LEAST32_MAX UINT32_MAX | |
147 | #define UINT_LEAST64_MAX UINT64_MAX | |
148 | ||
149 | /* 7.18.2.3 Limits of fastest minimum-width integer types */ | |
150 | #define INT_FAST8_MIN INT8_MIN | |
151 | #define INT_FAST16_MIN INT16_MIN | |
152 | #define INT_FAST32_MIN INT32_MIN | |
153 | #define INT_FAST64_MIN INT64_MIN | |
154 | ||
155 | #define INT_FAST8_MAX INT8_MAX | |
156 | #define INT_FAST16_MAX INT16_MAX | |
157 | #define INT_FAST32_MAX INT32_MAX | |
158 | #define INT_FAST64_MAX INT64_MAX | |
159 | ||
160 | #define UINT_FAST8_MAX UINT8_MAX | |
161 | #define UINT_FAST16_MAX UINT16_MAX | |
162 | #define UINT_FAST32_MAX UINT32_MAX | |
163 | #define UINT_FAST64_MAX UINT64_MAX | |
164 | ||
165 | /* 7.18.2.4 Limits of integer types capable of holding object pointers */ | |
166 | ||
167 | #if __WORDSIZE == 64 | |
168 | #define INTPTR_MAX 9223372036854775807L | |
169 | #else | |
170 | #define INTPTR_MAX 2147483647L | |
171 | #endif | |
172 | #define INTPTR_MIN (-INTPTR_MAX-1) | |
173 | ||
174 | #if __WORDSIZE == 64 | |
175 | #define UINTPTR_MAX 18446744073709551615UL | |
176 | #else | |
177 | #define UINTPTR_MAX 4294967295UL | |
178 | #endif | |
179 | ||
180 | /* 7.18.2.5 Limits of greatest-width integer types */ | |
181 | #define INTMAX_MAX INTMAX_C(9223372036854775807) | |
182 | #define UINTMAX_MAX UINTMAX_C(18446744073709551615) | |
183 | #define INTMAX_MIN (-INTMAX_MAX-1) | |
184 | ||
185 | /* 7.18.3 "Other" */ | |
186 | #if __WORDSIZE == 64 | |
187 | #define PTRDIFF_MIN INTMAX_MIN | |
188 | #define PTRDIFF_MAX INTMAX_MAX | |
189 | #else | |
190 | #define PTRDIFF_MIN INT32_MIN | |
191 | #define PTRDIFF_MAX INT32_MAX | |
192 | #endif | |
193 | ||
194 | #define SIZE_MAX UINTPTR_MAX | |
195 | ||
196 | #if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 | |
197 | #define RSIZE_MAX (SIZE_MAX >> 1) | |
198 | #endif | |
199 | ||
200 | #ifndef WCHAR_MAX | |
201 | # ifdef __WCHAR_MAX__ | |
202 | # define WCHAR_MAX __WCHAR_MAX__ | |
203 | # else | |
204 | # define WCHAR_MAX 0x7fffffff | |
205 | # endif | |
206 | #endif | |
207 | ||
208 | /* WCHAR_MIN should be 0 if wchar_t is an unsigned type and | |
209 | (-WCHAR_MAX-1) if wchar_t is a signed type. Unfortunately, | |
210 | it turns out that -fshort-wchar changes the signedness of | |
211 | the type. */ | |
212 | #ifndef WCHAR_MIN | |
213 | # if WCHAR_MAX == 0xffff | |
214 | # define WCHAR_MIN 0 | |
215 | # else | |
216 | # define WCHAR_MIN (-WCHAR_MAX-1) | |
217 | # endif | |
218 | #endif | |
219 | ||
220 | #define WINT_MIN INT32_MIN | |
221 | #define WINT_MAX INT32_MAX | |
222 | ||
223 | #define SIG_ATOMIC_MIN INT32_MIN | |
224 | #define SIG_ATOMIC_MAX INT32_MAX | |
225 | ||
226 | #endif /* KERNEL */ | |
227 | ||
228 | #endif /* _KERNEL_STDINT_H_ */ |