#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
use core::ffi::{c_char, c_int, c_uchar, c_uint, c_ulong, c_void};
use crate::allocate::Allocator;
pub type alloc_func = unsafe extern "C" fn(voidpf, uInt, uInt) -> voidpf;
pub type free_func = unsafe extern "C" fn(voidpf, voidpf);
pub type Bytef = u8;
pub type in_func = unsafe extern "C" fn(*mut c_void, *mut *const c_uchar) -> c_uint;
pub type out_func = unsafe extern "C" fn(*mut c_void, *mut c_uchar, c_uint) -> c_int;
pub type uInt = c_uint;
pub type uLong = c_ulong;
pub type uLongf = c_ulong;
pub type voidp = *mut c_void;
pub type voidpc = *const c_void;
pub type voidpf = *mut c_void;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct z_stream {
pub next_in: *const Bytef,
pub avail_in: uInt,
pub total_in: z_size,
pub next_out: *mut Bytef,
pub avail_out: uInt,
pub total_out: z_size,
pub msg: *mut c_char,
pub state: *mut internal_state,
pub zalloc: Option<alloc_func>,
pub zfree: Option<free_func>,
pub opaque: voidpf,
pub data_type: c_int,
pub adler: z_checksum,
pub reserved: uLong,
}
pub type z_streamp = *mut z_stream;
impl Default for z_stream {
fn default() -> Self {
let mut stream = Self {
next_in: core::ptr::null_mut(),
avail_in: 0,
total_in: 0,
next_out: core::ptr::null_mut(),
avail_out: 0,
total_out: 0,
msg: core::ptr::null_mut(),
state: core::ptr::null_mut(),
zalloc: None,
zfree: None,
opaque: core::ptr::null_mut(),
data_type: 0,
adler: 0,
reserved: 0,
};
#[cfg(feature = "rust-allocator")]
if stream.zalloc.is_none() || stream.zfree.is_none() {
stream.configure_default_rust_allocator()
}
#[cfg(feature = "c-allocator")]
if stream.zalloc.is_none() || stream.zfree.is_none() {
stream.configure_default_c_allocator()
}
stream
}
}
impl z_stream {
fn configure_allocator(&mut self, alloc: Allocator) {
self.zalloc = Some(alloc.zalloc);
self.zfree = Some(alloc.zfree);
self.opaque = alloc.opaque;
}
#[cfg(feature = "rust-allocator")]
pub fn configure_default_rust_allocator(&mut self) {
self.configure_allocator(Allocator::RUST)
}
#[cfg(feature = "c-allocator")]
pub fn configure_default_c_allocator(&mut self) {
self.configure_allocator(Allocator::C)
}
}
pub(crate) type z_size = c_ulong;
pub(crate) type z_checksum = c_ulong;
pub enum internal_state {}
pub const Z_NO_FLUSH: c_int = 0;
pub const Z_PARTIAL_FLUSH: c_int = 1;
pub const Z_SYNC_FLUSH: c_int = 2;
pub const Z_FULL_FLUSH: c_int = 3;
pub const Z_FINISH: c_int = 4;
pub const Z_BLOCK: c_int = 5;
pub const Z_TREES: c_int = 6;
pub const Z_OK: c_int = 0;
pub const Z_STREAM_END: c_int = 1;
pub const Z_NEED_DICT: c_int = 2;
pub const Z_ERRNO: c_int = -1;
pub const Z_STREAM_ERROR: c_int = -2;
pub const Z_DATA_ERROR: c_int = -3;
pub const Z_MEM_ERROR: c_int = -4;
pub const Z_BUF_ERROR: c_int = -5;
pub const Z_VERSION_ERROR: c_int = -6;
pub const Z_NO_COMPRESSION: c_int = 0;
pub const Z_BEST_SPEED: c_int = 1;
pub const Z_BEST_COMPRESSION: c_int = 9;
pub const Z_DEFAULT_COMPRESSION: c_int = -1;
pub const Z_DEFLATED: c_int = 8;
pub const Z_BINARY: c_int = 0;
pub const Z_TEXT: c_int = 1;
pub const Z_ASCII: c_int = Z_TEXT; pub const Z_UNKNOWN: c_int = 2;
pub const Z_FILTERED: c_int = 1;
pub const Z_HUFFMAN_ONLY: c_int = 2;
pub const Z_RLE: c_int = 3;
pub const Z_FIXED: c_int = 4;
pub const Z_DEFAULT_STRATEGY: c_int = 0;
pub type gz_headerp = *mut gz_header;
#[derive(Debug)]
#[repr(C)]
pub struct gz_header {
pub text: i32,
pub time: c_ulong,
pub xflags: i32,
pub os: i32,
pub extra: *mut u8,
pub extra_len: u32,
pub extra_max: u32,
pub name: *mut u8,
pub name_max: u32,
pub comment: *mut u8,
pub comm_max: u32,
pub hcrc: i32,
pub done: i32,
}
impl Default for gz_header {
fn default() -> Self {
Self {
text: 0,
time: 0,
xflags: 0,
os: 0,
extra: core::ptr::null_mut(),
extra_len: 0,
extra_max: 0,
name: core::ptr::null_mut(),
name_max: 0,
comment: core::ptr::null_mut(),
comm_max: 0,
hcrc: 0,
done: 0,
}
}
}
impl gz_header {
#[allow(clippy::if_same_then_else)]
pub const OS_CODE: u8 = {
if cfg!(windows) {
10
} else if cfg!(target_os = "macos") {
19
} else if cfg!(unix) {
3
} else {
3 }
};
pub(crate) fn flags(&self) -> u8 {
(if self.text > 0 { 1 } else { 0 })
+ (if self.hcrc > 0 { 2 } else { 0 })
+ (if self.extra.is_null() { 0 } else { 4 })
+ (if self.name.is_null() { 0 } else { 8 })
+ (if self.comment.is_null() { 0 } else { 16 })
}
}