diff options
-rw-r--r-- | base/format_macros.h | 50 | ||||
-rw-r--r-- | base/trace_event.cc | 3 | ||||
-rw-r--r-- | build/common.gypi | 8 | ||||
-rw-r--r-- | chrome/common/ipc_message_utils.h | 7 | ||||
-rw-r--r-- | net/base/cookie_monster.cc | 9 | ||||
-rw-r--r-- | net/disk_cache/stats.cc | 3 |
6 files changed, 71 insertions, 9 deletions
diff --git a/base/format_macros.h b/base/format_macros.h new file mode 100644 index 0000000..4b713ef --- /dev/null +++ b/base/format_macros.h @@ -0,0 +1,50 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_FORMAT_MACROS_H_ +#define BASE_FORMAT_MACROS_H_ + +// This file defines the C99 format macros for 64-bit values. If you wish to +// print a 64-bit value in a portable way do: +// int64_t value; +// printf("xyz:%" PRId64, value); +// +// For wide strings, prepend "Wide" to the macro: +// int64_t value; +// StringPrintf(L"xyz: %" WidePRId64, value); + +#include "build/build_config.h" + +#if defined(OS_POSIX) + +#if (defined(_INTTYPES_H) || defined(_INTTYPES_H_)) && !defined(PRId64) +#error "inttypes.h has already been included before this header file, but " +#error "without __STDC_FORMAT_MACROS defined." +#endif + +#if !defined(__STDC_FORMAT_MACROS) +#define __STDC_FORMAT_MACROS +#endif + +#include <inttypes.h> + +// GCC will concatenate wide and narrow strings correctly, so nothing needs to +// be done here. +#define WidePRId64 PRId64 +#define WidePRIu64 PRIu64 +#define WidePRIx64 PRIx64 + +#else // OS_WIN + +#define PRId64 "I64d" +#define PRIu64 "I64u" +#define PRIx64 "I64x" + +#define WidePRId64 L"I64d" +#define WidePRIu64 L"I64u" +#define WidePRIx64 L"I64x" + +#endif + +#endif // !BASE_FORMAT_MACROS_H_ diff --git a/base/trace_event.cc b/base/trace_event.cc index ccac825b..6c79825 100644 --- a/base/trace_event.cc +++ b/base/trace_event.cc @@ -4,6 +4,7 @@ #include "base/trace_event.h" +#include "base/format_macros.h" #include "base/file_path.h" #include "base/file_util.h" #include "base/path_service.h" @@ -132,7 +133,7 @@ void TraceLog::Trace(const std::string& name, std::string msg = StringPrintf("{'pid':'0x%lx', 'tid':'0x%lx', 'type':'%s', " "'name':'%s', 'id':'0x%lx', 'extra':'%s', 'file':'%s', " - "'line_number':'%d', 'usec_begin': %I64d},\n", + "'line_number':'%d', 'usec_begin': %" PRId64 "},\n", base::GetCurrentProcId(), PlatformThread::CurrentId(), kEventTypeNames[type], diff --git a/build/common.gypi b/build/common.gypi index 35cb3b9..1da2034 100644 --- a/build/common.gypi +++ b/build/common.gypi @@ -536,6 +536,14 @@ 'includes': [ 'external_code.gypi', ], + }, { + 'target_defaults': { + # In Chromium code, we define __STDC_FORMAT_MACROS in order to get the + # C99 macros on Mac and Linux. + 'defines': [ + '__STDC_FORMAT_MACROS', + ], + }, }], ], 'scons_settings': { diff --git a/chrome/common/ipc_message_utils.h b/chrome/common/ipc_message_utils.h index f777d06..53c7974 100644 --- a/chrome/common/ipc_message_utils.h +++ b/chrome/common/ipc_message_utils.h @@ -10,8 +10,9 @@ #include <map> #include "base/file_path.h" -#include "base/string_util.h" +#include "base/format_macros.h" #include "base/string16.h" +#include "base/string_util.h" #include "base/tuple.h" #if defined(OS_POSIX) #include "chrome/common/file_descriptor_set_posix.h" @@ -239,7 +240,7 @@ struct ParamTraits<int64> { return m->ReadInt64(iter, r); } static void Log(const param_type& p, std::wstring* l) { - l->append(StringPrintf(L"%I64d", p)); + l->append(StringPrintf(L"%" WidePRId64, p)); } }; @@ -253,7 +254,7 @@ struct ParamTraits<uint64> { return m->ReadInt64(iter, reinterpret_cast<int64*>(r)); } static void Log(const param_type& p, std::wstring* l) { - l->append(StringPrintf(L"%I64u", p)); + l->append(StringPrintf(L"%" WidePRId64, p)); } }; diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc index 31d55dc..e20c03d 100644 --- a/net/base/cookie_monster.cc +++ b/net/base/cookie_monster.cc @@ -47,6 +47,7 @@ #include <algorithm> #include "base/basictypes.h" +#include "base/format_macros.h" #include "base/logging.h" #include "base/scoped_ptr.h" #include "base/string_tokenizer.h" @@ -351,12 +352,12 @@ static Time CanonExpiration(const CookieMonster::ParsedCookie& pc, // First, try the Max-Age attribute. uint64 max_age = 0; if (pc.HasMaxAge() && -#if defined(COMPILER_MSVC) - sscanf_s(pc.MaxAge().c_str(), " %I64u", &max_age) == 1) { - +#ifdef COMPILER_MSVC + sscanf_s( #else - sscanf(pc.MaxAge().c_str(), " %llu", &max_age) == 1) { + sscanf( #endif + pc.MaxAge().c_str(), " %" PRIu64, &max_age) == 1) { return current + TimeDelta::FromSeconds(max_age); } diff --git a/net/disk_cache/stats.cc b/net/disk_cache/stats.cc index 702b2a36..a351a6c 100644 --- a/net/disk_cache/stats.cc +++ b/net/disk_cache/stats.cc @@ -4,6 +4,7 @@ #include "net/disk_cache/stats.h" +#include "base/format_macros.h" #include "base/logging.h" #include "base/string_util.h" #include "net/disk_cache/backend_impl.h" @@ -263,7 +264,7 @@ void Stats::GetItems(StatsItems* items) { for (int i = MIN_COUNTER + 1; i < MAX_COUNTER; i++) { item.first = kCounterNames[i]; - item.second = StringPrintf("0x%I64x", counters_[i]); + item.second = StringPrintf("0x%" PRIx64, counters_[i]); items->push_back(item); } } |