1 | /* |
---|---|

2 | * Copyright (c) 2000-2010 Apple Inc. |

3 | * All rights reserved. |

4 | */ |

5 | #if (defined(__has_include) && __has_include(<__xnu_libcxx_sentinel.h>) && !defined(XNU_LIBCXX_SDKROOT)) |

6 | |

7 | #if !__has_include_next(<stdint.h>) |

8 | #error Do not build with -nostdinc (use GCC_USE_STANDARD_INCLUDE_SEARCHING=NO) |

9 | #endif /* __has_include_next */ |

10 | |

11 | #include_next <stdint.h> |

12 | |

13 | #else /* (defined(__has_include) && __has_include(<__xnu_libcxx_sentinel.h>) && !defined(XNU_LIBCXX_SDKROOT)) */ |

14 | |

15 | #ifndef _KERNEL_STDINT_H_ |

16 | #define _KERNEL_STDINT_H_ |

17 | |

18 | #ifndef KERNEL |

19 | /* For user-space code that may include this header */ |

20 | #include_next <stdint.h> |

21 | #else /* KERNEL */ |

22 | |

23 | #include <machine/types.h> |

24 | |

25 | #if __LP64__ |

26 | #define __WORDSIZE 64 |

27 | #else |

28 | #define __WORDSIZE 32 |

29 | #endif |

30 | |

31 | /* from ISO/IEC 988:1999 spec */ |

32 | |

33 | /* 7.18.1.1 Exact-width integer types */ |

34 | /* int8_t is defined in <machine/types.h> */ |

35 | /* int16_t is defined in <machine/types.h> */ |

36 | /* int32_t is defined in <machine/types.h> */ |

37 | /* int64_t is defined in <machine/types.h> */ |

38 | typedef u_int8_t uint8_t; /* u_int8_t is defined in <machine/types.h> */ |

39 | typedef u_int16_t uint16_t; /* u_int16_t is defined in <machine/types.h> */ |

40 | typedef u_int32_t uint32_t; /* u_int32_t is defined in <machine/types.h> */ |

41 | typedef u_int64_t uint64_t; /* u_int64_t is defined in <machine/types.h> */ |

42 | |

43 | |

44 | /* 7.18.1.2 Minimum-width integer types */ |

45 | typedef int8_t int_least8_t; |

46 | typedef int16_t int_least16_t; |

47 | typedef int32_t int_least32_t; |

48 | typedef int64_t int_least64_t; |

49 | typedef uint8_t uint_least8_t; |

50 | typedef uint16_t uint_least16_t; |

51 | typedef uint32_t uint_least32_t; |

52 | typedef uint64_t uint_least64_t; |

53 | |

54 | |

55 | /* 7.18.1.3 Fastest-width integer types */ |

56 | typedef int8_t int_fast8_t; |

57 | typedef int16_t int_fast16_t; |

58 | typedef int32_t int_fast32_t; |

59 | typedef int64_t int_fast64_t; |

60 | typedef uint8_t uint_fast8_t; |

61 | typedef uint16_t uint_fast16_t; |

62 | typedef uint32_t uint_fast32_t; |

63 | typedef uint64_t uint_fast64_t; |

64 | |

65 | |

66 | /* 7.18.1.4 Integer types capable of holding object pointers */ |

67 | /* intptr_t is defined in <machine/types.h> */ |

68 | /* uintptr_t is defined in <machine/types.h> */ |

69 | |

70 | |

71 | /* 7.18.1.5 Greatest-width integer types */ |

72 | #ifdef __INTMAX_TYPE__ |

73 | typedef __INTMAX_TYPE__ intmax_t; |

74 | #else |

75 | #ifdef __LP64__ |

76 | typedef long int intmax_t; |

77 | #else |

78 | typedef long long int intmax_t; |

79 | #endif /* __LP64__ */ |

80 | #endif /* __INTMAX_TYPE__ */ |

81 | #ifdef __UINTMAX_TYPE__ |

82 | typedef __UINTMAX_TYPE__ uintmax_t; |

83 | #else |

84 | #ifdef __LP64__ |

85 | typedef long unsigned int uintmax_t; |

86 | #else |

87 | typedef long long unsigned int uintmax_t; |

88 | #endif /* __LP64__ */ |

89 | #endif /* __UINTMAX_TYPE__ */ |

90 | |

91 | /* 7.18.4 Macros for integer constants */ |

92 | #define INT8_C(v) (v) |

93 | #define INT16_C(v) (v) |

94 | #define INT32_C(v) (v) |

95 | #define INT64_C(v) (v ## LL) |

96 | |

97 | #define UINT8_C(v) (v) |

98 | #define UINT16_C(v) (v) |

99 | #define UINT32_C(v) (v ## U) |

100 | #define UINT64_C(v) (v ## ULL) |

101 | |

102 | #ifdef __LP64__ |

103 | #define INTMAX_C(v) (v ## L) |

104 | #define UINTMAX_C(v) (v ## UL) |

105 | #else |

106 | #define INTMAX_C(v) (v ## LL) |

107 | #define UINTMAX_C(v) (v ## ULL) |

108 | #endif |

109 | |

110 | /* 7.18.2 Limits of specified-width integer types: |

111 | * These #defines specify the minimum and maximum limits |

112 | * of each of the types declared above. |

113 | * |

114 | * They must have "the same type as would an expression that is an |

115 | * object of the corresponding type converted according to the integer |

116 | * promotion". |

117 | */ |

118 | |

119 | |

120 | /* 7.18.2.1 Limits of exact-width integer types */ |

121 | #define INT8_MAX 127 |

