1#![allow(non_camel_case_types)]
2#![allow(non_snake_case)]
3
4use core::ffi::{c_char, c_int, c_uchar, c_uint, c_ulong, c_void};
5
6use crate::allocate::Allocator;
7
8pub type alloc_func = unsafe extern "C" fn(voidpf, uInt, uInt) -> voidpf;
9pub type free_func = unsafe extern "C" fn(voidpf, voidpf);
10
11pub type Bytef = u8;
12pub type in_func = unsafe extern "C" fn(*mut c_void, *mut *const c_uchar) -> c_uint;
13pub type out_func = unsafe extern "C" fn(*mut c_void, *mut c_uchar, c_uint) -> c_int;
14pub type uInt = c_uint;
15pub type uLong = c_ulong;
16pub type uLongf = c_ulong;
17pub type voidp = *mut c_void;
18pub type voidpc = *const c_void;
19pub type voidpf = *mut c_void;
20
21#[repr(C)]
55#[derive(Copy, Clone)]
56pub struct z_stream {
57 pub next_in: *const Bytef,
58 pub avail_in: uInt,
59 pub total_in: z_size,
60 pub next_out: *mut Bytef,
61 pub avail_out: uInt,
62 pub total_out: z_size,
63 pub msg: *mut c_char,
64 pub state: *mut internal_state,
65 pub zalloc: Option<alloc_func>,
66 pub zfree: Option<free_func>,
67 pub opaque: voidpf,
68 pub data_type: c_int,
69 pub adler: z_checksum,
70 pub reserved: uLong,
71}
72pub type z_streamp = *mut z_stream;
73
74impl Default for z_stream {
75 fn default() -> Self {
76 let mut stream = Self {
77 next_in: core::ptr::null_mut(),
78 avail_in: 0,
79 total_in: 0,
80 next_out: core::ptr::null_mut(),
81 avail_out: 0,
82 total_out: 0,
83 msg: core::ptr::null_mut(),
84 state: core::ptr::null_mut(),
85 zalloc: None,
86 zfree: None,
87 opaque: core::ptr::null_mut(),
88 data_type: 0,
89 adler: 0,
90 reserved: 0,
91 };
92
93 #[cfg(feature = "rust-allocator")]
94 if stream.zalloc.is_none() || stream.zfree.is_none() {
95 stream.configure_default_rust_allocator()
96 }
97
98 #[cfg(feature = "c-allocator")]
99 if stream.zalloc.is_none() || stream.zfree.is_none() {
100 stream.configure_default_c_allocator()
101 }
102
103 stream
104 }
105}
106
107impl z_stream {
108 fn configure_allocator(&mut self, alloc: Allocator) {
109 self.zalloc = Some(alloc.zalloc);
110 self.zfree = Some(alloc.zfree);
111 self.opaque = alloc.opaque;
112 }
113
114 #[cfg(feature = "rust-allocator")]
115 pub fn configure_default_rust_allocator(&mut self) {
116 self.configure_allocator(crate::allocate::RUST)
117 }
118
119 #[cfg(feature = "c-allocator")]
120 pub fn configure_default_c_allocator(&mut self) {
121 self.configure_allocator(crate::allocate::C)
122 }
123}
124
125pub(crate) type z_size = c_ulong;
127pub(crate) type z_checksum = c_ulong;
128
129pub enum internal_state {}
131
132pub const Z_NO_FLUSH: c_int = 0;
133pub const Z_PARTIAL_FLUSH: c_int = 1;
134pub const Z_SYNC_FLUSH: c_int = 2;
135pub const Z_FULL_FLUSH: c_int = 3;
136pub const Z_FINISH: c_int = 4;
137pub const Z_BLOCK: c_int = 5;
138pub const Z_TREES: c_int = 6;
139
140pub const Z_OK: c_int = 0;
141pub const Z_STREAM_END: c_int = 1;
142pub const Z_NEED_DICT: c_int = 2;
143pub const Z_ERRNO: c_int = -1;
144pub const Z_STREAM_ERROR: c_int = -2;
145pub const Z_DATA_ERROR: c_int = -3;
146pub const Z_MEM_ERROR: c_int = -4;
147pub const Z_BUF_ERROR: c_int = -5;
148pub const Z_VERSION_ERROR: c_int = -6;
149
150pub const Z_NO_COMPRESSION: c_int = 0;
151pub const Z_BEST_SPEED: c_int = 1;
152pub const Z_BEST_COMPRESSION: c_int = 9;
153pub const Z_DEFAULT_COMPRESSION: c_int = -1;
154
155pub const Z_DEFLATED: c_int = 8;
156
157pub const Z_BINARY: c_int = 0;
158pub const Z_TEXT: c_int = 1;
159pub const Z_ASCII: c_int = Z_TEXT; pub const Z_UNKNOWN: c_int = 2;
161
162pub const Z_FILTERED: c_int = 1;
163pub const Z_HUFFMAN_ONLY: c_int = 2;
164pub const Z_RLE: c_int = 3;
165pub const Z_FIXED: c_int = 4;
166pub const Z_DEFAULT_STRATEGY: c_int = 0;
167
168pub type gz_headerp = *mut gz_header;
169
170#[derive(Debug)]
173#[repr(C)]
174pub struct gz_header {
175 pub text: i32,
177 pub time: c_ulong,
179 pub xflags: i32,
181 pub os: i32,
183 pub extra: *mut u8,
185 pub extra_len: u32,
187 pub extra_max: u32,
189 pub name: *mut u8,
191 pub name_max: u32,
193 pub comment: *mut u8,
195 pub comm_max: u32,
197 pub hcrc: i32,
199 pub done: i32,
201}
202
203impl Default for gz_header {
204 fn default() -> Self {
205 Self {
206 text: 0,
207 time: 0,
208 xflags: 0,
209 os: 0,
210 extra: core::ptr::null_mut(),
211 extra_len: 0,
212 extra_max: 0,
213 name: core::ptr::null_mut(),
214 name_max: 0,
215 comment: core::ptr::null_mut(),
216 comm_max: 0,
217 hcrc: 0,
218 done: 0,
219 }
220 }
221}
222
223impl gz_header {
224 #[allow(clippy::if_same_then_else)]
242 pub const OS_CODE: u8 = {
243 if cfg!(windows) {
244 10
245 } else if cfg!(target_os = "macos") {
246 19
247 } else if cfg!(unix) {
248 3
249 } else {
250 3 }
252 };
253
254 pub(crate) fn flags(&self) -> u8 {
255 (if self.text != 0 { 1 } else { 0 })
256 + (if self.hcrc != 0 { 2 } else { 0 })
257 + (if self.extra.is_null() { 0 } else { 4 })
258 + (if self.name.is_null() { 0 } else { 8 })
259 + (if self.comment.is_null() { 0 } else { 16 })
260 }
261}