summaryrefslogtreecommitdiff
path: root/src/unistd.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/unistd.rs')
-rw-r--r--src/unistd.rs12
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;