use std::process::ExitCode;
use syd::{eprintfln, printfln};
#[cfg(all(
not(target_os = "android"),
not(target_arch = "loongarch64"),
not(target_arch = "riscv64"),
target_page_size_4k,
target_pointer_width = "64"
))]
#[global_allocator]
static GLOBAL: hardened_malloc::HardenedMalloc = hardened_malloc::HardenedMalloc;
syd::main! {
syd::set_sigpipe_dfl()?;
let mut args = std::env::args();
match args.nth(1).as_deref() {
None | Some("-h") => {
printfln!("Usage: syd-size size")?;
printfln!("Given a number, print human-formatted size and exit.")?;
printfln!("Given a string, parse human-formatted size into bytes, print and exit.")?;
}
Some(value) => {
if value.chars().all(|c| c.is_ascii_digit()) {
match value.parse::<usize>() {
Ok(size) => {
printfln!("{}", syd::human_size(size))?;
}
Err(error) => {
eprintfln!("Failed to parse: {error}")?;
return Ok(ExitCode::FAILURE);
}
}
} else {
match parse_size::Config::new().with_binary().parse_size(value) {
Ok(size) => {
printfln!("{size}")?;
}
Err(error) => {
eprintfln!("Failed to parse: {error}")?;
return Ok(ExitCode::FAILURE);
}
}
}
}
}
Ok(ExitCode::SUCCESS)
}