Misc yanix fixes (#715)
* Correctly handle possibly misaligned pointers in readdir This reapplies #615, which was inadvertently reverted. * Tidy up unneeded `self::` qualifiers. * Make Dir's contents private. Also remove the `unsafe` from `impl_iter`. With `Dir`'s field being private, we can rely on the pointer being only what we've assigned to it. * Make `poll`'s timeout argument a `libc::c_int`. This clarifies that there are no subsequent conversions before calling the underlying libc API. * Use clock_gettime instead of clock_getres to get the time. * Mark FileType::from_raw as safe. It handles unknown values, so it can be marked safe.
This commit is contained in:
@@ -18,9 +18,9 @@ impl Deref for EntryImpl {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn iter_impl(dir: &Dir) -> Option<Result<EntryImpl>> {
|
||||
pub(crate) fn iter_impl(dir: &Dir) -> Option<Result<EntryImpl>> {
|
||||
let errno = Errno::last();
|
||||
let dirent = libc::readdir(dir.0.as_ptr());
|
||||
let dirent = unsafe { libc::readdir(dir.as_raw().as_ptr()) };
|
||||
if dirent.is_null() {
|
||||
if errno != Errno::last() {
|
||||
// TODO This should be verified on different BSD-flavours.
|
||||
@@ -35,7 +35,7 @@ pub(crate) unsafe fn iter_impl(dir: &Dir) -> Option<Result<EntryImpl>> {
|
||||
}
|
||||
} else {
|
||||
Some(Ok(EntryImpl {
|
||||
dirent: *dirent,
|
||||
dirent: unsafe { *dirent },
|
||||
loc: dir.tell(),
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ impl EntryExt for Entry {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn iter_impl(dir: &Dir) -> Option<Result<EntryImpl>> {
|
||||
pub(crate) fn iter_impl(dir: &Dir) -> Option<Result<EntryImpl>> {
|
||||
let errno = Errno::last();
|
||||
let dirent = libc::readdir64(dir.0.as_ptr());
|
||||
let dirent = unsafe { libc::readdir64(dir.as_raw().as_ptr()) };
|
||||
if dirent.is_null() {
|
||||
if errno != Errno::last() {
|
||||
// TODO This should be verified on different BSD-flavours.
|
||||
@@ -41,6 +41,6 @@ pub(crate) unsafe fn iter_impl(dir: &Dir) -> Option<Result<EntryImpl>> {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
Some(Ok(EntryImpl(*dirent)))
|
||||
Some(Ok(EntryImpl(unsafe { *dirent })))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@ cfg_if! {
|
||||
if #[cfg(any(target_os = "linux",
|
||||
target_os = "android"))] {
|
||||
mod linux;
|
||||
pub(crate) use self::linux::*;
|
||||
pub(crate) use linux::*;
|
||||
} else if #[cfg(target_os = "emscripten")] {
|
||||
mod emscripten;
|
||||
pub(crate) use self::emscripten::*;
|
||||
pub(crate) use emscripten::*;
|
||||
} else if #[cfg(any(target_os = "macos",
|
||||
target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
@@ -16,7 +16,7 @@ cfg_if! {
|
||||
target_os = "openbsd",
|
||||
target_os = "dragonfly"))] {
|
||||
mod bsd;
|
||||
pub(crate) use self::bsd::*;
|
||||
pub(crate) use bsd::*;
|
||||
} else {
|
||||
compile_error!("yanix doesn't compile for this platform yet");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user