Skip to content

Commit

Permalink
Fix issue #70
Browse files Browse the repository at this point in the history
  • Loading branch information
38 committed Feb 20, 2023
1 parent 29ba327 commit f8c0087
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions d4-framefile/src/randfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,15 @@ pub mod mapping {
}

#[derive(Clone)]
pub struct MappingHandle(Arc<Mmap>);
pub struct MappingHandle(Arc<Option<Mmap>>);

impl AsRef<[u8]> for MappingHandle {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
if let Some(ref mmap) = *self.0 {
mmap.as_ref()
} else {
&[]
}
}
}

Expand All @@ -283,7 +287,11 @@ pub mod mapping {
.inner
.lock()
.map_err(|_| Error::new(ErrorKind::Other, "Lock Error"))?;
let mapped = unsafe { MmapOptions::new().offset(offset).len(size).map(&*inner)? };
let mapped = if size > 0 {
Some(unsafe { MmapOptions::new().offset(offset).len(size).map(&*inner)? })
} else {
None
};
drop(inner);
Ok(MappingHandle(Arc::new(mapped)))
}
Expand Down

0 comments on commit f8c0087

Please sign in to comment.