1 /* Copyright (C) 1997-2020 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 <https://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 # define __PRI64_PREFIX "l"
45 # define __PRIPTR_PREFIX "l"
47 # define __PRI64_PREFIX "ll"
48 # define __PRIPTR_PREFIX
51 /* Macros for printing format specifiers. */
53 /* Decimal notation. */
57 # define PRId64 __PRI64_PREFIX "d"
59 # define PRIdLEAST8 "d"
60 # define PRIdLEAST16 "d"
61 # define PRIdLEAST32 "d"
62 # define PRIdLEAST64 __PRI64_PREFIX "d"
64 # define PRIdFAST8 "d"
65 # define PRIdFAST16 __PRIPTR_PREFIX "d"
66 # define PRIdFAST32 __PRIPTR_PREFIX "d"
67 # define PRIdFAST64 __PRI64_PREFIX "d"
73 # define PRIi64 __PRI64_PREFIX "i"
75 # define PRIiLEAST8 "i"
76 # define PRIiLEAST16 "i"
77 # define PRIiLEAST32 "i"
78 # define PRIiLEAST64 __PRI64_PREFIX "i"
80 # define PRIiFAST8 "i"
81 # define PRIiFAST16 __PRIPTR_PREFIX "i"
82 # define PRIiFAST32 __PRIPTR_PREFIX "i"
83 # define PRIiFAST64 __PRI64_PREFIX "i"
89 # define PRIo64 __PRI64_PREFIX "o"
91 # define PRIoLEAST8 "o"
92 # define PRIoLEAST16 "o"
93 # define PRIoLEAST32 "o"
94 # define PRIoLEAST64 __PRI64_PREFIX "o"
96 # define PRIoFAST8 "o"
97 # define PRIoFAST16 __PRIPTR_PREFIX "o"
98 # define PRIoFAST32 __PRIPTR_PREFIX "o"
99 # define PRIoFAST64 __PRI64_PREFIX "o"
101 /* Unsigned integers. */
105 # define PRIu64 __PRI64_PREFIX "u"
107 # define PRIuLEAST8 "u"
108 # define PRIuLEAST16 "u"
109 # define PRIuLEAST32 "u"
110 # define PRIuLEAST64 __PRI64_PREFIX "u"
112 # define PRIuFAST8 "u"
113 # define PRIuFAST16 __PRIPTR_PREFIX "u"
114 # define PRIuFAST32 __PRIPTR_PREFIX "u"
115 # define PRIuFAST64 __PRI64_PREFIX "u"
117 /* lowercase hexadecimal notation. */
121 # define PRIx64 __PRI64_PREFIX "x"
123 # define PRIxLEAST8 "x"
124 # define PRIxLEAST16 "x"
125 # define PRIxLEAST32 "x"
126 # define PRIxLEAST64 __PRI64_PREFIX "x"
128 # define PRIxFAST8 "x"
129 # define PRIxFAST16 __PRIPTR_PREFIX "x"
130 # define PRIxFAST32 __PRIPTR_PREFIX "x"
131 # define PRIxFAST64 __PRI64_PREFIX "x"
133 /* UPPERCASE hexadecimal notation. */
137 # define PRIX64 __PRI64_PREFIX "X"
139 # define PRIXLEAST8 "X"
140 # define PRIXLEAST16 "X"
141 # define PRIXLEAST32 "X"
142 # define PRIXLEAST64 __PRI64_PREFIX "X"
144 # define PRIXFAST8 "X"
145 # define PRIXFAST16 __PRIPTR_PREFIX "X"
146 # define PRIXFAST32 __PRIPTR_PREFIX "X"
147 # define PRIXFAST64 __PRI64_PREFIX "X"
150 /* Macros for printing `intmax_t' and `uintmax_t'. */
151 # define PRIdMAX __PRI64_PREFIX "d"
152 # define PRIiMAX __PRI64_PREFIX "i"
153 # define PRIoMAX __PRI64_PREFIX "o"
154 # define PRIuMAX __PRI64_PREFIX "u"
155 # define PRIxMAX __PRI64_PREFIX "x"
156 # define PRIXMAX __PRI64_PREFIX "X"
159 /* Macros for printing `intptr_t' and `uintptr_t'. */
160 # define PRIdPTR __PRIPTR_PREFIX "d"
161 # define PRIiPTR __PRIPTR_PREFIX "i"
162 # define PRIoPTR __PRIPTR_PREFIX "o"
163 # define PRIuPTR __PRIPTR_PREFIX "u"
164 # define PRIxPTR __PRIPTR_PREFIX "x"
165 # define PRIXPTR __PRIPTR_PREFIX "X"
168 /* Macros for scanning format specifiers. */
170 /* Signed decimal notation. */
174 # define SCNd64 __PRI64_PREFIX "d"
176 # define SCNdLEAST8 "hhd"
177 # define SCNdLEAST16 "hd"
178 # define SCNdLEAST32 "d"
179 # define SCNdLEAST64 __PRI64_PREFIX "d"
181 # define SCNdFAST8 "hhd"
182 # define SCNdFAST16 __PRIPTR_PREFIX "d"
183 # define SCNdFAST32 __PRIPTR_PREFIX "d"
184 # define SCNdFAST64 __PRI64_PREFIX "d"
186 /* Signed decimal notation. */
190 # define SCNi64 __PRI64_PREFIX "i"
192 # define SCNiLEAST8 "hhi"
193 # define SCNiLEAST16 "hi"
194 # define SCNiLEAST32 "i"
195 # define SCNiLEAST64 __PRI64_PREFIX "i"
197 # define SCNiFAST8 "hhi"
198 # define SCNiFAST16 __PRIPTR_PREFIX "i"
199 # define SCNiFAST32 __PRIPTR_PREFIX "i"
200 # define SCNiFAST64 __PRI64_PREFIX "i"
202 /* Unsigned decimal notation. */
206 # define SCNu64 __PRI64_PREFIX "u"
208 # define SCNuLEAST8 "hhu"
209 # define SCNuLEAST16 "hu"
210 # define SCNuLEAST32 "u"
211 # define SCNuLEAST64 __PRI64_PREFIX "u"
213 # define SCNuFAST8 "hhu"
214 # define SCNuFAST16 __PRIPTR_PREFIX "u"
215 # define SCNuFAST32 __PRIPTR_PREFIX "u"
216 # define SCNuFAST64 __PRI64_PREFIX "u"
218 /* Octal notation. */
222 # define SCNo64 __PRI64_PREFIX "o"
224 # define SCNoLEAST8 "hho"
225 # define SCNoLEAST16 "ho"
226 # define SCNoLEAST32 "o"
227 # define SCNoLEAST64 __PRI64_PREFIX "o"
229 # define SCNoFAST8 "hho"
230 # define SCNoFAST16 __PRIPTR_PREFIX "o"
231 # define SCNoFAST32 __PRIPTR_PREFIX "o"
232 # define SCNoFAST64 __PRI64_PREFIX "o"
234 /* Hexadecimal notation. */
238 # define SCNx64 __PRI64_PREFIX "x"
240 # define SCNxLEAST8 "hhx"
241 # define SCNxLEAST16 "hx"
242 # define SCNxLEAST32 "x"
243 # define SCNxLEAST64 __PRI64_PREFIX "x"
245 # define SCNxFAST8 "hhx"
246 # define SCNxFAST16 __PRIPTR_PREFIX "x"
247 # define SCNxFAST32 __PRIPTR_PREFIX "x"
248 # define SCNxFAST64 __PRI64_PREFIX "x"
251 /* Macros for scanning `intmax_t' and `uintmax_t'. */
252 # define SCNdMAX __PRI64_PREFIX "d"
253 # define SCNiMAX __PRI64_PREFIX "i"
254 # define SCNoMAX __PRI64_PREFIX "o"
255 # define SCNuMAX __PRI64_PREFIX "u"
256 # define SCNxMAX __PRI64_PREFIX "x"
258 /* Macros for scaning `intptr_t' and `uintptr_t'. */
259 # define SCNdPTR __PRIPTR_PREFIX "d"
260 # define SCNiPTR __PRIPTR_PREFIX "i"
261 # define SCNoPTR __PRIPTR_PREFIX "o"
262 # define SCNuPTR __PRIPTR_PREFIX "u"
263 # define SCNxPTR __PRIPTR_PREFIX "x"
270 /* We have to define the `uintmax_t' type using `ldiv_t'. */
273 long int quot
; /* Quotient. */
274 long int rem
; /* Remainder. */
279 /* We have to define the `uintmax_t' type using `lldiv_t'. */
282 __extension__
long long int quot
; /* Quotient. */
283 __extension__
long long int rem
; /* Remainder. */
289 /* Compute absolute value of N. */
290 extern intmax_t imaxabs (intmax_t __n
) __THROW
__attribute__ ((__const__
));
292 /* Return the `imaxdiv_t' representation of the value of NUMER over DENOM. */
293 extern imaxdiv_t
imaxdiv (intmax_t __numer
, intmax_t __denom
)
294 __THROW
__attribute__ ((__const__
));
296 /* Like `strtol' but convert to `intmax_t'. */
297 extern intmax_t strtoimax (const char *__restrict __nptr
,
298 char **__restrict __endptr
, int __base
) __THROW
;
300 /* Like `strtoul' but convert to `uintmax_t'. */
301 extern uintmax_t strtoumax (const char *__restrict __nptr
,
302 char ** __restrict __endptr
, int __base
) __THROW
;
304 /* Like `wcstol' but convert to `intmax_t'. */
305 extern intmax_t wcstoimax (const __gwchar_t
*__restrict __nptr
,
306 __gwchar_t
**__restrict __endptr
, int __base
)
309 /* Like `wcstoul' but convert to `uintmax_t'. */
310 extern uintmax_t wcstoumax (const __gwchar_t
*__restrict __nptr
,
311 __gwchar_t
** __restrict __endptr
, int __base
)
314 #ifdef __USE_EXTERN_INLINES
316 # if __WORDSIZE == 64
318 extern long int __strtol_internal (const char *__restrict __nptr
,
319 char **__restrict __endptr
,
320 int __base
, int __group
)
321 __THROW
__nonnull ((1)) __wur
;
322 /* Like `strtol' but convert to `intmax_t'. */
323 __extern_inline
intmax_t
324 __NTH (strtoimax (const char *__restrict __nptr
, char **__restrict __endptr
,
327 return __strtol_internal (__nptr
, __endptr
, __base
, 0);
330 extern unsigned long int __strtoul_internal (const char *__restrict __nptr
,
331 char ** __restrict __endptr
,
332 int __base
, int __group
)
333 __THROW
__nonnull ((1)) __wur
;
334 /* Like `strtoul' but convert to `uintmax_t'. */
335 __extern_inline
uintmax_t
336 __NTH (strtoumax (const char *__restrict __nptr
, char **__restrict __endptr
,
339 return __strtoul_internal (__nptr
, __endptr
, __base
, 0);
342 extern long int __wcstol_internal (const __gwchar_t
* __restrict __nptr
,
343 __gwchar_t
**__restrict __endptr
,
344 int __base
, int __group
)
345 __THROW
__nonnull ((1)) __wur
;
346 /* Like `wcstol' but convert to `intmax_t'. */
347 __extern_inline
intmax_t
348 __NTH (wcstoimax (const __gwchar_t
*__restrict __nptr
,
349 __gwchar_t
**__restrict __endptr
, int __base
))
351 return __wcstol_internal (__nptr
, __endptr
, __base
, 0);
354 extern unsigned long int __wcstoul_internal (const __gwchar_t
*
358 int __base
, int __group
)
359 __THROW
__nonnull ((1)) __wur
;
360 /* Like `wcstoul' but convert to `uintmax_t'. */
361 __extern_inline
uintmax_t
362 __NTH (wcstoumax (const __gwchar_t
*__restrict __nptr
,
363 __gwchar_t
**__restrict __endptr
, int __base
))
365 return __wcstoul_internal (__nptr
, __endptr
, __base
, 0);
368 # else /* __WORDSIZE == 32 */
371 extern long long int __strtoll_internal (const char *__restrict __nptr
,
372 char **__restrict __endptr
,
373 int __base
, int __group
)
374 __THROW
__nonnull ((1)) __wur
;
375 /* Like `strtol' but convert to `intmax_t'. */
376 __extern_inline
intmax_t
377 __NTH (strtoimax (const char *__restrict __nptr
, char **__restrict __endptr
,
380 return __strtoll_internal (__nptr
, __endptr
, __base
, 0);
384 extern unsigned long long int __strtoull_internal (const char *
390 __THROW
__nonnull ((1)) __wur
;
391 /* Like `strtoul' but convert to `uintmax_t'. */
392 __extern_inline
uintmax_t
393 __NTH (strtoumax (const char *__restrict __nptr
, char **__restrict __endptr
,
396 return __strtoull_internal (__nptr
, __endptr
, __base
, 0);
400 extern long long int __wcstoll_internal (const __gwchar_t
*__restrict __nptr
,
401 __gwchar_t
**__restrict __endptr
,
402 int __base
, int __group
)
403 __THROW
__nonnull ((1)) __wur
;
404 /* Like `wcstol' but convert to `intmax_t'. */
405 __extern_inline
intmax_t
406 __NTH (wcstoimax (const __gwchar_t
*__restrict __nptr
,
407 __gwchar_t
**__restrict __endptr
, int __base
))
409 return __wcstoll_internal (__nptr
, __endptr
, __base
, 0);
414 extern unsigned long long int __wcstoull_internal (const __gwchar_t
*
420 __THROW
__nonnull ((1)) __wur
;
421 /* Like `wcstoul' but convert to `uintmax_t'. */
422 __extern_inline
uintmax_t
423 __NTH (wcstoumax (const __gwchar_t
*__restrict __nptr
,
424 __gwchar_t
**__restrict __endptr
, int __base
))
426 return __wcstoull_internal (__nptr
, __endptr
, __base
, 0);
429 # endif /* __WORDSIZE == 32 */
430 #endif /* Use extern inlines. */
434 #endif /* inttypes.h */