inttypes.h 12 KB

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