]> git.lizzy.rs Git - rust.git/blob - src/test/ui/foreign/foreign-fn-linkname.rs
Auto merge of #97925 - the8472:cgroupv1, r=joshtriplett
[rust.git] / src / test / ui / foreign / foreign-fn-linkname.rs
1 // run-pass
2 // ignore-wasm32-bare no libc to test ffi with
3 // ignore-sgx no libc
4
5 #![feature(rustc_private)]
6
7 extern crate libc;
8 use std::ffi::CString;
9
10 mod mlibc {
11     use libc::{c_char, size_t};
12
13     extern "C" {
14         #[link_name = "strlen"]
15         pub fn my_strlen(str: *const c_char) -> size_t;
16     }
17 }
18
19 fn strlen(str: String) -> usize {
20     // C string is terminated with a zero
21     let s = CString::new(str).unwrap();
22     unsafe { mlibc::my_strlen(s.as_ptr()) as usize }
23 }
24
25 pub fn main() {
26     let len = strlen("Rust".to_string());
27     assert_eq!(len, 4);
28 }