IntegerPrintfMacros.h (3273B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 /* Implements the C99 <inttypes.h> interface. */ 8 9 #ifndef mozilla_IntegerPrintfMacros_h_ 10 #define mozilla_IntegerPrintfMacros_h_ 11 12 /* 13 * These macros should not be used with the NSPR printf-like functions or their 14 * users. If you need to use NSPR's facilities, see the comment on 15 * supported formats at the top of nsprpub/pr/include/prprf.h. 16 */ 17 18 /* 19 * scanf is a footgun: if the input number exceeds the bounds of the target 20 * type, behavior is undefined (in the compiler sense: that is, this code 21 * could overwrite your hard drive with zeroes): 22 * 23 * uint8_t u; 24 * sscanf("256", "%" SCNu8, &u); // BAD 25 * 26 * For this reason, *never* use the SCN* macros provided by this header! 27 */ 28 29 #include <inttypes.h> 30 31 /* 32 * Fix up Android's broken [u]intptr_t inttype macros. Android's PRI*PTR 33 * macros are defined as "ld", but sizeof(long) is 8 and sizeof(intptr_t) 34 * is 4 on 32-bit Android. TestTypeTraits.cpp asserts that these new macro 35 * definitions match the actual type sizes seen at compile time. 36 */ 37 #if defined(ANDROID) && !defined(__LP64__) 38 # undef PRIdPTR /* intptr_t */ 39 # define PRIdPTR "d" /* intptr_t */ 40 # undef PRIiPTR /* intptr_t */ 41 # define PRIiPTR "i" /* intptr_t */ 42 # undef PRIoPTR /* uintptr_t */ 43 # define PRIoPTR "o" /* uintptr_t */ 44 # undef PRIuPTR /* uintptr_t */ 45 # define PRIuPTR "u" /* uintptr_t */ 46 # undef PRIxPTR /* uintptr_t */ 47 # define PRIxPTR "x" /* uintptr_t */ 48 # undef PRIXPTR /* uintptr_t */ 49 # define PRIXPTR "X" /* uintptr_t */ 50 #endif 51 52 /* 53 * Fix up Android's broken macros for [u]int_fastN_t. On ARM64, Android's 54 * PRI*FAST16/32 macros are defined as "d", but the types themselves are defined 55 * as long and unsigned long. 56 */ 57 #if defined(ANDROID) && defined(__LP64__) 58 # undef PRIdFAST16 /* int_fast16_t */ 59 # define PRIdFAST16 PRId64 /* int_fast16_t */ 60 # undef PRIiFAST16 /* int_fast16_t */ 61 # define PRIiFAST16 PRIi64 /* int_fast16_t */ 62 # undef PRIoFAST16 /* uint_fast16_t */ 63 # define PRIoFAST16 PRIo64 /* uint_fast16_t */ 64 # undef PRIuFAST16 /* uint_fast16_t */ 65 # define PRIuFAST16 PRIu64 /* uint_fast16_t */ 66 # undef PRIxFAST16 /* uint_fast16_t */ 67 # define PRIxFAST16 PRIx64 /* uint_fast16_t */ 68 # undef PRIXFAST16 /* uint_fast16_t */ 69 # define PRIXFAST16 PRIX64 /* uint_fast16_t */ 70 # undef PRIdFAST32 /* int_fast32_t */ 71 # define PRIdFAST32 PRId64 /* int_fast32_t */ 72 # undef PRIiFAST32 /* int_fast32_t */ 73 # define PRIiFAST32 PRIi64 /* int_fast32_t */ 74 # undef PRIoFAST32 /* uint_fast32_t */ 75 # define PRIoFAST32 PRIo64 /* uint_fast32_t */ 76 # undef PRIuFAST32 /* uint_fast32_t */ 77 # define PRIuFAST32 PRIu64 /* uint_fast32_t */ 78 # undef PRIxFAST32 /* uint_fast32_t */ 79 # define PRIxFAST32 PRIx64 /* uint_fast32_t */ 80 # undef PRIXFAST32 /* uint_fast32_t */ 81 # define PRIXFAST32 PRIX64 /* uint_fast32_t */ 82 #endif 83 84 #endif /* mozilla_IntegerPrintfMacros_h_ */