feat: implement perror_nix

Similar to `perror_io`, we don't need to make a libc call for `nix`
results, since the error variant contains the errno, from which a static
mapping to an error message exists. Avoid using `perror` and instead use
`perror_io` or `perror_nix` as appropriate where possible.

The `perror_io` and `perror_nix` functions could be combined by
implementing `fish_printf::ToArg` for `nix::errno::Errno`, but such a
function would violate type safety, as it would allow passing any
formattable argument, not necessarily limited to functions with a `%s`
formatting.

Part of #12502
This commit is contained in:
Daniel Rainer
2026-03-02 02:51:57 +01:00
committed by Johannes Altmanninger
parent 735f3ae6ad
commit bf5fa4f681
9 changed files with 45 additions and 45 deletions

View File

@@ -81,6 +81,10 @@ pub fn perror(s: &str) {
let _ = stderr.write_all(b"\n");
}
pub fn perror_nix(s: &str, e: nix::errno::Errno) {
eprintf!("%s: %s\n", s, e.desc());
}
pub fn perror_io(s: &str, e: &io::Error) {
eprintf!("%s: %s\n", s, e);
}