update_engine: Use portable string format functions.
Replace usage of %zu by PRIuS or calls to std::to_string when possible.
This patch includes other minor linter fixes.
BUG=None
TEST=emerge-link update_engine
Change-Id: I9ff2b3677ed4218a140f9e91a2389cc756941b03
Reviewed-on: https://chromium-review.googlesource.com/293629
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Trybot-Ready: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/delta_performer.cc b/delta_performer.cc
index 81477de..0c06c8b 100644
--- a/delta_performer.cc
+++ b/delta_performer.cc
@@ -128,12 +128,12 @@
string total_operations_str("?");
string completed_percentage_str("");
if (num_total_operations_) {
- total_operations_str = base::StringPrintf("%zu", num_total_operations_);
+ total_operations_str = std::to_string(num_total_operations_);
// Upcasting to 64-bit to avoid overflow, back to size_t for formatting.
completed_percentage_str =
base::StringPrintf(" (%" PRIu64 "%%)",
- IntRatio(next_operation_num_, num_total_operations_,
- 100));
+ IntRatio(next_operation_num_, num_total_operations_,
+ 100));
}
// Format download total count and percentage.
@@ -141,11 +141,11 @@
string payload_size_str("?");
string downloaded_percentage_str("");
if (payload_size) {
- payload_size_str = base::StringPrintf("%zu", payload_size);
+ payload_size_str = std::to_string(payload_size);
// Upcasting to 64-bit to avoid overflow, back to size_t for formatting.
downloaded_percentage_str =
base::StringPrintf(" (%" PRIu64 "%%)",
- IntRatio(total_bytes_received_, payload_size, 100));
+ IntRatio(total_bytes_received_, payload_size, 100));
}
LOG(INFO) << (message_prefix ? message_prefix : "") << next_operation_num_
diff --git a/fake_p2p_manager_configuration.h b/fake_p2p_manager_configuration.h
index 1dc7c6e..806206c 100644
--- a/fake_p2p_manager_configuration.h
+++ b/fake_p2p_manager_configuration.h
@@ -47,7 +47,7 @@
size_t minimum_size) override {
std::vector<std::string> formatted_command = p2p_client_cmd_format_;
// Replace {variable} on the passed string.
- std::string str_minimum_size = base::SizeTToString(minimum_size);
+ std::string str_minimum_size = std::to_string(minimum_size);
for (std::string& arg : formatted_command) {
ReplaceSubstringsAfterOffset(&arg, 0, "{file_id}", file_id);
ReplaceSubstringsAfterOffset(&arg, 0, "{minsize}", str_minimum_size);
diff --git a/libcurl_http_fetcher.cc b/libcurl_http_fetcher.cc
index 9d32293..8010b8c 100644
--- a/libcurl_http_fetcher.cc
+++ b/libcurl_http_fetcher.cc
@@ -8,6 +8,7 @@
#include <string>
#include <base/bind.h>
+#include <base/format_macros.h>
#include <base/location.h>
#include <base/logging.h>
#include <base/strings/string_util.h>
@@ -132,10 +133,10 @@
}
// Create a string representation of the desired range.
- string range_str = (end_offset ?
- base::StringPrintf("%jd-%zu", resume_offset_,
- end_offset) :
- base::StringPrintf("%jd-", resume_offset_));
+ string range_str = base::StringPrintf(
+ "%" PRIu64 "-", static_cast<uint64_t>(resume_offset_));
+ if (end_offset)
+ range_str += std::to_string(end_offset);
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_RANGE, range_str.c_str()),
CURLE_OK);
}
diff --git a/multi_range_http_fetcher.cc b/multi_range_http_fetcher.cc
index 07118a3..8d1fd06 100644
--- a/multi_range_http_fetcher.cc
+++ b/multi_range_http_fetcher.cc
@@ -169,9 +169,9 @@
std::string MultiRangeHttpFetcher::Range::ToString() const {
std::string range_str = base::StringPrintf("%jd+", offset());
if (HasLength())
- base::StringAppendF(&range_str, "%zu", length());
+ range_str += std::to_string(length());
else
- base::StringAppendF(&range_str, "?");
+ range_str += "?";
return range_str;
}
diff --git a/p2p_manager.cc b/p2p_manager.cc
index daebe91..9b6a659 100644
--- a/p2p_manager.cc
+++ b/p2p_manager.cc
@@ -30,6 +30,7 @@
#include <base/bind.h>
#include <base/files/file_enumerator.h>
#include <base/files/file_path.h>
+#include <base/format_macros.h>
#include <base/logging.h>
#include <base/strings/string_util.h>
#include <base/strings/stringprintf.h>
@@ -90,7 +91,7 @@
vector<string> args;
args.push_back("p2p-client");
args.push_back(string("--get-url=") + file_id);
- args.push_back(StringPrintf("--minimum-size=%zu", minimum_size));
+ args.push_back(StringPrintf("--minimum-size=%" PRIuS, minimum_size));
return args;
}
@@ -553,7 +554,7 @@
}
}
- string decimal_size = StringPrintf("%zu", expected_size);
+ string decimal_size = std::to_string(expected_size);
if (fsetxattr(fd, kCrosP2PFileSizeXAttrName,
decimal_size.c_str(), decimal_size.size(), 0) != 0) {
PLOG(ERROR) << "Error setting xattr " << path.value();
diff --git a/p2p_manager_unittest.cc b/p2p_manager_unittest.cc
index 18b4184..7e3f57f 100644
--- a/p2p_manager_unittest.cc
+++ b/p2p_manager_unittest.cc
@@ -312,7 +312,7 @@
}
if (size_xattr != 0) {
- string decimal_size = base::StringPrintf("%zu", size_xattr);
+ string decimal_size = std::to_string(size_xattr);
if (fsetxattr(fd, "user.cros-p2p-filesize",
decimal_size.c_str(), decimal_size.size(), 0) != 0) {
PLOG(ERROR) << "Error setting xattr on " << path;
diff --git a/test_utils.cc b/test_utils.cc
index b4a8074..7965f85 100644
--- a/test_utils.cc
+++ b/test_utils.cc
@@ -18,6 +18,7 @@
#include <vector>
#include <base/files/file_util.h>
+#include <base/format_macros.h>
#include <base/logging.h>
#include <base/strings/string_util.h>
#include <base/strings/stringprintf.h>
@@ -168,7 +169,7 @@
size_t size,
int block_size) {
EXPECT_EQ(0, System(StringPrintf("dd if=/dev/zero of=%s"
- " seek=%zu bs=1 count=1 status=none",
+ " seek=%" PRIuS " bs=1 count=1 status=none",
path.c_str(), size)));
EXPECT_EQ(0, System(StringPrintf("mkfs.ext3 -q -b %d -F %s",
block_size, path.c_str())));
diff --git a/utils.cc b/utils.cc
index 7777fca..1366a39 100644
--- a/utils.cc
+++ b/utils.cc
@@ -29,6 +29,7 @@
#include <base/files/file_path.h>
#include <base/files/file_util.h>
#include <base/files/scoped_file.h>
+#include <base/format_macros.h>
#include <base/location.h>
#include <base/logging.h>
#include <base/posix/eintr_wrapper.h>
@@ -1518,7 +1519,7 @@
string CalculateP2PFileId(const string& payload_hash, size_t payload_size) {
string encoded_hash = chromeos::data_encoding::Base64Encode(payload_hash);
- return base::StringPrintf("cros_update_size_%zu_hash_%s",
+ return base::StringPrintf("cros_update_size_%" PRIuS "_hash_%s",
payload_size,
encoded_hash.c_str());
}