inttypes.h 12 KB

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