diff --git a/Cargo.lock b/Cargo.lock index b06d33e..a352bf4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -662,6 +662,7 @@ dependencies = [ "subtle", "tempfile", "thiserror", + "uucore", "zeroize", ] diff --git a/src/shadow-core/Cargo.toml b/src/shadow-core/Cargo.toml index 8bb8a97..ed335df 100644 --- a/src/shadow-core/Cargo.toml +++ b/src/shadow-core/Cargo.toml @@ -18,6 +18,7 @@ path = "src/lib.rs" libc = { workspace = true } rustix = { workspace = true } thiserror = { workspace = true } +uucore = { workspace = true } zeroize = { workspace = true } subtle = { workspace = true } landlock = { workspace = true, optional = true } diff --git a/src/shadow-core/src/os_error.rs b/src/shadow-core/src/os_error.rs index e1f922c..147a05a 100644 --- a/src/shadow-core/src/os_error.rs +++ b/src/shadow-core/src/os_error.rs @@ -19,15 +19,10 @@ #[must_use] pub fn strerror(errno: i32) -> String { // `io::Error::from_raw_os_error` carries libc's `strerror` text, but its - // `Display` appends Rust's own " (os error N)" suffix. Strip that so the - // result is the bare OS message (matching GNU/coreutils output). The - // suffix is emitted verbatim in English regardless of locale, so a - // localized message cannot contain it earlier in the string. - let rendered = std::io::Error::from_raw_os_error(errno).to_string(); - match rendered.rfind(" (os error ") { - Some(cut) => rendered[..cut].to_string(), - None => rendered, - } + // `Display` appends Rust's own " (os error N)" suffix. `strip_errno` (the + // same helper uucore uses for its own I/O errors) removes it, leaving the + // bare OS message — matching GNU/coreutils output. + uucore::error::strip_errno(&std::io::Error::from_raw_os_error(errno)) } /// The OS message for `EACCES` ("Permission denied"), sourced from libc.