-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathf_bytes.c
More file actions
29 lines (20 loc) · 632 Bytes
/
f_bytes.c
File metadata and controls
29 lines (20 loc) · 632 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# include "f_bytes.h"
# define KB ( (long)1024 )
# define MB ( KB * KB )
# define GB ( MB * KB )
int format_bytes(struct fmt_stream * out, const char * id, const char * options, va_list * arg){
int bytes = va_arg(*arg, int);
float number = bytes;
(void)id;
(void)options;
if(bytes < KB){
return( fmt_print_builtin(out, "%d bytes", bytes) );
}
if(bytes < MB){
return( fmt_print_builtin(out, "%.2f KB", number / KB) );
}
if(bytes < GB){
return( fmt_print_builtin(out, "%.2f MB", number / MB) );
}
return( fmt_print_builtin(out, "%.2f GB", number / GB) );
}