mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-08 10:51:15 -03:00
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:
committed by
Johannes Altmanninger
parent
735f3ae6ad
commit
bf5fa4f681
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user