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