diff options
author | Jörg Thalheim <joerg@thalheim.io> | 2017-03-08 00:11:36 +0100 |
---|---|---|
committer | Jörg Thalheim <joerg@thalheim.io> | 2017-03-21 00:46:29 +0100 |
commit | 2b0c63f56dcf69fba328e8d5b2139bc6e5cef930 (patch) | |
tree | 8b4c9e4794c1b09260bed83b6d37f5f1b2b89693 /test | |
parent | 0eef6515f265428e522eea3e2aa3dd936398c4e0 (diff) | |
download | nix-2b0c63f56dcf69fba328e8d5b2139bc6e5cef930.zip |
add support for `openat`
Diffstat (limited to 'test')
-rw-r--r-- | test/test_fcntl.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index ca2e89a3..8d3bd2da 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -1,3 +1,31 @@ +use nix::fcntl::{openat, open, O_PATH, O_RDONLY}; +use nix::sys::stat::Mode; +use nix::unistd::{close, read}; +use tempfile::NamedTempFile; +use std::io::prelude::*; + +#[test] +fn test_openat() { + const CONTENTS: &'static [u8] = b"abcd"; + let mut tmp = NamedTempFile::new().unwrap(); + tmp.write(CONTENTS).unwrap(); + + let dirfd = open(tmp.path().parent().unwrap(), + O_PATH, + Mode::empty()).unwrap(); + let fd = openat(dirfd, + tmp.path().file_name().unwrap(), + O_RDONLY, + Mode::empty()).unwrap(); + + let mut buf = [0u8; 1024]; + assert_eq!(4, read(fd, &mut buf).unwrap()); + assert_eq!(CONTENTS, &buf[0..4]); + + close(fd).unwrap(); + close(dirfd).unwrap(); +} + #[cfg(any(target_os = "linux", target_os = "android"))] mod linux_android { use std::io::prelude::*; |