1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! Bindings to [libtar][1].
//!
//! [1]: http://www.feep.net/libtar

extern crate libc;

use libc::{c_char, c_int, c_long, c_void};

// https://github.com/stainless-steel/libtar/blob/master/lib/libtar.h

#[repr(C)]
#[allow(dead_code, missing_copy_implementations)]
pub struct tar_header {
    name: [c_char; 100],
    mode: [c_char; 8],
    uid: [c_char; 8],
    gid: [c_char; 8],
    size: [c_char; 12],
    mtime: [c_char; 12],
    chksum: [c_char; 8],
    typeflag: c_char,
    linkname: [c_char; 100],
    magic: [c_char; 6],
    version: [c_char; 2],
    uname: [c_char; 32],
    gname: [c_char; 32],
    devmajor: [c_char; 8],
    devminor: [c_char; 8],
    prefix: [c_char; 155],
    padding: [c_char; 12],
    gnu_longname: *mut c_char,
    gnu_longlink: *mut c_char,
}

#[repr(C)]
#[allow(dead_code)]
pub struct TAR {
    typo: *mut c_void,
    pathname: *mut c_char,
    fd: c_long,
    oflags: c_int,
    options: c_int,
    th_buf: tar_header,
    h: *mut c_void,
}

extern {
    // https://github.com/stainless-steel/libtar/blob/master/lib/libtar.h

    pub fn tar_open(t: *mut *mut TAR, pathname: *const c_char, typo: *mut c_void,
                    oflags: c_int, mode: c_int, options: c_int) -> c_int;

    pub fn tar_close(t: *mut TAR) -> c_int;

    pub fn tar_extract_all(t: *mut TAR, prefix: *const c_char) -> c_int;
}