summary refs log tree commit diff
path: root/src/test/run-pass/native-fn-linkname.rs
blob: 72d0ab01f96617535a1972450e60790d76ecc3c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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);
}