Extra files to distribute in sysdeps/posix.
[glibc/history.git] / sysdeps / generic / inttypes.h
blob87f532f1d4bc56f39ac35fafc1305b6299f1c294
1 /* Copyright (C) 1997-2001, 2004 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, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 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>
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
45 /* The ISO C99 standard specifies that these macros must only be
46 defined if explicitly requested. */
47 #if !defined __cplusplus || defined __STDC_FORMAT_MACROS
49 # if __WORDSIZE == 64
50 # define __PRI64_PREFIX "l"
51 # define __PRIPTR_PREFIX "l"
52 # else
53 # define __PRI64_PREFIX "ll"
54 # define __PRIPTR_PREFIX
55 # endif
57 /* Macros for printing format specifiers. */
59 /* Decimal notation. */
60 # define PRId8 "d"
61 # define PRId16 "d"
62 # define PRId32 "d"
63 # define PRId64 __PRI64_PREFIX "d"
65 # define PRIdLEAST8 "d"
66 # define PRIdLEAST16 "d"
67 # define PRIdLEAST32 "d"
68 # define PRIdLEAST64 __PRI64_PREFIX "d"
70 # define PRIdFAST8 "d"
71 # define PRIdFAST16 __PRIPTR_PREFIX "d"
72 # define PRIdFAST32 __PRIPTR_PREFIX "d"
73 # define PRIdFAST64 __PRI64_PREFIX "d"
76 # define PRIi8 "i"
77 # define PRIi16 "i"
78 # define PRIi32 "i"
79 # define PRIi64 __PRI64_PREFIX "i"
81 # define PRIiLEAST8 "i"
82 # define PRIiLEAST16 "i"
83 # define PRIiLEAST32 "i"
84 # define PRIiLEAST64 __PRI64_PREFIX "i"
86 # define PRIiFAST8 "i"
87 # define PRIiFAST16 __PRIPTR_PREFIX "i"
88 # define PRIiFAST32 __PRIPTR_PREFIX "i"
89 # define PRIiFAST64 __PRI64_PREFIX "i"
91 /* Octal notation. */
92 # define PRIo8 "o"
93 # define PRIo16 "o"
94 # define PRIo32 "o"
95 # define PRIo64 __PRI64_PREFIX "o"
97 # define PRIoLEAST8 "o"
98 # define PRIoLEAST16 "o"
99 # define PRIoLEAST32 "o"
100 # define PRIoLEAST64 __PRI64_PREFIX "o"
102 # define PRIoFAST8 "o"
103 # define PRIoFAST16 __PRIPTR_PREFIX "o"
104 # define PRIoFAST32 __PRIPTR_PREFIX "o"
105 # define PRIoFAST64 __PRI64_PREFIX "o"
107 /* Unsigned integers. */
108 # define PRIu8 "u"
109 # define PRIu16 "u"
110 # define PRIu32 "u"
111 # define PRIu64 __PRI64_PREFIX "u"
113 # define PRIuLEAST8 "u"
114 # define PRIuLEAST16 "u"
115 # define PRIuLEAST32 "u"
116 # define PRIuLEAST64 __PRI64_PREFIX "u"
118 # define PRIuFAST8 "u"
119 # define PRIuFAST16 __PRIPTR_PREFIX "u"
120 # define PRIuFAST32 __PRIPTR_PREFIX "u"
121 # define PRIuFAST64 __PRI64_PREFIX "u"
123 /* lowercase hexadecimal notation. */
124 # define PRIx8 "x"
125 # define PRIx16 "x"
126 # define PRIx32 "x"
127 # define PRIx64 __PRI64_PREFIX "x"
129 # define PRIxLEAST8 "x"
130 # define PRIxLEAST16 "x"
131 # define PRIxLEAST32 "x"
132 # define PRIxLEAST64 __PRI64_PREFIX "x"
134 # define PRIxFAST8 "x"
135 # define PRIxFAST16 __PRIPTR_PREFIX "x"
136 # define PRIxFAST32 __PRIPTR_PREFIX "x"
137 # define PRIxFAST64 __PRI64_PREFIX "x"
139 /* UPPERCASE hexadecimal notation. */
140 # define PRIX8 "X"
141 # define PRIX16 "X"
142 # define PRIX32 "X"
143 # define PRIX64 __PRI64_PREFIX "X"
145 # define PRIXLEAST8 "X"
146 # define PRIXLEAST16 "X"
147 # define PRIXLEAST32 "X"
148 # define PRIXLEAST64 __PRI64_PREFIX "X"
150 # define PRIXFAST8 "X"
151 # define PRIXFAST16 __PRIPTR_PREFIX "X"
152 # define PRIXFAST32 __PRIPTR_PREFIX "X"
153 # define PRIXFAST64 __PRI64_PREFIX "X"
156 /* Macros for printing `intmax_t' and `uintmax_t'. */
157 # define PRIdMAX __PRI64_PREFIX "d"
158 # define PRIiMAX __PRI64_PREFIX "i"
159 # define PRIoMAX __PRI64_PREFIX "o"
160 # define PRIuMAX __PRI64_PREFIX "u"
161 # define PRIxMAX __PRI64_PREFIX "x"
162 # define PRIXMAX __PRI64_PREFIX "X"
165 /* Macros for printing `intptr_t' and `uintptr_t'. */
166 # define PRIdPTR __PRIPTR_PREFIX "d"
167 # define PRIiPTR __PRIPTR_PREFIX "i"
168 # define PRIoPTR __PRIPTR_PREFIX "o"
169 # define PRIuPTR __PRIPTR_PREFIX "u"
170 # define PRIxPTR __PRIPTR_PREFIX "x"
171 # define PRIXPTR __PRIPTR_PREFIX "X"
174 /* Macros for scanning format specifiers. */
176 /* Signed decimal notation. */
177 # define SCNd8 "hhd"
178 # define SCNd16 "hd"
179 # define SCNd32 "d"
180 # define SCNd64 __PRI64_PREFIX "d"
182 # define SCNdLEAST8 "hhd"
183 # define SCNdLEAST16 "hd"
184 # define SCNdLEAST32 "d"
185 # define SCNdLEAST64 __PRI64_PREFIX "d"
187 # define SCNdFAST8 "hhd"
188 # define SCNdFAST16 __PRIPTR_PREFIX "d"
189 # define SCNdFAST32 __PRIPTR_PREFIX "d"
190 # define SCNdFAST64 __PRI64_PREFIX "d"
192 /* Signed decimal notation. */
193 # define SCNi8 "hhi"
194 # define SCNi16 "hi"
195 # define SCNi32 "i"
196 # define SCNi64 __PRI64_PREFIX "i"
198 # define SCNiLEAST8 "hhi"
199 # define SCNiLEAST16 "hi"
200 # define SCNiLEAST32 "i"
201 # define SCNiLEAST64 __PRI64_PREFIX "i"
203 # define SCNiFAST8 "hhi"
204 # define SCNiFAST16 __PRIPTR_PREFIX "i"
205 # define SCNiFAST32 __PRIPTR_PREFIX "i"
206 # define SCNiFAST64 __PRI64_PREFIX "i"
208 /* Unsigned decimal notation. */
209 # define SCNu8 "hhu"
210 # define SCNu16 "hu"
211 # define SCNu32 "u"
212 # define SCNu64 __PRI64_PREFIX "u"
214 # define SCNuLEAST8 "hhu"
215 # define SCNuLEAST16 "hu"
216 # define SCNuLEAST32 "u"
217 # define SCNuLEAST64 __PRI64_PREFIX "u"
219 # define SCNuFAST8 "hhu"
220 # define SCNuFAST16 __PRIPTR_PREFIX "u"
221 # define SCNuFAST32 __PRIPTR_PREFIX "u"
222 # define SCNuFAST64 __PRI64_PREFIX "u"
224 /* Octal notation. */
225 # define SCNo8 "hho"
226 # define SCNo16 "ho"
227 # define SCNo32 "o"
228 # define SCNo64 __PRI64_PREFIX "o"
230 # define SCNoLEAST8 "hho"
231 # define SCNoLEAST16 "ho"
232 # define SCNoLEAST32 "o"
233 # define SCNoLEAST64 __PRI64_PREFIX "o"
235 # define SCNoFAST8 "hho"
236 # define SCNoFAST16 __PRIPTR_PREFIX "o"
237 # define SCNoFAST32 __PRIPTR_PREFIX "o"
238 # define SCNoFAST64 __PRI64_PREFIX "o"
240 /* Hexadecimal notation. */
241 # define SCNx8 "hhx"
242 # define SCNx16 "hx"
243 # define SCNx32 "x"
244 # define SCNx64 __PRI64_PREFIX "x"
246 # define SCNxLEAST8 "hhx"
247 # define SCNxLEAST16 "hx"
248 # define SCNxLEAST32 "x"
249 # define SCNxLEAST64 __PRI64_PREFIX "x"
251 # define SCNxFAST8 "hhx"
252 # define SCNxFAST16 __PRIPTR_PREFIX "x"
253 # define SCNxFAST32 __PRIPTR_PREFIX "x"
254 # define SCNxFAST64 __PRI64_PREFIX "x"
257 /* Macros for scanning `intmax_t' and `uintmax_t'. */
258 # define SCNdMAX __PRI64_PREFIX "d"
259 # define SCNiMAX __PRI64_PREFIX "i"
260 # define SCNoMAX __PRI64_PREFIX "o"
261 # define SCNuMAX __PRI64_PREFIX "u"
262 # define SCNxMAX __PRI64_PREFIX "x"
264 /* Macros for scaning `intptr_t' and `uintptr_t'. */
265 # define SCNdPTR __PRIPTR_PREFIX "d"
266 # define SCNiPTR __PRIPTR_PREFIX "i"
267 # define SCNoPTR __PRIPTR_PREFIX "o"
268 # define SCNuPTR __PRIPTR_PREFIX "u"
269 # define SCNxPTR __PRIPTR_PREFIX "x"
271 #endif /* C++ && format macros */
274 __BEGIN_DECLS
276 #if __WORDSIZE == 64
278 /* We have to define the `uintmax_t' type using `ldiv_t'. */
279 typedef struct
281 long int quot; /* Quotient. */
282 long int rem; /* Remainder. */
283 } imaxdiv_t;
285 #else
287 /* We have to define the `uintmax_t' type using `lldiv_t'. */
288 typedef struct
290 long long int quot; /* Quotient. */
291 long long int rem; /* Remainder. */
292 } 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 __gwchar_t *__restrict __nptr,
314 __gwchar_t **__restrict __endptr, int __base)
315 __THROW;
317 /* Like `wcstoul' but convert to `uintmax_t'. */
318 extern uintmax_t wcstoumax (__const __gwchar_t *__restrict __nptr,
319 __gwchar_t ** __restrict __endptr, int __base)
320 __THROW;
322 #ifdef __USE_EXTERN_INLINES
324 # if __WORDSIZE == 64
326 /* Like `strtol' but convert to `intmax_t'. */
327 # ifndef __strtol_internal_defined
328 extern long int __strtol_internal (__const char *__restrict __nptr,
329 char **__restrict __endptr,
330 int __base, int __group) __THROW;
331 # define __strtol_internal_defined 1
332 # endif
333 extern __inline intmax_t
334 __NTH (strtoimax (__const char *__restrict nptr, char **__restrict endptr,
335 int base))
337 return __strtol_internal (nptr, endptr, base, 0);
340 /* Like `strtoul' but convert to `uintmax_t'. */
341 # ifndef __strtoul_internal_defined
342 extern unsigned long int __strtoul_internal (__const char *
343 __restrict __nptr,
344 char ** __restrict __endptr,
345 int __base, int __group) __THROW;
346 # define __strtoul_internal_defined 1
347 # endif
348 extern __inline uintmax_t
349 __NTH (strtoumax (__const char *__restrict nptr, char **__restrict endptr,
350 int base))
352 return __strtoul_internal (nptr, endptr, base, 0);
355 /* Like `wcstol' but convert to `intmax_t'. */
356 # ifndef __wcstol_internal_defined
357 extern long int __wcstol_internal (__const __gwchar_t * __restrict __nptr,
358 __gwchar_t **__restrict __endptr,
359 int __base, int __group) __THROW;
360 # define __wcstol_internal_defined 1
361 # endif
362 extern __inline intmax_t
363 __NTH (wcstoimax (__const __gwchar_t *__restrict nptr,
364 __gwchar_t **__restrict endptr, int base))
366 return __wcstol_internal (nptr, endptr, base, 0);
370 /* Like `wcstoul' but convert to `uintmax_t'. */
371 # ifndef __wcstoul_internal_defined
372 extern unsigned long int __wcstoul_internal (__const __gwchar_t *
373 __restrict __nptr,
374 __gwchar_t **
375 __restrict __endptr,
376 int __base, int __group) __THROW;
377 # define __wcstoul_internal_defined 1
378 # endif
379 extern __inline uintmax_t
380 __NTH (wcstoumax (__const __gwchar_t *__restrict nptr,
381 __gwchar_t **__restrict endptr, int base))
383 return __wcstoul_internal (nptr, endptr, base, 0);
386 # else /* __WORDSIZE == 32 */
388 /* Like `strtol' but convert to `intmax_t'. */
389 # ifndef __strtoll_internal_defined
390 __extension__
391 extern long long int __strtoll_internal (__const char *__restrict __nptr,
392 char **__restrict __endptr,
393 int __base, int __group) __THROW;
394 # define __strtoll_internal_defined 1
395 # endif
396 extern __inline intmax_t
397 __NTH (strtoimax (__const char *__restrict nptr, char **__restrict endptr,
398 int base))
400 return __strtoll_internal (nptr, endptr, base, 0);
403 /* Like `strtoul' but convert to `uintmax_t'. */
404 # ifndef __strtoull_internal_defined
405 __extension__
406 extern unsigned long long int __strtoull_internal (__const char *
407 __restrict __nptr,
408 char **
409 __restrict __endptr,
410 int __base,
411 int __group) __THROW;
412 # define __strtoull_internal_defined 1
413 # endif
414 extern __inline uintmax_t
415 __NTH (strtoumax (__const char *__restrict nptr, char **__restrict endptr,
416 int base))
418 return __strtoull_internal (nptr, endptr, base, 0);
421 /* Like `wcstol' but convert to `intmax_t'. */
422 # ifndef __wcstoll_internal_defined
423 __extension__
424 extern long long int __wcstoll_internal (__const __gwchar_t *
425 __restrict __nptr,
426 __gwchar_t **__restrict __endptr,
427 int __base, int __group) __THROW;
428 # define __wcstoll_internal_defined 1
429 # endif
430 extern __inline intmax_t
431 __NTH (wcstoimax (__const __gwchar_t *__restrict nptr,
432 __gwchar_t **__restrict endptr, int base))
434 return __wcstoll_internal (nptr, endptr, base, 0);
438 /* Like `wcstoul' but convert to `uintmax_t'. */
439 # ifndef __wcstoull_internal_defined
440 __extension__
441 extern unsigned long long int __wcstoull_internal (__const __gwchar_t *
442 __restrict __nptr,
443 __gwchar_t **
444 __restrict __endptr,
445 int __base,
446 int __group) __THROW;
447 # define __wcstoull_internal_defined 1
448 # endif
449 extern __inline uintmax_t
450 __NTH (wcstoumax (__const __gwchar_t *__restrict nptr,
451 __gwchar_t **__restrict endptr, int base))
453 return __wcstoull_internal (nptr, endptr, base, 0);
456 # endif /* __WORDSIZE == 32 */
457 #endif /* Use extern inlines. */
459 __END_DECLS
461 #endif /* inttypes.h */