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