Update.
[platform/upstream/glibc.git] / sysdeps / wordsize-32 / inttypes.h
1 /* Copyright (C) 1997, 1998, 1999 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 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.
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    Library General Public License for more details.
13
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.  */
18
19 /*
20  *      ISO C 9X: 7.5 Format conversion of integer types        <inttypes.h>
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
30
31 /* The ISO C 9X standard specifies that these macros must only be
32    defined if explicitly requested.  */
33 #if !defined __cplusplus || defined __STDC_FORMAT_MACROS
34
35 /* Macros for printing format specifiers.  */
36
37 /* Decimal notation.  */
38 # define PRId8          "d"
39 # define PRId16         "d"
40 # define PRId32         "d"
41 # define PRId64         "lld"
42
43 # define PRIdLEAST8     "d"
44 # define PRIdLEAST16    "d"
45 # define PRIdLEAST32    "d"
46 # define PRIdLEAST64    "lld"
47
48 # define PRIdFAST8      "d"
49 # define PRIdFAST16     "d"
50 # define PRIdFAST32     "d"
51 # define PRIdFAST64     "lld"
52
53
54 # define PRIi8          "i"
55 # define PRIi16         "i"
56 # define PRIi32         "i"
57 # define PRIi64         "lli"
58
59 # define PRIiLEAST8     "i"
60 # define PRIiLEAST16    "i"
61 # define PRIiLEAST32    "i"
62 # define PRIiLEAST64    "lli"
63
64 # define PRIiFAST8      "i"
65 # define PRIiFAST16     "i"
66 # define PRIiFAST32     "i"
67 # define PRIiFAST64     "lli"
68
69 /* Octal notation.  */
70 # define PRIo8          "o"
71 # define PRIo16         "o"
72 # define PRIo32         "o"
73 # define PRIo64         "llo"
74
75 # define PRIoLEAST8     "o"
76 # define PRIoLEAST16    "o"
77 # define PRIoLEAST32    "o"
78 # define PRIoLEAST64    "llo"
79
80 # define PRIoFAST8      "o"
81 # define PRIoFAST16     "o"
82 # define PRIoFAST32     "o"
83 # define PRIoFAST64     "llo"
84
85 /* Unsigned integers.  */
86 # define PRIu8          "u"
87 # define PRIu16         "u"
88 # define PRIu32         "u"
89 # define PRIu64         "llu"
90
91 # define PRIuLEAST8     "u"
92 # define PRIuLEAST16    "u"
93 # define PRIuLEAST32    "u"
94 # define PRIuLEAST64    "llu"
95
96 # define PRIuFAST8      "u"
97 # define PRIuFAST16     "u"
98 # define PRIuFAST32     "u"
99 # define PRIuFAST64     "llu"
100
101 /* lowercase hexadecimal notation.  */
102 # define PRIx8          "x"
103 # define PRIx16         "x"
104 # define PRIx32         "x"
105 # define PRIx64         "llx"
106
107 # define PRIxLEAST8     "x"
108 # define PRIxLEAST16    "x"
109 # define PRIxLEAST32    "x"
110 # define PRIxLEAST64    "llx"
111
112 # define PRIxFAST8      "x"
113 # define PRIxFAST16     "x"
114 # define PRIxFAST32     "x"
115 # define PRIxFAST64     "llx"
116
117 /* UPPERCASE hexadecimal notation.  */
118 # define PRIX8          "X"
119 # define PRIX16         "X"
120 # define PRIX32         "X"
121 # define PRIX64         "llX"
122
123 # define PRIXLEAST8     "X"
124 # define PRIXLEAST16    "X"
125 # define PRIXLEAST32    "X"
126 # define PRIXLEAST64    "llX"
127
128 # define PRIXFAST8      "X"
129 # define PRIXFAST16     "X"
130 # define PRIXFAST32     "X"
131 # define PRIXFAST64     "llX"
132
133
134 /* Macros for printing `intmax_t' and `uintmax_t'.  */
135 # define PRIdMAX        "lld"
136 # define PRIiMAX        "lli"
137 # define PRIoMAX        "llo"
138 # define PRIuMAX        "llu"
139 # define PRIxMAX        "llx"
140 # define PRIXMAX        "llX"
141
142
143 /* Macros for printing `intptr_t' and `uintptr_t'.  */
144 # define PRIdPTR        "d"
145 # define PRIiPTR        "i"
146 # define PRIoPTR        "o"
147 # define PRIuPTR        "u"
148 # define PRIxPTR        "x"
149 # define PRIXPTR        "X"
150
151
152 /* Macros for scanning format specifiers.  */
153
154 /* Signed decimal notation.  */
155 # define SCNd8          "hhd"
156 # define SCNd16         "hd"
157 # define SCNd32         "d"
158 # define SCNd64         "lld"
159
160 # define SCNdLEAST8     "hhd"
161 # define SCNdLEAST16    "hd"
162 # define SCNdLEAST32    "d"
163 # define SCNdLEAST64    "lld"
164
165 # define SCNdFAST8      "hhd"
166 # define SCNdFAST16     "d"
167 # define SCNdFAST32     "d"
168 # define SCNdFAST64     "lld"
169
170 /* Signed decimal notation.  */
171 # define SCNi8          "hhi"
172 # define SCNi16         "hi"
173 # define SCNi32         "i"
174 # define SCNi64         "lli"
175
176 # define SCNiLEAST8     "hhi"
177 # define SCNiLEAST16    "hi"
178 # define SCNiLEAST32    "i"
179 # define SCNiLEAST64    "lli"
180
181 # define SCNiFAST8      "hhi"
182 # define SCNiFAST16     "i"
183 # define SCNiFAST32     "i"
184 # define SCNiFAST64     "lli"
185
186 /* Unsigned decimal notation.  */
187 # define SCNu8          "hhu"
188 # define SCNu16         "hu"
189 # define SCNu32         "u"
190 # define SCNu64         "llu"
191
192 # define SCNuLEAST8     "hhu"
193 # define SCNuLEAST16    "hu"
194 # define SCNuLEAST32    "u"
195 # define SCNuLEAST64    "llu"
196
197 # define SCNuFAST8      "hhu"
198 # define SCNuFAST16     "u"
199 # define SCNuFAST32     "u"
200 # define SCNuFAST64     "llu"
201
202 /* Octal notation.  */
203 # define SCNo8          "hho"
204 # define SCNo16         "ho"
205 # define SCNo32         "o"
206 # define SCNo64         "llo"
207
208 # define SCNoLEAST8     "hho"
209 # define SCNoLEAST16    "ho"
210 # define SCNoLEAST32    "o"
211 # define SCNoLEAST64    "llo"
212
213 # define SCNoFAST8      "hho"
214 # define SCNoFAST16     "o"
215 # define SCNoFAST32     "o"
216 # define SCNoFAST64     "llo"
217
218 /* Hexadecimal notation.  */
219 # define SCNx8          "hhx"
220 # define SCNx16         "hx"
221 # define SCNx32         "x"
222 # define SCNx64         "llx"
223
224 # define SCNxLEAST8     "hhx"
225 # define SCNxLEAST16    "hx"
226 # define SCNxLEAST32    "x"
227 # define SCNxLEAST64    "llx"
228
229 # define SCNxFAST8      "hhx"
230 # define SCNxFAST16     "x"
231 # define SCNxFAST32     "x"
232 # define SCNxFAST64     "llx"
233
234
235 /* Macros for scanning `intmax_t' and `uintmax_t'.  */
236 # define SCNdMAX        "lld"
237 # define SCNiMAX        "lli"
238 # define SCNoMAX        "llo"
239 # define SCNuMAX        "llu"
240 # define SCNxMAX        "llx"
241
242 /* Macros for scaning `intptr_t' and `uintptr_t'.  */
243 # define SCNdPTR        "d"
244 # define SCNiPTR        "i"
245 # define SCNoPTR        "o"
246 # define SCNuPTR        "u"
247 # define SCNxPTR        "x"
248
249 #endif  /* C++ && format macros */
250
251
252 __BEGIN_DECLS
253
254 /* We have to define the `uintmax_t' type using `lldiv_t'.  */
255 #ifndef _STDLIB_H
256 /* Returned by `lldiv'.  */
257 __extension__ typedef struct
258   {
259     long long int quot;         /* Quotient.  */
260     long long int rem;          /* Remainder.  */
261   } lldiv_t;
262 # define __lldiv_t_defined      1
263 #endif
264
265 /* Returned by `imaxdiv'.  */
266 typedef lldiv_t imaxdiv_t;
267
268
269 /* Compute absolute value of N.  */
270 extern intmax_t imaxabs __P ((intmax_t __n)) __attribute__ ((__const__));
271
272 /* Return the `imaxdiv_t' representation of the value of NUMER over DENOM. */
273 extern imaxdiv_t imaxdiv __P ((intmax_t __numer, intmax_t __denom))
274      __attribute__ ((__const__));
275
276 /* Like `strtol' but convert to `intmax_t'.  */
277 extern intmax_t strtoimax __P ((__const char *__restrict __nptr,
278                                 char **__restrict __endptr, int __base));
279
280 /* Like `strtoul' but convert to `uintmax_t'.  */
281 extern uintmax_t strtoumax __P ((__const char * __restrict __nptr,
282                                  char ** __restrict __endptr, int __base));
283
284 /* Like `wcstol' but convert to `intmax_t'.  */
285 extern intmax_t wcstoimax __P ((__const wchar_t * __restrict __nptr,
286                                 wchar_t **__restrict __endptr, int __base));
287
288 /* Like `wcstoul' but convert to `uintmax_t'.  */
289 extern uintmax_t wcstoumax __P ((__const wchar_t * __restrict __nptr,
290                                  wchar_t ** __restrict __endptr, int __base));
291
292 #ifdef __USE_EXTERN_INLINES
293
294 /* We ant to use the appropriate functions from <stdlib.h> but cannot
295    assume the header is read already.  */
296 __extension__ extern long long int llabs __P ((long long int __x))
297      __attribute__ ((__const__));
298 __extension__ extern lldiv_t lldiv __P ((long long int __numer,
299                                          long long int __denom))
300      __attribute__ ((__const__));
301
302
303 /* Compute absolute value of N.  */
304 extern __inline intmax_t
305 imaxabs (intmax_t __n) __THROW
306 {
307   return llabs (__n);
308 }
309
310 /* Return the `imaxdiv_t' representation of the value of NUMER over DENOM. */
311 extern __inline imaxdiv_t
312 imaxdiv (intmax_t __numer, intmax_t __denom) __THROW
313 {
314   return lldiv (__numer, __denom);
315 }
316
317 /* Like `strtol' but convert to `intmax_t'.  */
318 # ifndef __strtoll_internal_defined
319 __extension__
320 extern long long int __strtoll_internal __P ((__const char *__restrict __nptr,
321                                               char **__restrict __endptr,
322                                               int __base, int __group));
323 #  define __strtoll_internal_defined    1
324 # endif
325 extern __inline intmax_t
326 strtoimax (__const char *__restrict nptr, char **__restrict endptr,
327            int base) __THROW
328 {
329   return __strtoll_internal (nptr, endptr, base, 0);
330 }
331
332 /* Like `strtoul' but convert to `uintmax_t'.  */
333 # ifndef __strtoull_internal_defined
334 __extension__
335 extern unsigned long long int __strtoull_internal __P ((__const char *
336                                                         __restrict __nptr,
337                                                         char **
338                                                         __restrict __endptr,
339                                                         int __base,
340                                                         int __group));
341 #  define __strtoull_internal_defined   1
342 # endif
343 extern __inline uintmax_t
344 strtoumax (__const char *__restrict nptr, char **__restrict endptr,
345            int base) __THROW
346 {
347   return __strtoull_internal (nptr, endptr, base, 0);
348 }
349
350 /* Like `wcstol' but convert to `intmax_t'.  */
351 # ifndef __wcstoll_internal_defined
352 __extension__
353 extern long long int __wcstoll_internal __P ((__const wchar_t *
354                                               __restrict __nptr,
355                                               wchar_t **__restrict __endptr,
356                                               int __base, int __group));
357 #  define __wcstoll_internal_defined    1
358 # endif
359 extern __inline intmax_t
360 wcstoimax (__const wchar_t *__restrict nptr, wchar_t **__restrict endptr,
361            int base) __THROW
362 {
363   return __wcstoll_internal (nptr, endptr, base, 0);
364 }
365
366
367 /* Like `wcstoul' but convert to `uintmax_t'.  */
368 # ifndef __wcstoull_internal_defined
369 __extension__
370 extern unsigned long long int __wcstoull_internal __P ((__const wchar_t *
371                                                         __restrict __nptr,
372                                                         wchar_t **
373                                                         __restrict __endptr,
374                                                         int __base,
375                                                         int __group));
376 #  define __wcstoull_internal_defined   1
377 # endif
378 extern __inline uintmax_t
379 wcstoumax (__const wchar_t *__restrict nptr, wchar_t **__restrict endptr,
380            int base) __THROW
381 {
382   return __wcstoull_internal (nptr, endptr, base, 0);
383 }
384 #endif  /* Use extern inlines.  */
385
386 __END_DECLS
387
388 #endif /* inttypes.h */