39 lines
736 B
V
39 lines
736 B
V
module buildj_util
|
|
|
|
const (
|
|
ZERO = 0
|
|
KB = 1024
|
|
MB = KB * KB
|
|
)
|
|
|
|
pub fn check_os() {
|
|
$if linux {
|
|
return
|
|
}
|
|
$if mac {
|
|
return
|
|
}
|
|
println('[ERROR] Not supported OS.')
|
|
exit(1)
|
|
}
|
|
|
|
pub fn get_readable_size(size int) string {
|
|
if size <= ZERO {
|
|
return '${size} Byte'
|
|
} else if size < KB {
|
|
return '${size} Bytes'
|
|
} else if size < MB {
|
|
size_in_kb := f64_str_2f(f64(size) / f64(KB))
|
|
return '${size_in_kb} KB'
|
|
} else {
|
|
size_in_mb := f64_str_2f(f64(size) / f64(MB))
|
|
return '${size_in_mb} MB'
|
|
}
|
|
}
|
|
|
|
fn f64_str_2f(d f64) string {
|
|
buf := malloc(sizeof(f64) * 5 + 1)
|
|
C.sprintf(buf, '%.2f', d)
|
|
return tos(buf, C.strlen(buf))
|
|
}
|