From 2b0c63f56dcf69fba328e8d5b2139bc6e5cef930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 8 Mar 2017 00:11:36 +0100 Subject: add support for `openat` --- test/test_fcntl.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test') 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::*; -- cgit v1.2.3