summaryrefslogtreecommitdiff
path: root/Userland/ifconfig.cpp
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2020-08-15 14:05:46 -0400
committerAndreas Kling <kling@serenityos.org>2020-08-16 16:33:28 +0200
commitaa9716673988597d270ee6223b42d5207fddc1ad (patch)
tree2e17b9cb0762f60865d8605552763fb49f596f5e /Userland/ifconfig.cpp
parent430b265cd45167fb2dca2323ea5f5b910be00a1d (diff)
downloadserenity-aa9716673988597d270ee6223b42d5207fddc1ad.zip
Everywhere: Consolidate human_readable_size() implementations
Let's use the one in AK/NumberFormat.h everywhere. It has slightly different behavior than some of the copies this removes, but it's probably nice to have uniform human readable size outputs across the system.
Diffstat (limited to 'Userland/ifconfig.cpp')
-rw-r--r--Userland/ifconfig.cpp16
1 files changed, 3 insertions, 13 deletions
diff --git a/Userland/ifconfig.cpp b/Userland/ifconfig.cpp
index bd32b8ee68..eb5bd75cec 100644
--- a/Userland/ifconfig.cpp
+++ b/Userland/ifconfig.cpp
@@ -26,6 +26,7 @@
#include <AK/JsonArray.h>
#include <AK/JsonObject.h>
+#include <AK/NumberFormat.h>
#include <AK/String.h>
#include <AK/Types.h>
#include <LibCore/ArgsParser.h>
@@ -38,17 +39,6 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
-static String si_bytes(unsigned bytes)
-{
- if (bytes >= GiB)
- return String::format("%fGiB", (double)bytes / (double)GiB);
- if (bytes >= MiB)
- return String::format("%fMiB", (double)bytes / (double)MiB);
- if (bytes >= KiB)
- return String::format("%fkiB", (double)bytes / (double)KiB);
- return String::format("%dB", bytes);
-}
-
int main(int argc, char** argv)
{
const char* value_ipv4 = nullptr;
@@ -95,8 +85,8 @@ int main(int argc, char** argv)
printf("\tnetmask: %s\n", netmask.characters());
printf("\tgateway: %s\n", gateway.characters());
printf("\tclass: %s\n", class_name.characters());
- printf("\tRX: %u packets %u bytes (%s)\n", packets_in, bytes_in, si_bytes(bytes_in).characters());
- printf("\tTX: %u packets %u bytes (%s)\n", packets_out, bytes_out, si_bytes(bytes_out).characters());
+ printf("\tRX: %u packets %u bytes (%s)\n", packets_in, bytes_in, human_readable_size(bytes_in).characters());
+ printf("\tTX: %u packets %u bytes (%s)\n", packets_out, bytes_out, human_readable_size(bytes_out).characters());
printf("\tMTU: %u\n", mtu);
printf("\n");
});