From cf1d16f8609c531e69cce229b4d4719c75854275 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 1 Mar 2024 23:12:44 -0700 Subject: [PATCH] hru(1): changed to use strerror(3) --- src/hru.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/hru.rs b/src/hru.rs index 0e0b25d..ad73070 100644 --- a/src/hru.rs +++ b/src/hru.rs @@ -23,8 +23,10 @@ use std::{ process::{ ExitCode, exit }, }; +extern crate strerror; extern crate sysexits; +use strerror::c_error; use sysexits::{ EX_DATAERR, EX_IOERR, EX_SOFTWARE }; 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) { Some(c) => c, 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 }, Err(err) => { - eprintln!("{}: {}.", argv[0], err); + eprintln!("{}: {}", argv[0], err); return ExitCode::from(EX_DATAERR as u8); }, }; @@ -87,7 +89,7 @@ fn main() -> ExitCode { let (number, prefix) = match convert(n) { Ok(x) => x, Err(err) => { - eprintln!("{}: {}.", argv[0], err); + eprintln!("{}: {}", argv[0], err); return ExitCode::from(EX_SOFTWARE as u8); }, }; @@ -98,7 +100,7 @@ fn main() -> ExitCode { stdout().write_all(format!("{} {}\n", out, si_prefix).as_bytes()) .unwrap_or_else(|e| { - eprintln!("{}: {}.", argv[0], e); + eprintln!("{}: {}", argv[0], c_error(e)); exit(EX_IOERR); }); }