use libc::{c_char, c_int, c_void, free}; use std::error::Error as StdError; use std::ffi::CStr; use std::{fmt, str};
/// ALSA error /// /// Most ALSA functions can return a negative error code. /// If so, then that error code is wrapped into this `Error` struct. /// An Error is also returned in case ALSA returns a string that /// cannot be translated into Rust's UTF-8 strings. #[derive(Clone, PartialEq, Copy)] pubstruct Error(&'static str, i32);
/// The function which failed. pubfn func(&self) -> &'static str { self.0
}
/// Underlying error /// /// Match this against the re-export of `nix::Error` in this crate, not against a specific version /// of the nix crate. The nix crate version might be updated with minor updates of this library. pubfn errno(&self) -> i32 { self.1
}
}
impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f, "ALSA function '{}' failed with error '{} ({})'", self.0,
desc(self.1), self.1,
)
}
}
/// See <https://github.com/nix-rust/nix/blob/197f55b3ccbce3273bf6ce119d1a8541b5df5d66/src/errno.rs#L198> /// /// Note this doesn't include the total set of possible errno variants, but they /// can easily be added in the future for better error messages fn desc(errno: i32) -> &'static str { match errno {
libc::EPERM => "Operation not permitted",
libc::ENOENT => "No such file or directory",
libc::ESRCH => "No such process",
libc::EINTR => "Interrupted system call",
libc::EIO => "I/O error",
libc::ENXIO => "No such device or address",
libc::E2BIG => "Argument list too long",
libc::ENOEXEC => "Exec format error",
libc::EBADF => "Bad file number",
libc::ECHILD => "No child processes",
libc::EAGAIN => "Try again",
libc::ENOMEM => "Out of memory",
libc::EACCES => "Permission denied",
libc::EFAULT => "Bad address",
libc::ENOTBLK => "Block device required",
libc::EBUSY => "Device or resource busy",
libc::EEXIST => "File exists",
libc::EXDEV => "Cross-device link",
libc::ENODEV => "No such device",
libc::ENOTDIR => "Not a directory",
libc::EISDIR => "Is a directory",
libc::EINVAL => "Invalid argument",
libc::ENFILE => "File table overflow",
libc::EMFILE => "Too many open files",
libc::ENOTTY => "Not a typewriter",
libc::ETXTBSY => "Text file busy",
libc::EFBIG => "File too large",
libc::ENOSPC => "No space left on device",
libc::ESPIPE => "Illegal seek",
libc::EROFS => "Read-only file system",
libc::EMLINK => "Too many links",
libc::EPIPE => "Broken pipe",
libc::EDOM => "Math argument out of domain of func",
libc::ERANGE => "Math result not representable",
libc::EDEADLK => "Resource deadlock would occur",
libc::ENAMETOOLONG => "File name too long",
libc::ENOLCK => "No record locks available",
libc::ENOSYS => "Function not implemented",
libc::ENOTEMPTY => "Directory not empty",
libc::ELOOP => "Too many symbolic links encountered",
libc::ENOMSG => "No message of desired type",
libc::EIDRM => "Identifier removed",
libc::EINPROGRESS => "Operation now in progress",
libc::EALREADY => "Operation already in progress",
libc::ENOTSOCK => "Socket operation on non-socket",
libc::EDESTADDRREQ => "Destination address required",
libc::EMSGSIZE => "Message too long",
libc::EPROTOTYPE => "Protocol wrong type for socket",
libc::ENOPROTOOPT => "Protocol not available",
libc::EPROTONOSUPPORT => "Protocol not supported",
libc::ESOCKTNOSUPPORT => "Socket type not supported",
libc::EPFNOSUPPORT => "Protocol family not supported",
libc::EAFNOSUPPORT => "Address family not supported by protocol",
libc::EADDRINUSE => "Address already in use",
libc::EADDRNOTAVAIL => "Cannot assign requested address",
libc::ENETDOWN => "Network is down",
libc::ENETUNREACH => "Network is unreachable",
libc::ENETRESET => "Network dropped connection because of reset",
libc::ECONNABORTED => "Software caused connection abort",
libc::ECONNRESET => "Connection reset by peer",
libc::ENOBUFS => "No buffer space available",
libc::EISCONN => "Transport endpoint is already connected",
libc::ENOTCONN => "Transport endpoint is not connected",
libc::ESHUTDOWN => "Cannot send after transport endpoint shutdown",
libc::ETOOMANYREFS => "Too many references: cannot splice",
libc::ETIMEDOUT => "Connection timed out",
libc::ECONNREFUSED => "Connection refused",
libc::EHOSTDOWN => "Host is down",
libc::EHOSTUNREACH => "No route to host",
libc::ENOTSUP => "Operation not supported",
_ => "Unknown errno",
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.