Skip to content

Commit

Permalink
fix stubbed implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrmaxmeier committed Aug 5, 2021
1 parent 6b594bd commit 651ef08
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use crate::unix::MmapInner;
#[cfg(not(any(unix, windows)))]
mod stub;
#[cfg(not(any(unix, windows)))]
use crate::stub::file_len;
#[cfg(not(any(unix, windows)))]
use crate::stub::MmapInner;

use std::fmt;
Expand All @@ -36,6 +38,9 @@ pub struct MmapRawDescriptor<'a>(&'a File);
#[cfg(unix)]
pub struct MmapRawDescriptor(std::os::unix::io::RawFd);

#[cfg(not(any(unix, windows)))]
pub struct MmapRawDescriptor<'a>(&'a File);

pub trait MmapAsRawDesc {
fn as_raw_desc(&self) -> MmapRawDescriptor;
}
Expand All @@ -61,6 +66,13 @@ impl MmapAsRawDesc for std::os::unix::io::RawFd {
}
}

#[cfg(not(any(unix, windows)))]
impl MmapAsRawDesc for &File {
fn as_raw_desc(&self) -> MmapRawDescriptor {
MmapRawDescriptor(self)
}
}

/// A memory map builder, providing advanced options and flags for specifying memory map behavior.
///
/// `MmapOptions` can be used to create an anonymous memory map using [`map_anon()`], or a
Expand Down
14 changes: 9 additions & 5 deletions src/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ impl MmapInner {
))
}

pub fn map(_: usize, _: &File, _: u64) -> io::Result<MmapInner> {
pub fn map(_: usize, _: &File, _: u64, _: bool) -> io::Result<MmapInner> {
MmapInner::new()
}

pub fn map_exec(_: usize, _: &File, _: u64) -> io::Result<MmapInner> {
pub fn map_exec(_: usize, _: &File, _: u64, _: bool) -> io::Result<MmapInner> {
MmapInner::new()
}

pub fn map_mut(_: usize, _: &File, _: u64) -> io::Result<MmapInner> {
pub fn map_mut(_: usize, _: &File, _: u64, _: bool) -> io::Result<MmapInner> {
MmapInner::new()
}

pub fn map_copy(_: usize, _: &File, _: u64) -> io::Result<MmapInner> {
pub fn map_copy(_: usize, _: &File, _: u64, _: bool) -> io::Result<MmapInner> {
MmapInner::new()
}

pub fn map_copy_read_only(_: usize, _: &File, _: u64) -> io::Result<MmapInner> {
pub fn map_copy_read_only(_: usize, _: &File, _: u64, _: bool) -> io::Result<MmapInner> {
MmapInner::new()
}

Expand Down Expand Up @@ -74,3 +74,7 @@ impl MmapInner {
unreachable!("self unconstructable");
}
}

pub fn file_len(file: &File) -> io::Result<usize> {
Ok(file.metadata()?.len() as usize)
}

0 comments on commit 651ef08

Please sign in to comment.