Clang Project

include/inttypes.h
1/* Copyright (C) 1997-2016 Free Software Foundation, Inc.
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
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.
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
12   Lesser General Public License for more details.
13
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/>.  */
17
18/*
19 * ISO C99: 7.8 Format conversion of integer types <inttypes.h>
20 */
21
22#ifndef _INTTYPES_H
23#define _INTTYPES_H 1
24
25#include <features.h>
26/* Get the type definitions.  */
27#include <stdint.h>
28
29/* Get a definition for wchar_t.  But we must not define wchar_t itself.  */
30#ifndef ____gwchar_t_defined
31ifdef __cplusplus
32#  define __gwchar_t wchar_t
33elif defined __WCHAR_TYPE__
34typedef __WCHAR_TYPE__ __gwchar_t;
35else
36#  define __need_wchar_t
37#  include <stddef.h>
38typedef wchar_t __gwchar_t;
39endif
40define ____gwchar_t_defined 1
41#endif
42
43if __WORDSIZE == 64
44#  define __PRI64_PREFIX "l"
45#  define __PRIPTR_PREFIX "l"
46else
47#  define __PRI64_PREFIX "ll"
48#  define __PRIPTR_PREFIX
49endif
50
51/* Macros for printing format specifiers.  */
52
53/* Decimal notation.  */
54define PRId8 "d"
55define PRId16 "d"
56define PRId32 "d"
57define PRId64 __PRI64_PREFIX "d"
58
59define PRIdLEAST8 "d"
60define PRIdLEAST16 "d"
61define PRIdLEAST32 "d"
62define PRIdLEAST64 __PRI64_PREFIX "d"
63
64define PRIdFAST8 "d"
65define PRIdFAST16 __PRIPTR_PREFIX "d"
66define PRIdFAST32 __PRIPTR_PREFIX "d"
67define PRIdFAST64 __PRI64_PREFIX "d"
68
69
70define PRIi8 "i"
71define PRIi16 "i"
72define PRIi32 "i"
73define PRIi64 __PRI64_PREFIX "i"
74
75define PRIiLEAST8 "i"
76define PRIiLEAST16 "i"
77define PRIiLEAST32 "i"
78define PRIiLEAST64 __PRI64_PREFIX "i"
79
80define PRIiFAST8 "i"
81define PRIiFAST16 __PRIPTR_PREFIX "i"
82define PRIiFAST32 __PRIPTR_PREFIX "i"
83define PRIiFAST64 __PRI64_PREFIX "i"
84
85/* Octal notation.  */
86define PRIo8 "o"
87define PRIo16 "o"
88define PRIo32 "o"
89define PRIo64 __PRI64_PREFIX "o"
90
91define PRIoLEAST8 "o"
92define PRIoLEAST16 "o"
93define PRIoLEAST32 "o"
94define PRIoLEAST64 __PRI64_PREFIX "o"
95
96define PRIoFAST8 "o"
97define PRIoFAST16 __PRIPTR_PREFIX "o"
98define PRIoFAST32 __PRIPTR_PREFIX "o"
99define PRIoFAST64 __PRI64_PREFIX "o"
100
101/* Unsigned integers.  */
102define PRIu8 "u"
103define PRIu16 "u"
104define PRIu32 "u"
105define PRIu64 __PRI64_PREFIX "u"
106
107define PRIuLEAST8 "u"
108define PRIuLEAST16 "u"
109define PRIuLEAST32 "u"
110define PRIuLEAST64 __PRI64_PREFIX "u"
111
112define PRIuFAST8 "u"
113define PRIuFAST16 __PRIPTR_PREFIX "u"
114define PRIuFAST32 __PRIPTR_PREFIX "u"
115define PRIuFAST64 __PRI64_PREFIX "u"
116
117/* lowercase hexadecimal notation.  */
118define PRIx8 "x"
119define PRIx16 "x"
120define PRIx32 "x"
121define PRIx64 __PRI64_PREFIX "x"
122
123define PRIxLEAST8 "x"
124define PRIxLEAST16 "x"
125define PRIxLEAST32 "x"
126define PRIxLEAST64 __PRI64_PREFIX "x"
127
128define PRIxFAST8 "x"
129define PRIxFAST16 __PRIPTR_PREFIX "x"
130define PRIxFAST32 __PRIPTR_PREFIX "x"
131define PRIxFAST64 __PRI64_PREFIX "x"
132
133/* UPPERCASE hexadecimal notation.  */
134define PRIX8 "X"
135define PRIX16 "X"
136define PRIX32 "X"
137define PRIX64 __PRI64_PREFIX "X"
138
139define PRIXLEAST8 "X"
140define PRIXLEAST16 "X"
141define PRIXLEAST32 "X"
142define PRIXLEAST64 __PRI64_PREFIX "X"
143
144define PRIXFAST8 "X"
145define PRIXFAST16 __PRIPTR_PREFIX "X"
146define PRIXFAST32 __PRIPTR_PREFIX "X"
147define PRIXFAST64 __PRI64_PREFIX "X"
148
149
150/* Macros for printing `intmax_t' and `uintmax_t'.  */
151define PRIdMAX __PRI64_PREFIX "d"
152define PRIiMAX __PRI64_PREFIX "i"
153define PRIoMAX __PRI64_PREFIX "o"
154define PRIuMAX __PRI64_PREFIX "u"
155define PRIxMAX __PRI64_PREFIX "x"
156define PRIXMAX __PRI64_PREFIX "X"
157
158
159/* Macros for printing `intptr_t' and `uintptr_t'.  */
160define PRIdPTR __PRIPTR_PREFIX "d"
161define PRIiPTR __PRIPTR_PREFIX "i"
162define PRIoPTR __PRIPTR_PREFIX "o"
163define PRIuPTR __PRIPTR_PREFIX "u"
164define PRIxPTR __PRIPTR_PREFIX "x"
165define PRIXPTR __PRIPTR_PREFIX "X"
166
167
168/* Macros for scanning format specifiers.  */
169
170/* Signed decimal notation.  */
171define SCNd8 "hhd"
172define SCNd16 "hd"
173define SCNd32 "d"
174define SCNd64 __PRI64_PREFIX "d"
175
176define SCNdLEAST8 "hhd"
177define SCNdLEAST16 "hd"
178define SCNdLEAST32 "d"
179define SCNdLEAST64 __PRI64_PREFIX "d"
180
181define SCNdFAST8 "hhd"
182define SCNdFAST16 __PRIPTR_PREFIX "d"
183define SCNdFAST32 __PRIPTR_PREFIX "d"
184define SCNdFAST64 __PRI64_PREFIX "d"
185
186/* Signed decimal notation.  */
187define SCNi8 "hhi"
188define SCNi16 "hi"
189define SCNi32 "i"
190define SCNi64 __PRI64_PREFIX "i"
191
192define SCNiLEAST8 "hhi"
193define SCNiLEAST16 "hi"
194define SCNiLEAST32 "i"
195define SCNiLEAST64 __PRI64_PREFIX "i"
196
197define SCNiFAST8 "hhi"
198define SCNiFAST16 __PRIPTR_PREFIX "i"
199define SCNiFAST32 __PRIPTR_PREFIX "i"
200define SCNiFAST64 __PRI64_PREFIX "i"
201
202/* Unsigned decimal notation.  */
203define SCNu8 "hhu"
204define SCNu16 "hu"
205define SCNu32 "u"
206define SCNu64 __PRI64_PREFIX "u"
207
208define SCNuLEAST8 "hhu"
209define SCNuLEAST16 "hu"
210define SCNuLEAST32 "u"
211define SCNuLEAST64 __PRI64_PREFIX "u"
212
213define SCNuFAST8 "hhu"
214define SCNuFAST16 __PRIPTR_PREFIX "u"
215define SCNuFAST32 __PRIPTR_PREFIX "u"
216define SCNuFAST64 __PRI64_PREFIX "u"
217
218/* Octal notation.  */
219define SCNo8 "hho"
220define SCNo16 "ho"
221define SCNo32 "o"
222define SCNo64 __PRI64_PREFIX "o"
223
224define SCNoLEAST8 "hho"
225define SCNoLEAST16 "ho"
226define SCNoLEAST32 "o"
227define SCNoLEAST64 __PRI64_PREFIX "o"
228
229define SCNoFAST8 "hho"
230define SCNoFAST16 __PRIPTR_PREFIX "o"
231define SCNoFAST32 __PRIPTR_PREFIX "o"
232define SCNoFAST64 __PRI64_PREFIX "o"
233
234/* Hexadecimal notation.  */
235define SCNx8 "hhx"
236define SCNx16 "hx"
237define SCNx32 "x"
238define SCNx64 __PRI64_PREFIX "x"
239
240define SCNxLEAST8 "hhx"
241define SCNxLEAST16 "hx"
242define SCNxLEAST32 "x"
243define SCNxLEAST64 __PRI64_PREFIX "x"
244
245define SCNxFAST8 "hhx"
246define SCNxFAST16 __PRIPTR_PREFIX "x"
247define SCNxFAST32 __PRIPTR_PREFIX "x"
248define SCNxFAST64 __PRI64_PREFIX "x"
249
250
251/* Macros for scanning `intmax_t' and `uintmax_t'.  */
252define SCNdMAX __PRI64_PREFIX "d"
253define SCNiMAX __PRI64_PREFIX "i"
254define SCNoMAX __PRI64_PREFIX "o"
255define SCNuMAX __PRI64_PREFIX "u"
256define SCNxMAX __PRI64_PREFIX "x"
257
258/* Macros for scaning `intptr_t' and `uintptr_t'.  */
259define SCNdPTR __PRIPTR_PREFIX "d"
260define SCNiPTR __PRIPTR_PREFIX "i"
261define SCNoPTR __PRIPTR_PREFIX "o"
262define SCNuPTR __PRIPTR_PREFIX "u"
263define SCNxPTR __PRIPTR_PREFIX "x"
264
265
266__BEGIN_DECLS
267
268#if __WORDSIZE == 64
269
270/* We have to define the `uintmax_t' type using `ldiv_t'.  */
271typedef struct
272  {
273    long int quot; /* Quotient.  */
274    long int rem; /* Remainder.  */
275  } imaxdiv_t;
276
277#else
278
279/* We have to define the `uintmax_t' type using `lldiv_t'.  */
280typedef struct
281  {
282    __extension__ long long int quot; /* Quotient.  */
283    __extension__ long long int rem; /* Remainder.  */
284  } imaxdiv_t;
285
286#endif
287
288
289/* Compute absolute value of N.  */
290extern intmax_t imaxabs (intmax_t __n__THROW __attribute__ ((__const__));
291
292/* Return the `imaxdiv_t' representation of the value of NUMER over DENOM. */
293extern imaxdiv_t imaxdiv (intmax_t __numerintmax_t __denom)
294      __THROW __attribute__ ((__const__));
295
296/* Like `strtol' but convert to `intmax_t'.  */
297extern intmax_t strtoimax (const char *__restrict __nptr,
298    char **__restrict __endptrint __base__THROW;
299
300/* Like `strtoul' but convert to `uintmax_t'.  */
301extern uintmax_t strtoumax (const char *__restrict __nptr,
302     char ** __restrict __endptrint __base__THROW;
303
304/* Like `wcstol' but convert to `intmax_t'.  */
305extern intmax_t wcstoimax (const __gwchar_t *__restrict __nptr,
306    __gwchar_t **__restrict __endptrint __base)
307     __THROW;
308
309/* Like `wcstoul' but convert to `uintmax_t'.  */
310extern uintmax_t wcstoumax (const __gwchar_t *__restrict __nptr,
311     __gwchar_t ** __restrict __endptrint __base)
312     __THROW;
313
314#ifdef __USE_EXTERN_INLINES
315
316# if __WORDSIZE == 64
317
318extern 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,
325   int base))
326{
327  return __strtol_internal (nptr, endptr, base, 0);
328}
329
330extern 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,
337   int base))
338{
339  return __strtoul_internal (nptr, endptr, base, 0);
340}
341
342extern 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))
350{
351  return __wcstol_internal (nptr, endptr, base, 0);
352}
353
354extern unsigned long int __wcstoul_internal (const __gwchar_t *
355      __restrict __nptr,
356      __gwchar_t **
357      __restrict __endptr,
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))
364{
365  return __wcstoul_internal (nptr, endptr, base, 0);
366}
367
368# else /* __WORDSIZE == 32 */
369
370__extension__
371extern 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,
378   int base))
379{
380  return __strtoll_internal (nptr, endptr, base, 0);
381}
382
383__extension__
384extern unsigned long long int __strtoull_internal (const char *
385    __restrict __nptr,
386    char **
387    __restrict __endptr,
388    int __base,
389    int __group)
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,
394   int base))
395{
396  return __strtoull_internal (nptr, endptr, base, 0);
397}
398
399__extension__
400extern 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))
408{
409  return __wcstoll_internal (nptr, endptr, base, 0);
410}
411
412
413__extension__
414extern unsigned long long int __wcstoull_internal (const __gwchar_t *
415    __restrict __nptr,
416    __gwchar_t **
417    __restrict __endptr,
418    int __base,
419    int __group)
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))
425{
426  return __wcstoull_internal (nptr, endptr, base, 0);
427}
428
429# endif /* __WORDSIZE == 32 */
430#endif /* Use extern inlines.  */
431
432__END_DECLS
433
434#endif /* inttypes.h */
435
(anonymous struct)::quot
(anonymous struct)::rem