rust/tests/ui/foreign/foreign-fn-linkname.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

25 lines
469 B
Rust
Raw Normal View History

//@ run-pass
2019-04-24 16:26:33 +00:00
//@ ignore-sgx no libc
use std::ffi::CString;
2014-02-26 17:58:41 +00:00
mod mlibc {
2024-04-18 21:39:35 +00:00
use std::ffi::c_char;
2013-08-17 15:37:42 +00:00
2020-09-01 21:12:52 +00:00
extern "C" {
#[link_name = "strlen"]
2024-04-18 21:39:35 +00:00
pub fn my_strlen(str: *const c_char) -> usize;
}
}
fn strlen(str: String) -> usize {
2013-08-17 15:37:42 +00:00
// C string is terminated with a zero
2015-02-18 22:39:37 +00:00
let s = CString::new(str).unwrap();
2020-09-01 21:12:52 +00:00
unsafe { mlibc::my_strlen(s.as_ptr()) as usize }
}
pub fn main() {
let len = strlen("Rust".to_string());
assert_eq!(len, 4);
}