1use std::{ffi::CStr, os::raw::c_char};
2#[allow(clippy::needless_range_loop)]
3pub fn string_to_array<const COUNT: usize>(s: &str) -> [c_char; COUNT] {
4 let mut a = [0 as c_char; COUNT];
5 let len = std::cmp::min(a.len() - 1, s.len());
6 for i in 0..len {
7 a[i] = s.as_bytes()[i] as c_char;
8 }
9 a
10}
11
12#[allow(clippy::not_unsafe_ptr_arg_deref)]
13pub fn cchar_to_string(c_str: *const c_char) -> String {
14 if c_str.is_null() {
15 return String::new();
16 }
17 unsafe { CStr::from_ptr(c_str).to_string_lossy().into_owned() }
18}
19
20#[allow(clippy::not_unsafe_ptr_arg_deref)]
21pub fn string_to_buffer(s: &str, buf: *mut u8, buf_max: usize) {
22 crate::xffi::xtr::string_to_buffer(s, buf, buf_max)
23}
24
25#[allow(clippy::not_unsafe_ptr_arg_deref)]
26pub fn string_to_dbuffer(s: &str, buf: *mut *mut u8, buf_max: *mut usize) {
27 crate::xffi::xtr::string_to_dbuffer(s, buf, buf_max)
28}