Skip to content

Commit

Permalink
Use i32 in SystemError::Unknown instead of nix Errno
Browse files Browse the repository at this point in the history
This way users of `drm` can match on constants from `libc`, or can
convert it to the error types from any version of `nix` or `rustix`.
This addresses a bit of awkwardness in
Smithay/smithay#1162 and
rust-windowing/softbuffer#164.

This should eliminate nix as a "public dependency" of `drm`, though it's
still exposed by `drm-ffi`.
  • Loading branch information
ids1024 committed Oct 17, 2023
1 parent 250fa4a commit a6b5b32
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions drm-ffi/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ pub enum SystemError {

/// Unknown system error.
Unknown {
/// Unknown [`nix::errno::Errno`] returned by the system call.
errno: Errno,
/// Unknown errno value returned by the system call.
errno: i32,
},
}

Expand All @@ -53,7 +53,7 @@ impl fmt::Display for SystemError {
SystemError::PermissionDenied => "permission denied",
SystemError::UnknownFourcc => "unknown fourcc",
SystemError::Unknown { errno } => {
return write!(fmt, "unknown system error: {}", errno)
return write!(fmt, "unknown system error: {}", Errno::from_i32(*errno))
}
})
}
Expand All @@ -69,7 +69,9 @@ impl From<Errno> for SystemError {
Errno::EINVAL => SystemError::InvalidArgument,
Errno::ENOTTY => SystemError::InvalidFileDescriptor,
Errno::EACCES => SystemError::PermissionDenied,
_ => SystemError::Unknown { errno },
_ => SystemError::Unknown {
errno: errno as i32,
},
}
}
}

0 comments on commit a6b5b32

Please sign in to comment.