bzip2_sys/
lib.rs

1#![doc(html_root_url = "https://docs.rs/bzip2-sys/0.1")]
2
3extern crate libc;
4
5use libc::{c_char, c_int, c_uint, c_void};
6
7pub const BZ_RUN: c_int = 0;
8pub const BZ_FLUSH: c_int = 1;
9pub const BZ_FINISH: c_int = 2;
10
11pub const BZ_OK: c_int = 0;
12pub const BZ_RUN_OK: c_int = 1;
13pub const BZ_FLUSH_OK: c_int = 2;
14pub const BZ_FINISH_OK: c_int = 3;
15pub const BZ_STREAM_END: c_int = 4;
16pub const BZ_SEQUENCE_ERROR: c_int = -1;
17pub const BZ_PARAM_ERROR: c_int = -2;
18pub const BZ_MEM_ERROR: c_int = -3;
19pub const BZ_DATA_ERROR: c_int = -4;
20pub const BZ_DATA_ERROR_MAGIC: c_int = -5;
21pub const BZ_IO_ERROR: c_int = -6;
22pub const BZ_UNEXPECTED_EOF: c_int = -7;
23pub const BZ_OUTBUFF_FULL: c_int = -8;
24pub const BZ_CONFIG_ERROR: c_int = -9;
25
26#[repr(C)]
27pub struct bz_stream {
28    pub next_in: *mut c_char,
29    pub avail_in: c_uint,
30    pub total_in_lo32: c_uint,
31    pub total_in_hi32: c_uint,
32
33    pub next_out: *mut c_char,
34    pub avail_out: c_uint,
35    pub total_out_lo32: c_uint,
36    pub total_out_hi32: c_uint,
37
38    pub state: *mut c_void,
39
40    pub bzalloc: Option<extern "C" fn(*mut c_void, c_int, c_int) -> *mut c_void>,
41    pub bzfree: Option<extern "C" fn(*mut c_void, *mut c_void)>,
42    pub opaque: *mut c_void,
43}
44
45macro_rules! abi_compat {
46    ($(pub fn $name:ident($($arg:ident: $t:ty),*) -> $ret:ty,)*) => {
47        #[cfg(windows)]
48        extern "system" {
49            $(pub fn $name($($arg: $t),*) -> $ret;)*
50        }
51        #[cfg(not(windows))]
52        extern {
53            $(pub fn $name($($arg: $t),*) -> $ret;)*
54        }
55    }
56}
57
58abi_compat! {
59    pub fn BZ2_bzCompressInit(stream: *mut bz_stream,
60                              blockSize100k: c_int,
61                              verbosity: c_int,
62                              workFactor: c_int) -> c_int,
63    pub fn BZ2_bzCompress(stream: *mut bz_stream, action: c_int) -> c_int,
64    pub fn BZ2_bzCompressEnd(stream: *mut bz_stream) -> c_int,
65    pub fn BZ2_bzDecompressInit(stream: *mut bz_stream,
66                                verbosity: c_int,
67                                small: c_int) -> c_int,
68    pub fn BZ2_bzDecompress(stream: *mut bz_stream) -> c_int,
69    pub fn BZ2_bzDecompressEnd(stream: *mut bz_stream) -> c_int,
70}
71
72#[no_mangle]
73pub fn bz_internal_error(errcode: c_int) {
74    panic!("bz internal error: {}", errcode);
75}