]>
Commit | Line | Data |
---|---|---|
a784e502 | 1 | /* Copyright (C) 1997-2001, 2004, 2007, 2012 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 | 35 | typedef __WCHAR_TYPE__ __gwchar_t; |
68984987 | 36 | # else |
b61345a1 | 37 | # define __need_wchar_t |
68984987 | 38 | # include <stddef.h> |
647eb037 | 39 | typedef 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 |
279 | typedef 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 | 288 | typedef 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 | 298 | extern 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 |
301 | extern imaxdiv_t imaxdiv (intmax_t __numer, intmax_t __denom) |
302 | __THROW __attribute__ ((__const__)); | |
1c25bcac UD |
303 | |
304 | /* Like `strtol' but convert to `intmax_t'. */ | |
a784e502 | 305 | extern intmax_t strtoimax (const char *__restrict __nptr, |
d8cf93f4 | 306 | char **__restrict __endptr, int __base) __THROW; |
1c25bcac UD |
307 | |
308 | /* Like `strtoul' but convert to `uintmax_t'. */ | |
a784e502 | 309 | extern 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'. */ | |
a784e502 | 313 | extern intmax_t wcstoimax (const __gwchar_t *__restrict __nptr, |
647eb037 | 314 | __gwchar_t **__restrict __endptr, int __base) |
68984987 | 315 | __THROW; |
1c25bcac UD |
316 | |
317 | /* Like `wcstoul' but convert to `uintmax_t'. */ | |
a784e502 | 318 | extern uintmax_t wcstoumax (const __gwchar_t *__restrict __nptr, |
647eb037 | 319 | __gwchar_t ** __restrict __endptr, int __base) |
68984987 | 320 | __THROW; |
1c25bcac UD |
321 | |
322 | #ifdef __USE_EXTERN_INLINES | |
323 | ||
324 | # if __WORDSIZE == 64 | |
325 | ||
a784e502 | 326 | extern long int __strtol_internal (const char *__restrict __nptr, |
d8cf93f4 | 327 | char **__restrict __endptr, |
9b2e9577 UD |
328 | int __base, int __group) |
329 | __THROW __nonnull ((1)) __wur; | |
330 | /* Like `strtol' but convert to `intmax_t'. */ | |
b037a293 | 331 | __extern_inline intmax_t |
a784e502 | 332 | __NTH (strtoimax (const char *__restrict nptr, char **__restrict endptr, |
f377d022 | 333 | int base)) |
1c25bcac UD |
334 | { |
335 | return __strtol_internal (nptr, endptr, base, 0); | |
336 | } | |
337 | ||
a784e502 | 338 | extern unsigned long int __strtoul_internal (const char *__restrict __nptr, |
d8cf93f4 | 339 | char ** __restrict __endptr, |
9b2e9577 UD |
340 | int __base, int __group) |
341 | __THROW __nonnull ((1)) __wur; | |
342 | /* Like `strtoul' but convert to `uintmax_t'. */ | |
b037a293 | 343 | __extern_inline uintmax_t |
a784e502 | 344 | __NTH (strtoumax (const char *__restrict nptr, char **__restrict endptr, |
f377d022 | 345 | int base)) |
1c25bcac UD |
346 | { |
347 | return __strtoul_internal (nptr, endptr, base, 0); | |
348 | } | |
349 | ||
a784e502 | 350 | extern long int __wcstol_internal (const __gwchar_t * __restrict __nptr, |
647eb037 | 351 | __gwchar_t **__restrict __endptr, |
9b2e9577 UD |
352 | int __base, int __group) |
353 | __THROW __nonnull ((1)) __wur; | |
354 | /* Like `wcstol' but convert to `intmax_t'. */ | |
b037a293 | 355 | __extern_inline intmax_t |
a784e502 | 356 | __NTH (wcstoimax (const __gwchar_t *__restrict nptr, |
f377d022 | 357 | __gwchar_t **__restrict endptr, int base)) |
1c25bcac UD |
358 | { |
359 | return __wcstol_internal (nptr, endptr, base, 0); | |
360 | } | |
361 | ||
a784e502 | 362 | extern unsigned long int __wcstoul_internal (const __gwchar_t * |
d8cf93f4 | 363 | __restrict __nptr, |
647eb037 | 364 | __gwchar_t ** |
d8cf93f4 | 365 | __restrict __endptr, |
9b2e9577 UD |
366 | int __base, int __group) |
367 | __THROW __nonnull ((1)) __wur; | |
368 | /* Like `wcstoul' but convert to `uintmax_t'. */ | |
b037a293 | 369 | __extern_inline uintmax_t |
a784e502 | 370 | __NTH (wcstoumax (const __gwchar_t *__restrict nptr, |
f377d022 | 371 | __gwchar_t **__restrict endptr, int base)) |
1c25bcac UD |
372 | { |
373 | return __wcstoul_internal (nptr, endptr, base, 0); | |
374 | } | |
375 | ||
376 | # else /* __WORDSIZE == 32 */ | |
377 | ||
1c25bcac | 378 | __extension__ |
a784e502 | 379 | extern long long int __strtoll_internal (const char *__restrict __nptr, |
d8cf93f4 | 380 | char **__restrict __endptr, |
9b2e9577 UD |
381 | int __base, int __group) |
382 | __THROW __nonnull ((1)) __wur; | |
383 | /* Like `strtol' but convert to `intmax_t'. */ | |
b037a293 | 384 | __extern_inline intmax_t |
a784e502 | 385 | __NTH (strtoimax (const char *__restrict nptr, char **__restrict endptr, |
f377d022 | 386 | int base)) |
1c25bcac UD |
387 | { |
388 | return __strtoll_internal (nptr, endptr, base, 0); | |
389 | } | |
390 | ||
1c25bcac | 391 | __extension__ |
a784e502 | 392 | extern unsigned long long int __strtoull_internal (const char * |
d8cf93f4 UD |
393 | __restrict __nptr, |
394 | char ** | |
395 | __restrict __endptr, | |
396 | int __base, | |
9b2e9577 UD |
397 | int __group) |
398 | __THROW __nonnull ((1)) __wur; | |
399 | /* Like `strtoul' but convert to `uintmax_t'. */ | |
b037a293 | 400 | __extern_inline uintmax_t |
a784e502 | 401 | __NTH (strtoumax (const char *__restrict nptr, char **__restrict endptr, |
f377d022 | 402 | int base)) |
1c25bcac UD |
403 | { |
404 | return __strtoull_internal (nptr, endptr, base, 0); | |
405 | } | |
406 | ||
1c25bcac | 407 | __extension__ |
a784e502 | 408 | extern long long int __wcstoll_internal (const __gwchar_t *__restrict __nptr, |
647eb037 | 409 | __gwchar_t **__restrict __endptr, |
9b2e9577 UD |
410 | int __base, int __group) |
411 | __THROW __nonnull ((1)) __wur; | |
412 | /* Like `wcstol' but convert to `intmax_t'. */ | |
b037a293 | 413 | __extern_inline intmax_t |
a784e502 | 414 | __NTH (wcstoimax (const __gwchar_t *__restrict nptr, |
f377d022 | 415 | __gwchar_t **__restrict endptr, int base)) |
1c25bcac UD |
416 | { |
417 | return __wcstoll_internal (nptr, endptr, base, 0); | |
418 | } | |
419 | ||
420 | ||
1c25bcac | 421 | __extension__ |
a784e502 | 422 | extern unsigned long long int __wcstoull_internal (const __gwchar_t * |
d8cf93f4 | 423 | __restrict __nptr, |
647eb037 | 424 | __gwchar_t ** |
d8cf93f4 UD |
425 | __restrict __endptr, |
426 | int __base, | |
9b2e9577 UD |
427 | int __group) |
428 | __THROW __nonnull ((1)) __wur; | |
429 | /* Like `wcstoul' but convert to `uintmax_t'. */ | |
b037a293 | 430 | __extern_inline uintmax_t |
a784e502 | 431 | __NTH (wcstoumax (const __gwchar_t *__restrict nptr, |
f377d022 | 432 | __gwchar_t **__restrict endptr, int base)) |
1c25bcac UD |
433 | { |
434 | return __wcstoull_internal (nptr, endptr, base, 0); | |
435 | } | |
436 | ||
437 | # endif /* __WORDSIZE == 32 */ | |
438 | #endif /* Use extern inlines. */ | |
439 | ||
440 | __END_DECLS | |
441 | ||
442 | #endif /* inttypes.h */ |