mmap-sync 2.0.4

A Rust package allowing sharing of data between processes in a wait-free and zero-copy fashion from mapped memory.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::fs::File;
use std::io;
#[cfg(target_os = "linux")]
use std::os::fd::AsRawFd;

/// Set the length of the file to the specified length.
pub(crate) fn set_len(file: &File, len: i64) -> Result<(), io::Error> {
    // On Linux platforms, `.set_len()` may not return an error of the disk is full, so we allocate
    // the entire file to ensure space is available.
    #[cfg(target_os = "linux")]
    match unsafe { libc::posix_fallocate(file.as_raw_fd(), 0, len) } {
        0 => Ok(()),
        err => Err(io::Error::from_raw_os_error(err)),
    }
    // Support for non-Linux platforms is best-effort.
    #[cfg(not(target_os = "linux"))]
    file.set_len(len as u64)
}