#![cfg_attr(feature="clippy", feature(plugin))]
#![cfg_attr(feature="clippy", plugin(clippy))]
extern crate libc;
use std::fs::File;
use std::io::{Result, Error};
use libc::c_int;
use libc::pipe as raw_pipe;
use std::os::unix::io::FromRawFd;
pub struct PipeFile {
pub read_end: File,
pub write_end: File
}
pub fn pipe() -> Result<PipeFile> {
let mut fds: [c_int; 2] = [0; 2];
match unsafe { raw_pipe((&mut fds).as_mut_ptr()) } {
0 => Ok(PipeFile {
read_end: unsafe { FromRawFd::from_raw_fd(fds[0]) },
write_end: unsafe { FromRawFd::from_raw_fd(fds[1]) }
}),
_ => Err(Error::last_os_error())
}
}