From 334a5698eb666529ff01230122896fdd6b89dad6 Mon Sep 17 00:00:00 2001 From: pjht Date: Fri, 4 Oct 2024 10:03:24 -0500 Subject: [PATCH] mikros: Impl From for Errno --- library/std/src/os/mikros/errno.rs | 68 ++++++++++++++++++++++++ library/std/src/sys/pal/mikros/common.rs | 42 ++++++++------- 2 files changed, 91 insertions(+), 19 deletions(-) diff --git a/library/std/src/os/mikros/errno.rs b/library/std/src/os/mikros/errno.rs index 9a7079b2e5d..1f1942d699c 100644 --- a/library/std/src/os/mikros/errno.rs +++ b/library/std/src/os/mikros/errno.rs @@ -134,6 +134,9 @@ pub enum Errno { ERFKILL = 132, EHWPOISON = 133, EAGAIN = 134, + EEOF = 135, + EINVALDAT = 136, + EWRZERO = 137, } #[stable(feature = "mikros", since = "1.80.0")] @@ -275,6 +278,9 @@ fn try_from(value: i32) -> Result { 132 => Ok(ERFKILL), 133 => Ok(EHWPOISON), 134 => Ok(EAGAIN), + 135 => Ok(EEOF), + 136 => Ok(EINVALDAT), + 137 => Ok(EWRZERO), x => Err(x), } } @@ -417,7 +423,69 @@ fn fmt(&self, f: &mut crate::fmt::Formatter<'_>) -> Result<(), crate::fmt::Error ENOTRECOVERABLE => "State not recoverable", ERFKILL => "Operation not possible due to RF-kill", EHWPOISON => "Memory page has hardware error", + EEOF => "Unexpected EOF", + EINVALDAT => "Invalid data", + EWRZERO => "Write zero", }; f.write_str(errno_name) } } + +#[stable(feature = "mikros", since = "1.80.0")] +impl From for Errno { + fn from(kind: crate::io::ErrorKind) -> Self { + use Errno::*; + + use crate::io::ErrorKind; + match kind { + ErrorKind::AddrInUse => EADDRINUSE, + ErrorKind::AddrNotAvailable => EADDRNOTAVAIL, + ErrorKind::AlreadyExists => EEXIST, + ErrorKind::ArgumentListTooLong => E2BIG, + ErrorKind::BrokenPipe => EPIPE, + ErrorKind::ConnectionAborted => ECONNABORTED, + ErrorKind::ConnectionRefused => ECONNREFUSED, + ErrorKind::ConnectionReset => ECONNRESET, + ErrorKind::CrossesDevices => EXDEV, + ErrorKind::Deadlock => EDEADLK, + ErrorKind::DirectoryNotEmpty => ENOTEMPTY, + ErrorKind::ExecutableFileBusy => ETXTBSY, + ErrorKind::FileTooLarge => EFBIG, + ErrorKind::FilesystemLoop => ELOOP, + ErrorKind::FilesystemQuotaExceeded => EDQUOT, + ErrorKind::HostUnreachable => EHOSTUNREACH, + //ErrorKind::InProgress => EINPROGRESS, + ErrorKind::Interrupted => EINTR, + ErrorKind::InvalidData => EINVALDAT, + ErrorKind::InvalidFilename => ENAMETOOLONG, + ErrorKind::InvalidInput => EINVAL, + ErrorKind::IsADirectory => EISDIR, + ErrorKind::NetworkDown => ENETDOWN, + ErrorKind::NetworkUnreachable => ENETUNREACH, + ErrorKind::NotADirectory => ENOTDIR, + ErrorKind::NotConnected => ENOTCONN, + ErrorKind::NotFound => ENOENT, + ErrorKind::NotSeekable => ESPIPE, + ErrorKind::OutOfMemory => ENOMEM, + ErrorKind::PermissionDenied => EPERM, + ErrorKind::ReadOnlyFilesystem => EROFS, + ErrorKind::ResourceBusy => EBUSY, + ErrorKind::StaleNetworkFileHandle => ESTALE, + ErrorKind::StorageFull => ENOSPC, + ErrorKind::TimedOut => ETIMEDOUT, + ErrorKind::TooManyLinks => EMLINK, + ErrorKind::UnexpectedEof => EEOF, + ErrorKind::Unsupported => ENOSYS, + ErrorKind::WouldBlock => EWOULDBLOCK, + ErrorKind::WriteZero => EWRZERO, + ErrorKind::Other | ErrorKind::Uncategorized => EIO, + } + } +} + +#[stable(feature = "mikros", since = "1.80.0")] +impl From for Errno { + fn from(error: crate::io::Error) -> Self { + Self::from(error.kind()) + } +} diff --git a/library/std/src/sys/pal/mikros/common.rs b/library/std/src/sys/pal/mikros/common.rs index 69897bf02b2..a6957639875 100644 --- a/library/std/src/sys/pal/mikros/common.rs +++ b/library/std/src/sys/pal/mikros/common.rs @@ -32,42 +32,46 @@ pub fn decode_error_kind(errno: RawOsError) -> crate::io::ErrorKind { use crate::io::ErrorKind::*; match errno { - Errno::E2BIG => ArgumentListTooLong, Errno::EADDRINUSE => AddrInUse, Errno::EADDRNOTAVAIL => AddrNotAvailable, - Errno::EBUSY => ResourceBusy, + Errno::EEXIST => AlreadyExists, + Errno::E2BIG => ArgumentListTooLong, + Errno::EPIPE => BrokenPipe, Errno::ECONNABORTED => ConnectionAborted, Errno::ECONNREFUSED => ConnectionRefused, Errno::ECONNRESET => ConnectionReset, + Errno::EXDEV => CrossesDevices, Errno::EDEADLK => Deadlock, - Errno::EDQUOT => FilesystemQuotaExceeded, - Errno::EEXIST => AlreadyExists, + Errno::ENOTEMPTY => DirectoryNotEmpty, + Errno::ETXTBSY => ExecutableFileBusy, Errno::EFBIG => FileTooLarge, + Errno::ELOOP => FilesystemLoop, + Errno::EDQUOT => FilesystemQuotaExceeded, Errno::EHOSTUNREACH => HostUnreachable, + //Errno::EINPROGRESS => InProgress, Errno::EINTR => Interrupted, + Errno::EINVALDAT => InvalidData, + Errno::ENAMETOOLONG => InvalidFilename, Errno::EINVAL => InvalidInput, Errno::EISDIR => IsADirectory, - Errno::ELOOP => FilesystemLoop, - Errno::ENOENT => NotFound, - Errno::ENOMEM => OutOfMemory, - Errno::ENOSPC => StorageFull, - Errno::ENOSYS => Unsupported, - Errno::EMLINK => TooManyLinks, - Errno::ENAMETOOLONG => InvalidFilename, Errno::ENETDOWN => NetworkDown, Errno::ENETUNREACH => NetworkUnreachable, - Errno::ENOTCONN => NotConnected, Errno::ENOTDIR => NotADirectory, - Errno::ENOTEMPTY => DirectoryNotEmpty, - Errno::EPIPE => BrokenPipe, - Errno::EROFS => ReadOnlyFilesystem, + Errno::ENOTCONN => NotConnected, + Errno::ENOENT => NotFound, Errno::ESPIPE => NotSeekable, - Errno::ESTALE => StaleNetworkFileHandle, - Errno::ETIMEDOUT => TimedOut, - Errno::ETXTBSY => ExecutableFileBusy, - Errno::EXDEV => CrossesDevices, + Errno::ENOMEM => OutOfMemory, Errno::EACCES | Errno::EPERM => PermissionDenied, + Errno::EROFS => ReadOnlyFilesystem, + Errno::EBUSY => ResourceBusy, + Errno::ESTALE => StaleNetworkFileHandle, + Errno::ENOSPC => StorageFull, + Errno::ETIMEDOUT => TimedOut, + Errno::EMLINK => TooManyLinks, + Errno::EEOF => UnexpectedEof, + Errno::ENOSYS => Unsupported, Errno::EAGAIN | Errno::EWOULDBLOCK => WouldBlock, + Errno::EWRZERO => WriteZero, _ => Uncategorized, } }