Subversion Repositories Kolibri OS

Rev

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