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:
Jakub Konka
2020-03-05 10:08:28 +01:00
committed by GitHub
parent 19d8ff2bf5
commit 135a48ca7e
25 changed files with 524 additions and 705 deletions

View File

@@ -1,10 +1,10 @@
use crate::{
file::FileType,
sys::dir::{iter_impl, EntryImpl},
Errno, Result,
Result,
};
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
use std::{ffi::CStr, ops::Deref, ptr};
use std::{ffi::CStr, io, ops::Deref, ptr};
pub use crate::sys::EntryExt;
@@ -25,7 +25,7 @@ impl Dir {
if let Some(d) = ptr::NonNull::new(d) {
Ok(Self(d))
} else {
let e = Errno::last();
let e = io::Error::last_os_error();
libc::close(fd);
Err(e.into())
}