1 /* Copyright (C) 1997-2013 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 /* Get a definition for wchar_t. But we must not define wchar_t itself. */
30 #ifndef ____gwchar_t_defined
32 # define __gwchar_t wchar_t
33 # elif defined __WCHAR_TYPE__
34 typedef __WCHAR_TYPE__ __gwchar_t
;
36 # define __need_wchar_t
38 typedef wchar_t __gwchar_t
;
40 # define ____gwchar_t_defined 1
44 /* The ISO C99 standard specifies that these macros must only be
45 defined if explicitly requested. */
46 #if !defined __cplusplus || defined __STDC_FORMAT_MACROS
49 # define __PRI64_PREFIX "l"
50 # define __PRIPTR_PREFIX "l"
52 # define __PRI64_PREFIX "ll"
53 # define __PRIPTR_PREFIX
56 /* Macros for printing format specifiers. */
58 /* Decimal notation. */
62 # define PRId64 __PRI64_PREFIX "d"
64 # define PRIdLEAST8 "d"
65 # define PRIdLEAST16 "d"
66 # define PRIdLEAST32 "d"
67 # define PRIdLEAST64 __PRI64_PREFIX "d"
69 # define PRIdFAST8 "d"
70 # define PRIdFAST16 __PRIPTR_PREFIX "d"
71 # define PRIdFAST32 __PRIPTR_PREFIX "d"
72 # define PRIdFAST64 __PRI64_PREFIX "d"
78 # define PRIi64 __PRI64_PREFIX "i"
80 # define PRIiLEAST8 "i"
81 # define PRIiLEAST16 "i"
82 # define PRIiLEAST32 "i"
83 # define PRIiLEAST64 __PRI64_PREFIX "i"
85 # define PRIiFAST8 "i"
86 # define PRIiFAST16 __PRIPTR_PREFIX "i"
87 # define PRIiFAST32 __PRIPTR_PREFIX "i"
88 # define PRIiFAST64 __PRI64_PREFIX "i"
94 # define PRIo64 __PRI64_PREFIX "o"
96 # define PRIoLEAST8 "o"
97 # define PRIoLEAST16 "o"
98 # define PRIoLEAST32 "o"
99 # define PRIoLEAST64 __PRI64_PREFIX "o"
101 # define PRIoFAST8 "o"
102 # define PRIoFAST16 __PRIPTR_PREFIX "o"
103 # define PRIoFAST32 __PRIPTR_PREFIX "o"
104 # define PRIoFAST64 __PRI64_PREFIX "o"
106 /* Unsigned integers. */
110 # define PRIu64 __PRI64_PREFIX "u"
112 # define PRIuLEAST8 "u"
113 # define PRIuLEAST16 "u"
114 # define PRIuLEAST32 "u"
115 # define PRIuLEAST64 __PRI64_PREFIX "u"
117 # define PRIuFAST8 "u"
118 # define PRIuFAST16 __PRIPTR_PREFIX "u"
119 # define PRIuFAST32 __PRIPTR_PREFIX "u"
120 # define PRIuFAST64 __PRI64_PREFIX "u"
122 /* lowercase hexadecimal notation. */
126 # define PRIx64 __PRI64_PREFIX "x"
128 # define PRIxLEAST8 "x"
129 # define PRIxLEAST16 "x"
130 # define PRIxLEAST32 "x"
131 # define PRIxLEAST64 __PRI64_PREFIX "x"
133 # define PRIxFAST8 "x"
134 # define PRIxFAST16 __PRIPTR_PREFIX "x"
135 # define PRIxFAST32 __PRIPTR_PREFIX "x"
136 # define PRIxFAST64 __PRI64_PREFIX "x"
138 /* UPPERCASE hexadecimal notation. */
142 # define PRIX64 __PRI64_PREFIX "X"
144 # define PRIXLEAST8 "X"
145 # define PRIXLEAST16 "X"
146 # define PRIXLEAST32 "X"
147 # define PRIXLEAST64 __PRI64_PREFIX "X"
149 # define PRIXFAST8 "X"
150 # define PRIXFAST16 __PRIPTR_PREFIX "X"
151 # define PRIXFAST32 __PRIPTR_PREFIX "X"
152 # define PRIXFAST64 __PRI64_PREFIX "X"
155 /* Macros for printing `intmax_t' and `uintmax_t'. */
156 # define PRIdMAX __PRI64_PREFIX "d"
157 # define PRIiMAX __PRI64_PREFIX "i"
158 # define PRIoMAX __PRI64_PREFIX "o"
159 # define PRIuMAX __PRI64_PREFIX "u"
160 # define PRIxMAX __PRI64_PREFIX "x"
161 # define PRIXMAX __PRI64_PREFIX "X"
164 /* Macros for printing `intptr_t' and `uintptr_t'. */
165 # define PRIdPTR __PRIPTR_PREFIX "d"
166 # define PRIiPTR __PRIPTR_PREFIX "i"
167 # define PRIoPTR __PRIPTR_PREFIX "o"
168 # define PRIuPTR __PRIPTR_PREFIX "u"
169 # define PRIxPTR __PRIPTR_PREFIX "x"
170 # define PRIXPTR __PRIPTR_PREFIX "X"
173 /* Macros for scanning format specifiers. */
175 /* Signed decimal notation. */
179 # define SCNd64 __PRI64_PREFIX "d"
181 # define SCNdLEAST8 "hhd"
182 # define SCNdLEAST16 "hd"
183 # define SCNdLEAST32 "d"
184 # define SCNdLEAST64 __PRI64_PREFIX "d"
186 # define SCNdFAST8 "hhd"
187 # define SCNdFAST16 __PRIPTR_PREFIX "d"
188 # define SCNdFAST32 __PRIPTR_PREFIX "d"
189 # define SCNdFAST64 __PRI64_PREFIX "d"
191 /* Signed decimal notation. */
195 # define SCNi64 __PRI64_PREFIX "i"
197 # define SCNiLEAST8 "hhi"
198 # define SCNiLEAST16 "hi"
199 # define SCNiLEAST32 "i"
200 # define SCNiLEAST64 __PRI64_PREFIX "i"
202 # define SCNiFAST8 "hhi"
203 # define SCNiFAST16 __PRIPTR_PREFIX "i"
204 # define SCNiFAST32 __PRIPTR_PREFIX "i"
205 # define SCNiFAST64 __PRI64_PREFIX "i"
207 /* Unsigned decimal notation. */
211 # define SCNu64 __PRI64_PREFIX "u"
213 # define SCNuLEAST8 "hhu"
214 # define SCNuLEAST16 "hu"
215 # define SCNuLEAST32 "u"
216 # define SCNuLEAST64 __PRI64_PREFIX "u"
218 # define SCNuFAST8 "hhu"
219 # define SCNuFAST16 __PRIPTR_PREFIX "u"
220 # define SCNuFAST32 __PRIPTR_PREFIX "u"
221 # define SCNuFAST64 __PRI64_PREFIX "u"
223 /* Octal notation. */
227 # define SCNo64 __PRI64_PREFIX "o"
229 # define SCNoLEAST8 "hho"
230 # define SCNoLEAST16 "ho"
231 # define SCNoLEAST32 "o"
232 # define SCNoLEAST64 __PRI64_PREFIX "o"
234 # define SCNoFAST8 "hho"
235 # define SCNoFAST16 __PRIPTR_PREFIX "o"
236 # define SCNoFAST32 __PRIPTR_PREFIX "o"
237 # define SCNoFAST64 __PRI64_PREFIX "o"
239 /* Hexadecimal notation. */
243 # define SCNx64 __PRI64_PREFIX "x"
245 # define SCNxLEAST8 "hhx"
246 # define SCNxLEAST16 "hx"
247 # define SCNxLEAST32 "x"
248 # define SCNxLEAST64 __PRI64_PREFIX "x"
250 # define SCNxFAST8 "hhx"
251 # define SCNxFAST16 __PRIPTR_PREFIX "x"
252 # define SCNxFAST32 __PRIPTR_PREFIX "x"
253 # define SCNxFAST64 __PRI64_PREFIX "x"
256 /* Macros for scanning `intmax_t' and `uintmax_t'. */
257 # define SCNdMAX __PRI64_PREFIX "d"
258 # define SCNiMAX __PRI64_PREFIX "i"
259 # define SCNoMAX __PRI64_PREFIX "o"
260 # define SCNuMAX __PRI64_PREFIX "u"
261 # define SCNxMAX __PRI64_PREFIX "x"
263 /* Macros for scaning `intptr_t' and `uintptr_t'. */
264 # define SCNdPTR __PRIPTR_PREFIX "d"
265 # define SCNiPTR __PRIPTR_PREFIX "i"
266 # define SCNoPTR __PRIPTR_PREFIX "o"
267 # define SCNuPTR __PRIPTR_PREFIX "u"
268 # define SCNxPTR __PRIPTR_PREFIX "x"
270 #endif /* C++ && format macros */
277 /* We have to define the `uintmax_t' type using `ldiv_t'. */
280 long int quot
; /* Quotient. */
281 long int rem
; /* Remainder. */
286 /* We have to define the `uintmax_t' type using `lldiv_t'. */
289 long long int quot
; /* Quotient. */
290 long long int rem
; /* Remainder. */
296 /* Compute absolute value of N. */
297 extern intmax_t imaxabs (intmax_t __n
) __THROW
__attribute__ ((__const__
));
299 /* Return the `imaxdiv_t' representation of the value of NUMER over DENOM. */
300 extern imaxdiv_t
imaxdiv (intmax_t __numer
, intmax_t __denom
)
301 __THROW
__attribute__ ((__const__
));
303 /* Like `strtol' but convert to `intmax_t'. */
304 extern intmax_t strtoimax (const char *__restrict __nptr
,
305 char **__restrict __endptr
, int __base
) __THROW
;
307 /* Like `strtoul' but convert to `uintmax_t'. */
308 extern uintmax_t strtoumax (const char *__restrict __nptr
,
309 char ** __restrict __endptr
, int __base
) __THROW
;
311 /* Like `wcstol' but convert to `intmax_t'. */
312 extern intmax_t wcstoimax (const __gwchar_t
*__restrict __nptr
,
313 __gwchar_t
**__restrict __endptr
, int __base
)
316 /* Like `wcstoul' but convert to `uintmax_t'. */
317 extern uintmax_t wcstoumax (const __gwchar_t
*__restrict __nptr
,
318 __gwchar_t
** __restrict __endptr
, int __base
)
321 #ifdef __USE_EXTERN_INLINES
323 # if __WORDSIZE == 64
325 extern long int __strtol_internal (const char *__restrict __nptr
,
326 char **__restrict __endptr
,
327 int __base
, int __group
)
328 __THROW
__nonnull ((1)) __wur
;
329 /* Like `strtol' but convert to `intmax_t'. */
330 __extern_inline
intmax_t
331 __NTH (strtoimax (const char *__restrict nptr
, char **__restrict endptr
,
334 return __strtol_internal (nptr
, endptr
, base
, 0);
337 extern unsigned long int __strtoul_internal (const char *__restrict __nptr
,
338 char ** __restrict __endptr
,
339 int __base
, int __group
)
340 __THROW
__nonnull ((1)) __wur
;
341 /* Like `strtoul' but convert to `uintmax_t'. */
342 __extern_inline
uintmax_t
343 __NTH (strtoumax (const char *__restrict nptr
, char **__restrict endptr
,
346 return __strtoul_internal (nptr
, endptr
, base
, 0);
349 extern long int __wcstol_internal (const __gwchar_t
* __restrict __nptr
,
350 __gwchar_t
**__restrict __endptr
,
351 int __base
, int __group
)
352 __THROW
__nonnull ((1)) __wur
;
353 /* Like `wcstol' but convert to `intmax_t'. */
354 __extern_inline
intmax_t
355 __NTH (wcstoimax (const __gwchar_t
*__restrict nptr
,
356 __gwchar_t
**__restrict endptr
, int base
))
358 return __wcstol_internal (nptr
, endptr
, base
, 0);
361 extern unsigned long int __wcstoul_internal (const __gwchar_t
*
365 int __base
, int __group
)
366 __THROW
__nonnull ((1)) __wur
;
367 /* Like `wcstoul' but convert to `uintmax_t'. */
368 __extern_inline
uintmax_t
369 __NTH (wcstoumax (const __gwchar_t
*__restrict nptr
,
370 __gwchar_t
**__restrict endptr
, int base
))
372 return __wcstoul_internal (nptr
, endptr
, base
, 0);
375 # else /* __WORDSIZE == 32 */
378 extern long long int __strtoll_internal (const char *__restrict __nptr
,
379 char **__restrict __endptr
,
380 int __base
, int __group
)
381 __THROW
__nonnull ((1)) __wur
;
382 /* Like `strtol' but convert to `intmax_t'. */
383 __extern_inline
intmax_t
384 __NTH (strtoimax (const char *__restrict nptr
, char **__restrict endptr
,
387 return __strtoll_internal (nptr
, endptr
, base
, 0);
391 extern unsigned long long int __strtoull_internal (const char *
397 __THROW
__nonnull ((1)) __wur
;
398 /* Like `strtoul' but convert to `uintmax_t'. */
399 __extern_inline
uintmax_t
400 __NTH (strtoumax (const char *__restrict nptr
, char **__restrict endptr
,
403 return __strtoull_internal (nptr
, endptr
, base
, 0);
407 extern long long int __wcstoll_internal (const __gwchar_t
*__restrict __nptr
,
408 __gwchar_t
**__restrict __endptr
,
409 int __base
, int __group
)
410 __THROW
__nonnull ((1)) __wur
;
411 /* Like `wcstol' but convert to `intmax_t'. */
412 __extern_inline
intmax_t
413 __NTH (wcstoimax (const __gwchar_t
*__restrict nptr
,
414 __gwchar_t
**__restrict endptr
, int base
))
416 return __wcstoll_internal (nptr
, endptr
, base
, 0);
421 extern unsigned long long int __wcstoull_internal (const __gwchar_t
*
427 __THROW
__nonnull ((1)) __wur
;
428 /* Like `wcstoul' but convert to `uintmax_t'. */
429 __extern_inline
uintmax_t
430 __NTH (wcstoumax (const __gwchar_t
*__restrict nptr
,
431 __gwchar_t
**__restrict endptr
, int base
))
433 return __wcstoull_internal (nptr
, endptr
, base
, 0);
436 # endif /* __WORDSIZE == 32 */
437 #endif /* Use extern inlines. */
441 #endif /* inttypes.h */