mirror of
https://github.com/uutils/shadow.git
synced 2026-06-10 16:14:57 -07:00
shadow-core: use uucore::error::strip_errno instead of hand-rolling
Replace the local " (os error N)" suffix stripping with uucore's existing strip_errno helper, per review on #171. Adds uucore (already in the dependency tree via the tool crates) to shadow-core.
This commit is contained in:
Generated
+1
@@ -662,6 +662,7 @@ dependencies = [
|
||||
"subtle",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"uucore",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user