Skip to content

Commit a908509

Browse files
committed
Fixes for stdio and processes on Redox
1 parent ced32a0 commit a908509

File tree

6 files changed

+38
-6
lines changed

6 files changed

+38
-6
lines changed

src/libpanic_abort/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#![panic_runtime]
2929
#![feature(panic_runtime)]
3030
#![cfg_attr(unix, feature(libc))]
31-
#![cfg_attr(windows, feature(core_intrinsics))]
31+
#![cfg_attr(any(target_os = "redox", windows), feature(core_intrinsics))]
3232

3333
// Rust's "try" function, but if we're aborting on panics we just call the
3434
// 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 {
6161
libc::abort();
6262
}
6363

64-
#[cfg(windows)]
64+
#[cfg(any(target_os = "redox", windows))]
6565
unsafe fn abort() -> ! {
6666
core::intrinsics::abort();
6767
}

src/libpanic_unwind/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ mod imp;
6969

7070
// i686-pc-windows-gnu and all others
7171
#[cfg(any(all(unix, not(target_os = "emscripten")),
72+
target_os = "redox",
7273
all(windows, target_arch = "x86", target_env = "gnu")))]
7374
#[path = "gcc.rs"]
7475
mod imp;

src/libstd/io/stdio.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,17 @@ impl Read for StdinRaw {
8181
}
8282
impl Write for StdoutRaw {
8383
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.0.write(buf) }
84+
#[cfg(not(target_os = "redox"))]
8485
fn flush(&mut self) -> io::Result<()> { Ok(()) }
86+
#[cfg(target_os = "redox")]
87+
fn flush(&mut self) -> io::Result<()> { self.0.flush() }
8588
}
8689
impl Write for StderrRaw {
8790
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.0.write(buf) }
91+
#[cfg(not(target_os = "redox"))]
8892
fn flush(&mut self) -> io::Result<()> { Ok(()) }
93+
#[cfg(target_os = "redox")]
94+
fn flush(&mut self) -> io::Result<()> { self.0.flush() }
8995
}
9096

9197
enum Maybe<T> {

src/libstd/sys/redox/fd.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ impl FileDesc {
5050

5151
pub fn set_cloexec(&self) -> io::Result<()> {
5252
::sys_common::util::dumb_print(format_args!("{}: set cloexec\n", self.fd));
53-
//unimplemented!();
54-
Ok(())
53+
unimplemented!();
5554
}
5655

5756
pub fn set_nonblocking(&self, _nonblocking: bool) -> io::Result<()> {

src/libstd/sys/redox/process.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,21 @@ impl Command {
264264
env::set_var(key, val);
265265
}
266266

267-
if let Err(err) = libc::exec(&self.program, &args) {
267+
let program = if self.program.contains(':') || self.program.contains('/') {
268+
self.program.to_owned()
269+
} else {
270+
let mut path_env = ::env::var("PATH").unwrap_or(".".to_string());
271+
272+
if ! path_env.ends_with('/') {
273+
path_env.push('/');
274+
}
275+
276+
path_env.push_str(&self.program);
277+
278+
path_env
279+
};
280+
281+
if let Err(err) = libc::exec(&program, &args) {
268282
io::Error::from_raw_os_error(err.errno as i32)
269283
} else {
270284
panic!("return from exec without err");

src/libstd/sys/redox/stdio.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use io;
1212
use libc;
13+
use sys::cvt;
1314
use sys::fd::FileDesc;
1415

1516
pub struct Stdin(());
@@ -43,6 +44,10 @@ impl Stdout {
4344
fd.into_raw();
4445
ret
4546
}
47+
48+
pub fn flush(&self) -> io::Result<()> {
49+
cvt(libc::fsync(libc::STDOUT_FILENO)).and(Ok(()))
50+
}
4651
}
4752

4853
impl Stderr {
@@ -54,6 +59,10 @@ impl Stderr {
5459
fd.into_raw();
5560
ret
5661
}
62+
63+
pub fn flush(&self) -> io::Result<()> {
64+
cvt(libc::fsync(libc::STDERR_FILENO)).and(Ok(()))
65+
}
5766
}
5867

5968
// FIXME: right now this raw stderr handle is used in a few places because
@@ -63,7 +72,10 @@ impl io::Write for Stderr {
6372
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
6473
Stderr::write(self, data)
6574
}
66-
fn flush(&mut self) -> io::Result<()> { Ok(()) }
75+
76+
fn flush(&mut self) -> io::Result<()> {
77+
cvt(libc::fsync(libc::STDERR_FILENO)).and(Ok(()))
78+
}
6779
}
6880

6981
pub const EBADF_ERR: i32 = ::libc::EBADF;

0 commit comments

Comments
 (0)