stdint.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /* A portable stdint.h
  2. *
  3. * Copyright (c) 2005 Paul Hsieh
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * Redistributions in binary form must not misrepresent the orignal
  13. * source in the documentation and/or other materials provided
  14. * with the distribution.
  15. *
  16. * The names of the authors not its contributors may be used to
  17. * endorse or promote products derived from this software without
  18. * specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  24. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  26. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  29. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  31. * OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ****************************************************************************
  34. *
  35. * Version 0.1.5
  36. *
  37. * The ANSI C standard committee, for the C99 standard, specified the
  38. * inclusion of a new standard include file called stdint.h. This is
  39. * a very useful and long desired include file which contains several
  40. * very precise definitions for integer scalar types that is
  41. * critically important for making portable several classes of
  42. * applications including cryptography, hashing, variable length
  43. * integer libraries and so on. But for most developers its likely
  44. * useful just for programming sanity.
  45. *
  46. * The problem is that most compiler vendors have decided not to
  47. * implement the C99 standard, and the next C++ language standard
  48. * (which has a lot more mindshare these days) will be a long time in
  49. * coming and its unknown whether or not it will include stdint.h or
  50. * how much adoption it will have. Either way, it will be a long time
  51. * before all compilers come with a stdint.h and it also does nothing
  52. * for the extremely large number of compilers available today which
  53. * do not include this file, or anything comparable to it.
  54. *
  55. * So that's what this file is all about. Its an attempt to build a
  56. * single universal include file that works on as many platforms as
  57. * possible to deliver what stdint.h is supposed to. A few things
  58. * that should be noted about this file:
  59. *
  60. * 1) It is not guaranteed to be portable and/or present an identical
  61. * interface on all platforms. The extreme variability of the
  62. * ANSI C standard makes this an impossibility right from the
  63. * very get go. Its really only meant to be useful for the vast
  64. * majority of platforms that possess the capability of
  65. * implementing usefully and precisely defined, standard sized
  66. * integer scalars. Systems which are not intrinsically 2s
  67. * complement may produce invalid constants.
  68. *
  69. * 2) There is an unavoidable use of non-reserved symbols.
  70. *
  71. * 3) Other standard include files are invoked.
  72. *
  73. * 4) This file may come in conflict with future platforms that do
  74. * include stdint.h. The hope is that one or the other can be
  75. * used with no real difference.
  76. *
  77. * 5) In the current verison, if your platform can't represent
  78. * int32_t, int16_t and int8_t, it just dumps out with a compiler
  79. * error.
  80. *
  81. * 6) 64 bit integers may or may not be defined. Test for their
  82. * presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX.
  83. * Note that this is different from the C99 specification which
  84. * requires the existence of 64 bit support in the compiler. If
  85. * this is not defined for your platform, yet it is capable of
  86. * dealing with 64 bits then it is because this file has not yet
  87. * been extended to cover all of your system's capabilities.
  88. *
  89. * 7) (u)intptr_t may or may not be defined. Test for its presence
  90. * with the test: #ifdef PTRDIFF_MAX. If this is not defined
  91. * for your platform, then it is because this file has not yet
  92. * been extended to cover all of your system's capabilities, not
  93. * because its optional.
  94. *
  95. * 8) The following might not been defined even if your platform is
  96. * capable of defining it:
  97. *
  98. * WCHAR_MIN
  99. * WCHAR_MAX
  100. * (u)int64_t
  101. * PTRDIFF_MIN
  102. * PTRDIFF_MAX
  103. * (u)intptr_t
  104. *
  105. * 9) The following have not been defined:
  106. *
  107. * WINT_MIN
  108. * WINT_MAX
  109. *
  110. * 10) The criteria for defining (u)int_least(*)_t isn't clear,
  111. * except for systems which don't have a type that precisely
  112. * defined 8, 16, or 32 bit types (which this include file does
  113. * not support anyways). Default definitions have been given.
  114. *
  115. * 11) The criteria for defining (u)int_fast(*)_t isn't something I
  116. * would trust to any particular compiler vendor or the ANSI C
  117. * comittee. It is well known that "compatible systems" are
  118. * commonly created that have very different performance
  119. * characteristics from the systems they are compatible with,
  120. * especially those whose vendors make both the compiler and the
  121. * system. Default definitions have been given, but its strongly
  122. * recommended that users never use these definitions for any
  123. * reason (they do *NOT* deliver any serious guarantee of
  124. * improved performance -- not in this file, nor any vendor's
  125. * stdint.h).
  126. *
  127. * 12) The following macros:
  128. *
  129. * PRINTF_INTMAX_MODIFIER
  130. * PRINTF_INT64_MODIFIER
  131. * PRINTF_INT32_MODIFIER
  132. * PRINTF_INT16_MODIFIER
  133. * PRINTF_LEAST64_MODIFIER
  134. * PRINTF_LEAST32_MODIFIER
  135. * PRINTF_LEAST16_MODIFIER
  136. * PRINTF_INTPTR_MODIFIER
  137. *
  138. * are strings which have been defined as the modifiers required
  139. * for the "d", "u" and "x" printf formats to correctly output
  140. * (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t,
  141. * (u)least32_t, (u)least16_t and (u)intptr_t types respectively.
  142. * PRINTF_INTPTR_MODIFIER is not defined for some systems which
  143. * provide their own stdint.h. PRINTF_INT64_MODIFIER is not
  144. * defined if INT64_MAX is not defined. These are an extension
  145. * beyond what C99 specifies must be in stdint.h.
  146. *
  147. * In addition, the following macros are defined:
  148. *
  149. * PRINTF_INTMAX_HEX_WIDTH
  150. * PRINTF_INT64_HEX_WIDTH
  151. * PRINTF_INT32_HEX_WIDTH
  152. * PRINTF_INT16_HEX_WIDTH
  153. * PRINTF_INT8_HEX_WIDTH
  154. * PRINTF_INTMAX_DEC_WIDTH
  155. * PRINTF_INT64_DEC_WIDTH
  156. * PRINTF_INT32_DEC_WIDTH
  157. * PRINTF_INT16_DEC_WIDTH
  158. * PRINTF_INT8_DEC_WIDTH
  159. *
  160. * Which specifies the maximum number of characters required to
  161. * print the number of that type in either hexadecimal or decimal.
  162. * These are an extension beyond what C99 specifies must be in
  163. * stdint.h.
  164. *
  165. * Compilers tested (all with 0 warnings at their highest respective
  166. * settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32
  167. * bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio
  168. * .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3
  169. *
  170. * This file should be considered a work in progress. Suggestions for
  171. * improvements, especially those which increase coverage are strongly
  172. * encouraged.
  173. *
  174. * Acknowledgements
  175. *
  176. * The following people have made significant contributions to the
  177. * development and testing of this file:
  178. *
  179. * Chris Howie
  180. * John Steele Scott
  181. *
  182. */
  183. #include <stddef.h>
  184. #include <limits.h>
  185. #include <signal.h>
  186. /*
  187. * For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and
  188. * do nothing else.
  189. */
  190. #if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && defined(_STDINT_H))) && !defined (_PSTDINT_H_INCLUDED)
  191. #include <stdint.h>
  192. #define _PSTDINT_H_INCLUDED
  193. # ifndef PRINTF_INT64_MODIFIER
  194. # define PRINTF_INT64_MODIFIER "ll"
  195. # endif
  196. # ifndef PRINTF_INT32_MODIFIER
  197. # define PRINTF_INT32_MODIFIER "l"
  198. # endif
  199. # ifndef PRINTF_INT16_MODIFIER
  200. # define PRINTF_INT16_MODIFIER "h"
  201. # endif
  202. # ifndef PRINTF_INTMAX_MODIFIER
  203. # define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
  204. # endif
  205. # ifndef PRINTF_INT64_HEX_WIDTH
  206. # define PRINTF_INT64_HEX_WIDTH "16"
  207. # endif
  208. # ifndef PRINTF_INT32_HEX_WIDTH
  209. # define PRINTF_INT32_HEX_WIDTH "8"
  210. # endif
  211. # ifndef PRINTF_INT16_HEX_WIDTH
  212. # define PRINTF_INT16_HEX_WIDTH "4"
  213. # endif
  214. # ifndef PRINTF_INT8_HEX_WIDTH
  215. # define PRINTF_INT8_HEX_WIDTH "2"
  216. # endif
  217. # ifndef PRINTF_INT64_DEC_WIDTH
  218. # define PRINTF_INT64_DEC_WIDTH "20"
  219. # endif
  220. # ifndef PRINTF_INT32_DEC_WIDTH
  221. # define PRINTF_INT32_DEC_WIDTH "10"
  222. # endif
  223. # ifndef PRINTF_INT16_DEC_WIDTH
  224. # define PRINTF_INT16_DEC_WIDTH "5"
  225. # endif
  226. # ifndef PRINTF_INT8_DEC_WIDTH
  227. # define PRINTF_INT8_DEC_WIDTH "3"
  228. # endif
  229. # ifndef PRINTF_INTMAX_HEX_WIDTH
  230. # define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
  231. # endif
  232. # ifndef PRINTF_INTMAX_DEC_WIDTH
  233. # define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
  234. # endif
  235. #endif
  236. #ifndef _PSTDINT_H_INCLUDED
  237. #define _PSTDINT_H_INCLUDED
  238. #ifndef SIZE_MAX
  239. # define SIZE_MAX (~(size_t)0)
  240. #endif
  241. /*
  242. * Deduce the type assignments from limits.h under the assumption that
  243. * integer sizes in bits are powers of 2, and follow the ANSI
  244. * definitions.
  245. */
  246. #ifndef UINT8_MAX
  247. # define UINT8_MAX 0xff
  248. #endif
  249. #ifndef uint8_t
  250. # if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)
  251. typedef unsigned char uint8_t;
  252. # define UINT8_C(v) ((uint8_t) v)
  253. # else
  254. # error "Platform not supported"
  255. # endif
  256. #endif
  257. #ifndef INT8_MAX
  258. # define INT8_MAX 0x7f
  259. #endif
  260. #ifndef INT8_MIN
  261. # define INT8_MIN INT8_C(0x80)
  262. #endif
  263. #ifndef int8_t
  264. # if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)
  265. typedef signed char int8_t;
  266. # define INT8_C(v) ((int8_t) v)
  267. # else
  268. # error "Platform not supported"
  269. # endif
  270. #endif
  271. #ifndef UINT16_MAX
  272. # define UINT16_MAX 0xffff
  273. #endif
  274. #ifndef uint16_t
  275. #if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)
  276. typedef unsigned int uint16_t;
  277. # ifndef PRINTF_INT16_MODIFIER
  278. # define PRINTF_INT16_MODIFIER ""
  279. # endif
  280. # define UINT16_C(v) ((uint16_t) (v))
  281. #elif (USHRT_MAX == UINT16_MAX)
  282. typedef unsigned short uint16_t;
  283. # define UINT16_C(v) ((uint16_t) (v))
  284. # ifndef PRINTF_INT16_MODIFIER
  285. # define PRINTF_INT16_MODIFIER "h"
  286. # endif
  287. #else
  288. #error "Platform not supported"
  289. #endif
  290. #endif
  291. #ifndef INT16_MAX
  292. # define INT16_MAX 0x7fff
  293. #endif
  294. #ifndef INT16_MIN
  295. # define INT16_MIN INT16_C(0x8000)
  296. #endif
  297. #ifndef int16_t
  298. #if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)
  299. typedef signed int int16_t;
  300. # define INT16_C(v) ((int16_t) (v))
  301. # ifndef PRINTF_INT16_MODIFIER
  302. # define PRINTF_INT16_MODIFIER ""
  303. # endif
  304. #elif (SHRT_MAX == INT16_MAX)
  305. typedef signed short int16_t;
  306. # define INT16_C(v) ((int16_t) (v))
  307. # ifndef PRINTF_INT16_MODIFIER
  308. # define PRINTF_INT16_MODIFIER "h"
  309. # endif
  310. #else
  311. #error "Platform not supported"
  312. #endif
  313. #endif
  314. #ifndef UINT32_MAX
  315. # define UINT32_MAX (0xffffffffUL)
  316. #endif
  317. #ifndef uint32_t
  318. #if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)
  319. typedef unsigned long uint32_t;
  320. # define UINT32_C(v) v ## UL
  321. # ifndef PRINTF_INT32_MODIFIER
  322. # define PRINTF_INT32_MODIFIER "l"
  323. # endif
  324. #elif (UINT_MAX == UINT32_MAX)
  325. typedef unsigned int uint32_t;
  326. # ifndef PRINTF_INT32_MODIFIER
  327. # define PRINTF_INT32_MODIFIER ""
  328. # endif
  329. # define UINT32_C(v) v ## U
  330. #elif (USHRT_MAX == UINT32_MAX)
  331. typedef unsigned short uint32_t;
  332. # define UINT32_C(v) ((unsigned short) (v))
  333. # ifndef PRINTF_INT32_MODIFIER
  334. # define PRINTF_INT32_MODIFIER ""
  335. # endif
  336. #else
  337. #error "Platform not supported"
  338. #endif
  339. #endif
  340. #ifndef INT32_MAX
  341. # define INT32_MAX (0x7fffffffL)
  342. #endif
  343. #ifndef INT32_MIN
  344. # define INT32_MIN INT32_C(0x80000000)
  345. #endif
  346. #ifndef int32_t
  347. #if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)
  348. typedef signed long int32_t;
  349. # define INT32_C(v) v ## L
  350. # ifndef PRINTF_INT32_MODIFIER
  351. # define PRINTF_INT32_MODIFIER "l"
  352. # endif
  353. #elif (INT_MAX == INT32_MAX)
  354. typedef signed int int32_t;
  355. # define INT32_C(v) v
  356. # ifndef PRINTF_INT32_MODIFIER
  357. # define PRINTF_INT32_MODIFIER ""
  358. # endif
  359. #elif (SHRT_MAX == INT32_MAX)
  360. typedef signed short int32_t;
  361. # define INT32_C(v) ((short) (v))
  362. # ifndef PRINTF_INT32_MODIFIER
  363. # define PRINTF_INT32_MODIFIER ""
  364. # endif
  365. #else
  366. #error "Platform not supported"
  367. #endif
  368. #endif
  369. /*
  370. * The macro stdint_int64_defined is temporarily used to record
  371. * whether or not 64 integer support is available. It must be
  372. * defined for any 64 integer extensions for new platforms that are
  373. * added.
  374. */
  375. #undef stdint_int64_defined
  376. #if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)
  377. # if (__STDC__ && __STDC_VERSION >= 199901L) || defined (S_SPLINT_S)
  378. # define stdint_int64_defined
  379. typedef long long int64_t;
  380. typedef unsigned long long uint64_t;
  381. # define UINT64_C(v) v ## ULL
  382. # define INT64_C(v) v ## LL
  383. # ifndef PRINTF_INT64_MODIFIER
  384. # define PRINTF_INT64_MODIFIER "ll"
  385. # endif
  386. # endif
  387. #endif
  388. #if !defined (stdint_int64_defined)
  389. # if defined(__GNUC__)
  390. # define stdint_int64_defined
  391. __extension__ typedef long long int64_t;
  392. __extension__ typedef unsigned long long uint64_t;
  393. # define UINT64_C(v) v ## ULL
  394. # define INT64_C(v) v ## LL
  395. # ifndef PRINTF_INT64_MODIFIER
  396. # define PRINTF_INT64_MODIFIER "ll"
  397. # endif
  398. # elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)
  399. # define stdint_int64_defined
  400. typedef long long int64_t;
  401. typedef unsigned long long uint64_t;
  402. # define UINT64_C(v) v ## ULL
  403. # define INT64_C(v) v ## LL
  404. # ifndef PRINTF_INT64_MODIFIER
  405. # define PRINTF_INT64_MODIFIER "ll"
  406. # endif
  407. # elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
  408. # define stdint_int64_defined
  409. typedef __int64 int64_t;
  410. typedef unsigned __int64 uint64_t;
  411. # define UINT64_C(v) v ## UI64
  412. # define INT64_C(v) v ## I64
  413. # ifndef PRINTF_INT64_MODIFIER
  414. # define PRINTF_INT64_MODIFIER "I64"
  415. # endif
  416. # endif
  417. #endif
  418. #if !defined (LONG_LONG_MAX) && defined (INT64_C)
  419. # define LONG_LONG_MAX INT64_C (9223372036854775807)
  420. #endif
  421. #ifndef ULONG_LONG_MAX
  422. # define ULONG_LONG_MAX UINT64_C (18446744073709551615)
  423. #endif
  424. #if !defined (INT64_MAX) && defined (INT64_C)
  425. # define INT64_MAX INT64_C (9223372036854775807)
  426. #endif
  427. #if !defined (INT64_MIN) && defined (INT64_C)
  428. # define INT64_MIN INT64_C (-9223372036854775808)
  429. #endif
  430. #if !defined (UINT64_MAX) && defined (INT64_C)
  431. # define UINT64_MAX UINT64_C (18446744073709551615)
  432. #endif
  433. /*
  434. * Width of hexadecimal for number field.
  435. */
  436. #ifndef PRINTF_INT64_HEX_WIDTH
  437. # define PRINTF_INT64_HEX_WIDTH "16"
  438. #endif
  439. #ifndef PRINTF_INT32_HEX_WIDTH
  440. # define PRINTF_INT32_HEX_WIDTH "8"
  441. #endif
  442. #ifndef PRINTF_INT16_HEX_WIDTH
  443. # define PRINTF_INT16_HEX_WIDTH "4"
  444. #endif
  445. #ifndef PRINTF_INT8_HEX_WIDTH
  446. # define PRINTF_INT8_HEX_WIDTH "2"
  447. #endif
  448. #ifndef PRINTF_INT64_DEC_WIDTH
  449. # define PRINTF_INT64_DEC_WIDTH "20"
  450. #endif
  451. #ifndef PRINTF_INT32_DEC_WIDTH
  452. # define PRINTF_INT32_DEC_WIDTH "10"
  453. #endif
  454. #ifndef PRINTF_INT16_DEC_WIDTH
  455. # define PRINTF_INT16_DEC_WIDTH "5"
  456. #endif
  457. #ifndef PRINTF_INT8_DEC_WIDTH
  458. # define PRINTF_INT8_DEC_WIDTH "3"
  459. #endif
  460. /*
  461. * Ok, lets not worry about 128 bit integers for now. Moore's law says
  462. * we don't need to worry about that until about 2040 at which point
  463. * we'll have bigger things to worry about.
  464. */
  465. #ifdef stdint_int64_defined
  466. typedef int64_t intmax_t;
  467. typedef uint64_t uintmax_t;
  468. # define INTMAX_MAX INT64_MAX
  469. # define INTMAX_MIN INT64_MIN
  470. # define UINTMAX_MAX UINT64_MAX
  471. # define UINTMAX_C(v) UINT64_C(v)
  472. # define INTMAX_C(v) INT64_C(v)
  473. # ifndef PRINTF_INTMAX_MODIFIER
  474. # define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
  475. # endif
  476. # ifndef PRINTF_INTMAX_HEX_WIDTH
  477. # define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
  478. # endif
  479. # ifndef PRINTF_INTMAX_DEC_WIDTH
  480. # define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
  481. # endif
  482. #else
  483. typedef int32_t intmax_t;
  484. typedef uint32_t uintmax_t;
  485. # define INTMAX_MAX INT32_MAX
  486. # define UINTMAX_MAX UINT32_MAX
  487. # define UINTMAX_C(v) UINT32_C(v)
  488. # define INTMAX_C(v) INT32_C(v)
  489. # ifndef PRINTF_INTMAX_MODIFIER
  490. # define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER
  491. # endif
  492. # ifndef PRINTF_INTMAX_HEX_WIDTH
  493. # define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH
  494. # endif
  495. # ifndef PRINTF_INTMAX_DEC_WIDTH
  496. # define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH
  497. # endif
  498. #endif
  499. /*
  500. * Because this file currently only supports platforms which have
  501. * precise powers of 2 as bit sizes for the default integers, the
  502. * least definitions are all trivial. Its possible that a future
  503. * version of this file could have different definitions.
  504. */
  505. #ifndef stdint_least_defined
  506. typedef int8_t int_least8_t;
  507. typedef uint8_t uint_least8_t;
  508. typedef int16_t int_least16_t;
  509. typedef uint16_t uint_least16_t;
  510. typedef int32_t int_least32_t;
  511. typedef uint32_t uint_least32_t;
  512. # define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER
  513. # define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER
  514. # define UINT_LEAST8_MAX UINT8_MAX
  515. # define INT_LEAST8_MAX INT8_MAX
  516. # define UINT_LEAST16_MAX UINT16_MAX
  517. # define INT_LEAST16_MAX INT16_MAX
  518. # define UINT_LEAST32_MAX UINT32_MAX
  519. # define INT_LEAST32_MAX INT32_MAX
  520. # define INT_LEAST8_MIN INT8_MIN
  521. # define INT_LEAST16_MIN INT16_MIN
  522. # define INT_LEAST32_MIN INT32_MIN
  523. # ifdef stdint_int64_defined
  524. typedef int64_t int_least64_t;
  525. typedef uint64_t uint_least64_t;
  526. # define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER
  527. # define UINT_LEAST64_MAX UINT64_MAX
  528. # define INT_LEAST64_MAX INT64_MAX
  529. # define INT_LEAST64_MIN INT64_MIN
  530. # endif
  531. #endif
  532. #undef stdint_least_defined
  533. /*
  534. * The ANSI C committee pretending to know or specify anything about
  535. * performance is the epitome of misguided arrogance. The mandate of
  536. * this file is to *ONLY* ever support that absolute minimum
  537. * definition of the fast integer types, for compatibility purposes.
  538. * No extensions, and no attempt to suggest what may or may not be a
  539. * faster integer type will ever be made in this file. Developers are
  540. * warned to stay away from these types when using this or any other
  541. * stdint.h.
  542. */
  543. typedef int_least8_t int_fast8_t;
  544. typedef uint_least8_t uint_fast8_t;
  545. typedef int_least16_t int_fast16_t;
  546. typedef uint_least16_t uint_fast16_t;
  547. typedef int_least32_t int_fast32_t;
  548. typedef uint_least32_t uint_fast32_t;
  549. #define UINT_FAST8_MAX UINT_LEAST8_MAX
  550. #define INT_FAST8_MAX INT_LEAST8_MAX
  551. #define UINT_FAST16_MAX UINT_LEAST16_MAX
  552. #define INT_FAST16_MAX INT_LEAST16_MAX
  553. #define UINT_FAST32_MAX UINT_LEAST32_MAX
  554. #define INT_FAST32_MAX INT_LEAST32_MAX
  555. #define INT_FAST8_MIN IN_LEASTT8_MIN
  556. #define INT_FAST16_MIN INT_LEAST16_MIN
  557. #define INT_FAST32_MIN INT_LEAST32_MIN
  558. #ifdef stdint_int64_defined
  559. typedef int_least64_t int_fast64_t;
  560. typedef uint_least64_t uint_fast64_t;
  561. # define UINT_FAST64_MAX UINT_LEAST64_MAX
  562. # define INT_FAST64_MAX INT_LEAST64_MAX
  563. # define INT_FAST64_MIN INT_LEAST64_MIN
  564. #endif
  565. #undef stdint_int64_defined
  566. /*
  567. * Whatever piecemeal, per compiler thing we can do about the wchar_t
  568. * type limits.
  569. */
  570. #if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__)
  571. # include <wchar.h>
  572. # ifndef WCHAR_MIN
  573. # define WCHAR_MIN 0
  574. # endif
  575. # ifndef WCHAR_MAX
  576. # define WCHAR_MAX ((wchar_t)-1)
  577. # endif
  578. #endif
  579. /*
  580. * Whatever piecemeal, per compiler/platform thing we can do about the
  581. * (u)intptr_t types and limits.
  582. */
  583. #if defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)
  584. # define STDINT_H_UINTPTR_T_DEFINED
  585. #endif
  586. #ifndef STDINT_H_UINTPTR_T_DEFINED
  587. # if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64)
  588. # define stdint_intptr_bits 64
  589. # elif defined (__WATCOMC__) || defined (__TURBOC__)
  590. # if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
  591. # define stdint_intptr_bits 16
  592. # else
  593. # define stdint_intptr_bits 32
  594. # endif
  595. # elif defined (__i386__) || defined (_WIN32) || defined (WIN32)
  596. # define stdint_intptr_bits 32
  597. # elif defined (__INTEL_COMPILER)
  598. /* TODO -- what will Intel do about x86-64? */
  599. # endif
  600. # ifdef stdint_intptr_bits
  601. # define stdint_intptr_glue3_i(a,b,c) a##b##c
  602. # define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c)
  603. # ifndef PRINTF_INTPTR_MODIFIER
  604. # define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)
  605. # endif
  606. # ifndef PTRDIFF_MAX
  607. # define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
  608. # endif
  609. # ifndef PTRDIFF_MIN
  610. # define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
  611. # endif
  612. # ifndef UINTPTR_MAX
  613. # define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)
  614. # endif
  615. # ifndef INTPTR_MAX
  616. # define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
  617. # endif
  618. # ifndef INTPTR_MIN
  619. # define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
  620. # endif
  621. # ifndef INTPTR_C
  622. # define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)
  623. # endif
  624. # ifndef UINTPTR_C
  625. # define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)
  626. # endif
  627. typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;
  628. typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t;
  629. # else
  630. /* TODO -- This following is likely wrong for some platforms, and does
  631. nothing for the definition of uintptr_t. */
  632. typedef ptrdiff_t intptr_t;
  633. # endif
  634. # define STDINT_H_UINTPTR_T_DEFINED
  635. #endif
  636. /*
  637. * Assumes sig_atomic_t is signed and we have a 2s complement machine.
  638. */
  639. #ifndef SIG_ATOMIC_MAX
  640. # define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)
  641. #endif
  642. #endif