diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-01-16 13:01:36 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-01-16 13:01:36 -0500 |
| commit | fbe6af81fdb1b964bb0c28f51de2458800b8274c (patch) | |
| tree | 6d65a49b911ba665a7e2c28c6619d1aa6517a744 /src/util.cpp | |
| parent | 230d27c1cd00e7adf0ccfca2c8bb73ae1779aa4c (diff) | |
| parent | 7e5e767ba0fdde91dd66690168eff96b75c28e33 (diff) | |
| download | zig-fbe6af81fdb1b964bb0c28f51de2458800b8274c.tar.gz zig-fbe6af81fdb1b964bb0c28f51de2458800b8274c.zip | |
Merge remote-tracking branch 'origin/master' into llvm10
Diffstat (limited to 'src/util.cpp')
| -rw-r--r-- | src/util.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/util.cpp b/src/util.cpp index 13bfbbcd47..56f1de9839 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -5,13 +5,12 @@ * See http://opensource.org/licenses/MIT */ -#include <stdlib.h> -#include <stdio.h> -#include <stdarg.h> - #include "util.hpp" #include "userland.h" +#include <stdio.h> +#include <stdarg.h> + void zig_panic(const char *format, ...) { va_list ap; va_start(ap, format); @@ -119,3 +118,21 @@ Slice<uint8_t> SplitIterator_rest(SplitIterator *self) { SplitIterator memSplit(Slice<uint8_t> buffer, Slice<uint8_t> split_bytes) { return SplitIterator{0, buffer, split_bytes}; } + +void zig_pretty_print_bytes(FILE *f, double n) { + if (n > 1024.0 * 1024.0 * 1024.0) { + fprintf(f, "%.03f GiB", n / 1024.0 / 1024.0 / 1024.0); + return; + } + if (n > 1024.0 * 1024.0) { + fprintf(f, "%.03f MiB", n / 1024.0 / 1024.0); + return; + } + if (n > 1024.0) { + fprintf(f, "%.03f KiB", n / 1024.0); + return; + } + fprintf(f, "%.03f bytes", n ); + return; +} + |
