mirror of
https://git.proxmox.com/git/proxmox
synced 2025-10-18 23:10:16 +00:00
proxmox: add SysError::is_errno_raw
to work around missing errno values in nix 0.16 Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
c9aa2beb47
commit
8f57f29ca8
@ -55,7 +55,13 @@ pub fn io_err_other<E: ToString>(e: E) -> io::Error {
|
||||
/// ```
|
||||
pub trait SysError {
|
||||
/// Check if this error is a specific error returned from a system call.
|
||||
fn is_errno(&self, value: Errno) -> bool;
|
||||
fn is_errno(&self, value: Errno) -> bool {
|
||||
self.is_errno_raw(value as i32)
|
||||
}
|
||||
|
||||
/// Check if this error is a specific error returned from a system call, without involving the
|
||||
/// `nix::errno::Errno` type as it is incomplete.
|
||||
fn is_errno_raw(&self, value: i32) -> bool;
|
||||
|
||||
/// Convert this error into a `std::io::Error`. This must use the correct `std::io::ErrorKind`,
|
||||
/// so that for example `ErrorKind::WouldBlock` means that the previous system call failed with
|
||||
@ -83,8 +89,8 @@ pub trait SysError {
|
||||
|
||||
impl SysError for io::Error {
|
||||
#[inline]
|
||||
fn is_errno(&self, value: Errno) -> bool {
|
||||
self.raw_os_error() == Some(value as i32)
|
||||
fn is_errno_raw(&self, value: i32) -> bool {
|
||||
self.raw_os_error() == Some(value)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -99,6 +105,14 @@ impl SysError for nix::Error {
|
||||
*self == Error::Sys(value)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_errno_raw(&self, value: i32) -> bool {
|
||||
match *self {
|
||||
Error::Sys(errno) => value == errno as i32,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn into_io_error(self) -> io::Error {
|
||||
match self {
|
||||
|
Loading…
Reference in New Issue
Block a user