summaryrefslogtreecommitdiffstats
path: root/third_party/rust/cubeb-core/src/util.rs
blob: 33008b668efd67af4a9e7022c0997796b1df9845 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Copyright © 2017 Mozilla Foundation
//
// This program is made available under an ISC-style license.  See the
// accompanying file LICENSE for details.

use std::ffi::CStr;
use std::os::raw::c_char;

pub unsafe fn opt_bytes<'a>(c: *const c_char) -> Option<&'a [u8]> {
    if c.is_null() {
        None
    } else {
        Some(CStr::from_ptr(c).to_bytes())
    }
}