From 52b498494534784c77bfa4a93706be40620ebd9a Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 4 Apr 2020 01:47:30 +0200 Subject: Lots of changes --- src/main.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 15a2640..5f86a61 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,16 +9,22 @@ 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 { c::stdio::stdout() }; let x = c::string::CString::from("foo"); - let y = c::string::CBox::new(x); + let l = x.len(); + let y = x.into_raw(); + let z = unsafe { + c::string::CBox::slice_from_raw_parts(y, l) + }; + //let y = unsafe { c::string::CBox::from_raw(x) }; //let foo = cstr!("Foo! %p\n"); //c::stdio::stdout().puts(foo); - let mut stdout = c::stdio::stdout(); - writeln!(stdout, "Foo: {}", 42); + let _ = writeln!(stdout, "Foo: {} {} {}", z[0], z[1], z[2]); 0 } #[panic_handler] -fn panic(_info: &core::panic::PanicInfo) -> ! { +fn panic(info: &core::panic::PanicInfo) -> ! { + let _ = writeln!(unsafe { c::stdio::stderr() }, "Panic: {}", info); unsafe { libc::abort() } } -- cgit v1.2.3