babeltrace2-sys 0.3.1

Rust sys crate for babeltrace2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use crate::BtResult;
use std::ffi::CStr;
use std::os::raw::c_char;

pub(crate) fn opt_owned_cstr(ptr: *const c_char) -> BtResult<Option<String>> {
    if ptr.is_null() {
        Ok(None)
    } else {
        let s = unsafe { CStr::from_ptr(ptr) }.to_str()?;
        if s.is_empty() {
            Ok(None)
        } else {
            Ok(s.to_string().into())
        }
    }
}