Unify fd_readdir impl between *nixes (#613)
* Unify fd_readdir impl between *nixes This commit unifies the implementation of `fd_readdir` between Linux and BSD hosts. In particular, it re-uses the `Dirent`, `Entry`, and `Dir` (among others) building blocks introduced recently when `fd_readdir` was being implemented on Windows. Notable changes: * on BSD, wraps `readdir` syscall in an `Iterator` of the mutex-locked `Dir` struct * on BSD, removes `DirStream` struct from `OsFile`; `OsFile` now holds a mutex to `Dir` * makes `Dir` iterators implementation specific (Linux has its own, and so does BSD) * Lock mutex once only; explain dir in OsFile * Add more comments
This commit is contained in:
@@ -22,20 +22,5 @@ pub(crate) mod fdentry_impl {
|
||||
}
|
||||
|
||||
pub(crate) mod host_impl {
|
||||
use super::super::host_impl::dirent_filetype_from_host;
|
||||
use crate::{wasi, Result};
|
||||
|
||||
pub(crate) const O_RSYNC: nix::fcntl::OFlag = nix::fcntl::OFlag::O_SYNC;
|
||||
|
||||
pub(crate) fn dirent_from_host(
|
||||
host_entry: &nix::libc::dirent,
|
||||
) -> Result<wasi::__wasi_dirent_t> {
|
||||
let mut entry = unsafe { std::mem::zeroed::<wasi::__wasi_dirent_t>() };
|
||||
let d_type = dirent_filetype_from_host(host_entry)?;
|
||||
entry.d_ino = host_entry.d_ino;
|
||||
entry.d_next = host_entry.d_seekoff;
|
||||
entry.d_namlen = u32::from(host_entry.d_namlen);
|
||||
entry.d_type = d_type;
|
||||
Ok(entry)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user