unix_fd/
lib.rs

1#![allow(clippy::redundant_field_names)]
2
3#[macro_use]
4extern crate log;
5
6#[macro_use]
7extern crate error_chain;
8
9use std::ffi::CString;
10use std::path::Path;
11
12pub mod errors {
13    error_chain! {
14        foreign_links {
15            Io(::std::io::Error) #[cfg(unix)];
16        }
17    }
18}
19
20pub(crate) trait LibcString {
21    fn as_libc(&self) -> (*const i8, CString);
22}
23
24impl LibcString for Path {
25    fn as_libc(&self) -> (*const i8, CString) {
26        let res = unsafe {
27            use std::os::unix::ffi::OsStrExt;
28
29            CString::from_vec_unchecked(self.as_os_str().as_bytes().to_vec())
30        };
31
32        (res.as_ptr() as *const i8, res)
33    }
34}
35
36
37pub mod fd;
38pub mod dir;
39pub mod chroot;
40
41#[cfg(test)]
42extern crate libc;
43#[cfg(test)]
44extern crate tempdir;
45#[cfg(test)]
46extern crate env_logger;
47
48#[cfg(test)]
49#[path="tests/core.inc.rs"]
50mod test;