122 | #define INT16_MAX 32767 |

123 | #define INT32_MAX 2147483647 |

124 | #define INT64_MAX 9223372036854775807LL |

125 | |

126 | #define INT8_MIN -128 |

127 | #define INT16_MIN -32768 |

128 | /* |

129 | * Note: the literal "most negative int" cannot be written in C -- |

130 | * the rules in the standard (section 6.4.4.1 in C99) will give it |

131 | * an unsigned type, so INT32_MIN (and the most negative member of |

132 | * any larger signed type) must be written via a constant expression. |

133 | */ |

134 | #define INT32_MIN (-INT32_MAX-1) |

135 | #define INT64_MIN (-INT64_MAX-1) |

136 | |

137 | #define UINT8_MAX 255 |

138 | #define UINT16_MAX 65535 |

139 | #define UINT32_MAX 4294967295U |

140 | #define UINT64_MAX 18446744073709551615ULL |

141 | |

142 | /* 7.18.2.2 Limits of minimum-width integer types */ |

143 | #define INT_LEAST8_MIN INT8_MIN |

144 | #define INT_LEAST16_MIN INT16_MIN |

145 | #define INT_LEAST32_MIN INT32_MIN |

146 | #define INT_LEAST64_MIN INT64_MIN |

147 | |

148 | #define INT_LEAST8_MAX INT8_MAX |

149 | #define INT_LEAST16_MAX INT16_MAX |

150 | #define INT_LEAST32_MAX INT32_MAX |

151 | #define INT_LEAST64_MAX INT64_MAX |

152 | |

153 | #define UINT_LEAST8_MAX UINT8_MAX |

154 | #define UINT_LEAST16_MAX UINT16_MAX |

155 | #define UINT_LEAST32_MAX UINT32_MAX |

156 | #define UINT_LEAST64_MAX UINT64_MAX |

157 | |

158 | /* 7.18.2.3 Limits of fastest minimum-width integer types */ |

159 | #define INT_FAST8_MIN INT8_MIN |

160 | #define INT_FAST16_MIN INT16_MIN |

161 | #define INT_FAST32_MIN INT32_MIN |

162 | #define INT_FAST64_MIN INT64_MIN |

163 | |

164 | #define INT_FAST8_MAX INT8_MAX |

165 | #define INT_FAST16_MAX INT16_MAX |

166 | #define INT_FAST32_MAX INT32_MAX |

167 | #define INT_FAST64_MAX INT64_MAX |

168 | |

169 | #define UINT_FAST8_MAX UINT8_MAX |

170 | #define UINT_FAST16_MAX UINT16_MAX |

171 | #define UINT_FAST32_MAX UINT32_MAX |

172 | #define UINT_FAST64_MAX UINT64_MAX |

173 | |

174 | /* 7.18.2.4 Limits of integer types capable of holding object pointers */ |

175 | |

176 | #if __WORDSIZE == 64 |

177 | #define INTPTR_MAX 9223372036854775807L |

178 | #else |

179 | #define INTPTR_MAX 2147483647L |

180 | #endif |

181 | #define INTPTR_MIN (-INTPTR_MAX-1) |

182 | |

183 | #if __WORDSIZE == 64 |

184 | #define UINTPTR_MAX 18446744073709551615UL |

185 | #else |

186 | #define UINTPTR_MAX 4294967295UL |

187 | #endif |

188 | |

189 | /* 7.18.2.5 Limits of greatest-width integer types */ |

190 | #define INTMAX_MAX INTMAX_C(9223372036854775807) |

191 | #define UINTMAX_MAX UINTMAX_C(18446744073709551615) |

192 | #define INTMAX_MIN (-INTMAX_MAX-1) |

193 | |

194 | /* 7.18.3 "Other" */ |

195 | #if __WORDSIZE == 64 |

196 | #define PTRDIFF_MIN INTMAX_MIN |

197 | #define PTRDIFF_MAX INTMAX_MAX |

198 | #else |

199 | #define PTRDIFF_MIN INT32_MIN |

200 | #define PTRDIFF_MAX INT32_MAX |

201 | #endif |

202 | |

203 | #define SIZE_MAX UINTPTR_MAX |

204 | |

205 | #if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 |

206 | #define RSIZE_MAX (SIZE_MAX >> 1) |

207 | #endif |

208 | |

209 | #ifndef WCHAR_MAX |

210 | # ifdef __WCHAR_MAX__ |

211 | # define WCHAR_MAX __WCHAR_MAX__ |

212 | # else |

213 | # define WCHAR_MAX 0x7fffffff |

214 | # endif |

215 | #endif |

216 | |

217 | /* WCHAR_MIN should be 0 if wchar_t is an unsigned type and |

218 | * (-WCHAR_MAX-1) if wchar_t is a signed type. Unfortunately, |

219 | * it turns out that -fshort-wchar changes the signedness of |

220 | * the type. */ |

221 | #ifndef WCHAR_MIN |

222 | # if WCHAR_MAX == 0xffff |

223 | # define WCHAR_MIN 0 |

224 | # else |

225 | # define WCHAR_MIN (-WCHAR_MAX-1) |

226 | # endif |

227 | #endif |

228 | |

229 | #define WINT_MIN INT32_MIN |

230 | #define WINT_MAX INT32_MAX |

231 | |

232 | #define SIG_ATOMIC_MIN INT32_MIN |

233 | #define SIG_ATOMIC_MAX INT32_MAX |

234 | |

235 | #endif /* KERNEL */ |

236 | |

237 | #endif /* _KERNEL_STDINT_H_ */ |

238 | |

239 | #endif |

240 |