From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/rustix/src/io/errno.rs | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 third_party/rust/rustix/src/io/errno.rs (limited to 'third_party/rust/rustix/src/io/errno.rs') diff --git a/third_party/rust/rustix/src/io/errno.rs b/third_party/rust/rustix/src/io/errno.rs new file mode 100644 index 0000000000..2b72de005d --- /dev/null +++ b/third_party/rust/rustix/src/io/errno.rs @@ -0,0 +1,72 @@ +//! The `Errno` type, which is a minimal wrapper around an error code. +//! +//! We define the error constants as individual `const`s instead of an enum +//! because we may not know about all of the host's error values and we don't +//! want unrecognized values to create undefined behavior. + +use crate::backend; +use core::{fmt, result}; +#[cfg(feature = "std")] +use std::error; + +/// A specialized [`Result`] type for `rustix` APIs. +pub type Result = result::Result; + +pub use backend::io::errno::Errno; + +impl Errno { + /// Shorthand for `std::io::Error::from(self).kind()`. + #[cfg(feature = "std")] + #[inline] + pub fn kind(self) -> std::io::ErrorKind { + std::io::Error::from(self).kind() + } +} + +impl fmt::Display for Errno { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + #[cfg(feature = "std")] + { + std::io::Error::from(*self).fmt(fmt) + } + #[cfg(not(feature = "std"))] + { + write!(fmt, "os error {}", self.raw_os_error()) + } + } +} + +impl fmt::Debug for Errno { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + #[cfg(feature = "std")] + { + std::io::Error::from(*self).fmt(fmt) + } + #[cfg(not(feature = "std"))] + { + write!(fmt, "os error {}", self.raw_os_error()) + } + } +} + +#[cfg(feature = "std")] +impl error::Error for Errno {} + +#[cfg(feature = "std")] +impl From for std::io::Error { + #[inline] + fn from(err: Errno) -> Self { + Self::from_raw_os_error(err.raw_os_error() as _) + } +} + +/// Call `f` until it either succeeds or fails other than [`Errno::INTR`]. +#[inline] +pub fn retry_on_intr Result>(mut f: F) -> Result { + loop { + match f() { + Err(Errno::INTR) => (), + result => return result, + } + } +} -- cgit v1.2.3