1
0
forked from bonsai/harakit

hru(1): changed to use strerror(3)

This commit is contained in:
Emma Tebibyte 2024-03-01 23:12:44 -07:00
parent 8f956d775c
commit cf1d16f860
Signed by untrusted user: emma
GPG Key ID: 06FA419A1698C270

View File

@ -23,8 +23,10 @@ use std::{
process::{ ExitCode, exit }, process::{ ExitCode, exit },
}; };
extern crate strerror;
extern crate sysexits; extern crate sysexits;
use strerror::c_error;
use sysexits::{ EX_DATAERR, EX_IOERR, EX_SOFTWARE }; use sysexits::{ EX_DATAERR, EX_IOERR, EX_SOFTWARE };
const LIST: [(u32, &str); 10] = [ const LIST: [(u32, &str); 10] = [
@ -49,7 +51,7 @@ fn convert(input: u128) -> Result<(f64, (u32, &'static str)), String> {
let c = match 10_u128.checked_pow(n) { let c = match 10_u128.checked_pow(n) {
Some(c) => c, Some(c) => c,
None => { None => {
return Err(format!("10^{}: Integer overflow.", n.to_string())); return Err(format!("10^{}: Integer overflow", n.to_string()));
}, },
}; };
@ -79,7 +81,7 @@ fn main() -> ExitCode {
f f
}, },
Err(err) => { Err(err) => {
eprintln!("{}: {}.", argv[0], err); eprintln!("{}: {}", argv[0], err);
return ExitCode::from(EX_DATAERR as u8); return ExitCode::from(EX_DATAERR as u8);
}, },
}; };
@ -87,7 +89,7 @@ fn main() -> ExitCode {
let (number, prefix) = match convert(n) { let (number, prefix) = match convert(n) {
Ok(x) => x, Ok(x) => x,
Err(err) => { Err(err) => {
eprintln!("{}: {}.", argv[0], err); eprintln!("{}: {}", argv[0], err);
return ExitCode::from(EX_SOFTWARE as u8); return ExitCode::from(EX_SOFTWARE as u8);
}, },
}; };
@ -98,7 +100,7 @@ fn main() -> ExitCode {
stdout().write_all(format!("{} {}\n", out, si_prefix).as_bytes()) stdout().write_all(format!("{} {}\n", out, si_prefix).as_bytes())
.unwrap_or_else(|e| { .unwrap_or_else(|e| {
eprintln!("{}: {}.", argv[0], e); eprintln!("{}: {}", argv[0], c_error(e));
exit(EX_IOERR); exit(EX_IOERR);
}); });
} }