wasi-common error cleanup: part 1, yanix (#1226)
* Reuse std::io::Error for raw *nix errno This commit removes custom `yanix::Errno` and instead (as was previously suggested) reuses `std::io::Error` to generate and wrap raw *nix errno value. * Update wasi-common to use new Yanix error type This commit updates `wasi-common` to use new way of handling raw OS error in `yanix`; i.e., via re-use of `std::io::Error` instead of a custom `Errno` enum. * Fix formatting * Unwrap if io::Error created from raw OS error This commit calls `unwrap` on `err` if that one was created via `io::Error::last_os_error()`. It also refactors error matching in several syscalls on the BSD platform (mainly).
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
file::{FdFlag, OFlag},
|
||||
Errno, Result,
|
||||
Error, Result,
|
||||
};
|
||||
use std::os::unix::prelude::*;
|
||||
|
||||
@@ -9,7 +9,7 @@ pub unsafe fn dup_fd(fd: RawFd, close_on_exec: bool) -> Result<RawFd> {
|
||||
// the minimum duplicated RawFd number. In our case, I don't
|
||||
// think we have to worry about this that much, so passing in
|
||||
// the RawFd descriptor we want duplicated
|
||||
Errno::from_result(if close_on_exec {
|
||||
Error::from_result(if close_on_exec {
|
||||
libc::fcntl(fd, libc::F_DUPFD_CLOEXEC, fd)
|
||||
} else {
|
||||
libc::fcntl(fd, libc::F_DUPFD, fd)
|
||||
@@ -17,17 +17,17 @@ pub unsafe fn dup_fd(fd: RawFd, close_on_exec: bool) -> Result<RawFd> {
|
||||
}
|
||||
|
||||
pub unsafe fn get_fd_flags(fd: RawFd) -> Result<FdFlag> {
|
||||
Errno::from_result(libc::fcntl(fd, libc::F_GETFD)).map(FdFlag::from_bits_truncate)
|
||||
Error::from_result(libc::fcntl(fd, libc::F_GETFD)).map(FdFlag::from_bits_truncate)
|
||||
}
|
||||
|
||||
pub unsafe fn set_fd_flags(fd: RawFd, flags: FdFlag) -> Result<()> {
|
||||
Errno::from_success_code(libc::fcntl(fd, libc::F_SETFD, flags.bits()))
|
||||
Error::from_success_code(libc::fcntl(fd, libc::F_SETFD, flags.bits()))
|
||||
}
|
||||
|
||||
pub unsafe fn get_status_flags(fd: RawFd) -> Result<OFlag> {
|
||||
Errno::from_result(libc::fcntl(fd, libc::F_GETFL)).map(OFlag::from_bits_truncate)
|
||||
Error::from_result(libc::fcntl(fd, libc::F_GETFL)).map(OFlag::from_bits_truncate)
|
||||
}
|
||||
|
||||
pub unsafe fn set_status_flags(fd: RawFd, flags: OFlag) -> Result<()> {
|
||||
Errno::from_success_code(libc::fcntl(fd, libc::F_SETFL, flags.bits()))
|
||||
Error::from_success_code(libc::fcntl(fd, libc::F_SETFL, flags.bits()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user