diff options
Diffstat (limited to 'third_party/rust/nix/src/errno.rs')
-rw-r--r-- | third_party/rust/nix/src/errno.rs | 1114 |
1 files changed, 535 insertions, 579 deletions
diff --git a/third_party/rust/nix/src/errno.rs b/third_party/rust/nix/src/errno.rs index 50b35248f8..2e74a84454 100644 --- a/third_party/rust/nix/src/errno.rs +++ b/third_party/rust/nix/src/errno.rs @@ -1,74 +1,127 @@ +//! Safe wrappers around errno functions +//! +//! # Example +//! ``` +//! use nix::errno::Errno; +//! +//! Errno::EIO.set(); +//! assert_eq!(Errno::last(), Errno::EIO); +//! +//! Errno::clear(); +//! assert_eq!(Errno::last(), Errno::from_raw(0)); +//! ``` + use crate::Result; use cfg_if::cfg_if; use libc::{c_int, c_void}; -use std::convert::TryFrom; use std::{error, fmt, io}; pub use self::consts::*; cfg_if! { if #[cfg(any(target_os = "freebsd", - target_os = "ios", - target_os = "macos"))] { + apple_targets,))] { unsafe fn errno_location() -> *mut c_int { - libc::__error() + unsafe { libc::__error() } } - } else if #[cfg(any(target_os = "android", - target_os = "netbsd", - target_os = "openbsd"))] { + } else if #[cfg(any(target_os = "android", netbsdlike))] { unsafe fn errno_location() -> *mut c_int { - libc::__errno() + unsafe { libc::__errno() } } } else if #[cfg(any(target_os = "linux", target_os = "redox", target_os = "dragonfly", - target_os = "fuchsia"))] { + target_os = "fuchsia", + target_os = "hurd"))] { unsafe fn errno_location() -> *mut c_int { - libc::__errno_location() + unsafe { libc::__errno_location() } } - } else if #[cfg(any(target_os = "illumos", target_os = "solaris"))] { + } else if #[cfg(solarish)] { unsafe fn errno_location() -> *mut c_int { - libc::___errno() + unsafe { libc::___errno() } } } else if #[cfg(any(target_os = "haiku",))] { unsafe fn errno_location() -> *mut c_int { - libc::_errnop() + unsafe { libc::_errnop() } } } else if #[cfg(any(target_os = "aix"))] { unsafe fn errno_location() -> *mut c_int { - libc::_Errno() + unsafe { libc::_Errno() } } } } -/// Sets the platform-specific errno to no-error -fn clear() { - // Safe because errno is a thread-local variable - unsafe { - *errno_location() = 0; - } -} - /// Returns the platform-specific value of errno +#[deprecated(since = "0.28.0", note = "please use `Errno::last_raw()` instead")] pub fn errno() -> i32 { - unsafe { *errno_location() } + Errno::last_raw() } impl Errno { + /// Returns the current value of errno pub fn last() -> Self { - last() + Self::from_raw(Self::last_raw()) } - pub fn desc(self) -> &'static str { - desc(self) + /// Returns the current raw i32 value of errno + pub fn last_raw() -> i32 { + unsafe { *errno_location() } + } + + /// Sets the value of errno. + /// + /// # Example + /// ``` + /// use nix::errno::Errno; + /// + /// Errno::EIO.set(); + /// + /// assert_eq!(Errno::last(), Errno::EIO); + /// ``` + pub fn set(self) { + Self::set_raw(self as i32) } + /// Sets the raw i32 value of errno. + pub fn set_raw(errno: i32) { + // Safe because errno is a thread-local variable + unsafe { + *errno_location() = errno; + } + } + + #[deprecated( + since = "0.28.0", + note = "please use `Errno::from_raw()` instead" + )] pub const fn from_i32(err: i32) -> Errno { + Self::from_raw(err) + } + + pub const fn from_raw(err: i32) -> Errno { + #[allow(deprecated)] from_i32(err) } + pub fn desc(self) -> &'static str { + desc(self) + } + + /// Sets the platform-specific errno to no-error + /// + /// ``` + /// use nix::errno::Errno; + /// + /// Errno::EIO.set(); + /// + /// Errno::clear(); + /// + /// let err = Errno::last(); + /// assert_ne!(err, Errno::EIO); + /// assert_eq!(err, Errno::from_raw(0)); + /// ``` pub fn clear() { - clear() + Self::set_raw(0) } /// Returns `Ok(value)` if it does not contain the sentinel value. This @@ -137,14 +190,10 @@ impl TryFrom<io::Error> for Errno { type Error = io::Error; fn try_from(ioerror: io::Error) -> std::result::Result<Self, io::Error> { - ioerror.raw_os_error().map(Errno::from_i32).ok_or(ioerror) + ioerror.raw_os_error().map(Errno::from_raw).ok_or(ioerror) } } -fn last() -> Errno { - Errno::from_i32(errno()) -} - fn desc(errno: Errno) -> &'static str { use self::Errno::*; match errno { @@ -225,467 +274,270 @@ fn desc(errno: Errno) -> &'static str { EHOSTUNREACH => "No route to host", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, + solarish, target_os = "aix", - target_os = "illumos", - target_os = "solaris", target_os = "fuchsia" ))] ECHRNG => "Channel number out of range", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, + solarish, target_os = "aix", - target_os = "illumos", - target_os = "solaris", target_os = "fuchsia" ))] EL2NSYNC => "Level 2 not synchronized", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, + solarish, target_os = "aix", - target_os = "illumos", - target_os = "solaris", target_os = "fuchsia" ))] EL3HLT => "Level 3 halted", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, + solarish, target_os = "aix", - target_os = "illumos", - target_os = "solaris", target_os = "fuchsia" ))] EL3RST => "Level 3 reset", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, + solarish, target_os = "aix", - target_os = "illumos", - target_os = "solaris", target_os = "fuchsia" ))] ELNRNG => "Link number out of range", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, + solarish, target_os = "aix", - target_os = "illumos", - target_os = "solaris", target_os = "fuchsia" ))] EUNATCH => "Protocol driver not attached", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, + solarish, target_os = "aix", - target_os = "illumos", - target_os = "solaris", target_os = "fuchsia" ))] ENOCSI => "No CSI structure available", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, + solarish, target_os = "aix", - target_os = "illumos", - target_os = "solaris", target_os = "fuchsia" ))] EL2HLT => "Level 2 halted", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] EBADE => "Invalid exchange", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] EBADR => "Invalid request descriptor", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] EXFULL => "Exchange full", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] ENOANO => "No anode", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] EBADRQC => "Invalid request code", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] EBADSLT => "Invalid slot", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] EBFONT => "Bad font file format", #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" + linux_android, + solarish, + target_os = "fuchsia", + target_os = "hurd" ))] ENOSTR => "Device not a stream", #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" + linux_android, + solarish, + target_os = "fuchsia", + target_os = "hurd" ))] ENODATA => "No data available", #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" + linux_android, + solarish, + target_os = "fuchsia", + target_os = "hurd" ))] ETIME => "Timer expired", #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" + linux_android, + solarish, + target_os = "fuchsia", + target_os = "hurd" ))] ENOSR => "Out of streams resources", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] ENONET => "Machine is not on the network", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] ENOPKG => "Package not installed", #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" + linux_android, + solarish, + target_os = "fuchsia", + target_os = "hurd" ))] EREMOTE => "Object is remote", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, + solarish, target_os = "aix", - target_os = "illumos", - target_os = "solaris", target_os = "fuchsia" ))] ENOLINK => "Link has been severed", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] EADV => "Advertise error", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] ESRMNT => "Srmount error", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] ECOMM => "Communication error on send", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, + solarish, target_os = "aix", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" + target_os = "fuchsia", ))] EPROTO => "Protocol error", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, + solarish, target_os = "aix", - target_os = "illumos", - target_os = "solaris", target_os = "fuchsia" ))] EMULTIHOP => "Multihop attempted", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, target_os = "fuchsia"))] EDOTDOT => "RFS specific error", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "aix", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, target_os = "aix", target_os = "fuchsia"))] EBADMSG => "Not a data message", - #[cfg(any(target_os = "illumos", target_os = "solaris"))] + #[cfg(solarish)] EBADMSG => "Trying to read unreadable message", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, target_os = "aix", target_os = "fuchsia", - target_os = "haiku" + target_os = "haiku", + target_os = "hurd" ))] EOVERFLOW => "Value too large for defined data type", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] ENOTUNIQ => "Name not unique on network", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] EBADFD => "File descriptor in bad state", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] EREMCHG => "Remote address changed", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] ELIBACC => "Can not access a needed shared library", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] ELIBBAD => "Accessing a corrupted shared library", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] ELIBSCN => ".lib section in a.out corrupted", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] ELIBMAX => "Attempting to link in too many shared libraries", #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" + linux_android, + solarish, + target_os = "fuchsia", + target_os = "hurd" ))] ELIBEXEC => "Cannot exec a shared library directly", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, + solarish, target_os = "aix", - target_os = "illumos", - target_os = "solaris", target_os = "fuchsia", target_os = "openbsd" ))] EILSEQ => "Illegal byte sequence", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, + solarish, target_os = "aix", - target_os = "illumos", - target_os = "solaris", target_os = "fuchsia" ))] ERESTART => "Interrupted system call should be restarted", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] ESTRPIPE => "Streams pipe error", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] EUSERS => "Too many users", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, target_os = "fuchsia", target_os = "netbsd", target_os = "redox" ))] EOPNOTSUPP => "Operation not supported on transport endpoint", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, target_os = "fuchsia", target_os = "hurd"))] ESTALE => "Stale file handle", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, target_os = "fuchsia"))] EUCLEAN => "Structure needs cleaning", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, target_os = "fuchsia"))] ENOTNAM => "Not a XENIX named type file", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, target_os = "fuchsia"))] ENAVAIL => "No XENIX semaphores available", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, target_os = "fuchsia"))] EISNAM => "Is a named type file", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, target_os = "fuchsia"))] EREMOTEIO => "Remote I/O error", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, target_os = "fuchsia"))] EDQUOT => "Quota exceeded", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, target_os = "fuchsia", target_os = "openbsd", target_os = "dragonfly" @@ -693,71 +545,47 @@ fn desc(errno: Errno) -> &'static str { ENOMEDIUM => "No medium found", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, target_os = "fuchsia", target_os = "openbsd" ))] EMEDIUMTYPE => "Wrong medium type", #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "illumos", - target_os = "solaris", + linux_android, + solarish, target_os = "fuchsia", target_os = "haiku" ))] ECANCELED => "Operation canceled", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, target_os = "fuchsia"))] ENOKEY => "Required key not available", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, target_os = "fuchsia"))] EKEYEXPIRED => "Key has expired", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, target_os = "fuchsia"))] EKEYREVOKED => "Key has been revoked", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, target_os = "fuchsia"))] EKEYREJECTED => "Key was rejected by service", #[cfg(any( - target_os = "linux", - target_os = "android", + linux_android, target_os = "aix", - target_os = "fuchsia" + target_os = "fuchsia", + target_os = "hurd" ))] EOWNERDEAD => "Owner died", - #[cfg(any(target_os = "illumos", target_os = "solaris"))] + #[cfg(solarish)] EOWNERDEAD => "Process died with lock", - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "aix", - target_os = "fuchsia" - ))] + #[cfg(any(linux_android, target_os = "aix", target_os = "fuchsia"))] ENOTRECOVERABLE => "State not recoverable", - #[cfg(any(target_os = "illumos", target_os = "solaris"))] + #[cfg(solarish)] ENOTRECOVERABLE => "Lock is not recoverable", #[cfg(any( @@ -772,21 +600,13 @@ fn desc(errno: Errno) -> &'static str { ))] EHWPOISON => "Memory page has hardware error", - #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] + #[cfg(freebsdlike)] EDOOFUS => "Programming error", - #[cfg(any( - target_os = "freebsd", - target_os = "dragonfly", - target_os = "redox" - ))] + #[cfg(any(freebsdlike, target_os = "hurd", target_os = "redox"))] EMULTIHOP => "Multihop attempted", - #[cfg(any( - target_os = "freebsd", - target_os = "dragonfly", - target_os = "redox" - ))] + #[cfg(any(freebsdlike, target_os = "hurd", target_os = "redox"))] ENOLINK => "Link has been severed", #[cfg(target_os = "freebsd")] @@ -795,300 +615,157 @@ fn desc(errno: Errno) -> &'static str { #[cfg(target_os = "freebsd")] ECAPMODE => "Not permitted in capability mode", - #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "openbsd", - target_os = "netbsd" - ))] + #[cfg(any(bsd, target_os = "hurd"))] ENEEDAUTH => "Need authenticator", - #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "openbsd", - target_os = "netbsd", - target_os = "redox", - target_os = "illumos", - target_os = "solaris" - ))] + #[cfg(any(bsd, target_os = "redox", solarish))] EOVERFLOW => "Value too large to be stored in data type", #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", + freebsdlike, + apple_targets, target_os = "netbsd", target_os = "redox", - target_os = "haiku" + target_os = "haiku", + target_os = "hurd" ))] EILSEQ => "Illegal byte sequence", - #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "openbsd", - target_os = "netbsd", - target_os = "haiku" - ))] + #[cfg(any(bsd, target_os = "haiku"))] ENOATTR => "Attribute not found", #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "openbsd", - target_os = "netbsd", + bsd, target_os = "redox", - target_os = "haiku" + target_os = "haiku", + target_os = "hurd" ))] EBADMSG => "Bad message", #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "openbsd", - target_os = "netbsd", - target_os = "redox", - target_os = "haiku" + bsd, + target_os = "haiku", + target_os = "hurd", + target_os = "redox" ))] EPROTO => "Protocol error", #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "openbsd" + freebsdlike, + apple_targets, + target_os = "openbsd", + target_os = "hurd" ))] ENOTRECOVERABLE => "State not recoverable", - #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "openbsd" - ))] + #[cfg(any(freebsdlike, apple_targets, target_os = "openbsd"))] EOWNERDEAD => "Previous owner died", #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "openbsd", - target_os = "netbsd", + bsd, target_os = "aix", - target_os = "illumos", - target_os = "solaris", - target_os = "haiku" + solarish, + target_os = "haiku", + target_os = "hurd" ))] ENOTSUP => "Operation not supported", - #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "aix", - target_os = "openbsd", - target_os = "netbsd" - ))] + #[cfg(any(bsd, target_os = "aix", target_os = "hurd"))] EPROCLIM => "Too many processes", #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", + bsd, target_os = "aix", - target_os = "openbsd", - target_os = "netbsd", + target_os = "hurd", target_os = "redox" ))] EUSERS => "Too many users", #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "openbsd", - target_os = "netbsd", + bsd, + solarish, target_os = "redox", target_os = "aix", - target_os = "illumos", - target_os = "solaris", - target_os = "haiku" + target_os = "haiku", + target_os = "hurd" ))] EDQUOT => "Disc quota exceeded", #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "openbsd", - target_os = "netbsd", + bsd, + solarish, target_os = "redox", target_os = "aix", - target_os = "illumos", - target_os = "solaris", target_os = "haiku" ))] ESTALE => "Stale NFS file handle", - #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "aix", - target_os = "openbsd", - target_os = "netbsd", - target_os = "redox" - ))] + #[cfg(any(bsd, target_os = "aix", target_os = "redox"))] EREMOTE => "Too many levels of remote in path", - #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "openbsd", - target_os = "netbsd" - ))] + #[cfg(any(bsd, target_os = "hurd"))] EBADRPC => "RPC struct is bad", - #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "openbsd", - target_os = "netbsd" - ))] + #[cfg(any(bsd, target_os = "hurd"))] ERPCMISMATCH => "RPC version wrong", - #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "openbsd", - target_os = "netbsd" - ))] + #[cfg(any(bsd, target_os = "hurd"))] EPROGUNAVAIL => "RPC prog. not avail", - #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "openbsd", - target_os = "netbsd" - ))] + #[cfg(any(bsd, target_os = "hurd"))] EPROGMISMATCH => "Program version wrong", - #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "openbsd", - target_os = "netbsd" - ))] + #[cfg(any(bsd, target_os = "hurd"))] EPROCUNAVAIL => "Bad procedure for program", - #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "openbsd", - target_os = "netbsd" - ))] + #[cfg(any(bsd, target_os = "hurd"))] EFTYPE => "Inappropriate file type or format", - #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", - target_os = "openbsd", - target_os = "netbsd" - ))] + #[cfg(any(bsd, target_os = "hurd"))] EAUTH => "Authentication error", #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "ios", + bsd, target_os = "aix", - target_os = "openbsd", - target_os = "netbsd", + target_os = "hurd", target_os = "redox" ))] ECANCELED => "Operation canceled", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] EPWROFF => "Device power is off", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] EDEVERR => "Device error, e.g. paper out", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] EBADEXEC => "Bad executable", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] EBADARCH => "Bad CPU type in executable", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] ESHLIBVERS => "Shared library version mismatch", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] EBADMACHO => "Malformed Macho file", - #[cfg(any( - target_os = "macos", - target_os = "ios", - target_os = "netbsd", - target_os = "haiku" - ))] + #[cfg(any(apple_targets, target_os = "netbsd", target_os = "haiku"))] EMULTIHOP => "Reserved", #[cfg(any( - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "aix", target_os = "netbsd", target_os = "redox" ))] ENODATA => "No message available on STREAM", - #[cfg(any( - target_os = "macos", - target_os = "ios", - target_os = "netbsd", - target_os = "haiku" - ))] + #[cfg(any(apple_targets, target_os = "netbsd", target_os = "haiku"))] ENOLINK => "Reserved", #[cfg(any( - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "aix", target_os = "netbsd", target_os = "redox" @@ -1096,8 +773,7 @@ fn desc(errno: Errno) -> &'static str { ENOSR => "No STREAM resources", #[cfg(any( - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "aix", target_os = "netbsd", target_os = "redox" @@ -1105,30 +781,23 @@ fn desc(errno: Errno) -> &'static str { ENOSTR => "Not a STREAM", #[cfg(any( - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "aix", target_os = "netbsd", target_os = "redox" ))] ETIME => "STREAM ioctl timeout", - #[cfg(any( - target_os = "macos", - target_os = "ios", - target_os = "aix", - target_os = "illumos", - target_os = "solaris" - ))] + #[cfg(any(apple_targets, solarish, target_os = "aix"))] EOPNOTSUPP => "Operation not supported on socket", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] ENOPOLICY => "No such policy registered", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] EQFULL => "Interface output queue is full", - #[cfg(target_os = "openbsd")] + #[cfg(any(target_os = "openbsd", target_os = "hurd"))] EOPNOTSUPP => "Operation not supported", #[cfg(target_os = "openbsd")] @@ -1137,18 +806,33 @@ fn desc(errno: Errno) -> &'static str { #[cfg(target_os = "dragonfly")] EASYNC => "Async", - #[cfg(any(target_os = "illumos", target_os = "solaris"))] + #[cfg(solarish)] EDEADLOCK => "Resource deadlock would occur", - #[cfg(any(target_os = "illumos", target_os = "solaris"))] + #[cfg(solarish)] ELOCKUNMAPPED => "Locked lock was unmapped", - #[cfg(any(target_os = "illumos", target_os = "solaris"))] + #[cfg(solarish)] ENOTACTIVE => "Facility is not active", + + #[cfg(target_os = "hurd")] + EBACKGROUND => "Inappropriate operation for background process", + + #[cfg(target_os = "hurd")] + EDIED => "Translator died", + + #[cfg(target_os = "hurd")] + EGREGIOUS => "You really blew it this time", + + #[cfg(target_os = "hurd")] + EIEIO => "Computer bought the farm", + + #[cfg(target_os = "hurd")] + EGRATUITOUS => "Gratuitous error", } } -#[cfg(any(target_os = "linux", target_os = "android", target_os = "fuchsia"))] +#[cfg(any(linux_android, target_os = "fuchsia"))] mod consts { #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[repr(i32)] @@ -1296,6 +980,10 @@ mod consts { pub const ENOTSUP: Errno = Errno::EOPNOTSUPP; } + #[deprecated( + since = "0.28.0", + note = "please use `Errno::from_raw()` instead" + )] pub const fn from_i32(e: i32) -> Errno { use self::Errno::*; @@ -1438,7 +1126,7 @@ mod consts { } } -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(apple_targets)] mod consts { #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[repr(i32)] @@ -1559,6 +1247,10 @@ mod consts { pub const EDEADLOCK: Errno = Errno::EDEADLK; } + #[deprecated( + since = "0.28.0", + note = "please use `Errno::from_raw()` instead" + )] pub const fn from_i32(e: i32) -> Errno { use self::Errno::*; @@ -1786,6 +1478,10 @@ mod consts { pub const EOPNOTSUPP: Errno = Errno::ENOTSUP; } + #[deprecated( + since = "0.28.0", + note = "please use `Errno::from_raw()` instead" + )] pub const fn from_i32(e: i32) -> Errno { use self::Errno::*; @@ -2003,6 +1699,10 @@ mod consts { pub const EOPNOTSUPP: Errno = Errno::ENOTSUP; } + #[deprecated( + since = "0.28.0", + note = "please use `Errno::from_raw()` instead" + )] pub const fn from_i32(e: i32) -> Errno { use self::Errno::*; @@ -2215,6 +1915,10 @@ mod consts { pub const EWOULDBLOCK: Errno = Errno::EAGAIN; } + #[deprecated( + since = "0.28.0", + note = "please use `Errno::from_raw()` instead" + )] pub const fn from_i32(e: i32) -> Errno { use self::Errno::*; @@ -2429,6 +2133,10 @@ mod consts { pub const EWOULDBLOCK: Errno = Errno::EAGAIN; } + #[deprecated( + since = "0.28.0", + note = "please use `Errno::from_raw()` instead" + )] pub const fn from_i32(e: i32) -> Errno { use self::Errno::*; @@ -2632,6 +2340,10 @@ mod consts { pub const EWOULDBLOCK: Errno = Errno::EAGAIN; } + #[deprecated( + since = "0.28.0", + note = "please use `Errno::from_raw()` instead" + )] pub const fn from_i32(e: i32) -> Errno { use self::Errno::*; @@ -2726,7 +2438,7 @@ mod consts { } } -#[cfg(any(target_os = "illumos", target_os = "solaris"))] +#[cfg(solarish)] mod consts { #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[repr(i32)] @@ -2861,6 +2573,10 @@ mod consts { pub const EWOULDBLOCK: Errno = Errno::EAGAIN; } + #[deprecated( + since = "0.28.0", + note = "please use `Errno::from_raw()` instead" + )] pub const fn from_i32(e: i32) -> Errno { use self::Errno::*; @@ -3081,6 +2797,10 @@ mod consts { pub const EOPNOTSUPP: Errno = Errno::ENOTSUP; } + #[deprecated( + since = "0.28.0", + note = "please use `Errno::from_raw()` instead" + )] pub const fn from_i32(e: i32) -> Errno { use self::Errno::*; @@ -3272,6 +2992,10 @@ mod consts { EOPNOTSUPP = libc::EOPNOTSUPP, } + #[deprecated( + since = "0.28.0", + note = "please use `Errno::from_raw()` instead" + )] pub const fn from_i32(e: i32) -> Errno { use self::Errno::*; @@ -3378,3 +3102,235 @@ mod consts { } } } + +#[cfg(target_os = "hurd")] +mod consts { + #[derive(Clone, Copy, Debug, Eq, PartialEq)] + #[repr(i32)] + #[non_exhaustive] + pub enum Errno { + UnknownErrno = 0, + EPERM = libc::EPERM, + ENOENT = libc::ENOENT, + ESRCH = libc::ESRCH, + EINTR = libc::EINTR, + EIO = libc::EIO, + ENXIO = libc::ENXIO, + E2BIG = libc::E2BIG, + ENOEXEC = libc::ENOEXEC, + EBADF = libc::EBADF, + ECHILD = libc::ECHILD, + EDEADLK = libc::EDEADLK, + ENOMEM = libc::ENOMEM, + EACCES = libc::EACCES, + EFAULT = libc::EFAULT, + ENOTBLK = libc::ENOTBLK, + EBUSY = libc::EBUSY, + EEXIST = libc::EEXIST, + EXDEV = libc::EXDEV, + ENODEV = libc::ENODEV, + ENOTDIR = libc::ENOTDIR, + EISDIR = libc::EISDIR, + EINVAL = libc::EINVAL, + EMFILE = libc::EMFILE, + ENFILE = libc::ENFILE, + ENOTTY = libc::ENOTTY, + ETXTBSY = libc::ETXTBSY, + EFBIG = libc::EFBIG, + ENOSPC = libc::ENOSPC, + ESPIPE = libc::ESPIPE, + EROFS = libc::EROFS, + EMLINK = libc::EMLINK, + EPIPE = libc::EPIPE, + EDOM = libc::EDOM, + ERANGE = libc::ERANGE, + EAGAIN = libc::EAGAIN, + EINPROGRESS = libc::EINPROGRESS, + EALREADY = libc::EALREADY, + ENOTSOCK = libc::ENOTSOCK, + EMSGSIZE = libc::EMSGSIZE, + EPROTOTYPE = libc::EPROTOTYPE, + ENOPROTOOPT = libc::ENOPROTOOPT, + EPROTONOSUPPORT = libc::EPROTONOSUPPORT, + ESOCKTNOSUPPORT = libc::ESOCKTNOSUPPORT, + EOPNOTSUPP = libc::EOPNOTSUPP, + EPFNOSUPPORT = libc::EPFNOSUPPORT, + EAFNOSUPPORT = libc::EAFNOSUPPORT, + EADDRINUSE = libc::EADDRINUSE, + EADDRNOTAVAIL = libc::EADDRNOTAVAIL, + ENETDOWN = libc::ENETDOWN, + ENETUNREACH = libc::ENETUNREACH, + ENETRESET = libc::ENETRESET, + ECONNABORTED = libc::ECONNABORTED, + ECONNRESET = libc::ECONNRESET, + ENOBUFS = libc::ENOBUFS, + EISCONN = libc::EISCONN, + ENOTCONN = libc::ENOTCONN, + EDESTADDRREQ = libc::EDESTADDRREQ, + ESHUTDOWN = libc::ESHUTDOWN, + ETOOMANYREFS = libc::ETOOMANYREFS, + ETIMEDOUT = libc::ETIMEDOUT, + ECONNREFUSED = libc::ECONNREFUSED, + ELOOP = libc::ELOOP, + ENAMETOOLONG = libc::ENAMETOOLONG, + EHOSTDOWN = libc::EHOSTDOWN, + EHOSTUNREACH = libc::EHOSTUNREACH, + ENOTEMPTY = libc::ENOTEMPTY, + EPROCLIM = libc::EPROCLIM, + EUSERS = libc::EUSERS, + EDQUOT = libc::EDQUOT, + ESTALE = libc::ESTALE, + EREMOTE = libc::EREMOTE, + EBADRPC = libc::EBADRPC, + ERPCMISMATCH = libc::ERPCMISMATCH, + EPROGUNAVAIL = libc::EPROGUNAVAIL, + EPROGMISMATCH = libc::EPROGMISMATCH, + EPROCUNAVAIL = libc::EPROCUNAVAIL, + ENOLCK = libc::ENOLCK, + EFTYPE = libc::EFTYPE, + EAUTH = libc::EAUTH, + ENEEDAUTH = libc::ENEEDAUTH, + ENOSYS = libc::ENOSYS, + ELIBEXEC = libc::ELIBEXEC, + ENOTSUP = libc::ENOTSUP, + EILSEQ = libc::EILSEQ, + EBACKGROUND = libc::EBACKGROUND, + EDIED = libc::EDIED, + EGREGIOUS = libc::EGREGIOUS, + EIEIO = libc::EIEIO, + EGRATUITOUS = libc::EGRATUITOUS, + EBADMSG = libc::EBADMSG, + EIDRM = libc::EIDRM, + EMULTIHOP = libc::EMULTIHOP, + ENODATA = libc::ENODATA, + ENOLINK = libc::ENOLINK, + ENOMSG = libc::ENOMSG, + ENOSR = libc::ENOSR, + ENOSTR = libc::ENOSTR, + EOVERFLOW = libc::EOVERFLOW, + EPROTO = libc::EPROTO, + ETIME = libc::ETIME, + ECANCELED = libc::ECANCELED, + EOWNERDEAD = libc::EOWNERDEAD, + ENOTRECOVERABLE = libc::ENOTRECOVERABLE, + } + + impl Errno { + pub const EWOULDBLOCK: Errno = Errno::EAGAIN; + } + + #[deprecated( + since = "0.28.0", + note = "please use `Errno::from_raw()` instead" + )] + pub const fn from_i32(e: i32) -> Errno { + use self::Errno::*; + + match e { + libc::EPERM => EPERM, + libc::ENOENT => ENOENT, + libc::ESRCH => ESRCH, + libc::EINTR => EINTR, + libc::EIO => EIO, + libc::ENXIO => ENXIO, + libc::E2BIG => E2BIG, + libc::ENOEXEC => ENOEXEC, + libc::EBADF => EBADF, + libc::ECHILD => ECHILD, + libc::EDEADLK => EDEADLK, + libc::ENOMEM => ENOMEM, + libc::EACCES => EACCES, + libc::EFAULT => EFAULT, + libc::ENOTBLK => ENOTBLK, + libc::EBUSY => EBUSY, + libc::EEXIST => EEXIST, + libc::EXDEV => EXDEV, + libc::ENODEV => ENODEV, + libc::ENOTDIR => ENOTDIR, + libc::EISDIR => EISDIR, + libc::EINVAL => EINVAL, + libc::EMFILE => EMFILE, + libc::ENFILE => ENFILE, + libc::ENOTTY => ENOTTY, + libc::ETXTBSY => ETXTBSY, + libc::EFBIG => EFBIG, + libc::ENOSPC => ENOSPC, + libc::ESPIPE => ESPIPE, + libc::EROFS => EROFS, + libc::EMLINK => EMLINK, + libc::EPIPE => EPIPE, + libc::EDOM => EDOM, + libc::ERANGE => ERANGE, + libc::EAGAIN => EAGAIN, + libc::EINPROGRESS => EINPROGRESS, + libc::EALREADY => EALREADY, + libc::ENOTSOCK => ENOTSOCK, + libc::EMSGSIZE => EMSGSIZE, + libc::EPROTOTYPE => EPROTOTYPE, + libc::ENOPROTOOPT => ENOPROTOOPT, + libc::EPROTONOSUPPORT => EPROTONOSUPPORT, + libc::ESOCKTNOSUPPORT => ESOCKTNOSUPPORT, + libc::EOPNOTSUPP => EOPNOTSUPP, + libc::EPFNOSUPPORT => EPFNOSUPPORT, + libc::EAFNOSUPPORT => EAFNOSUPPORT, + libc::EADDRINUSE => EADDRINUSE, + libc::EADDRNOTAVAIL => EADDRNOTAVAIL, + libc::ENETDOWN => ENETDOWN, + libc::ENETUNREACH => ENETUNREACH, + libc::ENETRESET => ENETRESET, + libc::ECONNABORTED => ECONNABORTED, + libc::ECONNRESET => ECONNRESET, + libc::ENOBUFS => ENOBUFS, + libc::EISCONN => EISCONN, + libc::ENOTCONN => ENOTCONN, + libc::EDESTADDRREQ => EDESTADDRREQ, + libc::ESHUTDOWN => ESHUTDOWN, + libc::ETOOMANYREFS => ETOOMANYREFS, + libc::ETIMEDOUT => ETIMEDOUT, + libc::ECONNREFUSED => ECONNREFUSED, + libc::ELOOP => ELOOP, + libc::ENAMETOOLONG => ENAMETOOLONG, + libc::EHOSTDOWN => EHOSTDOWN, + libc::EHOSTUNREACH => EHOSTUNREACH, + libc::ENOTEMPTY => ENOTEMPTY, + libc::EPROCLIM => EPROCLIM, + libc::EUSERS => EUSERS, + libc::EDQUOT => EDQUOT, + libc::ESTALE => ESTALE, + libc::EREMOTE => EREMOTE, + libc::EBADRPC => EBADRPC, + libc::ERPCMISMATCH => ERPCMISMATCH, + libc::EPROGUNAVAIL => EPROGUNAVAIL, + libc::EPROGMISMATCH => EPROGMISMATCH, + libc::EPROCUNAVAIL => EPROCUNAVAIL, + libc::ENOLCK => ENOLCK, + libc::EFTYPE => EFTYPE, + libc::EAUTH => EAUTH, + libc::ENEEDAUTH => ENEEDAUTH, + libc::ENOSYS => ENOSYS, + libc::ELIBEXEC => ELIBEXEC, + libc::ENOTSUP => ENOTSUP, + libc::EILSEQ => EILSEQ, + libc::EBACKGROUND => EBACKGROUND, + libc::EDIED => EDIED, + libc::EGREGIOUS => EGREGIOUS, + libc::EIEIO => EIEIO, + libc::EGRATUITOUS => EGRATUITOUS, + libc::EBADMSG => EBADMSG, + libc::EIDRM => EIDRM, + libc::EMULTIHOP => EMULTIHOP, + libc::ENODATA => ENODATA, + libc::ENOLINK => ENOLINK, + libc::ENOMSG => ENOMSG, + libc::ENOSR => ENOSR, + libc::ENOSTR => ENOSTR, + libc::EOVERFLOW => EOVERFLOW, + libc::EPROTO => EPROTO, + libc::ETIME => ETIME, + libc::ECANCELED => ECANCELED, + libc::EOWNERDEAD => EOWNERDEAD, + libc::ENOTRECOVERABLE => ENOTRECOVERABLE, + _ => UnknownErrno, + } + } +} |