4
1
mirror of https://github.com/DragonOS-Community/DragonOS.git synced 2025-06-20 18:26:32 +00:00

部分函数从返回值为Result<<>,i32>修改为Result<<>,SystemError> (#210)

* 将Result<<>,i32>替换为Result<<>,SystemError>
* bugfix: 显示双缓冲区初始化的时候,连续注册了两次Video Softirq的问题。

Co-authored-by: longjin <longjin@RinGoTek.cn>
This commit is contained in:
Mork
2023-03-29 21:24:11 +08:00
committed by GitHub
parent 64aea4b349
commit 676b8ef62e
37 changed files with 801 additions and 786 deletions

@ -1,5 +1,7 @@
use num_traits::{FromPrimitive, ToPrimitive};
#[repr(i32)]
#[derive(Debug, FromPrimitive)]
#[derive(Debug, FromPrimitive, ToPrimitive, PartialEq, Eq, Clone)]
#[allow(dead_code)]
pub enum SystemError {
/// 参数列表过长或者在输出buffer中缺少空间 或者参数比系统内建的最大值要大 Argument list too long.
@ -165,3 +167,19 @@ pub enum SystemError {
/// 跨设备连接 Cross-device link.
EXDEV = 81,
}
impl SystemError {
/// @brief 把posix错误码转换为系统错误枚举类型。
pub fn from_posix_errno(errno: i32) -> Option<SystemError> {
// posix 错误码是小于0的
if errno >= 0 {
return None;
}
return <Self as FromPrimitive>::from_i32(-errno);
}
/// @brief 把系统错误枚举类型转换为负数posix错误码。
pub fn to_posix_errno(&self) -> i32 {
return -<Self as ToPrimitive>::to_i32(self).unwrap();
}
}