dope-core 0.77.0

Owned native I/O and completion driver for dope
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use o3::{alloc, alloc::BoxSliceExt as _};

pub(super) fn copy(base: &[u8], suffix: &[u8]) -> Result<Box<std::ffi::CStr>, alloc::Error> {
    let len = base.len() + suffix.len() + 1;
    let mut bytes = Box::<[u8]>::try_uninit(len)?;
    let (head, rest) = bytes.split_at_mut(base.len());
    let (tail, end) = rest.split_at_mut(suffix.len());
    head.write_copy_of_slice(base);
    tail.write_copy_of_slice(suffix);
    end[0].write(0);
    // SAFETY: both sources are NUL-free and every byte, including the terminator, is initialized.
    let name =
        unsafe { std::ffi::CString::from_vec_with_nul_unchecked(bytes.assume_init().into_vec()) };
    Ok(name.into_boxed_c_str())
}