* sysdeps/unix/readdir.c: Make sure we don't modify errno when we reached EOF.
[glibc.git] / sysdeps / generic / inttypes.h
blob16a698b4b5b98f8c27a19cd8c3dbfe3cdce5a28f
1 /* Copyright (C) 1997, 1998, 1999, 2000 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 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.
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.
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. */
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>
31 /* The ISO C99 standard specifies that these macros must only be
32 defined if explicitly requested. */
33 #if !defined __cplusplus || defined __STDC_FORMAT_MACROS
35 # if __WORDSIZE == 64
36 # define __PRI64_PREFIX "l"
37 # define __PRIPTR_PREFIX "l"
38 # else
39 # define __PRI64_PREFIX "ll"
40 # define __PRIPTR_PREFIX
41 # endif
43 /* Macros for printing format specifiers. */
45 /* Decimal notation. */
46 # define PRId8 "d"
47 # define PRId16 "d"
48 # define PRId32 "d"
49 # define PRId64 __PRI64_PREFIX "d"
51 # define PRIdLEAST8 "d"
52 # define PRIdLEAST16 "d"
53 # define PRIdLEAST32 "d"
54 # define PRIdLEAST64 __PRI64_PREFIX "d"
56 # define PRIdFAST8 "d"
57 # define PRIdFAST16 "d"
58 # define PRIdFAST32 "d"
59 # define PRIdFAST64 __PRI64_PREFIX "d"
62 # define PRIi8 "i"
63 # define PRIi16 "i"
64 # define PRIi32 "i"
65 # define PRIi64 __PRI64_PREFIX "i"
67 # define PRIiLEAST8 "i"
68 # define PRIiLEAST16 "i"
69 # define PRIiLEAST32 "i"
70 # define PRIiLEAST64 __PRI64_PREFIX "i"
72 # define PRIiFAST8 "i"
73 # define PRIiFAST16 "i"
74 # define PRIiFAST32 "i"
75 # define PRIiFAST64 __PRI64_PREFIX "i"
77 /* Octal notation. */
78 # define PRIo8 "o"
79 # define PRIo16 "o"
80 # define PRIo32 "o"
81 # define PRIo64 __PRI64_PREFIX "o"
83 # define PRIoLEAST8 "o"
84 # define PRIoLEAST16 "o"
85 # define PRIoLEAST32 "o"
86 # define PRIoLEAST64 __PRI64_PREFIX "o"
88 # define PRIoFAST8 "o"
89 # define PRIoFAST16 "o"
90 # define PRIoFAST32 "o"
91 # define PRIoFAST64 __PRI64_PREFIX "o"
93 /* Unsigned integers. */
94 # define PRIu8 "u"
95 # define PRIu16 "u"
96 # define PRIu32 "u"
97 # define PRIu64 __PRI64_PREFIX "u"
99 # define PRIuLEAST8 "u"
100 # define PRIuLEAST16 "u"
101 # define PRIuLEAST32 "u"
102 # define PRIuLEAST64 __PRI64_PREFIX "u"
104 # define PRIuFAST8 "u"
105 # define PRIuFAST16 "u"
106 # define PRIuFAST32 "u"
107 # define PRIuFAST64 __PRI64_PREFIX "u"
109 /* lowercase hexadecimal notation. */
110 # define PRIx8 "x"
111 # define PRIx16 "x"
112 # define PRIx32 "x"
113 # define PRIx64 __PRI64_PREFIX "x"
115 # define PRIxLEAST8 "x"
116 # define PRIxLEAST16 "x"
117 # define PRIxLEAST32 "x"
118 # define PRIxLEAST64 __PRI64_PREFIX "x"
120 # define PRIxFAST8 "x"
121 # define PRIxFAST16 "x"
122 # define PRIxFAST32 "x"
123 # define PRIxFAST64 __PRI64_PREFIX "x"
125 /* UPPERCASE hexadecimal notation. */
126 # define PRIX8 "X"
127 # define PRIX16 "X"
128 # define PRIX32 "X"
129 # define PRIX64 __PRI64_PREFIX "X"
131 # define PRIXLEAST8 "X"
132 # define PRIXLEAST16 "X"
133 # define PRIXLEAST32 "X"
134 # define PRIXLEAST64 __PRI64_PREFIX "X"
136 # define PRIXFAST8 "X"
137 # define PRIXFAST16 "X"
138 # define PRIXFAST32 "X"
139 # define PRIXFAST64 __PRI64_PREFIX "X"
142 /* Macros for printing `intmax_t' and `uintmax_t'. */
143 # define PRIdMAX __PRI64_PREFIX "d"
144 # define PRIiMAX __PRI64_PREFIX "i"
145 # define PRIoMAX __PRI64_PREFIX "o"
146 # define PRIuMAX __PRI64_PREFIX "u"
147 # define PRIxMAX __PRI64_PREFIX "x"
148 # define PRIXMAX __PRI64_PREFIX "X"
151 /* Macros for printing `intptr_t' and `uintptr_t'. */
152 # define PRIdPTR __PRIPTR_PREFIX "d"
153 # define PRIiPTR __PRIPTR_PREFIX "i"
154 # define PRIoPTR __PRIPTR_PREFIX "o"
155 # define PRIuPTR __PRIPTR_PREFIX "u"
156 # define PRIxPTR __PRIPTR_PREFIX "x"
157 # define PRIXPTR __PRIPTR_PREFIX "X"
160 /* Macros for scanning format specifiers. */
162 /* Signed decimal notation. */
163 # define SCNd8 "hhd"
164 # define SCNd16 "hd"
165 # define SCNd32 "d"
166 # define SCNd64 __PRI64_PREFIX "d"
168 # define SCNdLEAST8 "hhd"
169 # define SCNdLEAST16 "hd"
170 # define SCNdLEAST32 "d"
171 # define SCNdLEAST64 __PRI64_PREFIX "d"
173 # define SCNdFAST8 "hhd"
174 # define SCNdFAST16 __PRIPTR_PREFIX "d"
175 # define SCNdFAST32 __PRIPTR_PREFIX "d"
176 # define SCNdFAST64 __PRI64_PREFIX "d"
178 /* Signed decimal notation. */
179 # define SCNi8 "hhi"
180 # define SCNi16 "hi"
181 # define SCNi32 "i"
182 # define SCNi64 __PRI64_PREFIX "i"
184 # define SCNiLEAST8 "hhi"
185 # define SCNiLEAST16 "hi"
186 # define SCNiLEAST32 "i"
187 # define SCNiLEAST64 __PRI64_PREFIX "i"
189 # define SCNiFAST8 "hhi"
190 # define SCNiFAST16 __PRIPTR_PREFIX "i"
191 # define SCNiFAST32 __PRIPTR_PREFIX "i"
192 # define SCNiFAST64 __PRI64_PREFIX "i"
194 /* Unsigned decimal notation. */
195 # define SCNu8 "hhu"
196 # define SCNu16 "hu"
197 # define SCNu32 "u"
198 # define SCNu64 __PRI64_PREFIX "u"
200 # define SCNuLEAST8 "hhu"
201 # define SCNuLEAST16 "hu"
202 # define SCNuLEAST32 "u"
203 # define SCNuLEAST64 __PRI64_PREFIX "u"
205 # define SCNuFAST8 "hhu"
206 # define SCNuFAST16 __PRIPTR_PREFIX "u"
207 # define SCNuFAST32 __PRIPTR_PREFIX "u"
208 # define SCNuFAST64 __PRI64_PREFIX "u"
210 /* Octal notation. */
211 # define SCNo8 "hho"
212 # define SCNo16 "ho"
213 # define SCNo32 "o"
214 # define SCNo64 __PRI64_PREFIX "o"
216 # define SCNoLEAST8 "hho"
217 # define SCNoLEAST16 "ho"
218 # define SCNoLEAST32 "o"
219 # define SCNoLEAST64 __PRI64_PREFIX "o"
221 # define SCNoFAST8 "hho"
222 # define SCNoFAST16 __PRIPTR_PREFIX "o"
223 # define SCNoFAST32 __PRIPTR_PREFIX "o"
224 # define SCNoFAST64 __PRI64_PREFIX "o"
226 /* Hexadecimal notation. */
227 # define SCNx8 "hhx"
228 # define SCNx16 "hx"
229 # define SCNx32 "x"
230 # define SCNx64 __PRI64_PREFIX "x"
232 # define SCNxLEAST8 "hhx"
233 # define SCNxLEAST16 "hx"
234 # define SCNxLEAST32 "x"
235 # define SCNxLEAST64 __PRI64_PREFIX "x"
237 # define SCNxFAST8 "hhx"
238 # define SCNxFAST16 __PRIPTR_PREFIX "x"
239 # define SCNxFAST32 __PRIPTR_PREFIX "x"
240 # define SCNxFAST64 __PRI64_PREFIX "x"
243 /* Macros for scanning `intmax_t' and `uintmax_t'. */
244 # define SCNdMAX __PRI64_PREFIX "d"
245 # define SCNiMAX __PRI64_PREFIX "i"
246 # define SCNoMAX __PRI64_PREFIX "o"
247 # define SCNuMAX __PRI64_PREFIX "u"
248 # define SCNxMAX __PRI64_PREFIX "x"
250 /* Macros for scaning `intptr_t' and `uintptr_t'. */
251 # define SCNdPTR __PRIPTR_PREFIX "d"
252 # define SCNiPTR __PRIPTR_PREFIX "i"
253 # define SCNoPTR __PRIPTR_PREFIX "o"
254 # define SCNuPTR __PRIPTR_PREFIX "u"
255 # define SCNxPTR __PRIPTR_PREFIX "x"
257 #endif /* C++ && format macros */
260 __BEGIN_DECLS
262 #if __WORDSIZE == 64
264 /* We have to define the `uintmax_t' type using `ldiv_t'. */
265 typedef struct
267 long int quot; /* Quotient. */
268 long int rem; /* Remainder. */
269 } imaxdiv_t;
271 #else
273 /* We have to define the `uintmax_t' type using `lldiv_t'. */
274 typedef struct
276 long long int quot; /* Quotient. */
277 long long int rem; /* Remainder. */
278 } imaxdiv_t;
280 #endif
283 /* Compute absolute value of N. */
284 extern intmax_t imaxabs (intmax_t __n) __THROW __attribute__ ((__const__));
286 /* Return the `imaxdiv_t' representation of the value of NUMER over DENOM. */
287 extern imaxdiv_t imaxdiv (intmax_t __numer, intmax_t __denom)
288 __THROW __attribute__ ((__const__));
290 /* Like `strtol' but convert to `intmax_t'. */
291 extern intmax_t strtoimax (__const char *__restrict __nptr,
292 char **__restrict __endptr, int __base) __THROW;
294 /* Like `strtoul' but convert to `uintmax_t'. */
295 extern uintmax_t strtoumax (__const char * __restrict __nptr,
296 char ** __restrict __endptr, int __base) __THROW;
298 /* Like `wcstol' but convert to `intmax_t'. */
299 extern intmax_t wcstoimax (__const wchar_t * __restrict __nptr,
300 wchar_t **__restrict __endptr, int __base) __THROW;
302 /* Like `wcstoul' but convert to `uintmax_t'. */
303 extern uintmax_t wcstoumax (__const wchar_t * __restrict __nptr,
304 wchar_t ** __restrict __endptr, int __base) __THROW;
306 #ifdef __USE_EXTERN_INLINES
308 # if __WORDSIZE == 64
310 /* Like `strtol' but convert to `intmax_t'. */
311 # ifndef __strtol_internal_defined
312 extern long int __strtol_internal (__const char *__restrict __nptr,
313 char **__restrict __endptr,
314 int __base, int __group) __THROW;
315 # define __strtol_internal_defined 1
316 # endif
317 extern __inline intmax_t
318 strtoimax (__const char *__restrict nptr, char **__restrict endptr,
319 int base) __THROW
321 return __strtol_internal (nptr, endptr, base, 0);
324 /* Like `strtoul' but convert to `uintmax_t'. */
325 # ifndef __strtoul_internal_defined
326 extern unsigned long int __strtoul_internal (__const char *
327 __restrict __nptr,
328 char ** __restrict __endptr,
329 int __base, int __group) __THROW;
330 # define __strtoul_internal_defined 1
331 # endif
332 extern __inline uintmax_t
333 strtoumax (__const char *__restrict nptr, char **__restrict endptr,
334 int base) __THROW
336 return __strtoul_internal (nptr, endptr, base, 0);
339 /* Like `wcstol' but convert to `intmax_t'. */
340 # ifndef __wcstol_internal_defined
341 extern long int __wcstol_internal (__const wchar_t * __restrict __nptr,
342 wchar_t **__restrict __endptr,
343 int __base, int __group) __THROW;
344 # define __wcstol_internal_defined 1
345 # endif
346 extern __inline intmax_t
347 wcstoimax (__const wchar_t *__restrict nptr, wchar_t **__restrict endptr,
348 int base) __THROW
350 return __wcstol_internal (nptr, endptr, base, 0);
354 /* Like `wcstoul' but convert to `uintmax_t'. */
355 # ifndef __wcstoul_internal_defined
356 extern unsigned long int __wcstoul_internal (__const wchar_t *
357 __restrict __nptr,
358 wchar_t **
359 __restrict __endptr,
360 int __base, int __group) __THROW;
361 # define __wcstoul_internal_defined 1
362 # endif
363 extern __inline uintmax_t
364 wcstoumax (__const wchar_t *__restrict nptr, wchar_t **__restrict endptr,
365 int base) __THROW
367 return __wcstoul_internal (nptr, endptr, base, 0);
370 # else /* __WORDSIZE == 32 */
372 /* Like `strtol' but convert to `intmax_t'. */
373 # ifndef __strtoll_internal_defined
374 __extension__
375 extern long long int __strtoll_internal (__const char *__restrict __nptr,
376 char **__restrict __endptr,
377 int __base, int __group) __THROW;
378 # define __strtoll_internal_defined 1
379 # endif
380 extern __inline intmax_t
381 strtoimax (__const char *__restrict nptr, char **__restrict endptr,
382 int base) __THROW
384 return __strtoll_internal (nptr, endptr, base, 0);
387 /* Like `strtoul' but convert to `uintmax_t'. */
388 # ifndef __strtoull_internal_defined
389 __extension__
390 extern unsigned long long int __strtoull_internal (__const char *
391 __restrict __nptr,
392 char **
393 __restrict __endptr,
394 int __base,
395 int __group) __THROW;
396 # define __strtoull_internal_defined 1
397 # endif
398 extern __inline uintmax_t
399 strtoumax (__const char *__restrict nptr, char **__restrict endptr,
400 int base) __THROW
402 return __strtoull_internal (nptr, endptr, base, 0);
405 /* Like `wcstol' but convert to `intmax_t'. */
406 # ifndef __wcstoll_internal_defined
407 __extension__
408 extern long long int __wcstoll_internal (__const wchar_t *
409 __restrict __nptr,
410 wchar_t **__restrict __endptr,
411 int __base, int __group) __THROW;
412 # define __wcstoll_internal_defined 1
413 # endif
414 extern __inline intmax_t
415 wcstoimax (__const wchar_t *__restrict nptr, wchar_t **__restrict endptr,
416 int base) __THROW
418 return __wcstoll_internal (nptr, endptr, base, 0);
422 /* Like `wcstoul' but convert to `uintmax_t'. */
423 # ifndef __wcstoull_internal_defined
424 __extension__
425 extern unsigned long long int __wcstoull_internal (__const wchar_t *
426 __restrict __nptr,
427 wchar_t **
428 __restrict __endptr,
429 int __base,
430 int __group) __THROW;
431 # define __wcstoull_internal_defined 1
432 # endif
433 extern __inline uintmax_t
434 wcstoumax (__const wchar_t *__restrict nptr, wchar_t **__restrict endptr,
435 int base) __THROW
437 return __wcstoull_internal (nptr, endptr, base, 0);
440 # endif /* __WORDSIZE == 32 */
441 #endif /* Use extern inlines. */
443 __END_DECLS
445 #endif /* inttypes.h */