1 /* Copyright (C) 1997-2001, 2004, 2007 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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/>. */
19 * ISO C99: 7.8 Format conversion of integer types <inttypes.h>
26 /* Get the type definitions. */
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
33 # define __gwchar_t wchar_t
34 # elif defined __WCHAR_TYPE__
35 typedef __WCHAR_TYPE__ __gwchar_t
;
37 # define __need_wchar_t
39 typedef wchar_t __gwchar_t
;
41 # define ____gwchar_t_defined 1
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
51 # define __PRI64_PREFIX "l"
52 # define __PRIPTR_PREFIX "l"
54 # define __PRI64_PREFIX "ll"
55 # define __PRIPTR_PREFIX
58 /* Macros for printing format specifiers. */
60 /* Decimal notation. */
64 # define PRId64 __PRI64_PREFIX "d"
66 # define PRIdLEAST8 "d"
67 # define PRIdLEAST16 "d"
68 # define PRIdLEAST32 "d"
69 # define PRIdLEAST64 __PRI64_PREFIX "d"
71 # define PRIdFAST8 "d"
72 # define PRIdFAST16 __PRIPTR_PREFIX "d"
73 # define PRIdFAST32 __PRIPTR_PREFIX "d"
74 # define PRIdFAST64 __PRI64_PREFIX "d"
80 # define PRIi64 __PRI64_PREFIX "i"
82 # define PRIiLEAST8 "i"
83 # define PRIiLEAST16 "i"
84 # define PRIiLEAST32 "i"
85 # define PRIiLEAST64 __PRI64_PREFIX "i"
87 # define PRIiFAST8 "i"
88 # define PRIiFAST16 __PRIPTR_PREFIX "i"
89 # define PRIiFAST32 __PRIPTR_PREFIX "i"
90 # define PRIiFAST64 __PRI64_PREFIX "i"
96 # define PRIo64 __PRI64_PREFIX "o"
98 # define PRIoLEAST8 "o"
99 # define PRIoLEAST16 "o"
100 # define PRIoLEAST32 "o"
101 # define PRIoLEAST64 __PRI64_PREFIX "o"
103 # define PRIoFAST8 "o"
104 # define PRIoFAST16 __PRIPTR_PREFIX "o"
105 # define PRIoFAST32 __PRIPTR_PREFIX "o"
106 # define PRIoFAST64 __PRI64_PREFIX "o"
108 /* Unsigned integers. */
112 # define PRIu64 __PRI64_PREFIX "u"
114 # define PRIuLEAST8 "u"
115 # define PRIuLEAST16 "u"
116 # define PRIuLEAST32 "u"
117 # define PRIuLEAST64 __PRI64_PREFIX "u"
119 # define PRIuFAST8 "u"
120 # define PRIuFAST16 __PRIPTR_PREFIX "u"
121 # define PRIuFAST32 __PRIPTR_PREFIX "u"
122 # define PRIuFAST64 __PRI64_PREFIX "u"
124 /* lowercase hexadecimal notation. */
128 # define PRIx64 __PRI64_PREFIX "x"
130 # define PRIxLEAST8 "x"
131 # define PRIxLEAST16 "x"
132 # define PRIxLEAST32 "x"
133 # define PRIxLEAST64 __PRI64_PREFIX "x"
135 # define PRIxFAST8 "x"
136 # define PRIxFAST16 __PRIPTR_PREFIX "x"
137 # define PRIxFAST32 __PRIPTR_PREFIX "x"
138 # define PRIxFAST64 __PRI64_PREFIX "x"
140 /* UPPERCASE hexadecimal notation. */
144 # define PRIX64 __PRI64_PREFIX "X"
146 # define PRIXLEAST8 "X"
147 # define PRIXLEAST16 "X"
148 # define PRIXLEAST32 "X"
149 # define PRIXLEAST64 __PRI64_PREFIX "X"
151 # define PRIXFAST8 "X"
152 # define PRIXFAST16 __PRIPTR_PREFIX "X"
153 # define PRIXFAST32 __PRIPTR_PREFIX "X"
154 # define PRIXFAST64 __PRI64_PREFIX "X"
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"
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"
175 /* Macros for scanning format specifiers. */
177 /* Signed decimal notation. */
181 # define SCNd64 __PRI64_PREFIX "d"
183 # define SCNdLEAST8 "hhd"
184 # define SCNdLEAST16 "hd"
185 # define SCNdLEAST32 "d"
186 # define SCNdLEAST64 __PRI64_PREFIX "d"
188 # define SCNdFAST8 "hhd"
189 # define SCNdFAST16 __PRIPTR_PREFIX "d"
190 # define SCNdFAST32 __PRIPTR_PREFIX "d"
191 # define SCNdFAST64 __PRI64_PREFIX "d"
193 /* Signed decimal notation. */
197 # define SCNi64 __PRI64_PREFIX "i"
199 # define SCNiLEAST8 "hhi"
200 # define SCNiLEAST16 "hi"
201 # define SCNiLEAST32 "i"
202 # define SCNiLEAST64 __PRI64_PREFIX "i"
204 # define SCNiFAST8 "hhi"
205 # define SCNiFAST16 __PRIPTR_PREFIX "i"
206 # define SCNiFAST32 __PRIPTR_PREFIX "i"
207 # define SCNiFAST64 __PRI64_PREFIX "i"
209 /* Unsigned decimal notation. */
213 # define SCNu64 __PRI64_PREFIX "u"
215 # define SCNuLEAST8 "hhu"
216 # define SCNuLEAST16 "hu"
217 # define SCNuLEAST32 "u"
218 # define SCNuLEAST64 __PRI64_PREFIX "u"
220 # define SCNuFAST8 "hhu"
221 # define SCNuFAST16 __PRIPTR_PREFIX "u"
222 # define SCNuFAST32 __PRIPTR_PREFIX "u"
223 # define SCNuFAST64 __PRI64_PREFIX "u"
225 /* Octal notation. */
229 # define SCNo64 __PRI64_PREFIX "o"
231 # define SCNoLEAST8 "hho"
232 # define SCNoLEAST16 "ho"
233 # define SCNoLEAST32 "o"
234 # define SCNoLEAST64 __PRI64_PREFIX "o"
236 # define SCNoFAST8 "hho"
237 # define SCNoFAST16 __PRIPTR_PREFIX "o"
238 # define SCNoFAST32 __PRIPTR_PREFIX "o"
239 # define SCNoFAST64 __PRI64_PREFIX "o"
241 /* Hexadecimal notation. */
245 # define SCNx64 __PRI64_PREFIX "x"
247 # define SCNxLEAST8 "hhx"
248 # define SCNxLEAST16 "hx"
249 # define SCNxLEAST32 "x"
250 # define SCNxLEAST64 __PRI64_PREFIX "x"
252 # define SCNxFAST8 "hhx"
253 # define SCNxFAST16 __PRIPTR_PREFIX "x"
254 # define SCNxFAST32 __PRIPTR_PREFIX "x"
255 # define SCNxFAST64 __PRI64_PREFIX "x"
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"
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"
272 #endif /* C++ && format macros */
279 /* We have to define the `uintmax_t' type using `ldiv_t'. */
282 long int quot
; /* Quotient. */
283 long int rem
; /* Remainder. */
288 /* We have to define the `uintmax_t' type using `lldiv_t'. */
291 long long int quot
; /* Quotient. */
292 long long int rem
; /* Remainder. */
298 /* Compute absolute value of N. */
299 extern intmax_t imaxabs (intmax_t __n
) __THROW
__attribute__ ((__const__
));
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__
));
305 /* Like `strtol' but convert to `intmax_t'. */
306 extern intmax_t strtoimax (const char *__restrict __nptr
,
307 char **__restrict __endptr
, int __base
) __THROW
;
309 /* Like `strtoul' but convert to `uintmax_t'. */
310 extern uintmax_t strtoumax (const char *__restrict __nptr
,
311 char ** __restrict __endptr
, int __base
) __THROW
;
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
)
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
)
325 #if 0 /*def __USE_EXTERN_INLINES*/
327 # if __WORDSIZE == 64
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
,
338 return __strtol_internal (nptr
, endptr
, base
, 0);
341 extern unsigned long int __strtoul_internal (const char *
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
,
351 return __strtoul_internal (nptr
, endptr
, base
, 0);
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
))
363 return __wcstol_internal (nptr
, endptr
, base
, 0);
366 extern unsigned long int __wcstoul_internal (const __gwchar_t
*
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
))
377 return __wcstoul_internal (nptr
, endptr
, base
, 0);
380 # else /* __WORDSIZE == 32 */
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
,
392 return __strtoll_internal (nptr
, endptr
, base
, 0);
396 extern unsigned long long int __strtoull_internal (const char *
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
,
408 return __strtoull_internal (nptr
, endptr
, base
, 0);
412 extern long long int __wcstoll_internal (const __gwchar_t
*
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
))
422 return __wcstoll_internal (nptr
, endptr
, base
, 0);
427 extern unsigned long long int __wcstoull_internal (const __gwchar_t
*
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
))
439 return __wcstoull_internal (nptr
, endptr
, base
, 0);
442 # endif /* __WORDSIZE == 32 */
443 #endif /* Use extern inlines. */
447 #endif /* inttypes.h */