1 /*
2  *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef RTC_BASE_FORMAT_MACROS_H_
12 #define RTC_BASE_FORMAT_MACROS_H_
13 
14 // This file defines the format macros for some integer types and is derived
15 // from Chromium's base/format_macros.h.
16 
17 // To print a 64-bit value in a portable way:
18 //   int64_t value;
19 //   printf("xyz:%" PRId64, value);
20 // The "d" in the macro corresponds to %d; you can also use PRIu64 etc.
21 //
22 // To print a size_t value in a portable way:
23 //   size_t size;
24 //   printf("xyz: %" PRIuS, size);
25 // The "u" in the macro corresponds to %u, and S is for "size".
26 
27 #include "typedefs.h"  // NOLINT(build/include)
28 
29 #if defined(WEBRTC_POSIX)
30 
31 #if (defined(_INTTYPES_H) || defined(_INTTYPES_H_)) && !defined(PRId64)
32 #error "inttypes.h has already been included before this header file, but "
33 #error "without __STDC_FORMAT_MACROS defined."
34 #endif
35 
36 #if !defined(__STDC_FORMAT_MACROS)
37 #define __STDC_FORMAT_MACROS
38 #endif
39 
40 #include <inttypes.h>
41 
42 #if !defined(PRIuS)
43 #define PRIuS "zu"
44 #endif
45 
46 // The size of NSInteger and NSUInteger varies between 32-bit and 64-bit
47 // architectures and Apple does not provides standard format macros and
48 // recommends casting. This has many drawbacks, so instead define macros
49 // for formatting those types.
50 #if defined(WEBRTC_MAC)
51 #if defined(WEBRTC_ARCH_64_BITS)
52 #if !defined(PRIdNS)
53 #define PRIdNS "ld"
54 #endif
55 #if !defined(PRIuNS)
56 #define PRIuNS "lu"
57 #endif
58 #if !defined(PRIxNS)
59 #define PRIxNS "lx"
60 #endif
61 #else  // defined(WEBRTC_ARCH_64_BITS)
62 #if !defined(PRIdNS)
63 #define PRIdNS "d"
64 #endif
65 #if !defined(PRIuNS)
66 #define PRIuNS "u"
67 #endif
68 #if !defined(PRIxNS)
69 #define PRIxNS "x"
70 #endif
71 #endif
72 #endif  // defined(WEBRTC_MAC)
73 
74 #else  // WEBRTC_WIN
75 
76 #include <inttypes.h>
77 
78 #if !defined(PRId64)
79 #define PRId64 "I64d"
80 #endif
81 
82 #if !defined(PRIu64)
83 #define PRIu64 "I64u"
84 #endif
85 
86 #if !defined(PRIx64)
87 #define PRIx64 "I64x"
88 #endif
89 
90 #if !defined(PRIuS)
91 #define PRIuS "Iu"
92 #endif
93 
94 #endif
95 
96 #endif  // RTC_BASE_FORMAT_MACROS_H_
97