1#![allow(non_camel_case_types)]
2#![allow(non_snake_case)]
3
4use std::os::raw::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_void};
5
6#[cfg(not(zng))]
9macro_rules! if_zng {
10 ($_zng:tt, $not_zng:tt) => {
11 $not_zng
12 };
13}
14
15#[cfg(zng)]
16macro_rules! if_zng {
17 ($zng:tt, $_not_zng:tt) => {
18 $zng
19 };
20}
21
22type z_size = if_zng!(usize, c_ulong);
24
25type z_checksum = if_zng!(u32, c_ulong);
27
28pub type alloc_func = unsafe extern "C" fn(voidpf, uInt, uInt) -> voidpf;
29pub type Bytef = u8;
30pub type free_func = unsafe extern "C" fn(voidpf, voidpf);
31#[cfg(any(zng, feature = "libc"))]
32pub type gzFile = *mut gzFile_s;
33pub type in_func = unsafe extern "C" fn(*mut c_void, *mut *const c_uchar) -> c_uint;
34pub type out_func = unsafe extern "C" fn(*mut c_void, *mut c_uchar, c_uint) -> c_int;
35pub type uInt = c_uint;
36pub type uLong = c_ulong;
37pub type uLongf = c_ulong;
38pub type voidp = *mut c_void;
39pub type voidpc = *const c_void;
40pub type voidpf = *mut c_void;
41
42#[cfg(any(zng, feature = "libc"))]
43pub enum gzFile_s {}
44pub enum internal_state {}
45
46#[cfg(all(
47 not(zng),
48 feature = "libc",
49 not(all(target_family = "wasm", target_os = "unknown"))
50))]
51pub type z_off_t = libc::off_t;
52
53#[cfg(all(
54 not(zng),
55 feature = "libc",
56 all(target_family = "wasm", target_os = "unknown")
57))]
58pub type z_off_t = c_long;
59
60#[cfg(all(zng, windows, not(target_env = "gnu")))]
61pub type z_off_t = i64;
62
63#[cfg(all(zng, not(all(windows, not(target_env = "gnu")))))]
64pub type z_off_t = libc::off_t;
65
66#[repr(C)]
67#[derive(Copy, Clone)]
68pub struct gz_header {
69 pub text: c_int,
70 pub time: uLong,
71 pub xflags: c_int,
72 pub os: c_int,
73 pub extra: *mut Bytef,
74 pub extra_len: uInt,
75 pub extra_max: uInt,
76 pub name: *mut Bytef,
77 pub name_max: uInt,
78 pub comment: *mut Bytef,
79 pub comm_max: uInt,
80 pub hcrc: c_int,
81 pub done: c_int,
82}
83pub type gz_headerp = *mut gz_header;
84
85#[repr(C)]
86#[derive(Copy, Clone)]
87pub struct z_stream {
88 pub next_in: *mut Bytef,
89 pub avail_in: uInt,
90 pub total_in: z_size,
91 pub next_out: *mut Bytef,
92 pub avail_out: uInt,
93 pub total_out: z_size,
94 pub msg: *mut c_char,
95 pub state: *mut internal_state,
96 pub zalloc: alloc_func,
97 pub zfree: free_func,
98 pub opaque: voidpf,
99 pub data_type: c_int,
100 pub adler: z_checksum,
101 pub reserved: uLong,
102}
103pub type z_streamp = *mut z_stream;
104
105#[cfg(not(zng))]
109macro_rules! zng_prefix {
110 ($name:expr) => {
111 stringify!($name)
112 };
113}
114
115#[cfg(zng)]
116macro_rules! zng_prefix {
117 ($name:expr) => {
118 concat!("zng_", stringify!($name))
119 };
120}
121
122extern "C" {
123 #[link_name = zng_prefix!(adler32)]
124 pub fn adler32(adler: z_checksum, buf: *const Bytef, len: uInt) -> z_checksum;
125 #[link_name = zng_prefix!(crc32)]
126 pub fn crc32(crc: z_checksum, buf: *const Bytef, len: uInt) -> z_checksum;
127 #[link_name = zng_prefix!(deflate)]
128 pub fn deflate(strm: z_streamp, flush: c_int) -> c_int;
129 #[link_name = zng_prefix!(deflateBound)]
130 pub fn deflateBound(strm: z_streamp, sourceLen: uLong) -> uLong;
131 #[link_name = zng_prefix!(deflateCopy)]
132 pub fn deflateCopy(dest: z_streamp, source: z_streamp) -> c_int;
133 #[link_name = zng_prefix!(deflateEnd)]
134 pub fn deflateEnd(strm: z_streamp) -> c_int;
135 #[link_name = zng_prefix!(deflateParams)]
136 pub fn deflateParams(strm: z_streamp, level: c_int, strategy: c_int) -> c_int;
137 #[link_name = zng_prefix!(deflatePrime)]
138 pub fn deflatePrime(strm: z_streamp, bits: c_int, value: c_int) -> c_int;
139 #[link_name = zng_prefix!(deflateReset)]
140 pub fn deflateReset(strm: z_streamp) -> c_int;
141 #[link_name = zng_prefix!(deflateSetDictionary)]
142 pub fn deflateSetDictionary(
143 strm: z_streamp,
144 dictionary: *const Bytef,
145 dictLength: uInt,
146 ) -> c_int;
147 #[link_name = zng_prefix!(deflateSetHeader)]
148 pub fn deflateSetHeader(strm: z_streamp, head: gz_headerp) -> c_int;
149 #[link_name = zng_prefix!(deflateTune)]
150 pub fn deflateTune(
151 strm: z_streamp,
152 good_length: c_int,
153 max_lazy: c_int,
154 nice_length: c_int,
155 max_chain: c_int,
156 ) -> c_int;
157 #[link_name = zng_prefix!(inflate)]
158 pub fn inflate(strm: z_streamp, flush: c_int) -> c_int;
159 #[link_name = zng_prefix!(inflateBack)]
160 pub fn inflateBack(
161 strm: z_streamp,
162 _in: in_func,
163 in_desc: *mut c_void,
164 out: out_func,
165 out_desc: *mut c_void,
166 ) -> c_int;
167 #[link_name = zng_prefix!(inflateBackEnd)]
168 pub fn inflateBackEnd(strm: z_streamp) -> c_int;
169 #[link_name = zng_prefix!(inflateCopy)]
170 pub fn inflateCopy(dest: z_streamp, source: z_streamp) -> c_int;
171 #[link_name = zng_prefix!(inflateEnd)]
172 pub fn inflateEnd(strm: z_streamp) -> c_int;
173 #[link_name = zng_prefix!(inflateGetHeader)]
174 pub fn inflateGetHeader(strm: z_streamp, head: gz_headerp) -> c_int;
175 #[link_name = zng_prefix!(inflateMark)]
176 pub fn inflateMark(strm: z_streamp) -> c_long;
177 #[link_name = zng_prefix!(inflatePrime)]
178 pub fn inflatePrime(strm: z_streamp, bits: c_int, value: c_int) -> c_int;
179 #[link_name = zng_prefix!(inflateReset)]
180 pub fn inflateReset(strm: z_streamp) -> c_int;
181 #[link_name = zng_prefix!(inflateReset2)]
182 pub fn inflateReset2(strm: z_streamp, windowBits: c_int) -> c_int;
183 #[link_name = zng_prefix!(inflateSetDictionary)]
184 pub fn inflateSetDictionary(
185 strm: z_streamp,
186 dictionary: *const Bytef,
187 dictLength: uInt,
188 ) -> c_int;
189 #[link_name = zng_prefix!(inflateSync)]
190 pub fn inflateSync(strm: z_streamp) -> c_int;
191 #[link_name = zng_prefix!(zlibCompileFlags)]
192 pub fn zlibCompileFlags() -> uLong;
193
194 }
215
216extern "C" {
217 #[link_name = if_zng!("zlibng_version", "zlibVersion")]
218 pub fn zlibVersion() -> *const c_char;
219}
220
221#[cfg(not(zng))]
222extern "C" {
223 pub fn deflateInit_(
224 strm: z_streamp,
225 level: c_int,
226 version: *const c_char,
227 stream_size: c_int,
228 ) -> c_int;
229 pub fn deflateInit2_(
230 strm: z_streamp,
231 level: c_int,
232 method: c_int,
233 windowBits: c_int,
234 memLevel: c_int,
235 strategy: c_int,
236 version: *const c_char,
237 stream_size: c_int,
238 ) -> c_int;
239 pub fn inflateBackInit_(
240 strm: z_streamp,
241 windowBits: c_int,
242 window: *mut c_uchar,
243 version: *const c_char,
244 stream_size: c_int,
245 ) -> c_int;
246 pub fn inflateInit_(strm: z_streamp, version: *const c_char, stream_size: c_int) -> c_int;
247 pub fn inflateInit2_(
248 strm: z_streamp,
249 windowBits: c_int,
250 version: *const c_char,
251 stream_size: c_int,
252 ) -> c_int;
253}
254
255#[cfg(zng)]
256extern "C" {
257 pub fn zng_deflateInit(strm: z_streamp, level: c_int) -> c_int;
258 pub fn zng_deflateInit2(
259 strm: z_streamp,
260 level: c_int,
261 method: c_int,
262 windowBits: c_int,
263 memLevel: c_int,
264 strategy: c_int,
265 ) -> c_int;
266 pub fn zng_inflateBackInit(strm: z_streamp, windowBits: c_int, window: *mut c_uchar) -> c_int;
267 pub fn zng_inflateInit(strm: z_streamp) -> c_int;
268 pub fn zng_inflateInit2(strm: z_streamp, windowBits: c_int) -> c_int;
269}
270
271#[cfg(zng)]
273#[inline(always)]
274pub unsafe fn inflateInit2_(
275 strm: z_streamp,
276 windowBits: c_int,
277 _version: *const c_char,
278 _stream_size: c_int,
279) -> c_int {
280 zng_inflateInit2(strm, windowBits)
281}
282
283#[cfg(zng)]
284#[inline(always)]
285pub unsafe fn inflateInit_(strm: z_streamp, _version: *const c_char, _stream_size: c_int) -> c_int {
286 zng_inflateInit(strm)
287}
288
289#[cfg(zng)]
290#[inline(always)]
291pub unsafe fn inflateBackInit_(
292 strm: z_streamp,
293 windowBits: c_int,
294 window: *mut c_uchar,
295 _version: *const c_char,
296 _stream_size: c_int,
297) -> c_int {
298 zng_inflateBackInit(strm, windowBits, window)
299}
300
301#[cfg(zng)]
302#[inline(always)]
303pub unsafe fn deflateInit2_(
304 strm: z_streamp,
305 level: c_int,
306 method: c_int,
307 windowBits: c_int,
308 memLevel: c_int,
309 strategy: c_int,
310 _version: *const c_char,
311 _stream_size: c_int,
312) -> c_int {
313 zng_deflateInit2(strm, level, method, windowBits, memLevel, strategy)
314}
315
316#[cfg(zng)]
317#[inline]
318pub unsafe fn deflateInit_(
319 strm: z_streamp,
320 level: c_int,
321 _version: *const c_char,
322 _stream_size: c_int,
323) -> c_int {
324 zng_deflateInit(strm, level)
325}
326
327#[cfg(any(zng, feature = "libc"))]
328extern "C" {
329 #[link_name = zng_prefix!(adler32_combine)]
330 pub fn adler32_combine(adler1: z_checksum, adler2: z_checksum, len2: z_off_t) -> z_checksum;
331 #[link_name = zng_prefix!(compress)]
332 pub fn compress(
333 dest: *mut Bytef,
334 destLen: *mut z_size,
335 source: *const Bytef,
336 sourceLen: z_size,
337 ) -> c_int;
338 #[link_name = zng_prefix!(compress2)]
339 pub fn compress2(
340 dest: *mut Bytef,
341 destLen: *mut z_size,
342 source: *const Bytef,
343 sourceLen: z_size,
344 level: c_int,
345 ) -> c_int;
346 #[link_name = zng_prefix!(compressBound)]
347 pub fn compressBound(sourceLen: z_size) -> z_size;
348 #[link_name = zng_prefix!(crc32_combine)]
349 pub fn crc32_combine(crc1: z_checksum, crc2: z_checksum, len2: z_off_t) -> z_checksum;
350 #[link_name = zng_prefix!(gzdirect)]
351 pub fn gzdirect(file: gzFile) -> c_int;
352 #[link_name = zng_prefix!(gzdopen)]
353 pub fn gzdopen(fd: c_int, mode: *const c_char) -> gzFile;
354 #[link_name = zng_prefix!(gzclearerr)]
355 pub fn gzclearerr(file: gzFile);
356 #[link_name = zng_prefix!(gzclose)]
357 pub fn gzclose(file: gzFile) -> c_int;
358 #[link_name = zng_prefix!(gzeof)]
359 pub fn gzeof(file: gzFile) -> c_int;
360 #[link_name = zng_prefix!(gzerror)]
361 pub fn gzerror(file: gzFile, errnum: *mut c_int) -> *const c_char;
362 #[link_name = zng_prefix!(gzflush)]
363 pub fn gzflush(file: gzFile, flush: c_int) -> c_int;
364 #[link_name = zng_prefix!(gzgetc)]
365 pub fn gzgetc(file: gzFile) -> c_int;
366 #[link_name = zng_prefix!(gzgets)]
367 pub fn gzgets(file: gzFile, buf: *mut c_char, len: c_int) -> *mut c_char;
368 #[link_name = zng_prefix!(gzopen)]
369 pub fn gzopen(path: *const c_char, mode: *const c_char) -> gzFile;
370 #[link_name = zng_prefix!(gzputc)]
371 pub fn gzputc(file: gzFile, c: c_int) -> c_int;
372 #[link_name = zng_prefix!(gzputs)]
373 pub fn gzputs(file: gzFile, s: *const c_char) -> c_int;
374 #[link_name = zng_prefix!(gzread)]
375 pub fn gzread(file: gzFile, buf: voidp, len: c_uint) -> c_int;
376 #[link_name = zng_prefix!(gzrewind)]
377 pub fn gzrewind(file: gzFile) -> c_int;
378 #[link_name = zng_prefix!(gzseek)]
379 pub fn gzseek(file: gzFile, offset: z_off_t, whence: c_int) -> z_off_t;
380 #[link_name = zng_prefix!(gzsetparams)]
381 pub fn gzsetparams(file: gzFile, level: c_int, strategy: c_int) -> c_int;
382 #[link_name = zng_prefix!(gztell)]
383 pub fn gztell(file: gzFile) -> z_off_t;
384 #[link_name = zng_prefix!(gzungetc)]
385 pub fn gzungetc(c: c_int, file: gzFile) -> c_int;
386 #[link_name = zng_prefix!(gzwrite)]
387 pub fn gzwrite(file: gzFile, buf: voidpc, len: c_uint) -> c_int;
388 #[link_name = zng_prefix!(uncompress)]
389 pub fn uncompress(
390 dest: *mut Bytef,
391 destLen: *mut z_size,
392 source: *const Bytef,
393 sourceLen: z_size,
394 ) -> c_int;
395}
396
397pub const Z_NO_FLUSH: c_int = 0;
398pub const Z_PARTIAL_FLUSH: c_int = 1;
399pub const Z_SYNC_FLUSH: c_int = 2;
400pub const Z_FULL_FLUSH: c_int = 3;
401pub const Z_FINISH: c_int = 4;
402pub const Z_BLOCK: c_int = 5;
403pub const Z_TREES: c_int = 6;
404
405pub const Z_OK: c_int = 0;
406pub const Z_STREAM_END: c_int = 1;
407pub const Z_NEED_DICT: c_int = 2;
408pub const Z_ERRNO: c_int = -1;
409pub const Z_STREAM_ERROR: c_int = -2;
410pub const Z_DATA_ERROR: c_int = -3;
411pub const Z_MEM_ERROR: c_int = -4;
412pub const Z_BUF_ERROR: c_int = -5;
413pub const Z_VERSION_ERROR: c_int = -6;
414
415pub const Z_NO_COMPRESSION: c_int = 0;
416pub const Z_BEST_SPEED: c_int = 1;
417pub const Z_BEST_COMPRESSION: c_int = 9;
418pub const Z_DEFAULT_COMPRESSION: c_int = -1;
419
420pub const Z_FILTERED: c_int = 1;
421pub const Z_HUFFMAN_ONLY: c_int = 2;
422pub const Z_RLE: c_int = 3;
423pub const Z_FIXED: c_int = 4;
424pub const Z_DEFAULT_STRATEGY: c_int = 0;
425
426pub const Z_BINARY: c_int = 0;
427pub const Z_TEXT: c_int = 1;
428pub const Z_ASCII: c_int = Z_TEXT;
429pub const Z_UNKNOWN: c_int = 2;
430
431pub const Z_DEFLATED: c_int = 8;