1use std::{ffi::CString, os::raw::c_char};
2
3use crate::{BINK_FAIL, BINK_FAIL_NULL_POINTER, BINK_OK};
4
5#[allow(clippy::not_unsafe_ptr_arg_deref)]
6#[no_mangle]
7pub extern "C" fn bink_tags_get(
8 tags: *const Vec<String>,
9 idx: usize,
10 tag: *mut *mut c_char,
11) -> u32 {
12 if tags.is_null() {
13 return BINK_FAIL_NULL_POINTER;
14 }
15
16 let tags: &Vec<String> = unsafe { &*tags };
17
18 let t = tags.get(idx);
19
20 match t {
21 Some(t) => unsafe {
22 *tag = CString::new(t.as_str()).unwrap_or_default().into_raw();
23 },
24 None => {
25 return BINK_FAIL;
26 }
27 }
28
29 BINK_OK
30}
31
32#[allow(clippy::not_unsafe_ptr_arg_deref)]
33#[no_mangle]
34pub extern "C" fn bink_tags_free(tags: *mut Vec<String>) {
35 if !tags.is_null() {
36 unsafe {
37 drop(Box::from_raw(tags));
38 }
39 }
40}