we can now read c style string arrays
This commit is contained in:
30
src/lib.rs
30
src/lib.rs
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user