inttypes.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. * Copyright (c) 2004, 2005 by
  3. * Ralf Corsepius, Ulm/Germany. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and distribute this software
  6. * is freely granted, provided that this notice is preserved.
  7. */
  8. /**
  9. * @file inttypes.h
  10. */
  11. #ifndef _INTTYPES_H
  12. #define _INTTYPES_H
  13. #include <newlib.h>
  14. #include <sys/_intsup.h>
  15. #include <stdint.h>
  16. #define __need_wchar_t
  17. #include <stddef.h>
  18. #define __STRINGIFY(a) #a
  19. /* 8-bit types */
  20. #define __PRI8(x) __STRINGIFY(x)
  21. /* NOTICE: scanning 8-bit types requires use of the hh specifier
  22. * which is only supported on newlib platforms that
  23. * are built with C99 I/O format support enabled. If the flag in
  24. * newlib.h hasn't been set during configuration to indicate this, the 8-bit
  25. * scanning format macros are disabled here as they result in undefined
  26. * behaviour which can include memory overwrite. Overriding the flag after the
  27. * library has been built is not recommended as it will expose the underlying
  28. * undefined behaviour.
  29. */
  30. #if defined(_WANT_IO_C99_FORMATS)
  31. #define __SCN8(x) __STRINGIFY(hh##x)
  32. #endif /* _WANT_IO_C99_FORMATS */
  33. #define PRId8 __PRI8(d)
  34. #define PRIi8 __PRI8(i)
  35. #define PRIo8 __PRI8(o)
  36. #define PRIu8 __PRI8(u)
  37. #define PRIx8 __PRI8(x)
  38. #define PRIX8 __PRI8(X)
  39. /* Macros below are only enabled for a newlib built with C99 I/O format support. */
  40. #if defined(_WANT_IO_C99_FORMATS)
  41. #define SCNd8 __SCN8(d)
  42. #define SCNi8 __SCN8(i)
  43. #define SCNo8 __SCN8(o)
  44. #define SCNu8 __SCN8(u)
  45. #define SCNx8 __SCN8(x)
  46. #endif /* _WANT_IO_C99_FORMATS */
  47. #define PRIdLEAST8 __PRI8(d)
  48. #define PRIiLEAST8 __PRI8(i)
  49. #define PRIoLEAST8 __PRI8(o)
  50. #define PRIuLEAST8 __PRI8(u)
  51. #define PRIxLEAST8 __PRI8(x)
  52. #define PRIXLEAST8 __PRI8(X)
  53. /* Macros below are only enabled for a newlib built with C99 I/O format support. */
  54. #if defined(_WANT_IO_C99_FORMATS)
  55. #define SCNdLEAST8 __SCN8(d)
  56. #define SCNiLEAST8 __SCN8(i)
  57. #define SCNoLEAST8 __SCN8(o)
  58. #define SCNuLEAST8 __SCN8(u)
  59. #define SCNxLEAST8 __SCN8(x)
  60. #endif /* _WANT_IO_C99_FORMATS */
  61. #define PRIdFAST8 __PRI8(d)
  62. #define PRIiFAST8 __PRI8(i)
  63. #define PRIoFAST8 __PRI8(o)
  64. #define PRIuFAST8 __PRI8(u)
  65. #define PRIxFAST8 __PRI8(x)
  66. #define PRIXFAST8 __PRI8(X)
  67. /* Macros below are only enabled for a newlib built with C99 I/O format support. */
  68. #if defined(_WANT_IO_C99_FORMATS)
  69. #define SCNdFAST8 __SCN8(d)
  70. #define SCNiFAST8 __SCN8(i)
  71. #define SCNoFAST8 __SCN8(o)
  72. #define SCNuFAST8 __SCN8(u)
  73. #define SCNxFAST8 __SCN8(x)
  74. #endif /* _WANT_IO_C99_FORMATS */
  75. /* 16-bit types */
  76. #define __PRI16(x) __STRINGIFY(x)
  77. #define __SCN16(x) __STRINGIFY(h##x)
  78. #define PRId16 __PRI16(d)
  79. #define PRIi16 __PRI16(i)
  80. #define PRIo16 __PRI16(o)
  81. #define PRIu16 __PRI16(u)
  82. #define PRIx16 __PRI16(x)
  83. #define PRIX16 __PRI16(X)
  84. #define SCNd16 __SCN16(d)
  85. #define SCNi16 __SCN16(i)
  86. #define SCNo16 __SCN16(o)
  87. #define SCNu16 __SCN16(u)
  88. #define SCNx16 __SCN16(x)
  89. #define PRIdLEAST16 __PRI16(d)
  90. #define PRIiLEAST16 __PRI16(i)
  91. #define PRIoLEAST16 __PRI16(o)
  92. #define PRIuLEAST16 __PRI16(u)
  93. #define PRIxLEAST16 __PRI16(x)
  94. #define PRIXLEAST16 __PRI16(X)
  95. #define SCNdLEAST16 __SCN16(d)
  96. #define SCNiLEAST16 __SCN16(i)
  97. #define SCNoLEAST16 __SCN16(o)
  98. #define SCNuLEAST16 __SCN16(u)
  99. #define SCNxLEAST16 __SCN16(x)
  100. #define PRIdFAST16 __PRI16(d)
  101. #define PRIiFAST16 __PRI16(i)
  102. #define PRIoFAST16 __PRI16(o)
  103. #define PRIuFAST16 __PRI16(u)
  104. #define PRIxFAST16 __PRI16(x)
  105. #define PRIXFAST16 __PRI16(X)
  106. #define SCNdFAST16 __SCN16(d)
  107. #define SCNiFAST16 __SCN16(i)
  108. #define SCNoFAST16 __SCN16(o)
  109. #define SCNuFAST16 __SCN16(u)
  110. #define SCNxFAST16 __SCN16(x)
  111. /* 32-bit types */
  112. #if __have_long32
  113. #define __PRI32(x) __STRINGIFY(l##x)
  114. #define __SCN32(x) __STRINGIFY(l##x)
  115. #else
  116. #define __PRI32(x) __STRINGIFY(x)
  117. #define __SCN32(x) __STRINGIFY(x)
  118. #endif
  119. #define PRId32 __PRI32(d)
  120. #define PRIi32 __PRI32(i)
  121. #define PRIo32 __PRI32(o)
  122. #define PRIu32 __PRI32(u)
  123. #define PRIx32 __PRI32(x)
  124. #define PRIX32 __PRI32(X)
  125. #define SCNd32 __SCN32(d)
  126. #define SCNi32 __SCN32(i)
  127. #define SCNo32 __SCN32(o)
  128. #define SCNu32 __SCN32(u)
  129. #define SCNx32 __SCN32(x)
  130. #define PRIdLEAST32 __PRI32(d)
  131. #define PRIiLEAST32 __PRI32(i)
  132. #define PRIoLEAST32 __PRI32(o)
  133. #define PRIuLEAST32 __PRI32(u)
  134. #define PRIxLEAST32 __PRI32(x)
  135. #define PRIXLEAST32 __PRI32(X)
  136. #define SCNdLEAST32 __SCN32(d)
  137. #define SCNiLEAST32 __SCN32(i)
  138. #define SCNoLEAST32 __SCN32(o)
  139. #define SCNuLEAST32 __SCN32(u)
  140. #define SCNxLEAST32 __SCN32(x)
  141. #define PRIdFAST32 __PRI32(d)
  142. #define PRIiFAST32 __PRI32(i)
  143. #define PRIoFAST32 __PRI32(o)
  144. #define PRIuFAST32 __PRI32(u)
  145. #define PRIxFAST32 __PRI32(x)
  146. #define PRIXFAST32 __PRI32(X)
  147. #define SCNdFAST32 __SCN32(d)
  148. #define SCNiFAST32 __SCN32(i)
  149. #define SCNoFAST32 __SCN32(o)
  150. #define SCNuFAST32 __SCN32(u)
  151. #define SCNxFAST32 __SCN32(x)
  152. /* 64-bit types */
  153. #if __have_long64
  154. #define __PRI64(x) __STRINGIFY(l##x)
  155. #define __SCN64(x) __STRINGIFY(l##x)
  156. #elif __have_longlong64
  157. #define __PRI64(x) __STRINGIFY(ll##x)
  158. #define __SCN64(x) __STRINGIFY(ll##x)
  159. #else
  160. #define __PRI64(x) __STRINGIFY(x)
  161. #define __SCN64(x) __STRINGIFY(x)
  162. #endif
  163. #define PRId64 __PRI64(d)
  164. #define PRIi64 __PRI64(i)
  165. #define PRIo64 __PRI64(o)
  166. #define PRIu64 __PRI64(u)
  167. #define PRIx64 __PRI64(x)
  168. #define PRIX64 __PRI64(X)
  169. #define SCNd64 __SCN64(d)
  170. #define SCNi64 __SCN64(i)
  171. #define SCNo64 __SCN64(o)
  172. #define SCNu64 __SCN64(u)
  173. #define SCNx64 __SCN64(x)
  174. #if __int64_t_defined
  175. #define PRIdLEAST64 __PRI64(d)
  176. #define PRIiLEAST64 __PRI64(i)
  177. #define PRIoLEAST64 __PRI64(o)
  178. #define PRIuLEAST64 __PRI64(u)
  179. #define PRIxLEAST64 __PRI64(x)
  180. #define PRIXLEAST64 __PRI64(X)
  181. #define SCNdLEAST64 __SCN64(d)
  182. #define SCNiLEAST64 __SCN64(i)
  183. #define SCNoLEAST64 __SCN64(o)
  184. #define SCNuLEAST64 __SCN64(u)
  185. #define SCNxLEAST64 __SCN64(x)
  186. #define PRIdFAST64 __PRI64(d)
  187. #define PRIiFAST64 __PRI64(i)
  188. #define PRIoFAST64 __PRI64(o)
  189. #define PRIuFAST64 __PRI64(u)
  190. #define PRIxFAST64 __PRI64(x)
  191. #define PRIXFAST64 __PRI64(X)
  192. #define SCNdFAST64 __SCN64(d)
  193. #define SCNiFAST64 __SCN64(i)
  194. #define SCNoFAST64 __SCN64(o)
  195. #define SCNuFAST64 __SCN64(u)
  196. #define SCNxFAST64 __SCN64(x)
  197. #endif
  198. /* max-bit types */
  199. #if __have_long64
  200. #define __PRIMAX(x) __STRINGIFY(l##x)
  201. #define __SCNMAX(x) __STRINGIFY(l##x)
  202. #elif __have_longlong64
  203. #define __PRIMAX(x) __STRINGIFY(ll##x)
  204. #define __SCNMAX(x) __STRINGIFY(ll##x)
  205. #else
  206. #define __PRIMAX(x) __STRINGIFY(x)
  207. #define __SCNMAX(x) __STRINGIFY(x)
  208. #endif
  209. #define PRIdMAX __PRIMAX(d)
  210. #define PRIiMAX __PRIMAX(i)
  211. #define PRIoMAX __PRIMAX(o)
  212. #define PRIuMAX __PRIMAX(u)
  213. #define PRIxMAX __PRIMAX(x)
  214. #define PRIXMAX __PRIMAX(X)
  215. #define SCNdMAX __SCNMAX(d)
  216. #define SCNiMAX __SCNMAX(i)
  217. #define SCNoMAX __SCNMAX(o)
  218. #define SCNuMAX __SCNMAX(u)
  219. #define SCNxMAX __SCNMAX(x)
  220. /* ptr types */
  221. #if defined(_UINTPTR_EQ_ULONGLONG)
  222. # define __PRIPTR(x) __STRINGIFY(ll##x)
  223. # define __SCNPTR(x) __STRINGIFY(ll##x)
  224. #elif defined(_UINTPTR_EQ_ULONG)
  225. # define __PRIPTR(x) __STRINGIFY(l##x)
  226. # define __SCNPTR(x) __STRINGIFY(l##x)
  227. #else
  228. # define __PRIPTR(x) __STRINGIFY(x)
  229. # define __SCNPTR(x) __STRINGIFY(x)
  230. #endif
  231. #define PRIdPTR __PRIPTR(d)
  232. #define PRIiPTR __PRIPTR(i)
  233. #define PRIoPTR __PRIPTR(o)
  234. #define PRIuPTR __PRIPTR(u)
  235. #define PRIxPTR __PRIPTR(x)
  236. #define PRIXPTR __PRIPTR(X)
  237. #define SCNdPTR __SCNPTR(d)
  238. #define SCNiPTR __SCNPTR(i)
  239. #define SCNoPTR __SCNPTR(o)
  240. #define SCNuPTR __SCNPTR(u)
  241. #define SCNxPTR __SCNPTR(x)
  242. typedef struct {
  243. intmax_t quot;
  244. intmax_t rem;
  245. } imaxdiv_t;
  246. #ifdef __cplusplus
  247. extern "C" {
  248. #endif
  249. extern intmax_t imaxabs(intmax_t j);
  250. extern imaxdiv_t imaxdiv(intmax_t numer, intmax_t denomer);
  251. extern intmax_t strtoimax(const char *__restrict, char **__restrict, int);
  252. extern uintmax_t strtoumax(const char *__restrict, char **__restrict, int);
  253. extern intmax_t wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int);
  254. extern uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int);
  255. #ifdef __cplusplus
  256. }
  257. #endif
  258. #endif