blob: 428339614057cddca9b88de50451a6b1d264d17c (
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#![no_main]
#![no_std]
#![feature(alloc_error_handler)]
mod system_alloc;
extern crate alloc;
use libc::cstr;
use safe_libc as libc;
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 { alloc::boxed::Box::from_raw(core::ptr::slice_from_raw_parts_mut(y, l)) };
let _ = writeln!(stdout, "Foo: {} {} {}", z[0], z[1], z[2]);
}
{
let x = libc::string::CString::from("bar");
let _ = stdout.puts(&x);
}
{
let b = alloc::boxed::Box::new(42);
let _ = writeln!(stdout, "Bar: {}", b);
}
{
let x = alloc::boxed::Box::new(());
let _ = writeln!(stdout, "Box: {:?}", x);
}
0
}
#[cfg(not(test))]
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
let _ = writeln!(libc::stdio::stderr(), "Panic: {}", info);
unsafe { libc::abort() }
}
|