about summary refs log tree commit diff
path: root/src/tools/miri/tests/pass-dep/wcslen.rs
blob: c5c9d99247965c643ea553d985d5d6f75b0956b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn to_c_wchar_t_str(s: &str) -> Vec<libc::wchar_t> {
    let mut r = Vec::<libc::wchar_t>::new();
    for c in s.bytes() {
        if c == 0 {
            panic!("can't contain a null character");
        }
        if c >= 128 {
            panic!("only ASCII supported");
        }
        r.push(c.into());
    }
    r.push(0);
    r
}

pub fn main() {
    let s = to_c_wchar_t_str("Rust");
    let len = unsafe { libc::wcslen(s.as_ptr()) };
    assert_eq!(len, 4);
}