Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

467 linhas
12KB

  1. /*
  2. * Copyright (c) 2004, 2005 by
  3. * Ralf Corsepius, Ulm/Germany. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and distribute this software
  6. * is freely granted, provided that this notice is preserved.
  7. */
  8. #ifndef _STDINT_H
  9. #define _STDINT_H
  10. #include <machine/_default_types.h>
  11. #include <sys/_intsup.h>
  12. #include <sys/_stdint.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #ifdef ___int_least8_t_defined
  17. typedef __int_least8_t int_least8_t;
  18. typedef __uint_least8_t uint_least8_t;
  19. #define __int_least8_t_defined 1
  20. #endif
  21. #ifdef ___int_least16_t_defined
  22. typedef __int_least16_t int_least16_t;
  23. typedef __uint_least16_t uint_least16_t;
  24. #define __int_least16_t_defined 1
  25. #endif
  26. #ifdef ___int_least32_t_defined
  27. typedef __int_least32_t int_least32_t;
  28. typedef __uint_least32_t uint_least32_t;
  29. #define __int_least32_t_defined 1
  30. #endif
  31. #ifdef ___int_least64_t_defined
  32. typedef __int_least64_t int_least64_t;
  33. typedef __uint_least64_t uint_least64_t;
  34. #define __int_least64_t_defined 1
  35. #endif
  36. /*
  37. * Fastest minimum-width integer types
  38. *
  39. * Assume int to be the fastest type for all types with a width
  40. * less than __INT_MAX__ rsp. INT_MAX
  41. */
  42. #ifdef __INT_FAST8_TYPE__
  43. typedef __INT_FAST8_TYPE__ int_fast8_t;
  44. typedef __UINT_FAST8_TYPE__ uint_fast8_t;
  45. #define __int_fast8_t_defined 1
  46. #elif __STDINT_EXP(INT_MAX) >= 0x7f
  47. typedef signed int int_fast8_t;
  48. typedef unsigned int uint_fast8_t;
  49. #define __int_fast8_t_defined 1
  50. #endif
  51. #ifdef __INT_FAST16_TYPE__
  52. typedef __INT_FAST16_TYPE__ int_fast16_t;
  53. typedef __UINT_FAST16_TYPE__ uint_fast16_t;
  54. #define __int_fast16_t_defined 1
  55. #elif __STDINT_EXP(INT_MAX) >= 0x7fff
  56. typedef signed int int_fast16_t;
  57. typedef unsigned int uint_fast16_t;
  58. #define __int_fast16_t_defined 1
  59. #endif
  60. #ifdef __INT_FAST32_TYPE__
  61. typedef __INT_FAST32_TYPE__ int_fast32_t;
  62. typedef __UINT_FAST32_TYPE__ uint_fast32_t;
  63. #define __int_fast32_t_defined 1
  64. #elif __STDINT_EXP(INT_MAX) >= 0x7fffffff
  65. typedef signed int int_fast32_t;
  66. typedef unsigned int uint_fast32_t;
  67. #define __int_fast32_t_defined 1
  68. #endif
  69. #ifdef __INT_FAST64_TYPE__
  70. typedef __INT_FAST64_TYPE__ int_fast64_t;
  71. typedef __UINT_FAST64_TYPE__ uint_fast64_t;
  72. #define __int_fast64_t_defined 1
  73. #elif __STDINT_EXP(INT_MAX) > 0x7fffffff
  74. typedef signed int int_fast64_t;
  75. typedef unsigned int uint_fast64_t;
  76. #define __int_fast64_t_defined 1
  77. #endif
  78. /*
  79. * Fall back to [u]int_least<N>_t for [u]int_fast<N>_t types
  80. * not having been defined, yet.
  81. * Leave undefined, if [u]int_least<N>_t should not be available.
  82. */
  83. #if !__int_fast8_t_defined
  84. #if __int_least8_t_defined
  85. typedef int_least8_t int_fast8_t;
  86. typedef uint_least8_t uint_fast8_t;
  87. #define __int_fast8_t_defined 1
  88. #endif
  89. #endif
  90. #if !__int_fast16_t_defined
  91. #if __int_least16_t_defined
  92. typedef int_least16_t int_fast16_t;
  93. typedef uint_least16_t uint_fast16_t;
  94. #define __int_fast16_t_defined 1
  95. #endif
  96. #endif
  97. #if !__int_fast32_t_defined
  98. #if __int_least32_t_defined
  99. typedef int_least32_t int_fast32_t;
  100. typedef uint_least32_t uint_fast32_t;
  101. #define __int_fast32_t_defined 1
  102. #endif
  103. #endif
  104. #if !__int_fast64_t_defined
  105. #if __int_least64_t_defined
  106. typedef int_least64_t int_fast64_t;
  107. typedef uint_least64_t uint_fast64_t;
  108. #define __int_fast64_t_defined 1
  109. #endif
  110. #endif
  111. #ifdef __INTPTR_TYPE__
  112. #define INTPTR_MIN (-__INTPTR_MAX__ - 1)
  113. #define INTPTR_MAX (__INTPTR_MAX__)
  114. #define UINTPTR_MAX (__UINTPTR_MAX__)
  115. #elif defined(__PTRDIFF_TYPE__)
  116. #define INTPTR_MAX PTRDIFF_MAX
  117. #define INTPTR_MIN PTRDIFF_MIN
  118. #ifdef __UINTPTR_MAX__
  119. #define UINTPTR_MAX (__UINTPTR_MAX__)
  120. #else
  121. #define UINTPTR_MAX (2UL * PTRDIFF_MAX + 1)
  122. #endif
  123. #else
  124. /*
  125. * Fallback to hardcoded values,
  126. * should be valid on cpu's with 32bit int/32bit void*
  127. */
  128. #define INTPTR_MAX (__STDINT_EXP(LONG_MAX))
  129. #define INTPTR_MIN (-__STDINT_EXP(LONG_MAX) - 1)
  130. #define UINTPTR_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1)
  131. #endif
  132. /* Limits of Specified-Width Integer Types */
  133. #ifdef __INT8_MAX__
  134. #define INT8_MIN (-__INT8_MAX__ - 1)
  135. #define INT8_MAX (__INT8_MAX__)
  136. #define UINT8_MAX (__UINT8_MAX__)
  137. #elif defined(__int8_t_defined)
  138. #define INT8_MIN (-128)
  139. #define INT8_MAX (127)
  140. #define UINT8_MAX (255)
  141. #endif
  142. #ifdef __INT_LEAST8_MAX__
  143. #define INT_LEAST8_MIN (-__INT_LEAST8_MAX__ - 1)
  144. #define INT_LEAST8_MAX (__INT_LEAST8_MAX__)
  145. #define UINT_LEAST8_MAX (__UINT_LEAST8_MAX__)
  146. #elif defined(__int_least8_t_defined)
  147. #define INT_LEAST8_MIN (-128)
  148. #define INT_LEAST8_MAX (127)
  149. #define UINT_LEAST8_MAX (255)
  150. #else
  151. #error required type int_least8_t missing
  152. #endif
  153. #ifdef __INT16_MAX__
  154. #define INT16_MIN (-__INT16_MAX__ - 1)
  155. #define INT16_MAX (__INT16_MAX__)
  156. #define UINT16_MAX (__UINT16_MAX__)
  157. #elif defined(__int16_t_defined)
  158. #define INT16_MIN (-32768)
  159. #define INT16_MAX (32767)
  160. #define UINT16_MAX (65535)
  161. #endif
  162. #ifdef __INT_LEAST16_MAX__
  163. #define INT_LEAST16_MIN (-__INT_LEAST16_MAX__ - 1)
  164. #define INT_LEAST16_MAX (__INT_LEAST16_MAX__)
  165. #define UINT_LEAST16_MAX (__UINT_LEAST16_MAX__)
  166. #elif defined(__int_least16_t_defined)
  167. #define INT_LEAST16_MIN (-32768)
  168. #define INT_LEAST16_MAX (32767)
  169. #define UINT_LEAST16_MAX (65535)
  170. #else
  171. #error required type int_least16_t missing
  172. #endif
  173. #ifdef __INT32_MAX__
  174. #define INT32_MIN (-__INT32_MAX__ - 1)
  175. #define INT32_MAX (__INT32_MAX__)
  176. #define UINT32_MAX (__UINT32_MAX__)
  177. #elif defined(__int32_t_defined)
  178. #if defined (_INT32_EQ_LONG)
  179. #define INT32_MIN (-2147483647L-1)
  180. #define INT32_MAX (2147483647L)
  181. #define UINT32_MAX (4294967295UL)
  182. #else
  183. #define INT32_MIN (-2147483647-1)
  184. #define INT32_MAX (2147483647)
  185. #define UINT32_MAX (4294967295U)
  186. #endif
  187. #endif
  188. #ifdef __INT_LEAST32_MAX__
  189. #define INT_LEAST32_MIN (-__INT_LEAST32_MAX__ - 1)
  190. #define INT_LEAST32_MAX (__INT_LEAST32_MAX__)
  191. #define UINT_LEAST32_MAX (__UINT_LEAST32_MAX__)
  192. #elif defined(__int_least32_t_defined)
  193. #if defined (_INT32_EQ_LONG)
  194. #define INT_LEAST32_MIN (-2147483647L-1)
  195. #define INT_LEAST32_MAX (2147483647L)
  196. #define UINT_LEAST32_MAX (4294967295UL)
  197. #else
  198. #define INT_LEAST32_MIN (-2147483647-1)
  199. #define INT_LEAST32_MAX (2147483647)
  200. #define UINT_LEAST32_MAX (4294967295U)
  201. #endif
  202. #else
  203. #error required type int_least32_t missing
  204. #endif
  205. #ifdef __INT64_MAX__
  206. #define INT64_MIN (-__INT64_MAX__ - 1)
  207. #define INT64_MAX (__INT64_MAX__)
  208. #define UINT64_MAX (__UINT64_MAX__)
  209. #elif defined(__int64_t_defined)
  210. #if __have_long64
  211. #define INT64_MIN (-9223372036854775807L-1L)
  212. #define INT64_MAX (9223372036854775807L)
  213. #define UINT64_MAX (18446744073709551615U)
  214. #elif __have_longlong64
  215. #define INT64_MIN (-9223372036854775807LL-1LL)
  216. #define INT64_MAX (9223372036854775807LL)
  217. #define UINT64_MAX (18446744073709551615ULL)
  218. #endif
  219. #endif
  220. #ifdef __INT_LEAST64_MAX__
  221. #define INT_LEAST64_MIN (-__INT_LEAST64_MAX__ - 1)
  222. #define INT_LEAST64_MAX (__INT_LEAST64_MAX__)
  223. #define UINT_LEAST64_MAX (__UINT_LEAST64_MAX__)
  224. #elif defined(__int_least64_t_defined)
  225. #if __have_long64
  226. #define INT_LEAST64_MIN (-9223372036854775807L-1L)
  227. #define INT_LEAST64_MAX (9223372036854775807L)
  228. #define UINT_LEAST64_MAX (18446744073709551615U)
  229. #elif __have_longlong64
  230. #define INT_LEAST64_MIN (-9223372036854775807LL-1LL)
  231. #define INT_LEAST64_MAX (9223372036854775807LL)
  232. #define UINT_LEAST64_MAX (18446744073709551615ULL)
  233. #endif
  234. #endif
  235. #ifdef __INT_FAST8_MAX__
  236. #define INT_FAST8_MIN (-__INT_FAST8_MAX__ - 1)
  237. #define INT_FAST8_MAX (__INT_FAST8_MAX__)
  238. #define UINT_FAST8_MAX (__UINT_FAST8_MAX__)
  239. #elif defined(__int_fast8_t_defined)
  240. #if __STDINT_EXP(INT_MAX) >= 0x7f
  241. #define INT_FAST8_MIN (-__STDINT_EXP(INT_MAX)-1)
  242. #define INT_FAST8_MAX (__STDINT_EXP(INT_MAX))
  243. #define UINT_FAST8_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
  244. #else
  245. #define INT_FAST8_MIN INT_LEAST8_MIN
  246. #define INT_FAST8_MAX INT_LEAST8_MAX
  247. #define UINT_FAST8_MAX UINT_LEAST8_MAX
  248. #endif
  249. #endif
  250. #ifdef __INT_FAST16_MAX__
  251. #define INT_FAST16_MIN (-__INT_FAST16_MAX__ - 1)
  252. #define INT_FAST16_MAX (__INT_FAST16_MAX__)
  253. #define UINT_FAST16_MAX (__UINT_FAST16_MAX__)
  254. #elif defined(__int_fast16_t_defined)
  255. #if __STDINT_EXP(INT_MAX) >= 0x7fff
  256. #define INT_FAST16_MIN (-__STDINT_EXP(INT_MAX)-1)
  257. #define INT_FAST16_MAX (__STDINT_EXP(INT_MAX))
  258. #define UINT_FAST16_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
  259. #else
  260. #define INT_FAST16_MIN INT_LEAST16_MIN
  261. #define INT_FAST16_MAX INT_LEAST16_MAX
  262. #define UINT_FAST16_MAX UINT_LEAST16_MAX
  263. #endif
  264. #endif
  265. #ifdef __INT_FAST32_MAX__
  266. #define INT_FAST32_MIN (-__INT_FAST32_MAX__ - 1)
  267. #define INT_FAST32_MAX (__INT_FAST32_MAX__)
  268. #define UINT_FAST32_MAX (__UINT_FAST32_MAX__)
  269. #elif defined(__int_fast32_t_defined)
  270. #if __STDINT_EXP(INT_MAX) >= 0x7fffffff
  271. #define INT_FAST32_MIN (-__STDINT_EXP(INT_MAX)-1)
  272. #define INT_FAST32_MAX (__STDINT_EXP(INT_MAX))
  273. #define UINT_FAST32_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
  274. #else
  275. #define INT_FAST32_MIN INT_LEAST32_MIN
  276. #define INT_FAST32_MAX INT_LEAST32_MAX
  277. #define UINT_FAST32_MAX UINT_LEAST32_MAX
  278. #endif
  279. #endif
  280. #ifdef __INT_FAST64_MAX__
  281. #define INT_FAST64_MIN (-__INT_FAST64_MAX__ - 1)
  282. #define INT_FAST64_MAX (__INT_FAST64_MAX__)
  283. #define UINT_FAST64_MAX (__UINT_FAST64_MAX__)
  284. #elif defined(__int_fast64_t_defined)
  285. #if __STDINT_EXP(INT_MAX) > 0x7fffffff
  286. #define INT_FAST64_MIN (-__STDINT_EXP(INT_MAX)-1)
  287. #define INT_FAST64_MAX (__STDINT_EXP(INT_MAX))
  288. #define UINT_FAST64_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
  289. #else
  290. #define INT_FAST64_MIN INT_LEAST64_MIN
  291. #define INT_FAST64_MAX INT_LEAST64_MAX
  292. #define UINT_FAST64_MAX UINT_LEAST64_MAX
  293. #endif
  294. #endif
  295. #ifdef __INTMAX_MAX__
  296. #define INTMAX_MAX (__INTMAX_MAX__)
  297. #define INTMAX_MIN (-INTMAX_MAX - 1)
  298. #elif defined(__INTMAX_TYPE__)
  299. /* All relevant GCC versions prefer long to long long for intmax_t. */
  300. #define INTMAX_MAX INT64_MAX
  301. #define INTMAX_MIN INT64_MIN
  302. #endif
  303. #ifdef __UINTMAX_MAX__
  304. #define UINTMAX_MAX (__UINTMAX_MAX__)
  305. #elif defined(__UINTMAX_TYPE__)
  306. /* All relevant GCC versions prefer long to long long for intmax_t. */
  307. #define UINTMAX_MAX UINT64_MAX
  308. #endif
  309. /* This must match size_t in stddef.h, currently long unsigned int */
  310. #ifdef __SIZE_MAX__
  311. #define SIZE_MAX (__SIZE_MAX__)
  312. #else
  313. #define SIZE_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1)
  314. #endif
  315. /* This must match sig_atomic_t in <signal.h> (currently int) */
  316. #define SIG_ATOMIC_MIN (-__STDINT_EXP(INT_MAX) - 1)
  317. #define SIG_ATOMIC_MAX (__STDINT_EXP(INT_MAX))
  318. /* This must match ptrdiff_t in <stddef.h> (currently long int) */
  319. #ifdef __PTRDIFF_MAX__
  320. #define PTRDIFF_MAX (__PTRDIFF_MAX__)
  321. #else
  322. #define PTRDIFF_MAX (__STDINT_EXP(LONG_MAX))
  323. #endif
  324. #define PTRDIFF_MIN (-PTRDIFF_MAX - 1)
  325. /* This must match definition in <wchar.h> */
  326. #ifndef WCHAR_MIN
  327. #ifdef __WCHAR_MIN__
  328. #define WCHAR_MIN (__WCHAR_MIN__)
  329. #elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0)
  330. #define WCHAR_MIN (0 + L'\0')
  331. #else
  332. #define WCHAR_MIN (-0x7fffffff - 1 + L'\0')
  333. #endif
  334. #endif
  335. /* This must match definition in <wchar.h> */
  336. #ifndef WCHAR_MAX
  337. #ifdef __WCHAR_MAX__
  338. #define WCHAR_MAX (__WCHAR_MAX__)
  339. #elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0)
  340. #define WCHAR_MAX (0xffffffffu + L'\0')
  341. #else
  342. #define WCHAR_MAX (0x7fffffff + L'\0')
  343. #endif
  344. #endif
  345. /* wint_t is unsigned int on almost all GCC targets. */
  346. #ifdef __WINT_MAX__
  347. #define WINT_MAX (__WINT_MAX__)
  348. #else
  349. #define WINT_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U)
  350. #endif
  351. #ifdef __WINT_MIN__
  352. #define WINT_MIN (__WINT_MIN__)
  353. #else
  354. #define WINT_MIN (0U)
  355. #endif
  356. /** Macros for minimum-width integer constant expressions */
  357. #ifdef __INT8_C
  358. #define INT8_C(x) __INT8_C(x)
  359. #define UINT8_C(x) __UINT8_C(x)
  360. #else
  361. #define INT8_C(x) x
  362. #if __STDINT_EXP(INT_MAX) > 0x7f
  363. #define UINT8_C(x) x
  364. #else
  365. #define UINT8_C(x) x##U
  366. #endif
  367. #endif
  368. #ifdef __INT16_C
  369. #define INT16_C(x) __INT16_C(x)
  370. #define UINT16_C(x) __UINT16_C(x)
  371. #else
  372. #define INT16_C(x) x
  373. #if __STDINT_EXP(INT_MAX) > 0x7fff
  374. #define UINT16_C(x) x
  375. #else
  376. #define UINT16_C(x) x##U
  377. #endif
  378. #endif
  379. #ifdef __INT32_C
  380. #define INT32_C(x) __INT32_C(x)
  381. #define UINT32_C(x) __UINT32_C(x)
  382. #else
  383. #if defined (_INT32_EQ_LONG)
  384. #define INT32_C(x) x##L
  385. #define UINT32_C(x) x##UL
  386. #else
  387. #define INT32_C(x) x
  388. #define UINT32_C(x) x##U
  389. #endif
  390. #endif
  391. #ifdef __INT64_C
  392. #define INT64_C(x) __INT64_C(x)
  393. #define UINT64_C(x) __UINT64_C(x)
  394. #else
  395. #if __int64_t_defined
  396. #if __have_long64
  397. #define INT64_C(x) x##L
  398. #define UINT64_C(x) x##UL
  399. #else
  400. #define INT64_C(x) x##LL
  401. #define UINT64_C(x) x##ULL
  402. #endif
  403. #endif
  404. #endif
  405. /** Macros for greatest-width integer constant expression */
  406. #ifdef __INTMAX_C
  407. #define INTMAX_C(x) __INTMAX_C(x)
  408. #define UINTMAX_C(x) __UINTMAX_C(x)
  409. #else
  410. #if __have_long64
  411. #define INTMAX_C(x) x##L
  412. #define UINTMAX_C(x) x##UL
  413. #else
  414. #define INTMAX_C(x) x##LL
  415. #define UINTMAX_C(x) x##ULL
  416. #endif
  417. #endif
  418. #ifdef __cplusplus
  419. }
  420. #endif
  421. #endif /* _STDINT_H */