mirror of
https://github.com/szymon-jozef/libnotify-rs.git
synced 2026-10-27 19:20:43 +01:00
14 lines
371 B
Rust
14 lines
371 B
Rust
pub unsafe fn c_str_to_rs_str_and_free(c_str: *mut std::os::raw::c_char) -> Option<String> {
|
|
if c_str.is_null() {
|
|
return None;
|
|
}
|
|
|
|
let normal_string: String = unsafe { std::ffi::CStr::from_ptr(c_str) }
|
|
.to_string_lossy()
|
|
.to_string();
|
|
|
|
unsafe { super::libnotify::g_free(c_str as *mut std::ffi::c_void) };
|
|
|
|
Some(normal_string)
|
|
}
|