Skip to content

Commit

Permalink
Added byte unit (PiB) to C formatter and refactored code.
Browse files Browse the repository at this point in the history
  • Loading branch information
allinurl committed Feb 9, 2018
1 parent ad64170 commit 5b164ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
18 changes: 10 additions & 8 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,14 +706,16 @@ char *
filesize_str (unsigned long long log_size)
{
char *size = xmalloc (sizeof (char) * 12);
if (log_size >= TIB)
snprintf (size, 12, "%.2f TiB", (double) (log_size) / TIB);
else if (log_size >= GIB)
snprintf (size, 12, "%.2f GiB", (double) (log_size) / GIB);
else if (log_size >= MIB)
snprintf (size, 12, "%.2f MiB", (double) (log_size) / MIB);
else if (log_size >= KIB)
snprintf (size, 12, "%.2f KiB", (double) (log_size) / KIB);
if (log_size >= (1ULL << 50))
snprintf (size, 12, "%.2f PiB", (double) (log_size) / PIB (1ULL));
else if (log_size >= (1ULL << 40))
snprintf (size, 12, "%.2f TiB", (double) (log_size) / TIB (1ULL));
else if (log_size >= (1ULL << 30))
snprintf (size, 12, "%.2f GiB", (double) (log_size) / GIB (1ULL));
else if (log_size >= (1ULL << 20))
snprintf (size, 12, "%.2f MiB", (double) (log_size) / MIB (1ULL));
else if (log_size >= (1ULL << 10))
snprintf (size, 12, "%.2f KiB", (double) (log_size) / KIB (1ULL));
else
snprintf (size, 12, "%.1f B", (double) (log_size));

Expand Down
9 changes: 5 additions & 4 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@

#define REGEX_ERROR 100

#define KIB 1024
#define MIB 1048576
#define GIB 1073741824
#define TIB 1099511627776LL
#define KIB(n) (n << 10)
#define MIB(n) (n << 20)
#define GIB(n) (n << 30)
#define TIB(n) (n << 40)
#define PIB(n) (n << 50)

#define MILS 1000ULL
#define SECS 1000000ULL
Expand Down

0 comments on commit 5b164ae

Please sign in to comment.