From 008759711f698c5e5e16027387868916bb2f7b38 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 11 Nov 2019 16:50:55 -0800 Subject: [PATCH] unzip/zipinfo: use float percentages like the RI. Test: my new test runner, specifically developed for ziptool Change-Id: I1237d02daaf2939eebc4fd5ec19ccdd0de291ad5 --- libziparchive/unzip.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libziparchive/unzip.cpp b/libziparchive/unzip.cpp index e4839b474..81f8c0ff6 100644 --- a/libziparchive/unzip.cpp +++ b/libziparchive/unzip.cpp @@ -109,9 +109,9 @@ static bool MakeDirectoryHierarchy(const std::string& path) { return (mkdir(path.c_str(), 0777) != -1); } -static int CompressionRatio(int64_t uncompressed, int64_t compressed) { +static float CompressionRatio(int64_t uncompressed, int64_t compressed) { if (uncompressed == 0) return 0; - return static_cast((100LL * (uncompressed - compressed)) / uncompressed); + return static_cast(100LL * (uncompressed - compressed)) / uncompressed; } static void MaybeShowHeader(ZipArchiveHandle zah) { @@ -143,7 +143,7 @@ static void MaybeShowFooter() { if (flag_v) { printf( "-------- ------- --- -------\n" - "%8" PRId64 " %8" PRId64 " %3d%% %zu file%s\n", + "%8" PRId64 " %8" PRId64 " %3.0f%% %zu file%s\n", total_uncompressed_length, total_compressed_length, CompressionRatio(total_uncompressed_length, total_compressed_length), file_count, (file_count == 1) ? "" : "s"); @@ -155,7 +155,7 @@ static void MaybeShowFooter() { } } else { if (!flag_1 && includes.empty() && excludes.empty()) { - printf("%zu files, %" PRId64 " bytes uncompressed, %" PRId64 " bytes compressed: %3d%%\n", + printf("%zu files, %" PRId64 " bytes uncompressed, %" PRId64 " bytes compressed: %.1f%%\n", file_count, total_uncompressed_length, total_compressed_length, CompressionRatio(total_uncompressed_length, total_compressed_length)); } @@ -261,7 +261,7 @@ static void ListOne(const ZipEntry& entry, const std::string& name) { snprintf(time, sizeof(time), "%04d-%02d-%02d %02d:%02d", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min); if (flag_v) { - printf("%8d %s %7d %3d%% %s %08x %s\n", entry.uncompressed_length, + printf("%8d %s %7d %3.0f%% %s %08x %s\n", entry.uncompressed_length, (entry.method == kCompressStored) ? "Stored" : "Defl:N", entry.compressed_length, CompressionRatio(entry.uncompressed_length, entry.compressed_length), time, entry.crc32, name.c_str());