You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

inttypes.h 12KB

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