This commit is contained in:
Your Name 2024-07-10 22:59:28 +03:00
parent 1b9dc6d7dc
commit 0737916f1a
11 changed files with 71 additions and 35 deletions

View file

@ -2,22 +2,23 @@
char mu_hs_buf[MU_HUMAN_BUF_SIZE + 1];
char *mu_humansize(off_t n, off_t block) {
char *mu_humansize(off_t n, int block) {
memset(mu_hs_buf, '\0', sizeof(mu_hs_buf));
char *postfixes = "BKMGTPE";
size_t i = 0;
double size = n;
size_t i;
for (i = 0; i < strlen(postfixes) && size >= block; i++)
size /= block;
while (size > (off_t)block) {
size /= (off_t)block;
i++;
}
if (i)
snprintf(mu_hs_buf, sizeof(mu_hs_buf), "%.1f%c", size, postfixes[i]);
else
snprintf(mu_hs_buf, sizeof(mu_hs_buf), "%ju", n);
snprintf(mu_hs_buf, sizeof(mu_hs_buf), "%jd", n);
return mu_hs_buf;
}