rust/src/test/run-pass/native-fn-linkname.rs
Graham Fawcett 7ddd353ef6 implement #[nolink]; deprecate #[link_name = ""]; note in stdlib to remove empty link_name.
Can't remove them from stdlib until the snapshotted compiler supports #[nolink].
2011-12-16 15:29:59 -08:00

23 lines
390 B
Rust

use std;
import vec;
import str;
#[nolink]
#[abi = "cdecl"]
native mod libc {
#[link_name = "strlen"]
fn my_strlen(str: *u8) -> uint;
}
fn strlen(str: str) -> uint unsafe {
// C string is terminated with a zero
let bytes = str::bytes(str) + [0u8];
ret libc::my_strlen(vec::unsafe::to_ptr(bytes));
}
fn main() {
let len = strlen("Rust");
assert(len == 4u);
}