mirror of https://github.com/dnomd343/ClearDNS
Dnomd343
2 years ago
2 changed files with 19 additions and 15 deletions
@ -0,0 +1,18 @@ |
|||||
|
use std::ffi::{c_char, CStr, CString}; |
||||
|
|
||||
|
#[no_mangle] |
||||
|
pub unsafe extern "C" fn free_rust_string(string: *const c_char) { |
||||
|
let _ = CString::from_raw(string as *mut _); |
||||
|
} |
||||
|
|
||||
|
#[no_mangle] |
||||
|
pub unsafe extern "C" fn to_json_rust(content: *const c_char) -> *const c_char { |
||||
|
let content: &str = CStr::from_ptr(content).to_str().unwrap(); |
||||
|
|
||||
|
// TODO: remove test code
|
||||
|
println!("Raw content -> {}", content); |
||||
|
|
||||
|
// TODO: convert to JSON format
|
||||
|
|
||||
|
CString::new(content).unwrap().into_raw() |
||||
|
} |
@ -1,15 +1 @@ |
|||||
use std::ffi::{c_char, CStr, CString}; |
mod ffi; |
||||
|
|
||||
#[no_mangle] |
|
||||
pub unsafe extern "C" fn to_json_rust(content: *const c_char) -> *const c_char { |
|
||||
let content: &str = CStr::from_ptr(content).to_str().unwrap(); |
|
||||
|
|
||||
println!("Raw content -> {}", content); |
|
||||
|
|
||||
CString::new(content).unwrap().into_raw() |
|
||||
} |
|
||||
|
|
||||
#[no_mangle] |
|
||||
pub unsafe extern "C" fn free_rust_string(string: *const c_char) { |
|
||||
let _ = CString::from_raw(string as *mut _); |
|
||||
} |
|
||||
|
Loading…
Reference in new issue