Fixes for stdio and processes on Redox
This commit is contained in:
parent
ced32a08f3
commit
a90850995f
@ -28,7 +28,7 @@
|
||||
#![panic_runtime]
|
||||
#![feature(panic_runtime)]
|
||||
#![cfg_attr(unix, feature(libc))]
|
||||
#![cfg_attr(windows, feature(core_intrinsics))]
|
||||
#![cfg_attr(any(target_os = "redox", windows), feature(core_intrinsics))]
|
||||
|
||||
// Rust's "try" function, but if we're aborting on panics we just call the
|
||||
// function as there's nothing else we need to do here.
|
||||
@ -61,7 +61,7 @@ pub unsafe extern fn __rust_start_panic(_data: usize, _vtable: usize) -> u32 {
|
||||
libc::abort();
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[cfg(any(target_os = "redox", windows))]
|
||||
unsafe fn abort() -> ! {
|
||||
core::intrinsics::abort();
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ mod imp;
|
||||
|
||||
// i686-pc-windows-gnu and all others
|
||||
#[cfg(any(all(unix, not(target_os = "emscripten")),
|
||||
target_os = "redox",
|
||||
all(windows, target_arch = "x86", target_env = "gnu")))]
|
||||
#[path = "gcc.rs"]
|
||||
mod imp;
|
||||
|
@ -81,11 +81,17 @@ impl Read for StdinRaw {
|
||||
}
|
||||
impl Write for StdoutRaw {
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.0.write(buf) }
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
fn flush(&mut self) -> io::Result<()> { Ok(()) }
|
||||
#[cfg(target_os = "redox")]
|
||||
fn flush(&mut self) -> io::Result<()> { self.0.flush() }
|
||||
}
|
||||
impl Write for StderrRaw {
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.0.write(buf) }
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
fn flush(&mut self) -> io::Result<()> { Ok(()) }
|
||||
#[cfg(target_os = "redox")]
|
||||
fn flush(&mut self) -> io::Result<()> { self.0.flush() }
|
||||
}
|
||||
|
||||
enum Maybe<T> {
|
||||
|
@ -50,8 +50,7 @@ impl FileDesc {
|
||||
|
||||
pub fn set_cloexec(&self) -> io::Result<()> {
|
||||
::sys_common::util::dumb_print(format_args!("{}: set cloexec\n", self.fd));
|
||||
//unimplemented!();
|
||||
Ok(())
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
pub fn set_nonblocking(&self, _nonblocking: bool) -> io::Result<()> {
|
||||
|
@ -264,7 +264,21 @@ impl Command {
|
||||
env::set_var(key, val);
|
||||
}
|
||||
|
||||
if let Err(err) = libc::exec(&self.program, &args) {
|
||||
let program = if self.program.contains(':') || self.program.contains('/') {
|
||||
self.program.to_owned()
|
||||
} else {
|
||||
let mut path_env = ::env::var("PATH").unwrap_or(".".to_string());
|
||||
|
||||
if ! path_env.ends_with('/') {
|
||||
path_env.push('/');
|
||||
}
|
||||
|
||||
path_env.push_str(&self.program);
|
||||
|
||||
path_env
|
||||
};
|
||||
|
||||
if let Err(err) = libc::exec(&program, &args) {
|
||||
io::Error::from_raw_os_error(err.errno as i32)
|
||||
} else {
|
||||
panic!("return from exec without err");
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
use io;
|
||||
use libc;
|
||||
use sys::cvt;
|
||||
use sys::fd::FileDesc;
|
||||
|
||||
pub struct Stdin(());
|
||||
@ -43,6 +44,10 @@ impl Stdout {
|
||||
fd.into_raw();
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn flush(&self) -> io::Result<()> {
|
||||
cvt(libc::fsync(libc::STDOUT_FILENO)).and(Ok(()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Stderr {
|
||||
@ -54,6 +59,10 @@ impl Stderr {
|
||||
fd.into_raw();
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn flush(&self) -> io::Result<()> {
|
||||
cvt(libc::fsync(libc::STDERR_FILENO)).and(Ok(()))
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: right now this raw stderr handle is used in a few places because
|
||||
@ -63,7 +72,10 @@ impl io::Write for Stderr {
|
||||
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
|
||||
Stderr::write(self, data)
|
||||
}
|
||||
fn flush(&mut self) -> io::Result<()> { Ok(()) }
|
||||
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
cvt(libc::fsync(libc::STDERR_FILENO)).and(Ok(()))
|
||||
}
|
||||
}
|
||||
|
||||
pub const EBADF_ERR: i32 = ::libc::EBADF;
|
||||
|
Loading…
Reference in New Issue
Block a user