summaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: 5f86a6132fc218af7b78dbb28d10553f20ea9c4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#![no_main]
#![no_std]

extern crate libc;

mod c;

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 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 _ = 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);
	unsafe { libc::abort() }
}