IO, error handling

This commit is contained in:
Matthias Schiffer 2020-04-13 02:13:58 +02:00
parent fff906a78b
commit 5b449f4e1e
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
6 changed files with 138 additions and 34 deletions

View file

@ -8,11 +8,11 @@ use core::fmt::Write;
#[no_mangle]
pub extern "C" fn main(_nargs: libc::c_int, _args: *const *const libc::c_char) -> libc::c_int {
let mut stdout = unsafe { libc::stdio::stdout() };
let mut stdout = libc::stdio::stdout();
{
let foo = cstr!("Foo!\n");
stdout.puts(foo);
let _ = stdout.puts(foo);
}
{
@ -29,11 +29,12 @@ pub extern "C" fn main(_nargs: libc::c_int, _args: *const *const libc::c_char) -
let b = libc::boxed::CBox::new(42);
let _ = writeln!(stdout, "Bar: {}", b);
}
0
}
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
let _ = writeln!(unsafe { libc::stdio::stderr() }, "Panic: {}", info);
let _ = writeln!(libc::stdio::stderr(), "Panic: {}", info);
unsafe { libc::abort() }
}