diff --git a/src-tauri/plugins/tauri-plugin-hardware/src/vendor/vulkan.rs b/src-tauri/plugins/tauri-plugin-hardware/src/vendor/vulkan.rs index d9c896918..d911e7013 100644 --- a/src-tauri/plugins/tauri-plugin-hardware/src/vendor/vulkan.rs +++ b/src-tauri/plugins/tauri-plugin-hardware/src/vendor/vulkan.rs @@ -45,20 +45,41 @@ pub fn get_vulkan_gpus(lib_path: &str) -> Vec { } } -fn parse_c_string_i8(buf: &[i8]) -> String { - unsafe { std::ffi::CStr::from_ptr(buf.as_ptr() as *const u8) } +fn parse_c_string_u8(buf: &[u8]) -> String { + unsafe { std::ffi::CStr::from_ptr(buf.as_ptr() as *const std::ffi::c_char) } .to_str() .unwrap_or_default() .to_string() } -fn parse_c_string_u8(buf: &[u8]) -> String { - unsafe { std::ffi::CStr::from_ptr(buf.as_ptr()) } +fn parse_c_string_i8(buf: &[i8]) -> String { + unsafe { std::ffi::CStr::from_ptr(buf.as_ptr() as *const std::ffi::c_char) } .to_str() .unwrap_or_default() .to_string() } +fn parse_c_string_platform_specific(buf: &[std::ffi::c_char]) -> String { + #[cfg(target_os = "android")] + { + // Android typically uses i8 for c_char + let i8_buf = unsafe { std::slice::from_raw_parts(buf.as_ptr() as *const i8, buf.len()) }; + parse_c_string_i8(i8_buf) + } + #[cfg(target_os = "ios")] + { + // iOS typically uses i8 for c_char + let i8_buf = unsafe { std::slice::from_raw_parts(buf.as_ptr() as *const i8, buf.len()) }; + parse_c_string_i8(i8_buf) + } + #[cfg(not(any(target_os = "android", target_os = "ios")))] + { + // Desktop platforms typically use u8 for c_char + let u8_buf = unsafe { std::slice::from_raw_parts(buf.as_ptr() as *const u8, buf.len()) }; + parse_c_string_u8(u8_buf) + } +} + fn get_vulkan_gpus_internal(lib_path: &str) -> Result, Box> { let entry = if lib_path.is_empty() { unsafe { Entry::load()? } @@ -103,7 +124,7 @@ fn get_vulkan_gpus_internal(lib_path: &str) -> Result, Box Result, Box