bzip2_sys/
lib.rs

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