1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-20 23:28:26 -04:00
nix/nix-rust/src/lib.rs

34 lines
773 B
Rust
Raw Normal View History

2019-09-10 15:55:32 -04:00
mod error;
mod foreign;
mod tarfile;
2019-03-27 09:12:20 -04:00
2019-09-10 15:55:32 -04:00
pub use error::Error;
pub struct CBox<T> {
ptr: *mut libc::c_void,
phantom: std::marker::PhantomData<T>,
}
impl<T> CBox<T> {
fn new(t: T) -> Self {
unsafe {
let size = std::mem::size_of::<T>();
let ptr = libc::malloc(size);
eprintln!("PTR = {:?}, SIZE = {}", ptr, size);
*(ptr as *mut T) = t; // FIXME: probably UB
Self {
ptr,
phantom: std::marker::PhantomData,
}
}
}
}
2019-03-27 09:12:20 -04:00
#[no_mangle]
pub extern "C" fn unpack_tarfile(
source: foreign::Source,
dest_dir: &str,
) -> CBox<Result<(), error::CppException>> {
CBox::new(tarfile::unpack_tarfile(source, dest_dir).map_err(|err| err.into()))
2019-03-27 09:12:20 -04:00
}