Skip to content
This repository has been archived by the owner on Nov 9, 2019. It is now read-only.

Mark all functions in host_impl.rs as pub(crate) #43

Merged
merged 1 commit into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions src/sys/unix/host_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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<host::__wasi_filestat_t> {
pub(crate) fn filestat_from_nix(
filestat: nix::sys::stat::FileStat,
) -> Result<host::__wasi_filestat_t> {
use std::convert::TryFrom;

let filetype = nix::sys::stat::SFlag::from_bits_truncate(filestat.st_mode);
Expand All @@ -218,7 +220,7 @@ pub fn filestat_from_nix(filestat: nix::sys::stat::FileStat) -> Result<host::__w
}

#[cfg(target_os = "linux")]
pub fn dirent_from_host(host_entry: &nix::libc::dirent) -> Result<wasm32::__wasi_dirent_t> {
pub(crate) fn dirent_from_host(host_entry: &nix::libc::dirent) -> Result<wasm32::__wasi_dirent_t> {
let mut entry = unsafe { std::mem::zeroed::<wasm32::__wasi_dirent_t>() };
let d_namlen = unsafe { std::ffi::CStr::from_ptr(host_entry.d_name.as_ptr()) }
.to_bytes()
Expand All @@ -234,7 +236,7 @@ pub fn dirent_from_host(host_entry: &nix::libc::dirent) -> Result<wasm32::__wasi
}

#[cfg(not(target_os = "linux"))]
pub fn dirent_from_host(host_entry: &nix::libc::dirent) -> Result<wasm32::__wasi_dirent_t> {
pub(crate) fn dirent_from_host(host_entry: &nix::libc::dirent) -> Result<wasm32::__wasi_dirent_t> {
let mut entry = unsafe { std::mem::zeroed::<wasm32::__wasi_dirent_t>() };
entry.d_ino = memory::enc_inode(host_entry.d_ino);
entry.d_next = memory::enc_dircookie(host_entry.d_seekoff);
Expand All @@ -247,6 +249,6 @@ pub fn dirent_from_host(host_entry: &nix::libc::dirent) -> Result<wasm32::__wasi
///
/// NB WASI spec requires OS string to be valid UTF-8. Otherwise,
/// `__WASI_EILSEQ` error is returned.
pub fn path_from_host<S: AsRef<OsStr>>(s: S) -> Result<String> {
pub(crate) fn path_from_host<S: AsRef<OsStr>>(s: S) -> Result<String> {
host::path_from_slice(s.as_ref().as_bytes()).map(String::from)
}
10 changes: 5 additions & 5 deletions src/sys/windows/host_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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};
Expand All @@ -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!
Expand All @@ -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,
Expand Down Expand Up @@ -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: AsRef<OsStr>>(s: S) -> Result<String> {
pub(crate) fn path_from_host<S: AsRef<OsStr>>(s: S) -> Result<String> {
let vec: Vec<u16> = s.as_ref().encode_wide().collect();
String::from_utf16(&vec).map_err(|_| host::__WASI_EILSEQ)
}