[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_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 8 | |
[email protected] | 34b2b00 | 2009-11-20 06:53:28 | [diff] [blame] | 9 | // This file defines the format macros for some integer types. |
10 | |||||
11 | // To print a 64-bit value in a portable way: | ||||
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 12 | // int64_t value; |
13 | // printf("xyz:%" PRId64, value); | ||||
[email protected] | 34b2b00 | 2009-11-20 06:53:28 | [diff] [blame] | 14 | // 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] | 15 | // |
16 | // For wide strings, prepend "Wide" to the macro: | ||||
17 | // int64_t value; | ||||
18 | // StringPrintf(L"xyz: %" WidePRId64, value); | ||||
[email protected] | 34b2b00 | 2009-11-20 06:53:28 | [diff] [blame] | 19 | // |
20 | // To print a size_t value in a portable way: | ||||
21 | // size_t size; | ||||
22 | // printf("xyz: %" PRIuS, size); | ||||
23 | // The "u" in the macro corresponds to %u, and S is for "size". | ||||
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 24 | |
25 | #include "build/build_config.h" | ||||
26 | |||||
27 | #if defined(OS_POSIX) | ||||
28 | |||||
29 | #if (defined(_INTTYPES_H) || defined(_INTTYPES_H_)) && !defined(PRId64) | ||||
30 | #error "inttypes.h has already been included before this header file, but " | ||||
31 | #error "without __STDC_FORMAT_MACROS defined." | ||||
32 | #endif | ||||
33 | |||||
34 | #if !defined(__STDC_FORMAT_MACROS) | ||||
35 | #define __STDC_FORMAT_MACROS | ||||
36 | #endif | ||||
37 | |||||
38 | #include <inttypes.h> | ||||
39 | |||||
40 | // GCC will concatenate wide and narrow strings correctly, so nothing needs to | ||||
41 | // be done here. | ||||
42 | #define WidePRId64 PRId64 | ||||
43 | #define WidePRIu64 PRIu64 | ||||
44 | #define WidePRIx64 PRIx64 | ||||
45 | |||||
[email protected] | fa1c3378 | 2010-02-25 17:20:07 | [diff] [blame] | 46 | #if !defined(PRIuS) |
[email protected] | 34b2b00 | 2009-11-20 06:53:28 | [diff] [blame] | 47 | #define PRIuS "zu" |
[email protected] | fa1c3378 | 2010-02-25 17:20:07 | [diff] [blame] | 48 | #endif |
[email protected] | 34b2b00 | 2009-11-20 06:53:28 | [diff] [blame] | 49 | |
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 50 | #else // OS_WIN |
51 | |||||
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 52 | #if !defined(PRId64) |
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 53 | #define PRId64 "I64d" |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 54 | #endif |
55 | |||||
56 | #if !defined(PRIu64) | ||||
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 57 | #define PRIu64 "I64u" |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 58 | #endif |
59 | |||||
60 | #if !defined(PRIx64) | ||||
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 61 | #define PRIx64 "I64x" |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 62 | #endif |
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 63 | |
64 | #define WidePRId64 L"I64d" | ||||
65 | #define WidePRIu64 L"I64u" | ||||
66 | #define WidePRIx64 L"I64x" | ||||
67 | |||||
[email protected] | fa1c3378 | 2010-02-25 17:20:07 | [diff] [blame] | 68 | #if !defined(PRIuS) |
[email protected] | 34b2b00 | 2009-11-20 06:53:28 | [diff] [blame] | 69 | #define PRIuS "Iu" |
[email protected] | fa1c3378 | 2010-02-25 17:20:07 | [diff] [blame] | 70 | #endif |
[email protected] | 34b2b00 | 2009-11-20 06:53:28 | [diff] [blame] | 71 | |
[email protected] | dce5df5 | 2009-06-29 17:58:25 | [diff] [blame] | 72 | #endif |
73 | |||||
[email protected] | 81e8ebf | 2010-09-16 07:59:27 | [diff] [blame] | 74 | #endif // BASE_FORMAT_MACROS_H_ |