Home | History | Annotate | Download | only in include
      1 /* Copyright (C) 1997-2001, 2004, 2007 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, write to the Free
     16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
     17    02111-1307 USA.  */
     18 
     19 /*
     20  *	ISO C99: 7.8 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 /* Get a definition for wchar_t.  But we must not define wchar_t itself.  */
     31 #ifndef ____gwchar_t_defined
     32 # ifdef __cplusplus
     33 #  define __gwchar_t wchar_t
     34 # elif defined __WCHAR_TYPE__
     35 typedef __WCHAR_TYPE__ __gwchar_t;
     36 # else
     37 #  define __need_wchar_t
     38 #  include <stddef.h>
     39 typedef wchar_t __gwchar_t;
     40 # endif
     41 # define ____gwchar_t_defined	1
     42 #endif
     43 
     44 
     45 /* The ISO C99 standard specifies that these macros must only be
     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"
     71 # define PRIdFAST16	__PRIPTR_PREFIX "d"
     72 # define PRIdFAST32	__PRIPTR_PREFIX "d"
     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"
     87 # define PRIiFAST16	__PRIPTR_PREFIX "i"
     88 # define PRIiFAST32	__PRIPTR_PREFIX "i"
     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"
    103 # define PRIoFAST16	__PRIPTR_PREFIX "o"
    104 # define PRIoFAST32	__PRIPTR_PREFIX "o"
    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"
    119 # define PRIuFAST16	__PRIPTR_PREFIX "u"
    120 # define PRIuFAST32	__PRIPTR_PREFIX "u"
    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"
    135 # define PRIxFAST16	__PRIPTR_PREFIX "x"
    136 # define PRIxFAST32	__PRIPTR_PREFIX "x"
    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"
    151 # define PRIXFAST16	__PRIPTR_PREFIX "X"
    152 # define PRIXFAST32	__PRIPTR_PREFIX "X"
    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'.  */
    279 typedef struct
    280   {
    281     long int quot;		/* Quotient.  */
    282     long int rem;		/* Remainder.  */
    283   } imaxdiv_t;
    284 
    285 #else
    286 
    287 /* We have to define the `uintmax_t' type using `lldiv_t'.  */
    288 typedef struct
    289   {
    290     long long int quot;		/* Quotient.  */
    291     long long int rem;		/* Remainder.  */
    292   } imaxdiv_t;
    293 
    294 #endif
    295 
    296 
    297 /* Compute absolute value of N.  */
    298 extern intmax_t imaxabs (intmax_t __n) __THROW __attribute__ ((__const__));
    299 
    300 /* Return the `imaxdiv_t' representation of the value of NUMER over DENOM. */
    301 extern imaxdiv_t imaxdiv (intmax_t __numer, intmax_t __denom)
    302       __THROW __attribute__ ((__const__));
    303 
    304 /* Like `strtol' but convert to `intmax_t'.  */
    305 extern intmax_t strtoimax (__const char *__restrict __nptr,
    306 			   char **__restrict __endptr, int __base) __THROW;
    307 
    308 /* Like `strtoul' but convert to `uintmax_t'.  */
    309 extern uintmax_t strtoumax (__const char *__restrict __nptr,
    310 			    char ** __restrict __endptr, int __base) __THROW;
    311 
    312 /* Like `wcstol' but convert to `intmax_t'.  */
    313 extern intmax_t wcstoimax (__const __gwchar_t *__restrict __nptr,
    314 			   __gwchar_t **__restrict __endptr, int __base)
    315      __THROW;
    316 
    317 /* Like `wcstoul' but convert to `uintmax_t'.  */
    318 extern uintmax_t wcstoumax (__const __gwchar_t *__restrict __nptr,
    319 			    __gwchar_t ** __restrict __endptr, int __base)
    320      __THROW;
    321 
    322 #ifdef __USE_EXTERN_INLINES
    323 
    324 # if __WORDSIZE == 64
    325 
    326 extern long int __strtol_internal (__const char *__restrict __nptr,
    327 				   char **__restrict __endptr,
    328 				   int __base, int __group)
    329   __THROW __nonnull ((1)) __wur;
    330 /* Like `strtol' but convert to `intmax_t'.  */
    331 __extern_inline intmax_t
    332 __NTH (strtoimax (__const char *__restrict nptr, char **__restrict endptr,
    333 		  int base))
    334 {
    335   return __strtol_internal (nptr, endptr, base, 0);
    336 }
    337 
    338 extern unsigned long int __strtoul_internal (__const char *
    339 					     __restrict __nptr,
    340 					     char ** __restrict __endptr,
    341 					     int __base, int __group)
    342   __THROW __nonnull ((1)) __wur;
    343 /* Like `strtoul' but convert to `uintmax_t'.  */
    344 __extern_inline uintmax_t
    345 __NTH (strtoumax (__const char *__restrict nptr, char **__restrict endptr,
    346 		  int base))
    347 {
    348   return __strtoul_internal (nptr, endptr, base, 0);
    349 }
    350 
    351 extern long int __wcstol_internal (__const __gwchar_t * __restrict __nptr,
    352 				   __gwchar_t **__restrict __endptr,
    353 				   int __base, int __group)
    354   __THROW __nonnull ((1)) __wur;
    355 /* Like `wcstol' but convert to `intmax_t'.  */
    356 __extern_inline intmax_t
    357 __NTH (wcstoimax (__const __gwchar_t *__restrict nptr,
    358 		  __gwchar_t **__restrict endptr, int base))
    359 {
    360   return __wcstol_internal (nptr, endptr, base, 0);
    361 }
    362 
    363 extern unsigned long int __wcstoul_internal (__const __gwchar_t *
    364 					     __restrict __nptr,
    365 					     __gwchar_t **
    366 					     __restrict __endptr,
    367 					     int __base, int __group)
    368   __THROW __nonnull ((1)) __wur;
    369 /* Like `wcstoul' but convert to `uintmax_t'.  */
    370 __extern_inline uintmax_t
    371 __NTH (wcstoumax (__const __gwchar_t *__restrict nptr,
    372 		  __gwchar_t **__restrict endptr, int base))
    373 {
    374   return __wcstoul_internal (nptr, endptr, base, 0);
    375 }
    376 
    377 # else /* __WORDSIZE == 32 */
    378 
    379 __extension__
    380 extern long long int __strtoll_internal (__const char *__restrict __nptr,
    381 					 char **__restrict __endptr,
    382 					 int __base, int __group)
    383   __THROW __nonnull ((1)) __wur;
    384 /* Like `strtol' but convert to `intmax_t'.  */
    385 __extern_inline intmax_t
    386 __NTH (strtoimax (__const char *__restrict nptr, char **__restrict endptr,
    387 		  int base))
    388 {
    389   return __strtoll_internal (nptr, endptr, base, 0);
    390 }
    391 
    392 __extension__
    393 extern unsigned long long int __strtoull_internal (__const char *
    394 						   __restrict __nptr,
    395 						   char **
    396 						   __restrict __endptr,
    397 						   int __base,
    398 						   int __group)
    399   __THROW __nonnull ((1)) __wur;
    400 /* Like `strtoul' but convert to `uintmax_t'.  */
    401 __extern_inline uintmax_t
    402 __NTH (strtoumax (__const char *__restrict nptr, char **__restrict endptr,
    403 		  int base))
    404 {
    405   return __strtoull_internal (nptr, endptr, base, 0);
    406 }
    407 
    408 __extension__
    409 extern long long int __wcstoll_internal (__const __gwchar_t *
    410 					 __restrict __nptr,
    411 					 __gwchar_t **__restrict __endptr,
    412 					 int __base, int __group)
    413   __THROW __nonnull ((1)) __wur;
    414 /* Like `wcstol' but convert to `intmax_t'.  */
    415 __extern_inline intmax_t
    416 __NTH (wcstoimax (__const __gwchar_t *__restrict nptr,
    417 		  __gwchar_t **__restrict endptr, int base))
    418 {
    419   return __wcstoll_internal (nptr, endptr, base, 0);
    420 }
    421 
    422 
    423 __extension__
    424 extern unsigned long long int __wcstoull_internal (__const __gwchar_t *
    425 						   __restrict __nptr,
    426 						   __gwchar_t **
    427 						   __restrict __endptr,
    428 						   int __base,
    429 						   int __group)
    430   __THROW __nonnull ((1)) __wur;
    431 /* Like `wcstoul' but convert to `uintmax_t'.  */
    432 __extern_inline uintmax_t
    433 __NTH (wcstoumax (__const __gwchar_t *__restrict nptr,
    434 		  __gwchar_t **__restrict endptr, int base))
    435 {
    436   return __wcstoull_internal (nptr, endptr, base, 0);
    437 }
    438 
    439 # endif	/* __WORDSIZE == 32	*/
    440 #endif	/* Use extern inlines.  */
    441 
    442 __END_DECLS
    443 
    444 #endif /* inttypes.h */
    445