This commit is contained in:
Mackenzie Clark 2018-12-20 23:08:00 -08:00
parent bc63bb736a
commit cfb8442d6b
3 changed files with 12 additions and 11 deletions

View File

@ -1,8 +1,8 @@
use std::io::Read;
use std::ffi::CString;
use std::io;
use std::io::Error;
use std::io::ErrorKind;
use std::ffi::CString;
use std::io::Read;
pub struct FileDescriptor(libc::c_int);
@ -15,14 +15,12 @@ impl FileDescriptor {
impl Read for FileDescriptor {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let file_descriptor: libc::c_int = self.0;
let count = unsafe {
libc::read(file_descriptor, buf.as_mut_ptr() as *mut libc::c_void, 1)
};
let count =
unsafe { libc::read(file_descriptor, buf.as_mut_ptr() as *mut libc::c_void, 1) };
if count < 0 {
Err(Error::new(ErrorKind::Other, "read error"))
}
else {
} else {
Ok(count as usize)
}
}
}
}

View File

@ -1,6 +1,6 @@
pub mod mmap;
pub mod slice;
mod file_descriptor;
#[cfg(test)]
pub mod stdio;
mod file_descriptor;

View File

@ -1,7 +1,7 @@
use crate::common::file_descriptor::FileDescriptor;
use libc;
use std::io::BufReader;
use std::io::Read;
use crate::common::file_descriptor::FileDescriptor;
// A struct to hold the references to the base stdout and the captured one
pub struct StdioCapturer {
@ -21,7 +21,10 @@ impl StdioCapturer {
#[cfg(not(target_os = "windows"))]
assert_eq!(unsafe { libc::pipe(fds.as_mut_ptr()) }, 0);
#[cfg(target_os = "windows")]
assert_eq!(unsafe { libc::pipe(fds.as_mut_ptr(), 1000, libc::O_TEXT) }, 0);
assert_eq!(
unsafe { libc::pipe(fds.as_mut_ptr(), 1000, libc::O_TEXT) },
0
);
(fds[0], fds[1])
}