summaryrefslogtreecommitdiffstats
path: root/Meter.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2015-08-27 17:33:24 -0300
committerHisham Muhammad <hisham@gobolinux.org>2015-08-27 17:33:24 -0300
commitf585fc98257dbe1dc92aad6bc46c97d2a24b77d8 (patch)
tree71a8fe569a03e97e3806d70a5ed6363b81a2fcc5 /Meter.c
parent79356dc125e85b7107b8fe72a7f46a8b636d629a (diff)
parentcf47f4fca1bab93b81a2fb32cb548cb1722bb0f4 (diff)
Merge pull request #208 from eworm-de/dynamic-unit
Dynamic unit
Diffstat (limited to 'Meter.c')
-rw-r--r--Meter.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/Meter.c b/Meter.c
index cf4560fe..67ae96ef 100644
--- a/Meter.c
+++ b/Meter.c
@@ -141,6 +141,34 @@ Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type) {
return this;
}
+int Meter_humanUnit(char* buffer, unsigned long int value, int size) {
+ const char * prefix = "KMGTPEZY";
+ unsigned long int powi = 1;
+ unsigned int written, powj = 1, precision = 2;
+
+ for(;;) {
+ if (value / 1024 < powi)
+ break;
+
+ if (prefix[1] == 0)
+ break;
+
+ powi *= 1024;
+ ++prefix;
+ }
+
+ for (; precision > 0; precision--) {
+ powj *= 10;
+ if (value / powi < powj)
+ break;
+ }
+
+ written = snprintf(buffer, size, "%.*f%c",
+ precision, (double) value / powi, *prefix);
+
+ return written;
+}
+
void Meter_delete(Object* cast) {
if (!cast)
return;

© 2014-2024 Faster IT GmbH | imprint | privacy policy