Skip to content

Instantly share code, notes, and snippets.

@ragne
Created May 4, 2019 11:21
Show Gist options
  • Save ragne/dd71b822325f12f988f7fd12bad46ef5 to your computer and use it in GitHub Desktop.
Save ragne/dd71b822325f12f988f7fd12bad46ef5 to your computer and use it in GitHub Desktop.
// gr_mem: Vec<String>
let mut char_vec: Vec<*mut c_char> = Vec::new();
for mem in self.gr_mem.into_iter() {
let c_str = CString::new(mem).unwrap();
let cstr_len = c_str.to_bytes_with_nul().len();
let dst = buf.as_mut_ptr().offset(offset as isize) as *mut i8;
std::ptr::copy_nonoverlapping(c_str.as_ptr(), dst , cstr_len);
char_vec.push(dst);
offset += cstr_len;
}
char_vec.push(std::ptr::null_mut());
let dst = buf.as_mut_ptr().offset(offset as isize) as *mut i8;
std::ptr::copy(char_vec.as_ptr(), dst as *mut *mut i8, char_vec.len());
g.gr_mem = dst as *mut *mut i8;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment