Subversion Repositories Kolibri OS

Rev

Rev 4874 | Rev 4930 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  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.  
  9. #ifndef _STDINT_H
  10. #define _STDINT_H
  11.  
  12. #include <machine/_default_types.h>
  13.  
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17.  
  18. #if __GNUC_PREREQ (3, 2)
  19. /* gcc > 3.2 implicitly defines the values we are interested */
  20. #define __STDINT_EXP(x) __##x##__
  21. #else
  22. #define __STDINT_EXP(x) x
  23. #include <limits.h>
  24. #endif
  25.  
  26. /* Check if "long long" is 64bit wide */
  27. /* Modern GCCs provide __LONG_LONG_MAX__, SUSv3 wants LLONG_MAX */
  28. #if ( defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff) ) \
  29.   || ( defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff) )
  30. #define __have_longlong64 1
  31. #endif
  32.  
  33. /* Check if "long" is 64bit or 32bit wide */
  34. #if __STDINT_EXP(LONG_MAX) > 0x7fffffff
  35. #define __have_long64 1
  36. #elif __STDINT_EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__)
  37. #define __have_long32 1
  38. #endif
  39.  
  40. #ifdef ___int8_t_defined
  41. typedef __int8_t int8_t ;
  42. typedef __uint8_t uint8_t ;
  43. #define __int8_t_defined 1
  44. #endif
  45.  
  46. #ifdef ___int_least8_t_defined
  47. typedef __int_least8_t int_least8_t;
  48. typedef __uint_least8_t uint_least8_t;
  49. #define __int_least8_t_defined 1
  50. #endif
  51.  
  52. #ifdef ___int16_t_defined
  53. typedef __int16_t int16_t ;
  54. typedef __uint16_t uint16_t ;
  55. #define __int16_t_defined 1
  56. #endif
  57.  
  58. #ifdef ___int_least16_t_defined
  59. typedef __int_least16_t int_least16_t;
  60. typedef __uint_least16_t uint_least16_t;
  61. #define __int_least16_t_defined 1
  62. #endif
  63.  
  64. #ifdef ___int32_t_defined
  65. typedef __int32_t int32_t ;
  66. typedef __uint32_t uint32_t ;
  67. #define __int32_t_defined 1
  68. #endif
  69.  
  70. #ifdef ___int_least32_t_defined
  71. typedef __int_least32_t int_least32_t;
  72. typedef __uint_least32_t uint_least32_t;
  73. #define __int_least32_t_defined 1
  74. #endif
  75.  
  76. #ifdef ___int64_t_defined
  77. typedef __int64_t int64_t ;
  78. typedef __uint64_t uint64_t ;
  79. #define __int64_t_defined 1
  80. #endif
  81.  
  82. #ifdef ___int_least64_t_defined
  83. typedef __int_least64_t int_least64_t;
  84. typedef __uint_least64_t uint_least64_t;
  85. #define __int_least64_t_defined 1
  86. #endif
  87.  
  88. /*
  89.  * Fastest minimum-width integer types
  90.  *
  91.  * Assume int to be the fastest type for all types with a width
  92.  * less than __INT_MAX__ rsp. INT_MAX
  93.  */
  94. #ifdef __INT_FAST8_TYPE__
  95.   typedef __INT_FAST8_TYPE__ int_fast8_t;
  96.   typedef __UINT_FAST8_TYPE__ uint_fast8_t;
  97. #define __int_fast8_t_defined 1
  98. #elif __STDINT_EXP(INT_MAX) >= 0x7f
  99.   typedef signed int int_fast8_t;
  100.   typedef unsigned int uint_fast8_t;
  101. #define __int_fast8_t_defined 1
  102. #endif
  103.  
  104. #ifdef __INT_FAST16_TYPE__
  105.   typedef __INT_FAST16_TYPE__ int_fast16_t;
  106.   typedef __UINT_FAST16_TYPE__ uint_fast16_t;
  107. #define __int_fast16_t_defined 1
  108. #elif __STDINT_EXP(INT_MAX) >= 0x7fff
  109.   typedef signed int int_fast16_t;
  110.   typedef unsigned int uint_fast16_t;
  111. #define __int_fast16_t_defined 1
  112. #endif
  113.  
  114. #ifdef __INT_FAST32_TYPE__
  115.   typedef __INT_FAST32_TYPE__ int_fast32_t;
  116.   typedef __UINT_FAST32_TYPE__ uint_fast32_t;
  117. #define __int_fast32_t_defined 1
  118. #elif __STDINT_EXP(INT_MAX) >= 0x7fffffff
  119.   typedef signed int int_fast32_t;
  120.   typedef unsigned int uint_fast32_t;
  121. #define __int_fast32_t_defined 1
  122. #endif
  123.  
  124. #ifdef __INT_FAST64_TYPE__
  125.   typedef __INT_FAST64_TYPE__ int_fast64_t;
  126.   typedef __UINT_FAST64_TYPE__ uint_fast64_t;
  127. #define __int_fast64_t_defined 1
  128. #elif __STDINT_EXP(INT_MAX) > 0x7fffffff
  129.   typedef signed int int_fast64_t;
  130.   typedef unsigned int uint_fast64_t;
  131. #define __int_fast64_t_defined 1
  132. #endif
  133.  
  134. /*
  135.  * Fall back to [u]int_least<N>_t for [u]int_fast<N>_t types
  136.  * not having been defined, yet.
  137.  * Leave undefined, if [u]int_least<N>_t should not be available.
  138.  */
  139. #if !__int_fast8_t_defined
  140. #if __int_least8_t_defined
  141.   typedef int_least8_t int_fast8_t;
  142.   typedef uint_least8_t uint_fast8_t;
  143. #define __int_fast8_t_defined 1
  144. #endif
  145. #endif
  146.  
  147. #if !__int_fast16_t_defined
  148. #if __int_least16_t_defined
  149.   typedef int_least16_t int_fast16_t;
  150.   typedef uint_least16_t uint_fast16_t;
  151. #define __int_fast16_t_defined 1
  152. #endif
  153. #endif
  154.  
  155. #if !__int_fast32_t_defined
  156. #if __int_least32_t_defined
  157.   typedef int_least32_t int_fast32_t;
  158.   typedef uint_least32_t uint_fast32_t;
  159. #define __int_fast32_t_defined 1
  160. #endif
  161. #endif
  162.  
  163. #if !__int_fast64_t_defined
  164. #if __int_least64_t_defined
  165.   typedef int_least64_t int_fast64_t;
  166.   typedef uint_least64_t uint_fast64_t;
  167. #define __int_fast64_t_defined 1
  168. #endif
  169. #endif
  170.  
  171. /* Greatest-width integer types */
  172. /* Modern GCCs provide __INTMAX_TYPE__ */
  173. #if defined(__INTMAX_TYPE__)
  174.   typedef __INTMAX_TYPE__ intmax_t;
  175. #elif __have_longlong64
  176.   typedef signed long long intmax_t;
  177. #else
  178.   typedef signed long intmax_t;
  179. #endif
  180.  
  181. /* Modern GCCs provide __UINTMAX_TYPE__ */
  182. #if defined(__UINTMAX_TYPE__)
  183.   typedef __UINTMAX_TYPE__ uintmax_t;
  184. #elif __have_longlong64
  185.   typedef unsigned long long uintmax_t;
  186. #else
  187.   typedef unsigned long uintmax_t;
  188. #endif
  189.  
  190. typedef __intptr_t intptr_t;
  191. typedef __uintptr_t uintptr_t;
  192.  
  193. #ifdef __INTPTR_TYPE__
  194. #define INTPTR_MIN (-__INTPTR_MAX__ - 1)
  195. #define INTPTR_MAX __INTPTR_MAX__
  196. #define UINTPTR_MAX __UINTPTR_MAX__
  197. #elif defined(__PTRDIFF_TYPE__)
  198. #define INTPTR_MAX PTRDIFF_MAX
  199. #define INTPTR_MIN PTRDIFF_MIN
  200. #ifdef __UINTPTR_MAX__
  201. #define UINTPTR_MAX __UINTPTR_MAX__
  202. #else
  203. #define UINTPTR_MAX (2UL * PTRDIFF_MAX + 1)
  204. #endif
  205. #else
  206. /*
  207.  * Fallback to hardcoded values,
  208.  * should be valid on cpu's with 32bit int/32bit void*
  209.  */
  210. #define INTPTR_MAX __STDINT_EXP(LONG_MAX)
  211. #define INTPTR_MIN (-__STDINT_EXP(LONG_MAX) - 1)
  212. #define UINTPTR_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1)
  213. #endif
  214.  
  215. /* Limits of Specified-Width Integer Types */
  216.  
  217. #ifdef __INT8_MAX__
  218. #define INT8_MIN (-__INT8_MAX__ - 1)
  219. #define INT8_MAX __INT8_MAX__
  220. #define UINT8_MAX __UINT8_MAX__
  221. #elif defined(__int8_t_defined)
  222. #define INT8_MIN        -128
  223. #define INT8_MAX         127
  224. #define UINT8_MAX        255
  225. #endif
  226.  
  227. #ifdef __INT_LEAST8_MAX__
  228. #define INT_LEAST8_MIN (-__INT_LEAST8_MAX__ - 1)
  229. #define INT_LEAST8_MAX __INT_LEAST8_MAX__
  230. #define UINT_LEAST8_MAX __UINT_LEAST8_MAX__
  231. #elif defined(__int_least8_t_defined)
  232. #define INT_LEAST8_MIN  -128
  233. #define INT_LEAST8_MAX   127
  234. #define UINT_LEAST8_MAX  255
  235. #else
  236. #error required type int_least8_t missing
  237. #endif
  238.  
  239. #ifdef __INT16_MAX__
  240. #define INT16_MIN (-__INT16_MAX__ - 1)
  241. #define INT16_MAX __INT16_MAX__
  242. #define UINT16_MAX __UINT16_MAX__
  243. #elif defined(__int16_t_defined)
  244. #define INT16_MIN       -32768
  245. #define INT16_MAX        32767
  246. #define UINT16_MAX       65535
  247. #endif
  248.  
  249. #ifdef __INT_LEAST16_MAX__
  250. #define INT_LEAST16_MIN (-__INT_LEAST16_MAX__ - 1)
  251. #define INT_LEAST16_MAX __INT_LEAST16_MAX__
  252. #define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
  253. #elif defined(__int_least16_t_defined)
  254. #define INT_LEAST16_MIN -32768
  255. #define INT_LEAST16_MAX  32767
  256. #define UINT_LEAST16_MAX 65535
  257. #else
  258. #error required type int_least16_t missing
  259. #endif
  260.  
  261. #ifdef __INT32_MAX__
  262. #define INT32_MIN (-__INT32_MAX__ - 1)
  263. #define INT32_MAX __INT32_MAX__
  264. #define UINT32_MAX __UINT32_MAX__
  265. #elif defined(__int32_t_defined)
  266. #if __have_long32
  267. #define INT32_MIN        (-2147483647L-1)
  268. #define INT32_MAX        2147483647L
  269. #define UINT32_MAX       4294967295UL
  270. #else
  271. #define INT32_MIN        (-2147483647-1)
  272. #define INT32_MAX        2147483647
  273. #define UINT32_MAX       4294967295U
  274. #endif
  275. #endif
  276.  
  277. #ifdef __INT_LEAST32_MAX__
  278. #define INT_LEAST32_MIN (-__INT_LEAST32_MAX__ - 1)
  279. #define INT_LEAST32_MAX __INT_LEAST32_MAX__
  280. #define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
  281. #elif defined(__int_least32_t_defined)
  282. #if __have_long32
  283. #define INT_LEAST32_MIN  (-2147483647L-1)
  284. #define INT_LEAST32_MAX  2147483647L
  285. #define UINT_LEAST32_MAX 4294967295UL
  286. #else
  287. #define INT_LEAST32_MIN  (-2147483647-1)
  288. #define INT_LEAST32_MAX  2147483647
  289. #define UINT_LEAST32_MAX 4294967295U
  290. #endif
  291. #else
  292. #error required type int_least32_t missing
  293. #endif
  294.  
  295. #ifdef __INT64_MAX__
  296. #define INT64_MIN (-__INT64_MAX__ - 1)
  297. #define INT64_MAX __INT64_MAX__
  298. #define UINT64_MAX __UINT64_MAX__
  299. #elif defined(__int64_t_defined)
  300. #if __have_long64
  301. #define INT64_MIN       (-9223372036854775807L-1L)
  302. #define INT64_MAX        9223372036854775807L
  303. #define UINT64_MAX      18446744073709551615U
  304. #elif __have_longlong64
  305. #define INT64_MIN       (-9223372036854775807LL-1LL)
  306. #define INT64_MAX        9223372036854775807LL
  307. #define UINT64_MAX      18446744073709551615ULL
  308. #endif
  309. #endif
  310.  
  311. #ifdef __INT_LEAST64_MAX__
  312. #define INT_LEAST64_MIN (-__INT_LEAST64_MAX__ - 1)
  313. #define INT_LEAST64_MAX __INT_LEAST64_MAX__
  314. #define UINT_LEAST64_MAX __UINT_LEAST64_MAX__
  315. #elif defined(__int_least64_t_defined)
  316. #if __have_long64
  317. #define INT_LEAST64_MIN  (-9223372036854775807L-1L)
  318. #define INT_LEAST64_MAX  9223372036854775807L
  319. #define UINT_LEAST64_MAX 18446744073709551615U
  320. #elif __have_longlong64
  321. #define INT_LEAST64_MIN  (-9223372036854775807LL-1LL)
  322. #define INT_LEAST64_MAX  9223372036854775807LL
  323. #define UINT_LEAST64_MAX 18446744073709551615ULL
  324. #endif
  325. #endif
  326.  
  327. #ifdef __INT_FAST8_MAX__
  328. #define INT_FAST8_MIN (-__INT_FAST8_MAX__ - 1)
  329. #define INT_FAST8_MAX __INT_FAST8_MAX__
  330. #define UINT_FAST8_MAX __UINT_FAST8_MAX__
  331. #elif defined(__int_fast8_t_defined)
  332. #if __STDINT_EXP(INT_MAX) >= 0x7f
  333. #define INT_FAST8_MIN   (-__STDINT_EXP(INT_MAX)-1)
  334. #define INT_FAST8_MAX   __STDINT_EXP(INT_MAX)
  335. #define UINT_FAST8_MAX  (__STDINT_EXP(INT_MAX)*2U+1U)
  336. #else
  337. #define INT_FAST8_MIN   INT_LEAST8_MIN
  338. #define INT_FAST8_MAX   INT_LEAST8_MAX
  339. #define UINT_FAST8_MAX  UINT_LEAST8_MAX
  340. #endif
  341. #endif
  342.  
  343. #ifdef __INT_FAST16_MAX__
  344. #define INT_FAST16_MIN (-__INT_FAST16_MAX__ - 1)
  345. #define INT_FAST16_MAX __INT_FAST16_MAX__
  346. #define UINT_FAST16_MAX __UINT_FAST16_MAX__
  347. #elif defined(__int_fast16_t_defined)
  348. #if __STDINT_EXP(INT_MAX) >= 0x7fff
  349. #define INT_FAST16_MIN  (-__STDINT_EXP(INT_MAX)-1)
  350. #define INT_FAST16_MAX  __STDINT_EXP(INT_MAX)
  351. #define UINT_FAST16_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
  352. #else
  353. #define INT_FAST16_MIN  INT_LEAST16_MIN
  354. #define INT_FAST16_MAX  INT_LEAST16_MAX
  355. #define UINT_FAST16_MAX UINT_LEAST16_MAX
  356. #endif
  357. #endif
  358.  
  359. #ifdef __INT_FAST32_MAX__
  360. #define INT_FAST32_MIN (-__INT_FAST32_MAX__ - 1)
  361. #define INT_FAST32_MAX __INT_FAST32_MAX__
  362. #define UINT_FAST32_MAX __UINT_FAST32_MAX__
  363. #elif defined(__int_fast32_t_defined)
  364. #if __STDINT_EXP(INT_MAX) >= 0x7fffffff
  365. #define INT_FAST32_MIN  (-__STDINT_EXP(INT_MAX)-1)
  366. #define INT_FAST32_MAX  __STDINT_EXP(INT_MAX)
  367. #define UINT_FAST32_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
  368. #else
  369. #define INT_FAST32_MIN  INT_LEAST32_MIN
  370. #define INT_FAST32_MAX  INT_LEAST32_MAX
  371. #define UINT_FAST32_MAX UINT_LEAST32_MAX
  372. #endif
  373. #endif
  374.  
  375. #ifdef __INT_FAST64_MAX__
  376. #define INT_FAST64_MIN (-__INT_FAST64_MAX__ - 1)
  377. #define INT_FAST64_MAX __INT_FAST64_MAX__
  378. #define UINT_FAST64_MAX __UINT_FAST64_MAX__
  379. #elif defined(__int_fast64_t_defined)
  380. #if __STDINT_EXP(INT_MAX) > 0x7fffffff
  381. #define INT_FAST64_MIN  (-__STDINT_EXP(INT_MAX)-1)
  382. #define INT_FAST64_MAX  __STDINT_EXP(INT_MAX)
  383. #define UINT_FAST64_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
  384. #else
  385. #define INT_FAST64_MIN  INT_LEAST64_MIN
  386. #define INT_FAST64_MAX  INT_LEAST64_MAX
  387. #define UINT_FAST64_MAX UINT_LEAST64_MAX
  388. #endif
  389. #endif
  390.  
  391. #ifdef __INTMAX_MAX__
  392. #define INTMAX_MAX __INTMAX_MAX__
  393. #define INTMAX_MIN (-INTMAX_MAX - 1)
  394. #elif defined(__INTMAX_TYPE__)
  395. /* All relevant GCC versions prefer long to long long for intmax_t.  */
  396. #define INTMAX_MAX INT64_MAX
  397. #define INTMAX_MIN INT64_MIN
  398. #endif
  399.  
  400. #ifdef __UINTMAX_MAX__
  401. #define UINTMAX_MAX __UINTMAX_MAX__
  402. #elif defined(__UINTMAX_TYPE__)
  403. /* All relevant GCC versions prefer long to long long for intmax_t.  */
  404. #define UINTMAX_MAX UINT64_MAX
  405. #endif
  406.  
  407. /* This must match size_t in stddef.h, currently long unsigned int */
  408. #ifdef __SIZE_MAX__
  409. #define SIZE_MAX __SIZE_MAX__
  410. #else
  411. #define SIZE_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1)
  412. #endif
  413.  
  414. /* This must match sig_atomic_t in <signal.h> (currently int) */
  415. #define SIG_ATOMIC_MIN (-__STDINT_EXP(INT_MAX) - 1)
  416. #define SIG_ATOMIC_MAX __STDINT_EXP(INT_MAX)
  417.  
  418. /* This must match ptrdiff_t  in <stddef.h> (currently long int) */
  419. #ifdef __PTRDIFF_MAX__
  420. #define PTRDIFF_MAX __PTRDIFF_MAX__
  421. #else
  422. #define PTRDIFF_MAX __STDINT_EXP(LONG_MAX)
  423. #endif
  424. #define PTRDIFF_MIN (-PTRDIFF_MAX - 1)
  425.  
  426. #ifdef __WCHAR_MAX__
  427. #define WCHAR_MAX __WCHAR_MAX__
  428. #endif
  429. #ifdef __WCHAR_MIN__
  430. #define WCHAR_MIN __WCHAR_MIN__
  431. #endif
  432.  
  433. /* wint_t is unsigned int on almost all GCC targets.  */
  434. #ifdef __WINT_MAX__
  435. #define WINT_MAX __WINT_MAX__
  436. #else
  437. #define WINT_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U)
  438. #endif
  439. #ifdef __WINT_MIN__
  440. #define WINT_MIN __WINT_MIN__
  441. #else
  442. #define WINT_MIN 0U
  443. #endif
  444.  
  445. /** Macros for minimum-width integer constant expressions */
  446. #ifdef __INT8_C
  447. #define INT8_C(x) __INT8_C(x)
  448. #define UINT8_C(x) __UINT8_C(x)
  449. #else
  450. #define INT8_C(x)       x
  451. #if __STDINT_EXP(INT_MAX) > 0x7f
  452. #define UINT8_C(x)      x
  453. #else
  454. #define UINT8_C(x)      x##U
  455. #endif
  456. #endif
  457.  
  458. #ifdef __INT16_C
  459. #define INT16_C(x) __INT16_C(x)
  460. #define UINT16_C(x) __UINT16_C(x)
  461. #else
  462. #define INT16_C(x)      x
  463. #if __STDINT_EXP(INT_MAX) > 0x7fff
  464. #define UINT16_C(x)     x
  465. #else
  466. #define UINT16_C(x)     x##U
  467. #endif
  468. #endif
  469.  
  470. #ifdef __INT32_C
  471. #define INT32_C(x) __INT32_C(x)
  472. #define UINT32_C(x) __UINT32_C(x)
  473. #else
  474. #if __have_long32
  475. #define INT32_C(x)      x##L
  476. #define UINT32_C(x)     x##UL
  477. #else
  478. #define INT32_C(x)      x
  479. #define UINT32_C(x)     x##U
  480. #endif
  481. #endif
  482.  
  483. #ifdef __INT64_C
  484. #define INT64_C(x) __INT64_C(x)
  485. #define UINT64_C(x) __UINT64_C(x)
  486. #else
  487. #if __int64_t_defined
  488. #if __have_long64
  489. #define INT64_C(x)      x##L
  490. #define UINT64_C(x)     x##UL
  491. #else
  492. #define INT64_C(x)      x##LL
  493. #define UINT64_C(x)     x##ULL
  494. #endif
  495. #endif
  496. #endif
  497.  
  498. /** Macros for greatest-width integer constant expression */
  499. #ifdef __INTMAX_C
  500. #define INTMAX_C(x) __INTMAX_C(x)
  501. #define UINTMAX_C(x) __UINTMAX_C(x)
  502. #else
  503. #if __have_long64
  504. #define INTMAX_C(x)     x##L
  505. #define UINTMAX_C(x)    x##UL
  506. #else
  507. #define INTMAX_C(x)     x##LL
  508. #define UINTMAX_C(x)    x##ULL
  509. #endif
  510. #endif
  511.  
  512.  
  513. #ifdef __cplusplus
  514. }
  515. #endif
  516.  
  517. #endif /* _STDINT_H */
  518.