summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanchayan Maity <maitysanchayan@gmail.com>2017-10-07 19:13:22 +0530
committerSanchayan Maity <maitysanchayan@gmail.com>2017-10-07 19:13:22 +0530
commit724f7c734b5484116aefb9f055d6303204c7be8b (patch)
treece8ceae72e26758c50e9c43aeef5d68db4b16c26
parentb85d50147f1f503597d8f54e6be821dfd2379193 (diff)
downloadnix-724f7c734b5484116aefb9f055d6303204c7be8b.zip
Add test for 'fallocate'
-rw-r--r--test/test_fcntl.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs
index 43bfc091..d171b91d 100644
--- a/test/test_fcntl.rs
+++ b/test/test_fcntl.rs
@@ -54,11 +54,11 @@ mod linux_android {
use libc::loff_t;
- use nix::fcntl::{SpliceFFlags, splice, tee, vmsplice};
+ use nix::fcntl::{SpliceFFlags, FallocateFlags, fallocate, splice, tee, vmsplice};
use nix::sys::uio::IoVec;
use nix::unistd::{close, pipe, read, write};
- use tempfile::tempfile;
+ use tempfile::{tempfile, NamedTempFile};
#[test]
fn test_splice() {
@@ -131,4 +131,15 @@ mod linux_android {
close(wr).unwrap();
}
+ #[test]
+ fn test_fallocate() {
+ let tmp = NamedTempFile::new().unwrap();
+
+ let fd = tmp.as_raw_fd();
+ fallocate(fd, FallocateFlags::empty(), 0, 100).unwrap();
+
+ // Check if we read exactly 100 bytes
+ let mut buf = [0u8; 200];
+ assert_eq!(100, read(fd, &mut buf).unwrap());
+ }
}