String Conversion Revamp

- String/&str to C char logic is revamped
This commit is contained in:
*Nix Fanboy
2024-10-25 15:15:29 +03:00
parent a56894585c
commit 96bfb178b0
14 changed files with 107 additions and 93 deletions

View File

@@ -1,16 +1,11 @@
use goblin::error::Error as ObjectError;
use std::ffi::c_char;
use std::fmt::Display;
use std::ptr::null_mut;
use crate::impls::StringToCString;
use crate::structs::Debugging;
pub(crate) fn find_error_type(error: &ObjectError) -> i64 {
match error {
ObjectError::Malformed(_) => -1,
ObjectError::BadMagic(_) => -2,
ObjectError::Scroll(_) => -3,
ObjectError::BufferTooShort(_, _) => -4,
ObjectError::IO(_) => -5,
_ => -6,
}
pub(crate) fn option_to_c_string<T>(option: Option<T>) -> *mut c_char where T: Display {
option.map(|v| v.to_c_string()).unwrap_or(null_mut())
}
pub(crate) fn merge_members(member_names: &mut [&str]) -> String {