]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
39236c6e A |
2 | * Copyright (c) 2000-2010 Apple Inc. |
3 | * All rights reserved. | |
1c79356b A |
4 | */ |
5 | ||
39236c6e A |
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 */ | |
1c79356b A |
13 | |
14 | #include <machine/types.h> | |
15 | ||
39236c6e A |
16 | #if __LP64__ |
17 | #define __WORDSIZE 64 | |
18 | #else | |
19 | #define __WORDSIZE 32 | |
20 | #endif | |
21 | ||
1c79356b A |
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 | ||
39236c6e | 35 | /* 7.18.1.2 Minimum-width integer types */ |
1c79356b A |
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 | ||
39236c6e | 57 | /* 7.18.1.4 Integer types capable of holding object pointers */ |
1c79356b A |
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 | typedef long long intmax_t; | |
64 | typedef unsigned long long uintmax_t; | |
65 | ||
1c79356b A |
66 | /* 7.18.2 Limits of specified-width integer types: |
67 | * These #defines specify the minimum and maximum limits | |
68 | * of each of the types declared above. | |
69 | */ | |
70 | ||
71 | ||
72 | /* 7.18.2.1 Limits of exact-width integer types */ | |
39236c6e A |
73 | #define INT8_MAX 127 |
74 | #define INT16_MAX 32767 | |
75 | #define INT32_MAX 2147483647 | |
76 | #define INT64_MAX 9223372036854775807LL | |
77 | ||
78 | #define INT8_MIN -128 | |
79 | #define INT16_MIN -32768 | |
80 | /* | |
81 | Note: the literal "most negative int" cannot be written in C -- | |
82 | the rules in the standard (section 6.4.4.1 in C99) will give it | |
83 | an unsigned type, so INT32_MIN (and the most negative member of | |
84 | any larger signed type) must be written via a constant expression. | |
85 | */ | |
86 | #define INT32_MIN (-INT32_MAX-1) | |
87 | #define INT64_MIN (-INT64_MAX-1) | |
1c79356b A |
88 | |
89 | #define UINT8_MAX 255 | |
90 | #define UINT16_MAX 65535 | |
91 | #define UINT32_MAX 4294967295U | |
92 | #define UINT64_MAX 18446744073709551615ULL | |
93 | ||
94 | /* 7.18.2.2 Limits of minimum-width integer types */ | |
95 | #define INT_LEAST8_MIN INT8_MIN | |
96 | #define INT_LEAST16_MIN INT16_MIN | |
97 | #define INT_LEAST32_MIN INT32_MIN | |
98 | #define INT_LEAST64_MIN INT64_MIN | |
99 | ||
100 | #define INT_LEAST8_MAX INT8_MAX | |
101 | #define INT_LEAST16_MAX INT16_MAX | |
102 | #define INT_LEAST32_MAX INT32_MAX | |
103 | #define INT_LEAST64_MAX INT64_MAX | |
104 | ||
105 | #define UINT_LEAST8_MAX UINT8_MAX | |
106 | #define UINT_LEAST16_MAX UINT16_MAX | |
107 | #define UINT_LEAST32_MAX UINT32_MAX | |
108 | #define UINT_LEAST64_MAX UINT64_MAX | |
109 | ||
110 | /* 7.18.2.3 Limits of fastest minimum-width integer types */ | |
111 | #define INT_FAST8_MIN INT8_MIN | |
112 | #define INT_FAST16_MIN INT16_MIN | |
113 | #define INT_FAST32_MIN INT32_MIN | |
114 | #define INT_FAST64_MIN INT64_MIN | |
115 | ||
116 | #define INT_FAST8_MAX INT8_MAX | |
117 | #define INT_FAST16_MAX INT16_MAX | |
118 | #define INT_FAST32_MAX INT32_MAX | |
119 | #define INT_FAST64_MAX INT64_MAX | |
120 | ||
121 | #define UINT_FAST8_MAX UINT8_MAX | |
122 | #define UINT_FAST16_MAX UINT16_MAX | |
123 | #define UINT_FAST32_MAX UINT32_MAX | |
124 | #define UINT_FAST64_MAX UINT64_MAX | |
125 | ||
126 | /* 7.18.2.4 Limits of integer types capable of holding object pointers */ | |
39236c6e A |
127 | |
128 | #if __WORDSIZE == 64 | |
129 | #define INTPTR_MIN INT64_MIN | |
130 | #define INTPTR_MAX INT64_MAX | |
2d21ac55 | 131 | #else |
1c79356b A |
132 | #define INTPTR_MIN INT32_MIN |
133 | #define INTPTR_MAX INT32_MAX | |
39236c6e A |
134 | #endif |
135 | ||
136 | #if __WORDSIZE == 64 | |
137 | #define UINTPTR_MAX UINT64_MAX | |
138 | #else | |
1c79356b | 139 | #define UINTPTR_MAX UINT32_MAX |
2d21ac55 | 140 | #endif |
1c79356b A |
141 | |
142 | /* 7.18.2.5 Limits of greatest-width integer types */ | |
143 | #define INTMAX_MIN INT64_MIN | |
144 | #define INTMAX_MAX INT64_MAX | |
145 | ||
146 | #define UINTMAX_MAX UINT64_MAX | |
147 | ||
148 | /* 7.18.3 "Other" */ | |
39236c6e A |
149 | #if __WORDSIZE == 64 |
150 | #define PTRDIFF_MIN INT64_MIN | |
151 | #define PTRDIFF_MAX INT64_MAX | |
2d21ac55 | 152 | #else |
1c79356b A |
153 | #define PTRDIFF_MIN INT32_MIN |
154 | #define PTRDIFF_MAX INT32_MAX | |
2d21ac55 | 155 | #endif |
39236c6e | 156 | |
1c79356b A |
157 | /* We have no sig_atomic_t yet, so no SIG_ATOMIC_{MIN,MAX}. |
158 | Should end up being {-127,127} or {0,255} ... or bigger. | |
159 | My bet would be on one of {U}INT32_{MIN,MAX}. */ | |
160 | ||
39236c6e A |
161 | #if __WORDSIZE == 64 |
162 | #define SIZE_MAX UINT64_MAX | |
163 | #else | |
1c79356b | 164 | #define SIZE_MAX UINT32_MAX |
39236c6e | 165 | #endif |
1c79356b | 166 | |
39236c6e A |
167 | #if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 |
168 | #define RSIZE_MAX (SIZE_MAX >> 1) | |
316670eb | 169 | #endif |
1c79356b | 170 | |
39236c6e A |
171 | #ifndef WCHAR_MAX |
172 | # ifdef __WCHAR_MAX__ | |
173 | # define WCHAR_MAX __WCHAR_MAX__ | |
174 | # else | |
175 | # define WCHAR_MAX 0x7fffffff | |
176 | # endif | |
177 | #endif | |
1c79356b | 178 | |
39236c6e A |
179 | /* WCHAR_MIN should be 0 if wchar_t is an unsigned type and |
180 | (-WCHAR_MAX-1) if wchar_t is a signed type. Unfortunately, | |
181 | it turns out that -fshort-wchar changes the signedness of | |
182 | the type. */ | |
183 | #ifndef WCHAR_MIN | |
184 | # if WCHAR_MAX == 0xffff | |
185 | # define WCHAR_MIN 0 | |
186 | # else | |
187 | # define WCHAR_MIN (-WCHAR_MAX-1) | |
188 | # endif | |
189 | #endif | |
1c79356b | 190 | |
39236c6e A |
191 | #define WINT_MIN INT32_MIN |
192 | #define WINT_MAX INT32_MAX | |
1c79356b | 193 | |
39236c6e A |
194 | #define SIG_ATOMIC_MIN INT32_MIN |
195 | #define SIG_ATOMIC_MAX INT32_MAX | |
1c79356b A |
196 | |
197 | /* 7.18.4 Macros for integer constants */ | |
39236c6e A |
198 | #define INT8_C(v) (v) |
199 | #define INT16_C(v) (v) | |
200 | #define INT32_C(v) (v) | |
1c79356b A |
201 | #define INT64_C(v) (v ## LL) |
202 | ||
39236c6e A |
203 | #define UINT8_C(v) (v ## U) |
204 | #define UINT16_C(v) (v ## U) | |
205 | #define UINT32_C(v) (v ## U) | |
1c79356b A |
206 | #define UINT64_C(v) (v ## ULL) |
207 | ||
208 | #define INTMAX_C(v) (v ## LL) | |
209 | #define UINTMAX_C(v) (v ## ULL) | |
210 | ||
39236c6e | 211 | #endif /* KERNEL */ |
1c79356b | 212 | |
39236c6e | 213 | #endif /* _KERNEL_STDINT_H_ */ |