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.

346 lines
9.5KB

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