diff options
author | Phil Vachon <pvachon@12sidedtech.com> | 2014-10-24 17:18:44 -0400 |
---|---|---|
committer | Phil Vachon <pvachon@12sidedtech.com> | 2014-10-27 20:11:43 -0400 |
commit | bcf2f5e137740b5491070f15c0ea3470ce85025e (patch) | |
tree | 6ef6144bcd98c2a94c3995f804ac989c6eeb7cbb /src/unistd.rs | |
parent | 5510805c82f6ec1e25966eb639624529d1ae9bc7 (diff) | |
download | nix-bcf2f5e137740b5491070f15c0ea3470ce85025e.zip |
Add mmap, shm_open and other mman relatives
Add various wrappers to make interacting with Rust a bit more pleasant
for memory management.
Additionally, provide ftruncate(2), which is useful when working with
shared memory.
Allow managing CPU affinity of a Rust Task living in a system thread.
Diffstat (limited to 'src/unistd.rs')
-rw-r--r-- | src/unistd.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/unistd.rs b/src/unistd.rs index e658816b..1c8ed6ab 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -1,6 +1,6 @@ use std::{mem, ptr}; use std::c_str::{CString, ToCStr}; -use libc::{c_char, c_void, c_int, size_t, pid_t}; +use libc::{c_char, c_void, c_int, size_t, pid_t, off_t}; use fcntl::{fcntl, Fd, OFlag, O_NONBLOCK, O_CLOEXEC, FD_CLOEXEC, F_SETFD, F_SETFL}; use errno::{SysResult, SysError, from_ffi}; use core::raw::Slice as RawSlice; @@ -11,7 +11,7 @@ pub use self::linux::*; mod ffi { use super::{IovecR,IovecW}; use libc::{c_char, c_int, size_t, ssize_t}; - pub use libc::{close, read, write, pipe}; + pub use libc::{close, read, write, pipe, ftruncate}; pub use libc::funcs::posix88::unistd::fork; use fcntl::Fd; @@ -393,6 +393,14 @@ fn pipe2_setflags(fd1: Fd, fd2: Fd, flags: OFlag) -> SysResult<()> { } } +pub fn ftruncate(fd: Fd, len: off_t) -> SysResult<()> { + if unsafe { ffi::ftruncate(fd, len) } < 0 { + Err(SysError::last()) + } else { + Ok(()) + } +} + #[cfg(target_os = "linux")] mod linux { use std::path::Path; |