[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef BASE_FORMAT_MACROS_H_ | ||||
6 | #define BASE_FORMAT_MACROS_H_ | ||||
7 | |||||
[email protected] | 34b2b00 | 2009-11-20 06:53:28 | [diff] [blame^] | 8 | // This file defines the format macros for some integer types. |
9 | |||||
10 | // To print a 64-bit value in a portable way: | ||||
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 11 | // int64_t value; |
12 | // printf("xyz:%" PRId64, value); | ||||
[email protected] | 34b2b00 | 2009-11-20 06:53:28 | [diff] [blame^] | 13 | // The "d" in the macro corresponds to %d; you can also use PRIu64 etc. |
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 14 | // |
15 | // For wide strings, prepend "Wide" to the macro: | ||||
16 | // int64_t value; | ||||
17 | // StringPrintf(L"xyz: %" WidePRId64, value); | ||||
[email protected] | 34b2b00 | 2009-11-20 06:53:28 | [diff] [blame^] | 18 | // |
19 | // To print a size_t value in a portable way: | ||||
20 | // size_t size; | ||||
21 | // printf("xyz: %" PRIuS, size); | ||||
22 | // The "u" in the macro corresponds to %u, and S is for "size". | ||||
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 23 | |
24 | #include "build/build_config.h" | ||||
25 | |||||
26 | #if defined(OS_POSIX) | ||||
27 | |||||
28 | #if (defined(_INTTYPES_H) || defined(_INTTYPES_H_)) && !defined(PRId64) | ||||
29 | #error "inttypes.h has already been included before this header file, but " | ||||
30 | #error "without __STDC_FORMAT_MACROS defined." | ||||
31 | #endif | ||||
32 | |||||
33 | #if !defined(__STDC_FORMAT_MACROS) | ||||
34 | #define __STDC_FORMAT_MACROS | ||||
35 | #endif | ||||
36 | |||||
37 | #include <inttypes.h> | ||||
38 | |||||
39 | // GCC will concatenate wide and narrow strings correctly, so nothing needs to | ||||
40 | // be done here. | ||||
41 | #define WidePRId64 PRId64 | ||||
42 | #define WidePRIu64 PRIu64 | ||||
43 | #define WidePRIx64 PRIx64 | ||||
44 | |||||
[email protected] | 34b2b00 | 2009-11-20 06:53:28 | [diff] [blame^] | 45 | #define PRIuS "zu" |
46 | |||||
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 47 | #else // OS_WIN |
48 | |||||
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 49 | #if !defined(PRId64) |
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 50 | #define PRId64 "I64d" |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 51 | #endif |
52 | |||||
53 | #if !defined(PRIu64) | ||||
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 54 | #define PRIu64 "I64u" |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 55 | #endif |
56 | |||||
57 | #if !defined(PRIx64) | ||||
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 58 | #define PRIx64 "I64x" |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 59 | #endif |
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 60 | |
61 | #define WidePRId64 L"I64d" | ||||
62 | #define WidePRIu64 L"I64u" | ||||
63 | #define WidePRIx64 L"I64x" | ||||
64 | |||||
[email protected] | 34b2b00 | 2009-11-20 06:53:28 | [diff] [blame^] | 65 | #define PRIuS "Iu" |
66 | |||||
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 67 | #endif |
68 | |||||
69 | #endif // !BASE_FORMAT_MACROS_H_ |