2019-09-10 21:55:32 +02:00
|
|
|
mod error;
|
|
|
|
mod foreign;
|
|
|
|
mod tarfile;
|
2019-03-27 14:12:20 +01:00
|
|
|
|
2019-09-10 21:55:32 +02:00
|
|
|
pub use error::Error;
|
2019-03-27 20:45:56 +01:00
|
|
|
|
2019-09-11 01:15:20 +02:00
|
|
|
pub struct CBox<T> {
|
2019-09-11 12:44:31 +02:00
|
|
|
pub ptr: *mut libc::c_void,
|
2019-09-11 01:15:20 +02:00
|
|
|
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);
|
|
|
|
*(ptr as *mut T) = t; // FIXME: probably UB
|
|
|
|
Self {
|
|
|
|
ptr,
|
|
|
|
phantom: std::marker::PhantomData,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-27 14:12:20 +01:00
|
|
|
#[no_mangle]
|
2019-09-11 01:15:20 +02:00
|
|
|
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 14:12:20 +01:00
|
|
|
}
|