Skip to content

Instantly share code, notes, and snippets.

View FrancescoLuzzi's full-sized avatar

Francesco Luzzi FrancescoLuzzi

View GitHub Profile
@iskakaushik
iskakaushik / cstr_array.rs
Created February 12, 2021 05:31
Transfer rust vec to c array strings.
use std::ffi::CString;
use std::os::raw::{c_char, c_int};
use std::{ptr, mem};
#[no_mangle]
unsafe extern "C" fn get_strings(outlen: *mut c_int) -> *mut *mut c_char {
let mut v = vec![];
// Let's fill a vector with null-terminated strings
v.push(CString::new("Hello").unwrap());