1 /* Copyright (C) 1997-2001, 2004, 2007 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3 
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8 
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <http://www.gnu.org/licenses/>.  */
17 
18 /*
19  *	ISO C99: 7.8 Format conversion of integer types	<inttypes.h>
20  */
21 
22 #ifndef _INTTYPES_H
23 #define _INTTYPES_H	1
24 
25 #include <features.h>
26 /* Get the type definitions.  */
27 #include <stdint.h>
28 
29 #ifdef __UCLIBC_HAS_WCHAR__
30 /* Get a definition for wchar_t.  But we must not define wchar_t itself.  */
31 #ifndef ____gwchar_t_defined
32 # ifdef __cplusplus
33 #  define __gwchar_t wchar_t
34 # elif defined __WCHAR_TYPE__
35 typedef __WCHAR_TYPE__ __gwchar_t;
36 # else
37 #  define __need_wchar_t
38 #  include <stddef.h>
39 typedef wchar_t __gwchar_t;
40 # endif
41 # define ____gwchar_t_defined	1
42 #endif
43 #endif
44 
45 
46 /* The ISO C99 standard specifies that these macros must only be
47    defined if explicitly requested.  */
48 #if !defined __cplusplus || defined __STDC_FORMAT_MACROS
49 
50 # if __WORDSIZE == 64
51 #  define __PRI64_PREFIX	"l"
52 #  define __PRIPTR_PREFIX	"l"
53 # else
54 #  define __PRI64_PREFIX	"ll"
55 #  define __PRIPTR_PREFIX
56 # endif
57 
58 /* Macros for printing format specifiers.  */
59 
60 /* Decimal notation.  */
61 # define PRId8		"d"
62 # define PRId16		"d"
63 # define PRId32		"d"
64 # define PRId64		__PRI64_PREFIX "d"
65 
66 # define PRIdLEAST8	"d"
67 # define PRIdLEAST16	"d"
68 # define PRIdLEAST32	"d"
69 # define PRIdLEAST64	__PRI64_PREFIX "d"
70 
71 # define PRIdFAST8	"d"
72 # define PRIdFAST16	__PRIPTR_PREFIX "d"
73 # define PRIdFAST32	__PRIPTR_PREFIX "d"
74 # define PRIdFAST64	__PRI64_PREFIX "d"
75 
76 
77 # define PRIi8		"i"
78 # define PRIi16		"i"
79 # define PRIi32		"i"
80 # define PRIi64		__PRI64_PREFIX "i"
81 
82 # define PRIiLEAST8	"i"
83 # define PRIiLEAST16	"i"
84 # define PRIiLEAST32	"i"
85 # define PRIiLEAST64	__PRI64_PREFIX "i"
86 
87 # define PRIiFAST8	"i"
88 # define PRIiFAST16	__PRIPTR_PREFIX "i"
89 # define PRIiFAST32	__PRIPTR_PREFIX "i"
90 # define PRIiFAST64	__PRI64_PREFIX "i"
91 
92 /* Octal notation.  */
93 # define PRIo8		"o"
94 # define PRIo16		"o"
95 # define PRIo32		"o"
96 # define PRIo64		__PRI64_PREFIX "o"
97 
98 # define PRIoLEAST8	"o"
99 # define PRIoLEAST16	"o"
100 # define PRIoLEAST32	"o"
101 # define PRIoLEAST64	__PRI64_PREFIX "o"
102 
103 # define PRIoFAST8	"o"
104 # define PRIoFAST16	__PRIPTR_PREFIX "o"
105 # define PRIoFAST32	__PRIPTR_PREFIX "o"
106 # define PRIoFAST64	__PRI64_PREFIX "o"
107 
108 /* Unsigned integers.  */
109 # define PRIu8		"u"
110 # define PRIu16		"u"
111 # define PRIu32		"u"
112 # define PRIu64		__PRI64_PREFIX "u"
113 
114 # define PRIuLEAST8	"u"
115 # define PRIuLEAST16	"u"
116 # define PRIuLEAST32	"u"
117 # define PRIuLEAST64	__PRI64_PREFIX "u"
118 
119 # define PRIuFAST8	"u"
120 # define PRIuFAST16	__PRIPTR_PREFIX "u"
121 # define PRIuFAST32	__PRIPTR_PREFIX "u"
122 # define PRIuFAST64	__PRI64_PREFIX "u"
123 
124 /* lowercase hexadecimal notation.  */
125 # define PRIx8		"x"
126 # define PRIx16		"x"
127 # define PRIx32		"x"
128 # define PRIx64		__PRI64_PREFIX "x"
129 
130 # define PRIxLEAST8	"x"
131 # define PRIxLEAST16	"x"
132 # define PRIxLEAST32	"x"
133 # define PRIxLEAST64	__PRI64_PREFIX "x"
134 
135 # define PRIxFAST8	"x"
136 # define PRIxFAST16	__PRIPTR_PREFIX "x"
137 # define PRIxFAST32	__PRIPTR_PREFIX "x"
138 # define PRIxFAST64	__PRI64_PREFIX "x"
139 
140 /* UPPERCASE hexadecimal notation.  */
141 # define PRIX8		"X"
142 # define PRIX16		"X"
143 # define PRIX32		"X"
144 # define PRIX64		__PRI64_PREFIX "X"
145 
146 # define PRIXLEAST8	"X"
147 # define PRIXLEAST16	"X"
148 # define PRIXLEAST32	"X"
149 # define PRIXLEAST64	__PRI64_PREFIX "X"
150 
151 # define PRIXFAST8	"X"
152 # define PRIXFAST16	__PRIPTR_PREFIX "X"
153 # define PRIXFAST32	__PRIPTR_PREFIX "X"
154 # define PRIXFAST64	__PRI64_PREFIX "X"
155 
156 
157 /* Macros for printing `intmax_t' and `uintmax_t'.  */
158 # define PRIdMAX	__PRI64_PREFIX "d"
159 # define PRIiMAX	__PRI64_PREFIX "i"
160 # define PRIoMAX	__PRI64_PREFIX "o"
161 # define PRIuMAX	__PRI64_PREFIX "u"
162 # define PRIxMAX	__PRI64_PREFIX "x"
163 # define PRIXMAX	__PRI64_PREFIX "X"
164 
165 
166 /* Macros for printing `intptr_t' and `uintptr_t'.  */
167 # define PRIdPTR	__PRIPTR_PREFIX "d"
168 # define PRIiPTR	__PRIPTR_PREFIX "i"
169 # define PRIoPTR	__PRIPTR_PREFIX "o"
170 # define PRIuPTR	__PRIPTR_PREFIX "u"
171 # define PRIxPTR	__PRIPTR_PREFIX "x"
172 # define PRIXPTR	__PRIPTR_PREFIX "X"
173 
174 
175 /* Macros for scanning format specifiers.  */
176 
177 /* Signed decimal notation.  */
178 # define SCNd8		"hhd"
179 # define SCNd16		"hd"
180 # define SCNd32		"d"
181 # define SCNd64		__PRI64_PREFIX "d"
182 
183 # define SCNdLEAST8	"hhd"
184 # define SCNdLEAST16	"hd"
185 # define SCNdLEAST32	"d"
186 # define SCNdLEAST64	__PRI64_PREFIX "d"
187 
188 # define SCNdFAST8	"hhd"
189 # define SCNdFAST16	__PRIPTR_PREFIX "d"
190 # define SCNdFAST32	__PRIPTR_PREFIX "d"
191 # define SCNdFAST64	__PRI64_PREFIX "d"
192 
193 /* Signed decimal notation.  */
194 # define SCNi8		"hhi"
195 # define SCNi16		"hi"
196 # define SCNi32		"i"
197 # define SCNi64		__PRI64_PREFIX "i"
198 
199 # define SCNiLEAST8	"hhi"
200 # define SCNiLEAST16	"hi"
201 # define SCNiLEAST32	"i"
202 # define SCNiLEAST64	__PRI64_PREFIX "i"
203 
204 # define SCNiFAST8	"hhi"
205 # define SCNiFAST16	__PRIPTR_PREFIX "i"
206 # define SCNiFAST32	__PRIPTR_PREFIX "i"
207 # define SCNiFAST64	__PRI64_PREFIX "i"
208 
209 /* Unsigned decimal notation.  */
210 # define SCNu8		"hhu"
211 # define SCNu16		"hu"
212 # define SCNu32		"u"
213 # define SCNu64		__PRI64_PREFIX "u"
214 
215 # define SCNuLEAST8	"hhu"
216 # define SCNuLEAST16	"hu"
217 # define SCNuLEAST32	"u"
218 # define SCNuLEAST64	__PRI64_PREFIX "u"
219 
220 # define SCNuFAST8	"hhu"
221 # define SCNuFAST16	__PRIPTR_PREFIX "u"
222 # define SCNuFAST32	__PRIPTR_PREFIX "u"
223 # define SCNuFAST64	__PRI64_PREFIX "u"
224 
225 /* Octal notation.  */
226 # define SCNo8		"hho"
227 # define SCNo16		"ho"
228 # define SCNo32		"o"
229 # define SCNo64		__PRI64_PREFIX "o"
230 
231 # define SCNoLEAST8	"hho"
232 # define SCNoLEAST16	"ho"
233 # define SCNoLEAST32	"o"
234 # define SCNoLEAST64	__PRI64_PREFIX "o"
235 
236 # define SCNoFAST8	"hho"
237 # define SCNoFAST16	__PRIPTR_PREFIX "o"
238 # define SCNoFAST32	__PRIPTR_PREFIX "o"
239 # define SCNoFAST64	__PRI64_PREFIX "o"
240 
241 /* Hexadecimal notation.  */
242 # define SCNx8		"hhx"
243 # define SCNx16		"hx"
244 # define SCNx32		"x"
245 # define SCNx64		__PRI64_PREFIX "x"
246 
247 # define SCNxLEAST8	"hhx"
248 # define SCNxLEAST16	"hx"
249 # define SCNxLEAST32	"x"
250 # define SCNxLEAST64	__PRI64_PREFIX "x"
251 
252 # define SCNxFAST8	"hhx"
253 # define SCNxFAST16	__PRIPTR_PREFIX "x"
254 # define SCNxFAST32	__PRIPTR_PREFIX "x"
255 # define SCNxFAST64	__PRI64_PREFIX "x"
256 
257 
258 /* Macros for scanning `intmax_t' and `uintmax_t'.  */
259 # define SCNdMAX	__PRI64_PREFIX "d"
260 # define SCNiMAX	__PRI64_PREFIX "i"
261 # define SCNoMAX	__PRI64_PREFIX "o"
262 # define SCNuMAX	__PRI64_PREFIX "u"
263 # define SCNxMAX	__PRI64_PREFIX "x"
264 
265 /* Macros for scaning `intptr_t' and `uintptr_t'.  */
266 # define SCNdPTR	__PRIPTR_PREFIX "d"
267 # define SCNiPTR	__PRIPTR_PREFIX "i"
268 # define SCNoPTR	__PRIPTR_PREFIX "o"
269 # define SCNuPTR	__PRIPTR_PREFIX "u"
270 # define SCNxPTR	__PRIPTR_PREFIX "x"
271 
272 #endif	/* C++ && format macros */
273 
274 
275 __BEGIN_DECLS
276 
277 #if __WORDSIZE == 64
278 
279 /* We have to define the `uintmax_t' type using `ldiv_t'.  */
280 typedef struct
281   {
282     long int quot;		/* Quotient.  */
283     long int rem;		/* Remainder.  */
284   } imaxdiv_t;
285 
286 #else
287 
288 /* We have to define the `uintmax_t' type using `lldiv_t'.  */
289 typedef struct
290   {
291     long long int quot;		/* Quotient.  */
292     long long int rem;		/* Remainder.  */
293   } imaxdiv_t;
294 
295 #endif
296 
297 
298 /* Compute absolute value of N.  */
299 extern intmax_t imaxabs (intmax_t __n) __THROW __attribute__ ((__const__));
300 
301 /* Return the `imaxdiv_t' representation of the value of NUMER over DENOM. */
302 extern imaxdiv_t imaxdiv (intmax_t __numer, intmax_t __denom)
303       __THROW __attribute__ ((__const__));
304 
305 /* Like `strtol' but convert to `intmax_t'.  */
306 extern intmax_t strtoimax (const char *__restrict __nptr,
307 			   char **__restrict __endptr, int __base) __THROW;
308 
309 /* Like `strtoul' but convert to `uintmax_t'.  */
310 extern uintmax_t strtoumax (const char *__restrict __nptr,
311 			    char ** __restrict __endptr, int __base) __THROW;
312 
313 #ifdef __UCLIBC_HAS_WCHAR__
314 /* Like `wcstol' but convert to `intmax_t'.  */
315 extern intmax_t wcstoimax (const __gwchar_t *__restrict __nptr,
316 			   __gwchar_t **__restrict __endptr, int __base)
317      __THROW;
318 
319 /* Like `wcstoul' but convert to `uintmax_t'.  */
320 extern uintmax_t wcstoumax (const __gwchar_t *__restrict __nptr,
321 			    __gwchar_t ** __restrict __endptr, int __base)
322      __THROW;
323 #endif
324 
325 #if 0 /*def __USE_EXTERN_INLINES*/
326 
327 # if __WORDSIZE == 64
328 
329 extern long int __strtol_internal (const char *__restrict __nptr,
330 				   char **__restrict __endptr,
331 				   int __base, int __group)
332   __THROW __nonnull ((1)) __wur;
333 /* Like `strtol' but convert to `intmax_t'.  */
334 __extern_inline intmax_t
335 __NTH (strtoimax (const char *__restrict nptr, char **__restrict endptr,
336 		  int base))
337 {
338   return __strtol_internal (nptr, endptr, base, 0);
339 }
340 
341 extern unsigned long int __strtoul_internal (const char *
342 					     __restrict __nptr,
343 					     char ** __restrict __endptr,
344 					     int __base, int __group)
345   __THROW __nonnull ((1)) __wur;
346 /* Like `strtoul' but convert to `uintmax_t'.  */
347 __extern_inline uintmax_t
348 __NTH (strtoumax (const char *__restrict nptr, char **__restrict endptr,
349 		  int base))
350 {
351   return __strtoul_internal (nptr, endptr, base, 0);
352 }
353 
354 extern long int __wcstol_internal (const __gwchar_t * __restrict __nptr,
355 				   __gwchar_t **__restrict __endptr,
356 				   int __base, int __group)
357   __THROW __nonnull ((1)) __wur;
358 /* Like `wcstol' but convert to `intmax_t'.  */
359 __extern_inline intmax_t
360 __NTH (wcstoimax (const __gwchar_t *__restrict nptr,
361 		  __gwchar_t **__restrict endptr, int base))
362 {
363   return __wcstol_internal (nptr, endptr, base, 0);
364 }
365 
366 extern unsigned long int __wcstoul_internal (const __gwchar_t *
367 					     __restrict __nptr,
368 					     __gwchar_t **
369 					     __restrict __endptr,
370 					     int __base, int __group)
371   __THROW __nonnull ((1)) __wur;
372 /* Like `wcstoul' but convert to `uintmax_t'.  */
373 __extern_inline uintmax_t
374 __NTH (wcstoumax (const __gwchar_t *__restrict nptr,
375 		  __gwchar_t **__restrict endptr, int base))
376 {
377   return __wcstoul_internal (nptr, endptr, base, 0);
378 }
379 
380 # else /* __WORDSIZE == 32 */
381 
382 __extension__
383 extern long long int __strtoll_internal (const char *__restrict __nptr,
384 					 char **__restrict __endptr,
385 					 int __base, int __group)
386   __THROW __nonnull ((1)) __wur;
387 /* Like `strtol' but convert to `intmax_t'.  */
388 __extern_inline intmax_t
389 __NTH (strtoimax (const char *__restrict nptr, char **__restrict endptr,
390 		  int base))
391 {
392   return __strtoll_internal (nptr, endptr, base, 0);
393 }
394 
395 __extension__
396 extern unsigned long long int __strtoull_internal (const char *
397 						   __restrict __nptr,
398 						   char **
399 						   __restrict __endptr,
400 						   int __base,
401 						   int __group)
402   __THROW __nonnull ((1)) __wur;
403 /* Like `strtoul' but convert to `uintmax_t'.  */
404 __extern_inline uintmax_t
405 __NTH (strtoumax (const char *__restrict nptr, char **__restrict endptr,
406 		  int base))
407 {
408   return __strtoull_internal (nptr, endptr, base, 0);
409 }
410 
411 __extension__
412 extern long long int __wcstoll_internal (const __gwchar_t *
413 					 __restrict __nptr,
414 					 __gwchar_t **__restrict __endptr,
415 					 int __base, int __group)
416   __THROW __nonnull ((1)) __wur;
417 /* Like `wcstol' but convert to `intmax_t'.  */
418 __extern_inline intmax_t
419 __NTH (wcstoimax (const __gwchar_t *__restrict nptr,
420 		  __gwchar_t **__restrict endptr, int base))
421 {
422   return __wcstoll_internal (nptr, endptr, base, 0);
423 }
424 
425 
426 __extension__
427 extern unsigned long long int __wcstoull_internal (const __gwchar_t *
428 						   __restrict __nptr,
429 						   __gwchar_t **
430 						   __restrict __endptr,
431 						   int __base,
432 						   int __group)
433   __THROW __nonnull ((1)) __wur;
434 /* Like `wcstoul' but convert to `uintmax_t'.  */
435 __extern_inline uintmax_t
436 __NTH (wcstoumax (const __gwchar_t *__restrict nptr,
437 		  __gwchar_t **__restrict endptr, int base))
438 {
439   return __wcstoull_internal (nptr, endptr, base, 0);
440 }
441 
442 # endif	/* __WORDSIZE == 32	*/
443 #endif	/* Use extern inlines.  */
444 
445 __END_DECLS
446 
447 #endif /* inttypes.h */
448