summaryrefslogtreecommitdiff
path: root/src/fcntl.rs
diff options
context:
space:
mode:
authorDing Xiang Fei <dingxiangfei2009@gmail.com>2019-08-11 15:20:44 +0800
committerDing Xiang Fei <dingxiangfei2009@gmail.com>2019-09-12 09:30:54 +0800
commitdcf57baa8075e40c5697b553de6aa0e358d20020 (patch)
tree9198e7ba4760c1173ce2cb9987173bf3007c8ec3 /src/fcntl.rs
parent16624668d40cb3f8545188d95f96d635313d5479 (diff)
downloadnix-dcf57baa8075e40c5697b553de6aa0e358d20020.zip
posix_fallocate
Diffstat (limited to 'src/fcntl.rs')
-rw-r--r--src/fcntl.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/fcntl.rs b/src/fcntl.rs
index 2cb7f505..7d745b06 100644
--- a/src/fcntl.rs
+++ b/src/fcntl.rs
@@ -505,3 +505,24 @@ mod posix_fadvise {
Errno::result(res)
}
}
+
+#[cfg(any(
+ target_os = "linux",
+ target_os = "android",
+ target_os = "emscripten",
+ target_os = "fuchsia",
+ any(target_os = "wasi", target_env = "wasi"),
+ target_os = "freebsd"
+))]
+pub fn posix_fallocate(
+ fd: RawFd,
+ offset: libc::off_t,
+ len: libc::off_t
+) -> Result<()> {
+ let res = unsafe { libc::posix_fallocate(fd, offset, len) };
+ match Errno::result(res) {
+ Err(err) => Err(err),
+ Ok(0) => Ok(()),
+ Ok(errno) => Err(crate::Error::Sys(Errno::from_i32(errno))),
+ }
+}