From fe647abc862fadb2aaa546c4c8b413b614fa2af4 Mon Sep 17 00:00:00 2001 From: Marcin Mielniczuk Date: Thu, 25 Jul 2019 16:15:43 +0200 Subject: [PATCH] Mark all functions in host_impl.rs as pub(crate) It will allow the compiler to spot more unused functions. --- src/sys/unix/host_impl.rs | 26 ++++++++++++++------------ src/sys/windows/host_impl.rs | 10 +++++----- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/sys/unix/host_impl.rs b/src/sys/unix/host_impl.rs index fa7601a..9ec22b3 100644 --- a/src/sys/unix/host_impl.rs +++ b/src/sys/unix/host_impl.rs @@ -6,7 +6,7 @@ use crate::{host, memory, wasm32, Result}; use std::ffi::OsStr; use std::os::unix::prelude::OsStrExt; -pub fn errno_from_nix(errno: nix::errno::Errno) -> host::__wasi_errno_t { +pub(crate) fn errno_from_nix(errno: nix::errno::Errno) -> host::__wasi_errno_t { match errno { nix::errno::Errno::EPERM => host::__WASI_EPERM, nix::errno::Errno::ENOENT => host::__WASI_ENOENT, @@ -87,12 +87,12 @@ pub fn errno_from_nix(errno: nix::errno::Errno) -> host::__wasi_errno_t { } #[cfg(target_os = "linux")] -pub const O_RSYNC: nix::fcntl::OFlag = nix::fcntl::OFlag::O_RSYNC; +pub(crate) const O_RSYNC: nix::fcntl::OFlag = nix::fcntl::OFlag::O_RSYNC; #[cfg(not(target_os = "linux"))] -pub const O_RSYNC: nix::fcntl::OFlag = nix::fcntl::OFlag::O_SYNC; +pub(crate) const O_RSYNC: nix::fcntl::OFlag = nix::fcntl::OFlag::O_SYNC; -pub fn nix_from_fdflags(fdflags: host::__wasi_fdflags_t) -> nix::fcntl::OFlag { +pub(crate) fn nix_from_fdflags(fdflags: host::__wasi_fdflags_t) -> nix::fcntl::OFlag { use nix::fcntl::OFlag; let mut nix_flags = OFlag::empty(); if fdflags & host::__WASI_FDFLAG_APPEND != 0 { @@ -113,7 +113,7 @@ pub fn nix_from_fdflags(fdflags: host::__wasi_fdflags_t) -> nix::fcntl::OFlag { nix_flags } -pub fn fdflags_from_nix(oflags: nix::fcntl::OFlag) -> host::__wasi_fdflags_t { +pub(crate) fn fdflags_from_nix(oflags: nix::fcntl::OFlag) -> host::__wasi_fdflags_t { use nix::fcntl::OFlag; let mut fdflags = 0; if oflags.contains(OFlag::O_APPEND) { @@ -134,7 +134,7 @@ pub fn fdflags_from_nix(oflags: nix::fcntl::OFlag) -> host::__wasi_fdflags_t { fdflags } -pub fn nix_from_oflags(oflags: host::__wasi_oflags_t) -> nix::fcntl::OFlag { +pub(crate) fn nix_from_oflags(oflags: host::__wasi_oflags_t) -> nix::fcntl::OFlag { use nix::fcntl::OFlag; let mut nix_flags = OFlag::empty(); if oflags & host::__WASI_O_CREAT != 0 { @@ -152,7 +152,7 @@ pub fn nix_from_oflags(oflags: host::__wasi_oflags_t) -> nix::fcntl::OFlag { nix_flags } -pub fn filetype_from_nix(sflags: nix::sys::stat::SFlag) -> host::__wasi_filetype_t { +pub(crate) fn filetype_from_nix(sflags: nix::sys::stat::SFlag) -> host::__wasi_filetype_t { use nix::sys::stat::SFlag; if sflags.contains(SFlag::S_IFCHR) { host::__WASI_FILETYPE_CHARACTER_DEVICE @@ -171,7 +171,7 @@ pub fn filetype_from_nix(sflags: nix::sys::stat::SFlag) -> host::__wasi_filetype } } -pub fn nix_from_filetype(sflags: host::__wasi_filetype_t) -> nix::sys::stat::SFlag { +pub(crate) fn nix_from_filetype(sflags: host::__wasi_filetype_t) -> nix::sys::stat::SFlag { use nix::sys::stat::SFlag; let mut nix_sflags = SFlag::empty(); if sflags & host::__WASI_FILETYPE_CHARACTER_DEVICE != 0 { @@ -196,7 +196,9 @@ pub fn nix_from_filetype(sflags: host::__wasi_filetype_t) -> nix::sys::stat::SFl nix_sflags } -pub fn filestat_from_nix(filestat: nix::sys::stat::FileStat) -> Result { +pub(crate) fn filestat_from_nix( + filestat: nix::sys::stat::FileStat, +) -> Result { use std::convert::TryFrom; let filetype = nix::sys::stat::SFlag::from_bits_truncate(filestat.st_mode); @@ -218,7 +220,7 @@ pub fn filestat_from_nix(filestat: nix::sys::stat::FileStat) -> Result Result { +pub(crate) fn dirent_from_host(host_entry: &nix::libc::dirent) -> Result { let mut entry = unsafe { std::mem::zeroed::() }; let d_namlen = unsafe { std::ffi::CStr::from_ptr(host_entry.d_name.as_ptr()) } .to_bytes() @@ -234,7 +236,7 @@ pub fn dirent_from_host(host_entry: &nix::libc::dirent) -> Result Result { +pub(crate) fn dirent_from_host(host_entry: &nix::libc::dirent) -> Result { let mut entry = unsafe { std::mem::zeroed::() }; entry.d_ino = memory::enc_inode(host_entry.d_ino); entry.d_next = memory::enc_dircookie(host_entry.d_seekoff); @@ -247,6 +249,6 @@ pub fn dirent_from_host(host_entry: &nix::libc::dirent) -> Result>(s: S) -> Result { +pub(crate) fn path_from_host>(s: S) -> Result { host::path_from_slice(s.as_ref().as_bytes()).map(String::from) } diff --git a/src/sys/windows/host_impl.rs b/src/sys/windows/host_impl.rs index d8627b8..f05c1c8 100644 --- a/src/sys/windows/host_impl.rs +++ b/src/sys/windows/host_impl.rs @@ -6,7 +6,7 @@ use crate::{host, Result}; use std::ffi::OsStr; use std::os::windows::ffi::OsStrExt; -pub fn errno_from_win(error: winx::winerror::WinError) -> host::__wasi_errno_t { +pub(crate) fn errno_from_win(error: winx::winerror::WinError) -> host::__wasi_errno_t { // TODO: implement error mapping between Windows and WASI use winx::winerror::WinError::*; match error { @@ -30,7 +30,7 @@ pub fn errno_from_win(error: winx::winerror::WinError) -> host::__wasi_errno_t { } } -pub fn win_from_fdflags( +pub(crate) fn win_from_fdflags( fdflags: host::__wasi_fdflags_t, ) -> (winx::file::AccessRight, winx::file::FlagsAndAttributes) { use winx::file::{AccessRight, FlagsAndAttributes}; @@ -53,7 +53,7 @@ pub fn win_from_fdflags( (win_rights, win_flags_attrs) } -pub fn fdflags_from_win(rights: winx::file::AccessRight) -> host::__wasi_fdflags_t { +pub(crate) fn fdflags_from_win(rights: winx::file::AccessRight) -> host::__wasi_fdflags_t { use winx::file::AccessRight; let mut fdflags = 0; // TODO verify this! @@ -77,7 +77,7 @@ pub fn fdflags_from_win(rights: winx::file::AccessRight) -> host::__wasi_fdflags fdflags } -pub fn win_from_oflags( +pub(crate) fn win_from_oflags( oflags: host::__wasi_oflags_t, ) -> ( winx::file::CreationDisposition, @@ -108,7 +108,7 @@ pub fn win_from_oflags( /// /// NB WASI spec requires OS string to be valid UTF-8. Otherwise, /// `__WASI_EILSEQ` error is returned. -pub fn path_from_host>(s: S) -> Result { +pub(crate) fn path_from_host>(s: S) -> Result { let vec: Vec = s.as_ref().encode_wide().collect(); String::from_utf16(&vec).map_err(|_| host::__WASI_EILSEQ) }