Update.
[glibc.git] / sysdeps / generic / inttypes.h
blob1ac9114fc4f33d1729f3a82b5d17e28c4ea27346
1 /* Copyright (C) 1997, 1998, 1999 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 Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
20 * ISO C99: 7.8 Format conversion of integer types <inttypes.h>
23 #ifndef _INTTYPES_H
24 #define _INTTYPES_H 1
26 #include <features.h>
27 /* Get the type definitions. */
28 #include <stdint.h>
31 /* The ISO C99 standard specifies that these macros must only be
32 defined if explicitly requested. */
33 #if !defined __cplusplus || defined __STDC_FORMAT_MACROS
35 # if __WORDSIZE == 64
36 # define __PRI64_PREFIX "l"
37 # define __PRIPTR_PREFIX "l"
38 # else
39 # define __PRI64_PREFIX "ll"
40 # define __PRIPTR_PREFIX
41 # endif
43 /* Macros for printing format specifiers. */
45 /* Decimal notation. */
46 # define PRId8 "d"
47 # define PRId16 "d"
48 # define PRId32 "d"
49 # define PRId64 __PRI64_PREFIX "d"
51 # define PRIdLEAST8 "d"
52 # define PRIdLEAST16 "d"
53 # define PRIdLEAST32 "d"
54 # define PRIdLEAST64 __PRI64_PREFIX "d"
56 # define PRIdFAST8 "d"
57 # define PRIdFAST16 "d"
58 # define PRIdFAST32 "d"
59 # define PRIdFAST64 __PRI64_PREFIX "d"
62 # define PRIi8 "i"
63 # define PRIi16 "i"
64 # define PRIi32 "i"
65 # define PRIi64 __PRI64_PREFIX "i"
67 # define PRIiLEAST8 "i"
68 # define PRIiLEAST16 "i"
69 # define PRIiLEAST32 "i"
70 # define PRIiLEAST64 __PRI64_PREFIX "i"
72 # define PRIiFAST8 "i"
73 # define PRIiFAST16 "i"
74 # define PRIiFAST32 "i"
75 # define PRIiFAST64 __PRI64_PREFIX "i"
77 /* Octal notation. */
78 # define PRIo8 "o"
79 # define PRIo16 "o"
80 # define PRIo32 "o"
81 # define PRIo64 __PRI64_PREFIX "o"
83 # define PRIoLEAST8 "o"
84 # define PRIoLEAST16 "o"
85 # define PRIoLEAST32 "o"
86 # define PRIoLEAST64 __PRI64_PREFIX "o"
88 # define PRIoFAST8 "o"
89 # define PRIoFAST16 "o"
90 # define PRIoFAST32 "o"
91 # define PRIoFAST64 __PRI64_PREFIX "o"
93 /* Unsigned integers. */
94 # define PRIu8 "u"
95 # define PRIu16 "u"
96 # define PRIu32 "u"
97 # define PRIu64 __PRI64_PREFIX "u"
99 # define PRIuLEAST8 "u"
100 # define PRIuLEAST16 "u"
101 # define PRIuLEAST32 "u"
102 # define PRIuLEAST64 __PRI64_PREFIX "u"
104 # define PRIuFAST8 "u"
105 # define PRIuFAST16 "u"
106 # define PRIuFAST32 "u"
107 # define PRIuFAST64 __PRI64_PREFIX "u"
109 /* lowercase hexadecimal notation. */
110 # define PRIx8 "x"
111 # define PRIx16 "x"
112 # define PRIx32 "x"
113 # define PRIx64 __PRI64_PREFIX "x"
115 # define PRIxLEAST8 "x"
116 # define PRIxLEAST16 "x"
117 # define PRIxLEAST32 "x"
118 # define PRIxLEAST64 __PRI64_PREFIX "x"
120 # define PRIxFAST8 "x"
121 # define PRIxFAST16 "x"
122 # define PRIxFAST32 "x"
123 # define PRIxFAST64 __PRI64_PREFIX "x"
125 /* UPPERCASE hexadecimal notation. */
126 # define PRIX8 "X"
127 # define PRIX16 "X"
128 # define PRIX32 "X"
129 # define PRIX64 __PRI64_PREFIX "X"
131 # define PRIXLEAST8 "X"
132 # define PRIXLEAST16 "X"
133 # define PRIXLEAST32 "X"
134 # define PRIXLEAST64 __PRI64_PREFIX "X"
136 # define PRIXFAST8 "X"
137 # define PRIXFAST16 "X"
138 # define PRIXFAST32 "X"
139 # define PRIXFAST64 __PRI64_PREFIX "X"
142 /* Macros for printing `intmax_t' and `uintmax_t'. */
143 # define PRIdMAX __PRI64_PREFIX "d"
144 # define PRIiMAX __PRI64_PREFIX "i"
145 # define PRIoMAX __PRI64_PREFIX "o"
146 # define PRIuMAX __PRI64_PREFIX "u"
147 # define PRIxMAX __PRI64_PREFIX "x"
148 # define PRIXMAX __PRI64_PREFIX "X"
151 /* Macros for printing `intptr_t' and `uintptr_t'. */
152 # define PRIdPTR __PRIPTR_PREFIX "d"
153 # define PRIiPTR __PRIPTR_PREFIX "i"
154 # define PRIoPTR __PRIPTR_PREFIX "o"
155 # define PRIuPTR __PRIPTR_PREFIX "u"
156 # define PRIxPTR __PRIPTR_PREFIX "x"
157 # define PRIXPTR __PRIPTR_PREFIX "X"
160 /* Macros for scanning format specifiers. */
162 /* Signed decimal notation. */
163 # define SCNd8 "hhd"
164 # define SCNd16 "hd"
165 # define SCNd32 "d"
166 # define SCNd64 __PRI64_PREFIX "d"
168 # define SCNdLEAST8 "hhd"
169 # define SCNdLEAST16 "hd"
170 # define SCNdLEAST32 "d"
171 # define SCNdLEAST64 __PRI64_PREFIX "d"
173 # define SCNdFAST8 "hhd"
174 # define SCNdFAST16 __PRIPTR_PREFIX "d"
175 # define SCNdFAST32 __PRIPTR_PREFIX "d"
176 # define SCNdFAST64 __PRI64_PREFIX "d"
178 /* Signed decimal notation. */
179 # define SCNi8 "hhi"
180 # define SCNi16 "hi"
181 # define SCNi32 "i"
182 # define SCNi64 __PRI64_PREFIX "i"
184 # define SCNiLEAST8 "hhi"
185 # define SCNiLEAST16 "hi"
186 # define SCNiLEAST32 "i"
187 # define SCNiLEAST64 __PRI64_PREFIX "i"
189 # define SCNiFAST8 "hhi"
190 # define SCNiFAST16 __PRIPTR_PREFIX "i"
191 # define SCNiFAST32 __PRIPTR_PREFIX "i"
192 # define SCNiFAST64 __PRI64_PREFIX "i"
194 /* Unsigned decimal notation. */
195 # define SCNu8 "hhu"
196 # define SCNu16 "hu"
197 # define SCNu32 "u"
198 # define SCNu64 __PRI64_PREFIX "u"
200 # define SCNuLEAST8 "hhu"
201 # define SCNuLEAST16 "hu"
202 # define SCNuLEAST32 "u"
203 # define SCNuLEAST64 __PRI64_PREFIX "u"
205 # define SCNuFAST8 "hhu"
206 # define SCNuFAST16 __PRIPTR_PREFIX "u"
207 # define SCNuFAST32 __PRIPTR_PREFIX "u"
208 # define SCNuFAST64 __PRI64_PREFIX "u"
210 /* Octal notation. */
211 # define SCNo8 "hho"
212 # define SCNo16 "ho"
213 # define SCNo32 "o"
214 # define SCNo64 __PRI64_PREFIX "o"
216 # define SCNoLEAST8 "hho"
217 # define SCNoLEAST16 "ho"
218 # define SCNoLEAST32 "o"
219 # define SCNoLEAST64 __PRI64_PREFIX "o"
221 # define SCNoFAST8 "hho"
222 # define SCNoFAST16 __PRIPTR_PREFIX "o"
223 # define SCNoFAST32 __PRIPTR_PREFIX "o"
224 # define SCNoFAST64 __PRI64_PREFIX "o"
226 /* Hexadecimal notation. */
227 # define SCNx8 "hhx"
228 # define SCNx16 "hx"
229 # define SCNx32 "x"
230 # define SCNx64 __PRI64_PREFIX "x"
232 # define SCNxLEAST8 "hhx"
233 # define SCNxLEAST16 "hx"
234 # define SCNxLEAST32 "x"
235 # define SCNxLEAST64 __PRI64_PREFIX "x"
237 # define SCNxFAST8 "hhx"
238 # define SCNxFAST16 __PRIPTR_PREFIX "x"
239 # define SCNxFAST32 __PRIPTR_PREFIX "x"
240 # define SCNxFAST64 __PRI64_PREFIX "x"
243 /* Macros for scanning `intmax_t' and `uintmax_t'. */
244 # define SCNdMAX __PRI64_PREFIX "d"
245 # define SCNiMAX __PRI64_PREFIX "i"
246 # define SCNoMAX __PRI64_PREFIX "o"
247 # define SCNuMAX __PRI64_PREFIX "u"
248 # define SCNxMAX __PRI64_PREFIX "x"
250 /* Macros for scaning `intptr_t' and `uintptr_t'. */
251 # define SCNdPTR __PRIPTR_PREFIX "d"
252 # define SCNiPTR __PRIPTR_PREFIX "i"
253 # define SCNoPTR __PRIPTR_PREFIX "o"
254 # define SCNuPTR __PRIPTR_PREFIX "u"
255 # define SCNxPTR __PRIPTR_PREFIX "x"
257 #endif /* C++ && format macros */
260 __BEGIN_DECLS
262 #if __WORDSIZE == 64
264 /* We have to define the `uintmax_t' type using `ldiv_t'. */
265 # ifndef __ldiv_t_defined
266 /* Returned by `ldiv'. */
267 typedef struct
269 long int quot; /* Quotient. */
270 long int rem; /* Remainder. */
271 } ldiv_t;
272 # define __ldiv_t_defined 1
273 # endif
275 /* Returned by `imaxdiv'. */
276 typedef ldiv_t imaxdiv_t;
278 #else
280 /* We have to define the `uintmax_t' type using `lldiv_t'. */
281 # ifndef __lldiv_t_defined
282 /* Returned by `lldiv'. */
283 __extension__ typedef struct
285 long long int quot; /* Quotient. */
286 long long int rem; /* Remainder. */
287 } lldiv_t;
288 # define __lldiv_t_defined 1
289 # endif
291 /* Returned by `imaxdiv'. */
292 typedef lldiv_t imaxdiv_t;
294 #endif
297 /* Compute absolute value of N. */
298 extern intmax_t imaxabs (intmax_t __n) __THROW __attribute__ ((__const__));
300 /* Return the `imaxdiv_t' representation of the value of NUMER over DENOM. */
301 extern imaxdiv_t imaxdiv (intmax_t __numer, intmax_t __denom)
302 __THROW __attribute__ ((__const__));
304 /* Like `strtol' but convert to `intmax_t'. */
305 extern intmax_t strtoimax (__const char *__restrict __nptr,
306 char **__restrict __endptr, int __base) __THROW;
308 /* Like `strtoul' but convert to `uintmax_t'. */
309 extern uintmax_t strtoumax (__const char * __restrict __nptr,
310 char ** __restrict __endptr, int __base) __THROW;
312 /* Like `wcstol' but convert to `intmax_t'. */
313 extern intmax_t wcstoimax (__const wchar_t * __restrict __nptr,
314 wchar_t **__restrict __endptr, int __base) __THROW;
316 /* Like `wcstoul' but convert to `uintmax_t'. */
317 extern uintmax_t wcstoumax (__const wchar_t * __restrict __nptr,
318 wchar_t ** __restrict __endptr, int __base) __THROW;
320 #ifdef __USE_EXTERN_INLINES
322 # if __WORDSIZE == 64
324 /* We ant to use the appropriate functions from <stdlib.h> but cannot
325 assume the header is read already. */
326 __extension__ extern long int labs (long int __x)
327 __THROW __attribute__ ((__const__));
328 __extension__ extern ldiv_t ldiv (long int __numer, long int __denom)
329 __THROW __attribute__ ((__const__));
332 /* Compute absolute value of N. */
333 extern __inline intmax_t
334 imaxabs (intmax_t __n) __THROW
336 return labs (__n);
339 /* Return the `imaxdiv_t' representation of the value of NUMER over DENOM. */
340 extern __inline imaxdiv_t
341 imaxdiv (intmax_t __numer, intmax_t __denom) __THROW
343 return ldiv (__numer, __denom);
346 /* Like `strtol' but convert to `intmax_t'. */
347 # ifndef __strtol_internal_defined
348 extern long int __strtol_internal (__const char *__restrict __nptr,
349 char **__restrict __endptr,
350 int __base, int __group) __THROW;
351 # define __strtol_internal_defined 1
352 # endif
353 extern __inline intmax_t
354 strtoimax (__const char *__restrict nptr, char **__restrict endptr,
355 int base) __THROW
357 return __strtol_internal (nptr, endptr, base, 0);
360 /* Like `strtoul' but convert to `uintmax_t'. */
361 # ifndef __strtoul_internal_defined
362 extern unsigned long int __strtoul_internal (__const char *
363 __restrict __nptr,
364 char ** __restrict __endptr,
365 int __base, int __group) __THROW;
366 # define __strtoul_internal_defined 1
367 # endif
368 extern __inline uintmax_t
369 strtoumax (__const char *__restrict nptr, char **__restrict endptr,
370 int base) __THROW
372 return __strtoul_internal (nptr, endptr, base, 0);
375 /* Like `wcstol' but convert to `intmax_t'. */
376 # ifndef __wcstol_internal_defined
377 extern long int __wcstol_internal (__const wchar_t * __restrict __nptr,
378 wchar_t **__restrict __endptr,
379 int __base, int __group) __THROW;
380 # define __wcstol_internal_defined 1
381 # endif
382 extern __inline intmax_t
383 wcstoimax (__const wchar_t *__restrict nptr, wchar_t **__restrict endptr,
384 int base) __THROW
386 return __wcstol_internal (nptr, endptr, base, 0);
390 /* Like `wcstoul' but convert to `uintmax_t'. */
391 # ifndef __wcstoul_internal_defined
392 extern unsigned long int __wcstoul_internal (__const wchar_t *
393 __restrict __nptr,
394 wchar_t **
395 __restrict __endptr,
396 int __base, int __group) __THROW;
397 # define __wcstoul_internal_defined 1
398 # endif
399 extern __inline uintmax_t
400 wcstoumax (__const wchar_t *__restrict nptr, wchar_t **__restrict endptr,
401 int base) __THROW
403 return __wcstoul_internal (nptr, endptr, base, 0);
406 # else /* __WORDSIZE == 32 */
408 /* We want to use the appropriate functions from <stdlib.h> but cannot
409 assume the header is read already. */
410 __extension__ extern long long int llabs (long long int __x)
411 __THROW __attribute__ ((__const__));
412 __extension__ extern lldiv_t lldiv (long long int __numer,
413 long long int __denom)
414 __THROW __attribute__ ((__const__));
417 /* Compute absolute value of N. */
418 extern __inline intmax_t
419 imaxabs (intmax_t __n) __THROW
421 return llabs (__n);
424 /* Return the `imaxdiv_t' representation of the value of NUMER over DENOM. */
425 extern __inline imaxdiv_t
426 imaxdiv (intmax_t __numer, intmax_t __denom) __THROW
428 return lldiv (__numer, __denom);
431 /* Like `strtol' but convert to `intmax_t'. */
432 # ifndef __strtoll_internal_defined
433 __extension__
434 extern long long int __strtoll_internal (__const char *__restrict __nptr,
435 char **__restrict __endptr,
436 int __base, int __group) __THROW;
437 # define __strtoll_internal_defined 1
438 # endif
439 extern __inline intmax_t
440 strtoimax (__const char *__restrict nptr, char **__restrict endptr,
441 int base) __THROW
443 return __strtoll_internal (nptr, endptr, base, 0);
446 /* Like `strtoul' but convert to `uintmax_t'. */
447 # ifndef __strtoull_internal_defined
448 __extension__
449 extern unsigned long long int __strtoull_internal (__const char *
450 __restrict __nptr,
451 char **
452 __restrict __endptr,
453 int __base,
454 int __group) __THROW;
455 # define __strtoull_internal_defined 1
456 # endif
457 extern __inline uintmax_t
458 strtoumax (__const char *__restrict nptr, char **__restrict endptr,
459 int base) __THROW
461 return __strtoull_internal (nptr, endptr, base, 0);
464 /* Like `wcstol' but convert to `intmax_t'. */
465 # ifndef __wcstoll_internal_defined
466 __extension__
467 extern long long int __wcstoll_internal (__const wchar_t *
468 __restrict __nptr,
469 wchar_t **__restrict __endptr,
470 int __base, int __group) __THROW;
471 # define __wcstoll_internal_defined 1
472 # endif
473 extern __inline intmax_t
474 wcstoimax (__const wchar_t *__restrict nptr, wchar_t **__restrict endptr,
475 int base) __THROW
477 return __wcstoll_internal (nptr, endptr, base, 0);
481 /* Like `wcstoul' but convert to `uintmax_t'. */
482 # ifndef __wcstoull_internal_defined
483 __extension__
484 extern unsigned long long int __wcstoull_internal (__const wchar_t *
485 __restrict __nptr,
486 wchar_t **
487 __restrict __endptr,
488 int __base,
489 int __group) __THROW;
490 # define __wcstoull_internal_defined 1
491 # endif
492 extern __inline uintmax_t
493 wcstoumax (__const wchar_t *__restrict nptr, wchar_t **__restrict endptr,
494 int base) __THROW
496 return __wcstoull_internal (nptr, endptr, base, 0);
499 # endif /* __WORDSIZE == 32 */
500 #endif /* Use extern inlines. */
502 __END_DECLS
504 #endif /* inttypes.h */