use std::ffi::{CStr, CString, c_char};
pub unsafe fn borrow_cstr(p: *const c_char) -> Option<String> {
if p.is_null() {
return None;
}
Some(unsafe { CStr::from_ptr(p) }.to_string_lossy().into_owned())
}
pub fn cstring(value: &str, what: &str) -> CString {
CString::new(value)
.unwrap_or_else(|_| panic!("ek-ctp native: {what} contains an interior NUL byte"))
}
pub fn last_error() -> Option<String> {
let p = unsafe { ek_shim_last_error() };
unsafe { borrow_cstr(p) }
}
pub fn truncations() -> u64 {
unsafe { ek_shim_truncations() }
}
unsafe extern "C" {
fn ek_shim_last_error() -> *const c_char;
fn ek_shim_truncations() -> u64;
}