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, e.g. mozilla/Logging.h.  If you need to use NSPR's facilities, see the
15  * comment on 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 #endif  /* mozilla_IntegerPrintfMacros_h_ */
53