IntegerPrintfMacros.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. /* Implements the C99 <inttypes.h> interface. */
  7. #ifndef mozilla_IntegerPrintfMacros_h_
  8. #define mozilla_IntegerPrintfMacros_h_
  9. /*
  10. * These macros should not be used with the NSPR printf-like functions or their
  11. * users, e.g. mozilla/Logging.h. If you need to use NSPR's facilities, see the
  12. * comment on supported formats at the top of nsprpub/pr/include/prprf.h.
  13. */
  14. /*
  15. * scanf is a footgun: if the input number exceeds the bounds of the target
  16. * type, behavior is undefined (in the compiler sense: that is, this code
  17. * could overwrite your hard drive with zeroes):
  18. *
  19. * uint8_t u;
  20. * sscanf("256", "%" SCNu8, &u); // BAD
  21. *
  22. * For this reason, *never* use the SCN* macros provided by this header!
  23. */
  24. #include <inttypes.h>
  25. /*
  26. * Fix up Android's broken [u]intptr_t inttype macros. Android's PRI*PTR
  27. * macros are defined as "ld", but sizeof(long) is 8 and sizeof(intptr_t)
  28. * is 4 on 32-bit Android. TestTypeTraits.cpp asserts that these new macro
  29. * definitions match the actual type sizes seen at compile time.
  30. */
  31. #if defined(ANDROID) && !defined(__LP64__)
  32. # undef PRIdPTR /* intptr_t */
  33. # define PRIdPTR "d" /* intptr_t */
  34. # undef PRIiPTR /* intptr_t */
  35. # define PRIiPTR "i" /* intptr_t */
  36. # undef PRIoPTR /* uintptr_t */
  37. # define PRIoPTR "o" /* uintptr_t */
  38. # undef PRIuPTR /* uintptr_t */
  39. # define PRIuPTR "u" /* uintptr_t */
  40. # undef PRIxPTR /* uintptr_t */
  41. # define PRIxPTR "x" /* uintptr_t */
  42. # undef PRIXPTR /* uintptr_t */
  43. # define PRIXPTR "X" /* uintptr_t */
  44. #endif
  45. #endif /* mozilla_IntegerPrintfMacros_h_ */