fixed
This commit is contained in:
parent
7a048f8787
commit
f8dd7660ae
143 changed files with 74 additions and 248 deletions
30
include/human.h
Normal file
30
include/human.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
#ifndef _HUMAN_H
|
||||
#define _HUMAN_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define MU_HUMAN_BUF_SIZE 16
|
||||
|
||||
char *mu_humansize(off_t n, off_t block) {
|
||||
static char mu_hs_buf[MU_HUMAN_BUF_SIZE + 1];
|
||||
memset(mu_hs_buf, '\0', sizeof(mu_hs_buf));
|
||||
|
||||
char *postfixes = "BKMGTPE";
|
||||
|
||||
double size = n;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < strlen(postfixes) && size >= block; i++)
|
||||
size /= block;
|
||||
|
||||
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);
|
||||
|
||||
return mu_hs_buf;
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue