summaryrefslogtreecommitdiff
path: root/vendor/rustix/src/io/errno.rs
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-02 18:36:06 -0600
committermo khan <mo@mokhan.ca>2025-07-02 18:36:06 -0600
commit8cdfa445d6629ffef4cb84967ff7017654045bc2 (patch)
tree22f0b0907c024c78d26a731e2e1f5219407d8102 /vendor/rustix/src/io/errno.rs
parent4351c74c7c5f97156bc94d3a8549b9940ac80e3f (diff)
chore: add vendor directory
Diffstat (limited to 'vendor/rustix/src/io/errno.rs')
-rw-r--r--vendor/rustix/src/io/errno.rs74
1 files changed, 74 insertions, 0 deletions
diff --git a/vendor/rustix/src/io/errno.rs b/vendor/rustix/src/io/errno.rs
new file mode 100644
index 00000000..7d3eadf7
--- /dev/null
+++ b/vendor/rustix/src/io/errno.rs
@@ -0,0 +1,74 @@
+//! 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;
+#[cfg(all(not(feature = "std"), error_in_core))]
+use core::error;
+use core::{fmt, result};
+#[cfg(feature = "std")]
+use std::error;
+
+/// A specialized [`Result`] type for `rustix` APIs.
+pub type Result<T> = result::Result<T, Errno>;
+
+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, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ #[cfg(feature = "std")]
+ {
+ std::io::Error::from(*self).fmt(f)
+ }
+ #[cfg(not(feature = "std"))]
+ {
+ write!(f, "os error {}", self.raw_os_error())
+ }
+ }
+}
+
+impl fmt::Debug for Errno {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ #[cfg(feature = "std")]
+ {
+ std::io::Error::from(*self).fmt(f)
+ }
+ #[cfg(not(feature = "std"))]
+ {
+ write!(f, "os error {}", self.raw_os_error())
+ }
+ }
+}
+
+#[cfg(any(feature = "std", error_in_core))]
+impl error::Error for Errno {}
+
+#[cfg(feature = "std")]
+impl From<Errno> 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<T, F: FnMut() -> Result<T>>(mut f: F) -> Result<T> {
+ loop {
+ match f() {
+ Err(Errno::INTR) => (),
+ result => return result,
+ }
+ }
+}