#![no_main] #![no_std] use safe_libc as libc; use libc::cstr; 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 = libc::stdio::stdout(); { let foo = cstr!("Foo!\n"); let _ = stdout.puts(foo); } { let x = libc::string::CString::from("foo"); let l = x.len(); let y = x.into_raw(); let z = unsafe { libc::boxed::CBox::slice_from_raw_parts(y, l) }; let _ = writeln!(stdout, "Foo: {} {} {}", z[0], z[1], z[2]); } { let b = libc::boxed::CBox::new(42); let _ = writeln!(stdout, "Bar: {}", b); } 0 } #[panic_handler] fn panic(info: &core::panic::PanicInfo) -> ! { let _ = writeln!(libc::stdio::stderr(), "Panic: {}", info); unsafe { libc::abort() } }