Xinqi Bao's Git

Refactor ram.c
[slstatus.git] / components / disk.c
index f4031ea..998ad47 100644 (file)
@@ -16,8 +16,7 @@ disk_free(const char *mnt)
                return NULL;
        }
 
-       return bprintf("%f",
-                      (float)fs.f_frsize * (float)fs.f_bavail / 1024 / 1024 / 1024);
+       return fmt_human_2(fs.f_frsize * fs.f_bavail, "B");
 }
 
 const char *
@@ -30,7 +29,7 @@ disk_perc(const char *mnt)
                return NULL;
        }
 
-       return bprintf("%d", (int)(100 *
+       return bprintf("%d%%", (int)(100 *
                       (1.0f - ((float)fs.f_bavail / (float)fs.f_blocks))));
 }
 
@@ -44,8 +43,7 @@ disk_total(const char *mnt)
                return NULL;
        }
 
-       return bprintf("%f",
-                      (float)fs.f_frsize * (float)fs.f_blocks / 1024 / 1024 / 1024);
+       return fmt_human_2(fs.f_frsize * fs.f_blocks, "B");
 }
 
 const char *
@@ -58,7 +56,5 @@ disk_used(const char *mnt)
                return NULL;
        }
 
-       return bprintf("%f",
-                      (float)fs.f_frsize * ((float)fs.f_blocks -
-                      (float)fs.f_bfree) / 1024 / 1024 / 1024);
+       return fmt_human_2(fs.f_frsize * (fs.f_blocks - fs.f_bfree), "B");
 }