Rustify Sys::open and some fs:: error handling.

This commit is contained in:
4lDO2
2024-09-07 13:06:23 +02:00
parent b9653e689b
commit 198caa3bc5
13 changed files with 75 additions and 55 deletions
+12 -1
View File
@@ -1,4 +1,4 @@
use crate::platform::types::c_int;
use crate::{header::errno::STR_ERROR, platform::types::c_int};
/// Positive error codes (EINVAL, not -EINVAL).
#[derive(Debug, Eq, PartialEq)]
@@ -27,6 +27,17 @@ impl From<Errno> for crate::io::Error {
}
}
// TODO: core::error::Error
impl core::fmt::Display for Errno {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match usize::try_from(self.0).ok().and_then(|i| STR_ERROR.get(i)) {
Some(desc) => write!(f, "{desc}"),
None => write!(f, "unknown error ({})", self.0),
}
}
}
pub trait ResultExt<T> {
fn or_minus_one_errno(self) -> T;
}