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