inttypes.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /* $OpenBSD: inttypes.h,v 1.10 2009/01/13 18:13:51 kettenis Exp $ */
  2. /*
  3. * Copyright (c) 1997, 2005 Todd C. Miller <Todd.Miller@courtesan.com>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef _INTTYPES_H_
  18. #define _INTTYPES_H_
  19. #include <sys/stdint.h>
  20. /*
  21. * 7.8.1 Macros for format specifiers
  22. *
  23. * Each of the following object-like macros expands to a string
  24. * literal containing a conversion specifier, possibly modified by
  25. * a prefix such as hh, h, l, or ll, suitable for use within the
  26. * format argument of a formatted input/output function when
  27. * converting the corresponding integer type. These macro names
  28. * have the general form of PRI (character string literals for the
  29. * fprintf family) or SCN (character string literals for the fscanf
  30. * family), followed by the conversion specifier, followed by a
  31. * name corresponding to a similar typedef name. For example,
  32. * PRIdFAST32 can be used in a format string to print the value of
  33. * an integer of type int_fast32_t.
  34. */
  35. /* fprintf macros for signed integers */
  36. #define PRId8 "d" /* int8_t */
  37. #define PRId16 "d" /* int16_t */
  38. #define PRId32 "d" /* int32_t */
  39. #ifdef __x86_64__
  40. #define PRId64 "ld" /* int64_t */
  41. #else
  42. #define PRId64 "lld" /* int64_t */
  43. #endif
  44. #define PRIdLEAST8 "d" /* int_least8_t */
  45. #define PRIdLEAST16 "d" /* int_least16_t */
  46. #define PRIdLEAST32 "d" /* int_least32_t */
  47. #ifdef __x86_64__
  48. #define PRIdLEAST64 "ld" /* int_least64_t */
  49. #else
  50. #define PRIdLEAST64 "lld" /* int_least64_t */
  51. #endif
  52. #define PRIdFAST8 "d" /* int_fast8_t */
  53. #ifdef __x86_64__
  54. #define PRIdFAST16 "ld" /* int_fast16_t */
  55. #define PRIdFAST32 "ld" /* int_fast32_t */
  56. #define PRIdFAST64 "ld" /* int_fast64_t */
  57. #else
  58. #define PRIdFAST16 "d" /* int_fast16_t */
  59. #define PRIdFAST32 "d" /* int_fast32_t */
  60. #define PRIdFAST64 "lld" /* int_fast64_t */
  61. #endif
  62. #ifdef __x86_64__
  63. #define PRIdMAX "ld" /* intmax_t */
  64. #else
  65. #if defined(__i386__)
  66. #define PRIdMAX "lld" /* intmax_t */
  67. #else
  68. #define PRIdMAX "jd" /* intmax_t */
  69. #endif
  70. #endif
  71. #ifdef __i386__
  72. #define PRIdPTR "d" /* intptr_t */
  73. #else
  74. #define PRIdPTR "ld" /* intptr_t */
  75. #endif
  76. #define PRIi8 "i" /* int8_t */
  77. #define PRIi16 "i" /* int16_t */
  78. #define PRIi32 "i" /* int32_t */
  79. #ifdef __x86_64__
  80. #define PRIi64 "li" /* int64_t */
  81. #else
  82. #define PRIi64 "lli" /* int64_t */
  83. #endif
  84. #define PRIiLEAST8 "i" /* int_least8_t */
  85. #define PRIiLEAST16 "i" /* int_least16_t */
  86. #define PRIiLEAST32 "i" /* int_least32_t */
  87. #ifdef __x86_64__
  88. #define PRIiLEAST64 "li" /* int_least64_t */
  89. #else
  90. #define PRIiLEAST64 "lli" /* int_least64_t */
  91. #endif
  92. #define PRIiFAST8 "i" /* int_fast8_t */
  93. #ifdef __x86_64__
  94. #define PRIiFAST16 "li" /* int_fast16_t */
  95. #define PRIiFAST32 "li" /* int_fast32_t */
  96. #define PRIiFAST64 "li" /* int_fast64_t */
  97. #else
  98. #define PRIiFAST16 "i" /* int_fast16_t */
  99. #define PRIiFAST32 "i" /* int_fast32_t */
  100. #define PRIiFAST64 "lli" /* int_fast64_t */
  101. #endif
  102. #ifdef __x86_64__
  103. #define PRIiMAX "li" /* intmax_t */
  104. #else
  105. #if defined(__i386__)
  106. #define PRIiMAX "lli" /* intmax_t */
  107. #else
  108. #define PRIiMAX "ji" /* intmax_t */
  109. #endif
  110. #endif
  111. #ifdef __i386__
  112. #define PRIiPTR "i" /* intptr_t */
  113. #else
  114. #define PRIiPTR "li" /* intptr_t */
  115. #endif
  116. /* fprintf macros for unsigned integers */
  117. #define PRIo8 "o" /* int8_t */
  118. #define PRIo16 "o" /* int16_t */
  119. #define PRIo32 "o" /* int32_t */
  120. #ifdef __x86_64__
  121. #define PRIo64 "lo" /* int64_t */
  122. #else
  123. #define PRIo64 "llo" /* int64_t */
  124. #endif
  125. #define PRIoLEAST8 "o" /* int_least8_t */
  126. #define PRIoLEAST16 "o" /* int_least16_t */
  127. #define PRIoLEAST32 "o" /* int_least32_t */
  128. #ifdef __x86_64__
  129. #define PRIoLEAST64 "lo" /* int_least64_t */
  130. #else
  131. #define PRIoLEAST64 "llo" /* int_least64_t */
  132. #endif
  133. #define PRIoFAST8 "o" /* int_fast8_t */
  134. #ifdef __x86_64__
  135. #define PRIoFAST16 "lo" /* int_fast16_t */
  136. #define PRIoFAST32 "lo" /* int_fast32_t */
  137. #define PRIoFAST64 "lo" /* int_fast64_t */
  138. #else
  139. #define PRIoFAST16 "o" /* int_fast16_t */
  140. #define PRIoFAST32 "o" /* int_fast32_t */
  141. #define PRIoFAST64 "llo" /* int_fast64_t */
  142. #endif
  143. #ifdef __x86_64__
  144. #define PRIoMAX "lo" /* intmax_t */
  145. #else
  146. #if defined(__i386__)
  147. #define PRIoMAX "llo" /* intmax_t */
  148. #else
  149. #define PRIoMAX "jo" /* intmax_t */
  150. #endif
  151. #endif
  152. #ifdef __i386__
  153. #define PRIoPTR "o" /* intptr_t */
  154. #else
  155. #define PRIoPTR "lo" /* intptr_t */
  156. #endif
  157. #define PRIu8 "u" /* uint8_t */
  158. #define PRIu16 "u" /* uint16_t */
  159. #define PRIu32 "u" /* uint32_t */
  160. #ifdef __x86_64__
  161. #define PRIu64 "lu" /* uint64_t */
  162. #else
  163. #define PRIu64 "llu" /* uint64_t */
  164. #endif
  165. #define PRIuLEAST8 "u" /* uint_least8_t */
  166. #define PRIuLEAST16 "u" /* uint_least16_t */
  167. #define PRIuLEAST32 "u" /* uint_least32_t */
  168. #ifdef __x86_64__
  169. #define PRIuLEAST64 "lu" /* uint_least64_t */
  170. #else
  171. #define PRIuLEAST64 "llu" /* uint_least64_t */
  172. #endif
  173. #define PRIuFAST8 "u" /* uint_fast8_t */
  174. #ifdef __x86_64__
  175. #define PRIuFAST16 "lu" /* uint_fast16_t */
  176. #define PRIuFAST32 "lu" /* uint_fast32_t */
  177. #define PRIuFAST64 "lu" /* uint_fast64_t */
  178. #else
  179. #define PRIuFAST16 "u" /* uint_fast16_t */
  180. #define PRIuFAST32 "u" /* uint_fast32_t */
  181. #define PRIuFAST64 "llu" /* uint_fast64_t */
  182. #endif
  183. #ifdef __x86_64__
  184. #define PRIuMAX "lu" /* uintmax_t */
  185. #else
  186. #if defined(__i386__)
  187. #define PRIuMAX "llu" /* uintmax_t */
  188. #else
  189. #define PRIuMAX "ju" /* uintmax_t */
  190. #endif
  191. #endif
  192. #ifdef __i386__
  193. #define PRIuPTR "u" /* uintptr_t */
  194. #else
  195. #define PRIuPTR "lu" /* uintptr_t */
  196. #endif
  197. #define PRIx8 "x" /* uint8_t */
  198. #define PRIx16 "x" /* uint16_t */
  199. #define PRIx32 "x" /* uint32_t */
  200. #ifdef __x86_64__
  201. #define PRIx64 "lx" /* uint64_t */
  202. #else
  203. #define PRIx64 "llx" /* uint64_t */
  204. #endif
  205. #define PRIxLEAST8 "x" /* uint_least8_t */
  206. #define PRIxLEAST16 "x" /* uint_least16_t */
  207. #define PRIxLEAST32 "x" /* uint_least32_t */
  208. #ifdef __x86_64__
  209. #define PRIxLEAST64 "lx" /* uint_least64_t */
  210. #else
  211. #define PRIxLEAST64 "llx" /* uint_least64_t */
  212. #endif
  213. #define PRIxFAST8 "x" /* uint_fast8_t */
  214. #ifdef __x86_64__
  215. #define PRIxFAST16 "lx" /* uint_fast16_t */
  216. #define PRIxFAST32 "lx" /* uint_fast32_t */
  217. #define PRIxFAST64 "lx" /* uint_fast64_t */
  218. #else
  219. #define PRIxFAST16 "x" /* uint_fast16_t */
  220. #define PRIxFAST32 "x" /* uint_fast32_t */
  221. #define PRIxFAST64 "llx" /* uint_fast64_t */
  222. #endif
  223. #ifdef __x86_64__
  224. #define PRIxMAX "lx" /* uintmax_t */
  225. #else
  226. #if defined(__i386__)
  227. #define PRIxMAX "llx" /* uintmax_t */
  228. #else
  229. #define PRIxMAX "jx" /* uintmax_t */
  230. #endif
  231. #endif
  232. #ifdef __i386__
  233. #define PRIxPTR "x" /* uintptr_t */
  234. #else
  235. #define PRIxPTR "lx" /* uintptr_t */
  236. #endif
  237. #define PRIX8 "X" /* uint8_t */
  238. #define PRIX16 "X" /* uint16_t */
  239. #define PRIX32 "X" /* uint32_t */
  240. #ifdef __x86_64__
  241. #define PRIX64 "lX" /* uint64_t */
  242. #else
  243. #define PRIX64 "llX" /* uint64_t */
  244. #endif
  245. #define PRIXLEAST8 "X" /* uint_least8_t */
  246. #define PRIXLEAST16 "X" /* uint_least16_t */
  247. #define PRIXLEAST32 "X" /* uint_least32_t */
  248. #ifdef __x86_64__
  249. #define PRIXLEAST64 "lX" /* uint_least64_t */
  250. #else
  251. #define PRIXLEAST64 "llX" /* uint_least64_t */
  252. #endif
  253. #define PRIXFAST8 "X" /* uint_fast8_t */
  254. #ifdef __x86_64__
  255. #define PRIXFAST16 "lX" /* uint_fast16_t */
  256. #define PRIXFAST32 "lX" /* uint_fast32_t */
  257. #define PRIXFAST64 "lX" /* uint_fast64_t */
  258. #else
  259. #define PRIXFAST16 "X" /* uint_fast16_t */
  260. #define PRIXFAST32 "X" /* uint_fast32_t */
  261. #define PRIXFAST64 "llX" /* uint_fast64_t */
  262. #endif
  263. #ifdef __x86_64__
  264. #define PRIXMAX "lX" /* uintmax_t */
  265. #else
  266. #if defined(__i386__)
  267. #define PRIXMAX "llX" /* uintmax_t */
  268. #else
  269. #define PRIXMAX "jX" /* uintmax_t */
  270. #endif
  271. #endif
  272. #ifdef __i386__
  273. #define PRIXPTR "X" /* uintptr_t */
  274. #else
  275. #define PRIXPTR "lX" /* uintptr_t */
  276. #endif
  277. typedef struct {
  278. intmax_t quot; /* quotient */
  279. intmax_t rem; /* remainder */
  280. } imaxdiv_t;
  281. __BEGIN_DECLS
  282. intmax_t _TLIBC_CDECL_ imaxabs(intmax_t);
  283. imaxdiv_t _TLIBC_CDECL_ imaxdiv(intmax_t, intmax_t);
  284. intmax_t _TLIBC_CDECL_ strtoimax(const char *, char **, int);
  285. uintmax_t _TLIBC_CDECL_ strtoumax(const char *, char **, int);
  286. __END_DECLS
  287. #endif /* _INTTYPES_H_ */