inttypes.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. /* Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. /*
  16. * ISO C99: 7.8 Format conversion of integer types <inttypes.h>
  17. */
  18. #ifndef _INTTYPES_H
  19. #define _INTTYPES_H 1
  20. #include <features.h>
  21. /* Get the type definitions. */
  22. #include <stdint.h>
  23. /* Get a definition for wchar_t. But we must not define wchar_t itself. */
  24. #ifndef ____gwchar_t_defined
  25. # ifdef __cplusplus
  26. # define __gwchar_t wchar_t
  27. # elif defined __WCHAR_TYPE__
  28. typedef __WCHAR_TYPE__ __gwchar_t;
  29. # else
  30. # define __need_wchar_t
  31. # include <stddef.h>
  32. typedef wchar_t __gwchar_t;
  33. # endif
  34. # define ____gwchar_t_defined 1
  35. #endif
  36. /* The ISO C99 standard specifies that these macros must only be
  37. defined if explicitly requested. */
  38. #if !defined __cplusplus || defined __STDC_FORMAT_MACROS
  39. # if __WORDSIZE == 64
  40. # define __PRI64_PREFIX "l"
  41. # define __PRIPTR_PREFIX "l"
  42. # else
  43. # define __PRI64_PREFIX "ll"
  44. # define __PRIPTR_PREFIX
  45. # endif
  46. /* Macros for printing format specifiers. */
  47. /* Decimal notation. */
  48. # define PRId8 "d"
  49. # define PRId16 "d"
  50. # define PRId32 "d"
  51. # define PRId64 __PRI64_PREFIX "d"
  52. # define PRIdLEAST8 "d"
  53. # define PRIdLEAST16 "d"
  54. # define PRIdLEAST32 "d"
  55. # define PRIdLEAST64 __PRI64_PREFIX "d"
  56. # define PRIdFAST8 "d"
  57. # define PRIdFAST16 "d"
  58. # define PRIdFAST32 "d"
  59. # define PRIdFAST64 __PRI64_PREFIX "d"
  60. # define PRIi8 "i"
  61. # define PRIi16 "i"
  62. # define PRIi32 "i"
  63. # define PRIi64 __PRI64_PREFIX "i"
  64. # define PRIiLEAST8 "i"
  65. # define PRIiLEAST16 "i"
  66. # define PRIiLEAST32 "i"
  67. # define PRIiLEAST64 __PRI64_PREFIX "i"
  68. # define PRIiFAST8 "i"
  69. # define PRIiFAST16 "i"
  70. # define PRIiFAST32 "i"
  71. # define PRIiFAST64 __PRI64_PREFIX "i"
  72. /* Octal notation. */
  73. # define PRIo8 "o"
  74. # define PRIo16 "o"
  75. # define PRIo32 "o"
  76. # define PRIo64 __PRI64_PREFIX "o"
  77. # define PRIoLEAST8 "o"
  78. # define PRIoLEAST16 "o"
  79. # define PRIoLEAST32 "o"
  80. # define PRIoLEAST64 __PRI64_PREFIX "o"
  81. # define PRIoFAST8 "o"
  82. # define PRIoFAST16 "o"
  83. # define PRIoFAST32 "o"
  84. # define PRIoFAST64 __PRI64_PREFIX "o"
  85. /* Unsigned integers. */
  86. # define PRIu8 "u"
  87. # define PRIu16 "u"
  88. # define PRIu32 "u"
  89. # define PRIu64 __PRI64_PREFIX "u"
  90. # define PRIuLEAST8 "u"
  91. # define PRIuLEAST16 "u"
  92. # define PRIuLEAST32 "u"
  93. # define PRIuLEAST64 __PRI64_PREFIX "u"
  94. # define PRIuFAST8 "u"
  95. # define PRIuFAST16 "u"
  96. # define PRIuFAST32 "u"
  97. # define PRIuFAST64 __PRI64_PREFIX "u"
  98. /* lowercase hexadecimal notation. */
  99. # define PRIx8 "x"
  100. # define PRIx16 "x"
  101. # define PRIx32 "x"
  102. # define PRIx64 __PRI64_PREFIX "x"
  103. # define PRIxLEAST8 "x"
  104. # define PRIxLEAST16 "x"
  105. # define PRIxLEAST32 "x"
  106. # define PRIxLEAST64 __PRI64_PREFIX "x"
  107. # define PRIxFAST8 "x"
  108. # define PRIxFAST16 "x"
  109. # define PRIxFAST32 "x"
  110. # define PRIxFAST64 __PRI64_PREFIX "x"
  111. /* UPPERCASE hexadecimal notation. */
  112. # define PRIX8 "X"
  113. # define PRIX16 "X"
  114. # define PRIX32 "X"
  115. # define PRIX64 __PRI64_PREFIX "X"
  116. # define PRIXLEAST8 "X"
  117. # define PRIXLEAST16 "X"
  118. # define PRIXLEAST32 "X"
  119. # define PRIXLEAST64 __PRI64_PREFIX "X"
  120. # define PRIXFAST8 "X"
  121. # define PRIXFAST16 "X"
  122. # define PRIXFAST32 "X"
  123. # define PRIXFAST64 __PRI64_PREFIX "X"
  124. /* Macros for printing `intmax_t' and `uintmax_t'. */
  125. # define PRIdMAX __PRI64_PREFIX "d"
  126. # define PRIiMAX __PRI64_PREFIX "i"
  127. # define PRIoMAX __PRI64_PREFIX "o"
  128. # define PRIuMAX __PRI64_PREFIX "u"
  129. # define PRIxMAX __PRI64_PREFIX "x"
  130. # define PRIXMAX __PRI64_PREFIX "X"
  131. /* Macros for printing `intptr_t' and `uintptr_t'. */
  132. # define PRIdPTR __PRIPTR_PREFIX "d"
  133. # define PRIiPTR __PRIPTR_PREFIX "i"
  134. # define PRIoPTR __PRIPTR_PREFIX "o"
  135. # define PRIuPTR __PRIPTR_PREFIX "u"
  136. # define PRIxPTR __PRIPTR_PREFIX "x"
  137. # define PRIXPTR __PRIPTR_PREFIX "X"
  138. /* Macros for scanning format specifiers. */
  139. /* Signed decimal notation. */
  140. # define SCNd8 "hhd"
  141. # define SCNd16 "hd"
  142. # define SCNd32 "d"
  143. # define SCNd64 __PRI64_PREFIX "d"
  144. # define SCNdLEAST8 "hhd"
  145. # define SCNdLEAST16 "hd"
  146. # define SCNdLEAST32 "d"
  147. # define SCNdLEAST64 __PRI64_PREFIX "d"
  148. # define SCNdFAST8 "hhd"
  149. # define SCNdFAST16 __PRIPTR_PREFIX "d"
  150. # define SCNdFAST32 __PRIPTR_PREFIX "d"
  151. # define SCNdFAST64 __PRI64_PREFIX "d"
  152. /* Signed decimal notation. */
  153. # define SCNi8 "hhi"
  154. # define SCNi16 "hi"
  155. # define SCNi32 "i"
  156. # define SCNi64 __PRI64_PREFIX "i"
  157. # define SCNiLEAST8 "hhi"
  158. # define SCNiLEAST16 "hi"
  159. # define SCNiLEAST32 "i"
  160. # define SCNiLEAST64 __PRI64_PREFIX "i"
  161. # define SCNiFAST8 "hhi"
  162. # define SCNiFAST16 __PRIPTR_PREFIX "i"
  163. # define SCNiFAST32 __PRIPTR_PREFIX "i"
  164. # define SCNiFAST64 __PRI64_PREFIX "i"
  165. /* Unsigned decimal notation. */
  166. # define SCNu8 "hhu"
  167. # define SCNu16 "hu"
  168. # define SCNu32 "u"
  169. # define SCNu64 __PRI64_PREFIX "u"
  170. # define SCNuLEAST8 "hhu"
  171. # define SCNuLEAST16 "hu"
  172. # define SCNuLEAST32 "u"
  173. # define SCNuLEAST64 __PRI64_PREFIX "u"
  174. # define SCNuFAST8 "hhu"
  175. # define SCNuFAST16 __PRIPTR_PREFIX "u"
  176. # define SCNuFAST32 __PRIPTR_PREFIX "u"
  177. # define SCNuFAST64 __PRI64_PREFIX "u"
  178. /* Octal notation. */
  179. # define SCNo8 "hho"
  180. # define SCNo16 "ho"
  181. # define SCNo32 "o"
  182. # define SCNo64 __PRI64_PREFIX "o"
  183. # define SCNoLEAST8 "hho"
  184. # define SCNoLEAST16 "ho"
  185. # define SCNoLEAST32 "o"
  186. # define SCNoLEAST64 __PRI64_PREFIX "o"
  187. # define SCNoFAST8 "hho"
  188. # define SCNoFAST16 __PRIPTR_PREFIX "o"
  189. # define SCNoFAST32 __PRIPTR_PREFIX "o"
  190. # define SCNoFAST64 __PRI64_PREFIX "o"
  191. /* Hexadecimal notation. */
  192. # define SCNx8 "hhx"
  193. # define SCNx16 "hx"
  194. # define SCNx32 "x"
  195. # define SCNx64 __PRI64_PREFIX "x"
  196. # define SCNxLEAST8 "hhx"
  197. # define SCNxLEAST16 "hx"
  198. # define SCNxLEAST32 "x"
  199. # define SCNxLEAST64 __PRI64_PREFIX "x"
  200. # define SCNxFAST8 "hhx"
  201. # define SCNxFAST16 __PRIPTR_PREFIX "x"
  202. # define SCNxFAST32 __PRIPTR_PREFIX "x"
  203. # define SCNxFAST64 __PRI64_PREFIX "x"
  204. /* Macros for scanning `intmax_t' and `uintmax_t'. */
  205. # define SCNdMAX __PRI64_PREFIX "d"
  206. # define SCNiMAX __PRI64_PREFIX "i"
  207. # define SCNoMAX __PRI64_PREFIX "o"
  208. # define SCNuMAX __PRI64_PREFIX "u"
  209. # define SCNxMAX __PRI64_PREFIX "x"
  210. /* Macros for scaning `intptr_t' and `uintptr_t'. */
  211. # define SCNdPTR __PRIPTR_PREFIX "d"
  212. # define SCNiPTR __PRIPTR_PREFIX "i"
  213. # define SCNoPTR __PRIPTR_PREFIX "o"
  214. # define SCNuPTR __PRIPTR_PREFIX "u"
  215. # define SCNxPTR __PRIPTR_PREFIX "x"
  216. #endif /* C++ && format macros */
  217. __BEGIN_DECLS
  218. #if __WORDSIZE == 64
  219. /* We have to define the `uintmax_t' type using `ldiv_t'. */
  220. typedef struct
  221. {
  222. long int quot; /* Quotient. */
  223. long int rem; /* Remainder. */
  224. } imaxdiv_t;
  225. #else
  226. /* We have to define the `uintmax_t' type using `lldiv_t'. */
  227. typedef struct
  228. {
  229. long long int quot; /* Quotient. */
  230. long long int rem; /* Remainder. */
  231. } imaxdiv_t;
  232. #endif
  233. /* Compute absolute value of N. */
  234. extern intmax_t imaxabs (intmax_t __n) __THROW __attribute__ ((__const__));
  235. /* Return the `imaxdiv_t' representation of the value of NUMER over DENOM. */
  236. extern imaxdiv_t imaxdiv (intmax_t __numer, intmax_t __denom)
  237. __THROW __attribute__ ((__const__));
  238. /* Like `strtol' but convert to `intmax_t'. */
  239. extern intmax_t strtoimax (__const char *__restrict __nptr,
  240. char **__restrict __endptr, int __base) __THROW;
  241. /* Like `strtoul' but convert to `uintmax_t'. */
  242. extern uintmax_t strtoumax (__const char *__restrict __nptr,
  243. char ** __restrict __endptr, int __base) __THROW;
  244. /* Like `wcstol' but convert to `intmax_t'. */
  245. extern intmax_t wcstoimax (__const __gwchar_t *__restrict __nptr,
  246. __gwchar_t **__restrict __endptr, int __base)
  247. __THROW;
  248. /* Like `wcstoul' but convert to `uintmax_t'. */
  249. extern uintmax_t wcstoumax (__const __gwchar_t *__restrict __nptr,
  250. __gwchar_t ** __restrict __endptr, int __base)
  251. __THROW;
  252. #ifdef __USE_EXTERN_INLINES
  253. # if __WORDSIZE == 64
  254. /* Like `strtol' but convert to `intmax_t'. */
  255. # ifndef __strtol_internal_defined
  256. extern long int __strtol_internal (__const char *__restrict __nptr,
  257. char **__restrict __endptr,
  258. int __base, int __group) __THROW;
  259. # define __strtol_internal_defined 1
  260. # endif
  261. extern __inline intmax_t
  262. strtoimax (__const char *__restrict nptr, char **__restrict endptr,
  263. int base) __THROW
  264. {
  265. return __strtol_internal (nptr, endptr, base, 0);
  266. }
  267. /* Like `strtoul' but convert to `uintmax_t'. */
  268. # ifndef __strtoul_internal_defined
  269. extern unsigned long int __strtoul_internal (__const char *
  270. __restrict __nptr,
  271. char ** __restrict __endptr,
  272. int __base, int __group) __THROW;
  273. # define __strtoul_internal_defined 1
  274. # endif
  275. extern __inline uintmax_t
  276. strtoumax (__const char *__restrict nptr, char **__restrict endptr,
  277. int base) __THROW
  278. {
  279. return __strtoul_internal (nptr, endptr, base, 0);
  280. }
  281. /* Like `wcstol' but convert to `intmax_t'. */
  282. # ifndef __wcstol_internal_defined
  283. extern long int __wcstol_internal (__const __gwchar_t * __restrict __nptr,
  284. __gwchar_t **__restrict __endptr,
  285. int __base, int __group) __THROW;
  286. # define __wcstol_internal_defined 1
  287. # endif
  288. extern __inline intmax_t
  289. wcstoimax (__const __gwchar_t *__restrict nptr, __gwchar_t **__restrict endptr,
  290. int base) __THROW
  291. {
  292. return __wcstol_internal (nptr, endptr, base, 0);
  293. }
  294. /* Like `wcstoul' but convert to `uintmax_t'. */
  295. # ifndef __wcstoul_internal_defined
  296. extern unsigned long int __wcstoul_internal (__const __gwchar_t *
  297. __restrict __nptr,
  298. __gwchar_t **
  299. __restrict __endptr,
  300. int __base, int __group) __THROW;
  301. # define __wcstoul_internal_defined 1
  302. # endif
  303. extern __inline uintmax_t
  304. wcstoumax (__const __gwchar_t *__restrict nptr, __gwchar_t **__restrict endptr,
  305. int base) __THROW
  306. {
  307. return __wcstoul_internal (nptr, endptr, base, 0);
  308. }
  309. # else /* __WORDSIZE == 32 */
  310. /* Like `strtol' but convert to `intmax_t'. */
  311. # ifndef __strtoll_internal_defined
  312. __extension__
  313. extern long long int __strtoll_internal (__const char *__restrict __nptr,
  314. char **__restrict __endptr,
  315. int __base, int __group) __THROW;
  316. # define __strtoll_internal_defined 1
  317. # endif
  318. extern __inline intmax_t
  319. strtoimax (__const char *__restrict nptr, char **__restrict endptr,
  320. int base) __THROW
  321. {
  322. return __strtoll_internal (nptr, endptr, base, 0);
  323. }
  324. /* Like `strtoul' but convert to `uintmax_t'. */
  325. # ifndef __strtoull_internal_defined
  326. __extension__
  327. extern unsigned long long int __strtoull_internal (__const char *
  328. __restrict __nptr,
  329. char **
  330. __restrict __endptr,
  331. int __base,
  332. int __group) __THROW;
  333. # define __strtoull_internal_defined 1
  334. # endif
  335. extern __inline uintmax_t
  336. strtoumax (__const char *__restrict nptr, char **__restrict endptr,
  337. int base) __THROW
  338. {
  339. return __strtoull_internal (nptr, endptr, base, 0);
  340. }
  341. /* Like `wcstol' but convert to `intmax_t'. */
  342. # ifndef __wcstoll_internal_defined
  343. __extension__
  344. extern long long int __wcstoll_internal (__const __gwchar_t *
  345. __restrict __nptr,
  346. __gwchar_t **__restrict __endptr,
  347. int __base, int __group) __THROW;
  348. # define __wcstoll_internal_defined 1
  349. # endif
  350. extern __inline intmax_t
  351. wcstoimax (__const __gwchar_t *__restrict nptr, __gwchar_t **__restrict endptr,
  352. int base) __THROW
  353. {
  354. return __wcstoll_internal (nptr, endptr, base, 0);
  355. }
  356. /* Like `wcstoul' but convert to `uintmax_t'. */
  357. # ifndef __wcstoull_internal_defined
  358. __extension__
  359. extern unsigned long long int __wcstoull_internal (__const __gwchar_t *
  360. __restrict __nptr,
  361. __gwchar_t **
  362. __restrict __endptr,
  363. int __base,
  364. int __group) __THROW;
  365. # define __wcstoull_internal_defined 1
  366. # endif
  367. extern __inline uintmax_t
  368. wcstoumax (__const __gwchar_t *__restrict nptr, __gwchar_t **__restrict endptr,
  369. int base) __THROW
  370. {
  371. return __wcstoull_internal (nptr, endptr, base, 0);
  372. }
  373. # endif /* __WORDSIZE == 32 */
  374. #endif /* Use extern inlines. */
  375. __END_DECLS
  376. #endif /* inttypes.h */