test cases/rust/20 rust and cpp/main.rs
raw| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright © 2023 Intel Corporation |
| 3 | |
| 4 | use std::ffi::CString; |
| 5 | use std::os::raw::c_char; |
| 6 | |
| 7 | extern "C" { |
| 8 | fn lib_length(s: *const c_char) -> u64; |
| 9 | } |
| 10 | |
| 11 | fn main() { |
| 12 | let len: u64; |
| 13 | unsafe { |
| 14 | let c_str = CString::new("Hello, world!").unwrap(); |
| 15 | len = lib_length(c_str.as_ptr()); |
| 16 | } |
| 17 | |
| 18 | std::process::exit(if len == 13 { 0 } else { 1 }) |
| 19 | } |