summaryrefslogtreecommitdiff
path: root/src/gallium/frontends/rusticl/util/string.rs
blob: eea8e4f867a56927d0cd269c1ba74e673bbd35ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
use std::ffi::CStr;
use std::os::raw::c_char;

#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn c_string_to_string(cstr: *const c_char) -> String {
    if cstr.is_null() {
        return String::from("");
    }

    let res = unsafe { CStr::from_ptr(cstr).to_str() };
    assert!(res.is_ok());
    String::from(res.unwrap_or(""))
}