Skip to content

Commit 724f7c7

Browse files
Add test for 'fallocate'
1 parent b85d501 commit 724f7c7

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

test/test_fcntl.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ mod linux_android {
5454

5555
use libc::loff_t;
5656

57-
use nix::fcntl::{SpliceFFlags, splice, tee, vmsplice};
57+
use nix::fcntl::{SpliceFFlags, FallocateFlags, fallocate, splice, tee, vmsplice};
5858
use nix::sys::uio::IoVec;
5959
use nix::unistd::{close, pipe, read, write};
6060

61-
use tempfile::tempfile;
61+
use tempfile::{tempfile, NamedTempFile};
6262

6363
#[test]
6464
fn test_splice() {
@@ -131,4 +131,15 @@ mod linux_android {
131131
close(wr).unwrap();
132132
}
133133

134+
#[test]
135+
fn test_fallocate() {
136+
let tmp = NamedTempFile::new().unwrap();
137+
138+
let fd = tmp.as_raw_fd();
139+
fallocate(fd, FallocateFlags::empty(), 0, 100).unwrap();
140+
141+
// Check if we read exactly 100 bytes
142+
let mut buf = [0u8; 200];
143+
assert_eq!(100, read(fd, &mut buf).unwrap());
144+
}
134145
}

0 commit comments

Comments
 (0)