we can now read c style string arrays

This commit is contained in:
2021-06-02 00:45:26 +02:00
parent b1e39cdb75
commit e4f07ffe2f
7 changed files with 77 additions and 2 deletions

View File

@@ -1,7 +1,35 @@
extern crate ffi_convert;
extern crate libc;
use ffi_convert::{AsRust, CReprOf, CStringArray};
use libc::c_char;
use libc::size_t;
//use std::ffi::CStr;
//use std::ffi::CString;
use std::path::Path;
//use std::slice;
fn file_exists(file_path: &str) -> bool {
return Path::new(file_path).is_file();
}
#[no_mangle]
pub extern "C" fn files_exist(f: *const *const c_char, len: size_t) -> () {
let files = unsafe {
assert!(!f.is_null());
CStringArray { data: f, size: len }
};
println!("{:?}", files.as_rust().unwrap());
std::mem::forget(files);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
assert_eq!(file_exists("/home/nathan/Downloads/cert.sh"), true);
}
}