From f0b3d5166ef1255fac880b146875ef46d2599a13 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 4 Apr 2020 13:22:18 +0200 Subject: Reorganize --- src/main.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 5f86a61..67d8baa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,30 +1,29 @@ #![no_main] #![no_std] -extern crate libc; - -mod c; +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 = unsafe { c::stdio::stdout() }; - let x = c::string::CString::from("foo"); + let mut stdout = unsafe { libc::stdio::stdout() }; + let x = libc::string::CString::from("foo"); let l = x.len(); let y = x.into_raw(); let z = unsafe { - c::string::CBox::slice_from_raw_parts(y, l) + libc::boxed::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 foo = cstr!("Foo!\n"); + stdout.puts(foo); let _ = writeln!(stdout, "Foo: {} {} {}", z[0], z[1], z[2]); 0 } #[panic_handler] fn panic(info: &core::panic::PanicInfo) -> ! { - let _ = writeln!(unsafe { c::stdio::stderr() }, "Panic: {}", info); + let _ = writeln!(unsafe { libc::stdio::stderr() }, "Panic: {}", info); unsafe { libc::abort() } } -- cgit v1.2.3