Subversion Repositories Kolibri OS

Rev

Rev 6099 | Blame | Compare with Previous | Last modification | View Log | RSS feed

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