123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- #![no_std]
- #![allow(clippy::needless_return)]
- #![allow(clippy::upper_case_acronyms)]
- #![allow(non_local_definitions)]
- use num_derive::{FromPrimitive, ToPrimitive};
- #[repr(i32)]
- #[derive(Debug, FromPrimitive, ToPrimitive, PartialEq, Eq, Clone)]
- #[allow(dead_code, non_camel_case_types)]
- pub enum SystemError {
-
- EPERM = 1,
-
- ENOENT = 2,
-
- ESRCH = 3,
-
- EINTR = 4,
-
- EIO = 5,
-
- ENXIO = 6,
-
- E2BIG = 7,
-
- ENOEXEC = 8,
-
- EBADF = 9,
-
- ECHILD = 10,
-
-
-
- EAGAIN_OR_EWOULDBLOCK = 11,
-
- ENOMEM = 12,
-
- EACCES = 13,
-
- EFAULT = 14,
-
- ENOTBLK = 15,
-
- EBUSY = 16,
-
- EEXIST = 17,
-
- EXDEV = 18,
-
- ENODEV = 19,
-
- ENOTDIR = 20,
-
- EISDIR = 21,
-
- EINVAL = 22,
-
- ENFILE = 23,
-
- EMFILE = 24,
-
- ENOTTY = 25,
-
- ETXTBSY = 26,
-
- EFBIG = 27,
-
- ENOSPC = 28,
-
- ESPIPE = 29,
-
- EROFS = 30,
-
- EMLINK = 31,
-
- EPIPE = 32,
-
- EDOM = 33,
-
- ERANGE = 34,
-
- EDEADLK_OR_EDEADLOCK = 35,
-
- ENAMETOOLONG = 36,
-
- ENOLCK = 37,
-
- ENOSYS = 38,
-
- ENOTEMPTY = 39,
-
- ELOOP = 40,
-
- ENOMSG = 42,
-
- EIDRM = 43,
-
- ECHRNG = 44,
-
- EL2NSYNC = 45,
-
- EL3HLT = 46,
-
- EL3RST = 47,
-
- ELNRNG = 48,
-
- EUNATCH = 49,
-
- ENOCSI = 50,
-
- EL2HLT = 51,
-
- EBADE = 52,
-
- EBADR = 53,
-
- EXFULL = 54,
-
- ENOANO = 55,
-
- EBADRQC = 56,
-
- EBADSLT = 57,
-
- EBFONT = 59,
-
- ENOSTR = 60,
-
- ENODATA = 61,
-
- ETIME = 62,
-
- ENOSR = 63,
-
- ENONET = 64,
-
- ENOPKG = 65,
-
- EREMOTE = 66,
-
- ENOLINK = 67,
-
- EADV = 68,
-
- ESRMNT = 69,
-
- ECOMM = 70,
-
- EPROTO = 71,
-
- EMULTIHOP = 72,
-
- EDOTDOT = 73,
-
- EBADMSG = 74,
-
- EOVERFLOW = 75,
-
- ENOTUNIQ = 76,
-
- EBADFD = 77,
-
- EREMCHG = 78,
-
- ELIBACC = 79,
-
- ELIBBAD = 80,
-
- ELIBSCN = 81,
-
- ELIBMAX = 82,
-
- ELIBEXEC = 83,
-
- EILSEQ = 84,
-
- ERESTART = 85,
-
- ESTRPIPE = 86,
-
- EUSERS = 87,
-
- ENOTSOCK = 88,
-
- EDESTADDRREQ = 89,
-
- EMSGSIZE = 90,
-
- EPROTOTYPE = 91,
-
- ENOPROTOOPT = 92,
-
- EPROTONOSUPPORT = 93,
-
- ESOCKTNOSUPPORT = 94,
-
-
-
- EOPNOTSUPP_OR_ENOTSUP = 95,
-
- EPFNOSUPPORT = 96,
-
- EAFNOSUPPORT = 97,
-
- EADDRINUSE = 98,
-
- EADDRNOTAVAIL = 99,
-
- ENETDOWN = 100,
-
- ENETUNREACH = 101,
-
- ENETRESET = 102,
-
- ECONNABORTED = 103,
-
- ECONNRESET = 104,
-
- ENOBUFS = 105,
-
- EISCONN = 106,
-
- ENOTCONN = 107,
-
- ESHUTDOWN = 108,
-
- ETOOMANYREFS = 109,
-
- ETIMEDOUT = 110,
-
- ECONNREFUSED = 111,
-
- EHOSTDOWN = 112,
-
- EHOSTUNREACH = 113,
-
- EALREADY = 114,
-
- EINPROGRESS = 115,
-
- ESTALE = 116,
-
- EUCLEAN = 117,
-
- ENOTNAM = 118,
-
- ENAVAIL = 119,
-
- EISNAM = 120,
-
- EREMOTEIO = 121,
-
- EDQUOT = 122,
-
- ENOMEDIUM = 123,
-
- EMEDIUMTYPE = 124,
-
- ECANCELED = 125,
-
- ENOKEY = 126,
-
- EKEYEXPIRED = 127,
-
- EKEYREVOKED = 128,
-
- EKEYREJECTED = 129,
-
- EOWNERDEAD = 130,
-
- ENOTRECOVERABLE = 131,
-
- ERFKILL = 132,
-
- EHWPOISON = 133,
-
- ERESTARTSYS = 512,
- ERESTARTNOINTR = 513,
-
- ERESTARTNOHAND = 514,
-
- ENOIOCTLCMD = 515,
-
- ERESTART_RESTARTBLOCK = 516,
-
-
- EVMXONFailed = 1513,
-
- EVMXOFFFailed = 1514,
-
- EVMWRITEFailed = 1515,
- EVMREADFailed = 1516,
- EVMPRTLDFailed = 1517,
- EVMLAUNCHFailed = 1518,
- KVM_HVA_ERR_BAD = 1519,
- MAXERRNO = 4095,
- }
- impl SystemError {
-
- pub fn is_valid_posix_errno<T>(val: T) -> bool
- where
- T: PartialOrd + From<i32>,
- {
- let max_errno = T::from(-(Self::MAXERRNO as i32));
- val < T::from(0) && val >= max_errno
- }
-
- pub fn from_posix_errno(errno: i32) -> Option<SystemError> {
-
- if !Self::is_valid_posix_errno(errno) {
- return None;
- }
- return <Self as num_traits::FromPrimitive>::from_i32(-errno);
- }
-
- pub fn to_posix_errno(&self) -> i32 {
- return -<Self as num_traits::ToPrimitive>::to_i32(self).unwrap();
- }
- }
- #[cfg(test)]
- mod tests {
- use super::*;
- #[test]
- fn it_works() {
- assert_eq!(SystemError::EPERM.to_posix_errno(), -1);
- }
- }
|