]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/generic/inttypes.h
Use __PMT instead of __P where appropriate.
[thirdparty/glibc.git] / sysdeps / generic / inttypes.h
CommitLineData
a658675d 1/* Copyright (C) 1997-2001, 2004 Free Software Foundation, Inc.
1c25bcac
UD
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
1c25bcac
UD
8
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
41bdb6e2 12 Lesser General Public License for more details.
1c25bcac 13
41bdb6e2
AJ
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. */
1c25bcac
UD
18
19/*
63ae7b63 20 * ISO C99: 7.8 Format conversion of integer types <inttypes.h>
1c25bcac
UD
21 */
22
23#ifndef _INTTYPES_H
24#define _INTTYPES_H 1
25
26#include <features.h>
27/* Get the type definitions. */
28#include <stdint.h>
29
68984987 30/* Get a definition for wchar_t. But we must not define wchar_t itself. */
647eb037 31#ifndef ____gwchar_t_defined
1bc83d2b
UD
32# ifdef __cplusplus
33# define __gwchar_t wchar_t
34# elif defined __WCHAR_TYPE__
647eb037 35typedef __WCHAR_TYPE__ __gwchar_t;
68984987 36# else
b61345a1 37# define __need_wchar_t
68984987 38# include <stddef.h>
647eb037 39typedef wchar_t __gwchar_t;
68984987 40# endif
647eb037 41# define ____gwchar_t_defined 1
68984987
UD
42#endif
43
1c25bcac 44
63ae7b63 45/* The ISO C99 standard specifies that these macros must only be
1c25bcac
UD
46 defined if explicitly requested. */
47#if !defined __cplusplus || defined __STDC_FORMAT_MACROS
48
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
56
57/* Macros for printing format specifiers. */
58
59/* Decimal notation. */
60# define PRId8 "d"
61# define PRId16 "d"
62# define PRId32 "d"
63# define PRId64 __PRI64_PREFIX "d"
64
65# define PRIdLEAST8 "d"
66# define PRIdLEAST16 "d"
67# define PRIdLEAST32 "d"
68# define PRIdLEAST64 __PRI64_PREFIX "d"
69
70# define PRIdFAST8 "d"
a658675d
UD
71# define PRIdFAST16 __PRIPTR_PREFIX "d"
72# define PRIdFAST32 __PRIPTR_PREFIX "d"
1c25bcac
UD
73# define PRIdFAST64 __PRI64_PREFIX "d"
74
75
76# define PRIi8 "i"
77# define PRIi16 "i"
78# define PRIi32 "i"
79# define PRIi64 __PRI64_PREFIX "i"
80
81# define PRIiLEAST8 "i"
82# define PRIiLEAST16 "i"
83# define PRIiLEAST32 "i"
84# define PRIiLEAST64 __PRI64_PREFIX "i"
85
86# define PRIiFAST8 "i"
a658675d
UD
87# define PRIiFAST16 __PRIPTR_PREFIX "i"
88# define PRIiFAST32 __PRIPTR_PREFIX "i"
1c25bcac
UD
89# define PRIiFAST64 __PRI64_PREFIX "i"
90
91/* Octal notation. */
92# define PRIo8 "o"
93# define PRIo16 "o"
94# define PRIo32 "o"
95# define PRIo64 __PRI64_PREFIX "o"
96
97# define PRIoLEAST8 "o"
98# define PRIoLEAST16 "o"
99# define PRIoLEAST32 "o"
100# define PRIoLEAST64 __PRI64_PREFIX "o"
101
102# define PRIoFAST8 "o"
a658675d
UD
103# define PRIoFAST16 __PRIPTR_PREFIX "o"
104# define PRIoFAST32 __PRIPTR_PREFIX "o"
1c25bcac
UD
105# define PRIoFAST64 __PRI64_PREFIX "o"
106
107/* Unsigned integers. */
108# define PRIu8 "u"
109# define PRIu16 "u"
110# define PRIu32 "u"
111# define PRIu64 __PRI64_PREFIX "u"
112
113# define PRIuLEAST8 "u"
114# define PRIuLEAST16 "u"
115# define PRIuLEAST32 "u"
116# define PRIuLEAST64 __PRI64_PREFIX "u"
117
118# define PRIuFAST8 "u"
a658675d
UD
119# define PRIuFAST16 __PRIPTR_PREFIX "u"
120# define PRIuFAST32 __PRIPTR_PREFIX "u"
1c25bcac
UD
121# define PRIuFAST64 __PRI64_PREFIX "u"
122
123/* lowercase hexadecimal notation. */
124# define PRIx8 "x"
125# define PRIx16 "x"
126# define PRIx32 "x"
127# define PRIx64 __PRI64_PREFIX "x"
128
129# define PRIxLEAST8 "x"
130# define PRIxLEAST16 "x"
131# define PRIxLEAST32 "x"
132# define PRIxLEAST64 __PRI64_PREFIX "x"
133
134# define PRIxFAST8 "x"
a658675d
UD
135# define PRIxFAST16 __PRIPTR_PREFIX "x"
136# define PRIxFAST32 __PRIPTR_PREFIX "x"
1c25bcac
UD
137# define PRIxFAST64 __PRI64_PREFIX "x"
138
139/* UPPERCASE hexadecimal notation. */
140# define PRIX8 "X"
141# define PRIX16 "X"
142# define PRIX32 "X"
143# define PRIX64 __PRI64_PREFIX "X"
144
145# define PRIXLEAST8 "X"
146# define PRIXLEAST16 "X"
147# define PRIXLEAST32 "X"
148# define PRIXLEAST64 __PRI64_PREFIX "X"
149
150# define PRIXFAST8 "X"
a658675d
UD
151# define PRIXFAST16 __PRIPTR_PREFIX "X"
152# define PRIXFAST32 __PRIPTR_PREFIX "X"
1c25bcac
UD
153# define PRIXFAST64 __PRI64_PREFIX "X"
154
155
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"
163
164
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"
172
173
174/* Macros for scanning format specifiers. */
175
176/* Signed decimal notation. */
177# define SCNd8 "hhd"
178# define SCNd16 "hd"
179# define SCNd32 "d"
180# define SCNd64 __PRI64_PREFIX "d"
181
182# define SCNdLEAST8 "hhd"
183# define SCNdLEAST16 "hd"
184# define SCNdLEAST32 "d"
185# define SCNdLEAST64 __PRI64_PREFIX "d"
186
187# define SCNdFAST8 "hhd"
188# define SCNdFAST16 __PRIPTR_PREFIX "d"
189# define SCNdFAST32 __PRIPTR_PREFIX "d"
190# define SCNdFAST64 __PRI64_PREFIX "d"
191
192/* Signed decimal notation. */
193# define SCNi8 "hhi"
194# define SCNi16 "hi"
195# define SCNi32 "i"
196# define SCNi64 __PRI64_PREFIX "i"
197
198# define SCNiLEAST8 "hhi"
199# define SCNiLEAST16 "hi"
200# define SCNiLEAST32 "i"
201# define SCNiLEAST64 __PRI64_PREFIX "i"
202
203# define SCNiFAST8 "hhi"
204# define SCNiFAST16 __PRIPTR_PREFIX "i"
205# define SCNiFAST32 __PRIPTR_PREFIX "i"
206# define SCNiFAST64 __PRI64_PREFIX "i"
207
208/* Unsigned decimal notation. */
209# define SCNu8 "hhu"
210# define SCNu16 "hu"
211# define SCNu32 "u"
212# define SCNu64 __PRI64_PREFIX "u"
213
214# define SCNuLEAST8 "hhu"
215# define SCNuLEAST16 "hu"
216# define SCNuLEAST32 "u"
217# define SCNuLEAST64 __PRI64_PREFIX "u"
218
219# define SCNuFAST8 "hhu"
220# define SCNuFAST16 __PRIPTR_PREFIX "u"
221# define SCNuFAST32 __PRIPTR_PREFIX "u"
222# define SCNuFAST64 __PRI64_PREFIX "u"
223
224/* Octal notation. */
225# define SCNo8 "hho"
226# define SCNo16 "ho"
227# define SCNo32 "o"
228# define SCNo64 __PRI64_PREFIX "o"
229
230# define SCNoLEAST8 "hho"
231# define SCNoLEAST16 "ho"
232# define SCNoLEAST32 "o"
233# define SCNoLEAST64 __PRI64_PREFIX "o"
234
235# define SCNoFAST8 "hho"
236# define SCNoFAST16 __PRIPTR_PREFIX "o"
237# define SCNoFAST32 __PRIPTR_PREFIX "o"
238# define SCNoFAST64 __PRI64_PREFIX "o"
239
240/* Hexadecimal notation. */
241# define SCNx8 "hhx"
242# define SCNx16 "hx"
243# define SCNx32 "x"
244# define SCNx64 __PRI64_PREFIX "x"
245
246# define SCNxLEAST8 "hhx"
247# define SCNxLEAST16 "hx"
248# define SCNxLEAST32 "x"
249# define SCNxLEAST64 __PRI64_PREFIX "x"
250
251# define SCNxFAST8 "hhx"
252# define SCNxFAST16 __PRIPTR_PREFIX "x"
253# define SCNxFAST32 __PRIPTR_PREFIX "x"
254# define SCNxFAST64 __PRI64_PREFIX "x"
255
256
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"
263
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"
270
271#endif /* C++ && format macros */
272
273
274__BEGIN_DECLS
275
276#if __WORDSIZE == 64
277
278/* We have to define the `uintmax_t' type using `ldiv_t'. */
1c25bcac
UD
279typedef struct
280 {
281 long int quot; /* Quotient. */
282 long int rem; /* Remainder. */
417bafec 283 } imaxdiv_t;
1c25bcac
UD
284
285#else
286
287/* We have to define the `uintmax_t' type using `lldiv_t'. */
417bafec 288typedef struct
1c25bcac
UD
289 {
290 long long int quot; /* Quotient. */
291 long long int rem; /* Remainder. */
417bafec 292 } imaxdiv_t;
1c25bcac
UD
293
294#endif
295
296
297/* Compute absolute value of N. */
d8cf93f4 298extern intmax_t imaxabs (intmax_t __n) __THROW __attribute__ ((__const__));
1c25bcac
UD
299
300/* Return the `imaxdiv_t' representation of the value of NUMER over DENOM. */
d8cf93f4
UD
301extern imaxdiv_t imaxdiv (intmax_t __numer, intmax_t __denom)
302 __THROW __attribute__ ((__const__));
1c25bcac
UD
303
304/* Like `strtol' but convert to `intmax_t'. */
d8cf93f4
UD
305extern intmax_t strtoimax (__const char *__restrict __nptr,
306 char **__restrict __endptr, int __base) __THROW;
1c25bcac
UD
307
308/* Like `strtoul' but convert to `uintmax_t'. */
68984987 309extern uintmax_t strtoumax (__const char *__restrict __nptr,
d8cf93f4 310 char ** __restrict __endptr, int __base) __THROW;
1c25bcac
UD
311
312/* Like `wcstol' but convert to `intmax_t'. */
647eb037
UD
313extern intmax_t wcstoimax (__const __gwchar_t *__restrict __nptr,
314 __gwchar_t **__restrict __endptr, int __base)
68984987 315 __THROW;
1c25bcac
UD
316
317/* Like `wcstoul' but convert to `uintmax_t'. */
647eb037
UD
318extern uintmax_t wcstoumax (__const __gwchar_t *__restrict __nptr,
319 __gwchar_t ** __restrict __endptr, int __base)
68984987 320 __THROW;
1c25bcac
UD
321
322#ifdef __USE_EXTERN_INLINES
323
324# if __WORDSIZE == 64
325
1c25bcac
UD
326/* Like `strtol' but convert to `intmax_t'. */
327# ifndef __strtol_internal_defined
d8cf93f4
UD
328extern long int __strtol_internal (__const char *__restrict __nptr,
329 char **__restrict __endptr,
330 int __base, int __group) __THROW;
1c25bcac
UD
331# define __strtol_internal_defined 1
332# endif
333extern __inline intmax_t
334strtoimax (__const char *__restrict nptr, char **__restrict endptr,
335 int base) __THROW
336{
337 return __strtol_internal (nptr, endptr, base, 0);
338}
339
340/* Like `strtoul' but convert to `uintmax_t'. */
341# ifndef __strtoul_internal_defined
d8cf93f4
UD
342extern unsigned long int __strtoul_internal (__const char *
343 __restrict __nptr,
344 char ** __restrict __endptr,
345 int __base, int __group) __THROW;
1c25bcac
UD
346# define __strtoul_internal_defined 1
347# endif
348extern __inline uintmax_t
349strtoumax (__const char *__restrict nptr, char **__restrict endptr,
350 int base) __THROW
351{
352 return __strtoul_internal (nptr, endptr, base, 0);
353}
354
355/* Like `wcstol' but convert to `intmax_t'. */
356# ifndef __wcstol_internal_defined
647eb037
UD
357extern long int __wcstol_internal (__const __gwchar_t * __restrict __nptr,
358 __gwchar_t **__restrict __endptr,
d8cf93f4 359 int __base, int __group) __THROW;
1c25bcac
UD
360# define __wcstol_internal_defined 1
361# endif
362extern __inline intmax_t
647eb037 363wcstoimax (__const __gwchar_t *__restrict nptr, __gwchar_t **__restrict endptr,
1c25bcac
UD
364 int base) __THROW
365{
366 return __wcstol_internal (nptr, endptr, base, 0);
367}
368
369
370/* Like `wcstoul' but convert to `uintmax_t'. */
371# ifndef __wcstoul_internal_defined
647eb037 372extern unsigned long int __wcstoul_internal (__const __gwchar_t *
d8cf93f4 373 __restrict __nptr,
647eb037 374 __gwchar_t **
d8cf93f4
UD
375 __restrict __endptr,
376 int __base, int __group) __THROW;
1c25bcac
UD
377# define __wcstoul_internal_defined 1
378# endif
379extern __inline uintmax_t
647eb037 380wcstoumax (__const __gwchar_t *__restrict nptr, __gwchar_t **__restrict endptr,
1c25bcac
UD
381 int base) __THROW
382{
383 return __wcstoul_internal (nptr, endptr, base, 0);
384}
385
386# else /* __WORDSIZE == 32 */
387
1c25bcac
UD
388/* Like `strtol' but convert to `intmax_t'. */
389# ifndef __strtoll_internal_defined
390__extension__
d8cf93f4
UD
391extern long long int __strtoll_internal (__const char *__restrict __nptr,
392 char **__restrict __endptr,
393 int __base, int __group) __THROW;
1c25bcac
UD
394# define __strtoll_internal_defined 1
395# endif
396extern __inline intmax_t
397strtoimax (__const char *__restrict nptr, char **__restrict endptr,
398 int base) __THROW
399{
400 return __strtoll_internal (nptr, endptr, base, 0);
401}
402
403/* Like `strtoul' but convert to `uintmax_t'. */
404# ifndef __strtoull_internal_defined
405__extension__
d8cf93f4
UD
406extern unsigned long long int __strtoull_internal (__const char *
407 __restrict __nptr,
408 char **
409 __restrict __endptr,
410 int __base,
411 int __group) __THROW;
1c25bcac
UD
412# define __strtoull_internal_defined 1
413# endif
414extern __inline uintmax_t
415strtoumax (__const char *__restrict nptr, char **__restrict endptr,
416 int base) __THROW
417{
418 return __strtoull_internal (nptr, endptr, base, 0);
419}
420
421/* Like `wcstol' but convert to `intmax_t'. */
422# ifndef __wcstoll_internal_defined
423__extension__
647eb037 424extern long long int __wcstoll_internal (__const __gwchar_t *
d8cf93f4 425 __restrict __nptr,
647eb037 426 __gwchar_t **__restrict __endptr,
d8cf93f4 427 int __base, int __group) __THROW;
1c25bcac
UD
428# define __wcstoll_internal_defined 1
429# endif
430extern __inline intmax_t
647eb037 431wcstoimax (__const __gwchar_t *__restrict nptr, __gwchar_t **__restrict endptr,
1c25bcac
UD
432 int base) __THROW
433{
434 return __wcstoll_internal (nptr, endptr, base, 0);
435}
436
437
438/* Like `wcstoul' but convert to `uintmax_t'. */
439# ifndef __wcstoull_internal_defined
440__extension__
647eb037 441extern unsigned long long int __wcstoull_internal (__const __gwchar_t *
d8cf93f4 442 __restrict __nptr,
647eb037 443 __gwchar_t **
d8cf93f4
UD
444 __restrict __endptr,
445 int __base,
446 int __group) __THROW;
1c25bcac
UD
447# define __wcstoull_internal_defined 1
448# endif
449extern __inline uintmax_t
647eb037 450wcstoumax (__const __gwchar_t *__restrict nptr, __gwchar_t **__restrict endptr,
1c25bcac
UD
451 int base) __THROW
452{
453 return __wcstoull_internal (nptr, endptr, base, 0);
454}
455
456# endif /* __WORDSIZE == 32 */
457#endif /* Use extern inlines. */
458
459__END_DECLS
460
461#endif /* inttypes.h */