diff options
author | Nico Weber <thakis@chromium.org> | 2020-08-15 14:05:46 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-16 16:33:28 +0200 |
commit | aa9716673988597d270ee6223b42d5207fddc1ad (patch) | |
tree | 2e17b9cb0762f60865d8605552763fb49f596f5e /Userland/df.cpp | |
parent | 430b265cd45167fb2dca2323ea5f5b910be00a1d (diff) | |
download | serenity-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/df.cpp')
-rw-r--r-- | Userland/df.cpp | 24 |
1 files changed, 3 insertions, 21 deletions
diff --git a/Userland/df.cpp b/Userland/df.cpp index 84681ee443..a28fe8cb93 100644 --- a/Userland/df.cpp +++ b/Userland/df.cpp @@ -24,16 +24,17 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <AK/String.h> #include <AK/JsonArray.h> #include <AK/JsonObject.h> +#include <AK/NumberFormat.h> +#include <AK/String.h> #include <AK/Vector.h> #include <LibCore/ArgsParser.h> #include <LibCore/File.h> -#include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> static bool flag_human_readable = false; @@ -48,25 +49,6 @@ struct FileSystem { String mount_point; }; -// FIXME: Remove this hackery once printf() supports floats. -// FIXME: Also, we should probably round the sizes in df -h output. -static String number_string_with_one_decimal(float number, const char* suffix) -{ - float decimals = number - (int)number; - return String::format("%d.%d%s", (int)number, (int)(decimals * 10), suffix); -} - -static String human_readable_size(size_t size) -{ - if (size < 1 * KiB) - return String::number(size); - if (size < 1 * MiB) - return number_string_with_one_decimal((float)size / (float)KiB, "K"); - if (size < 1 * GiB) - return number_string_with_one_decimal((float)size / (float)MiB, "M"); - return number_string_with_one_decimal((float)size / (float)GiB, "G"); -} - int main(int argc, char** argv) { Core::ArgsParser args_parser; |