summaryrefslogtreecommitdiff
path: root/src/shared.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared.c')
-rw-r--r--src/shared.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/shared.c b/src/shared.c
index ee3c2f1..a8837c4 100644
--- a/src/shared.c
+++ b/src/shared.c
@@ -4,6 +4,7 @@
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
void error(const char* format, ...) {
va_list list;
@@ -44,3 +45,41 @@ bool streql(const char* a, const char* b) {
bool prefix(const char* pre, const char* str) {
return strncmp(pre, str, strlen(pre)) == 0;
}
+
+static char fs_types[5] = {'K','M','G','T','P'};
+void print_file_size(size_t bytes) {
+ int index = 0;
+ float next = bytes;
+ while (true) {
+ if (next < 1000) {
+ break;
+ }
+ if (index == 5) {
+ printf("999P");
+ return;
+ };
+ next /= 1024;
+ index++;
+ }
+
+ if (next/100 < 1) putchar(' ');
+ if (next/10 < 1) putchar(' ');
+ if (index == 0) putchar(' ');
+
+ printf("%u", (int)(next+.5));
+ if (index > 0) {
+ putchar(fs_types[index - 1]);
+ }
+ putchar(' ');
+}
+
+static char* months[12] =
+ {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
+void print_date_time(time_t mills) {
+ struct tm* info;
+ info = localtime(&mills);
+ printf("%s ", months[info->tm_mon]);
+ if (info->tm_mday < 10)
+ printf(" ");
+ printf("%d %02d:%02d ", info->tm_mday, info->tm_hour, info->tm_sec);
+}