1 #![allow(non_camel_case_types)] 2 3 use std::os::raw::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_void}; 4 5 // Macro for variances between zlib-ng in native mode and either zlib or zlib-ng in zlib compat 6 // mode. Note in particular that zlib-ng in compat mode does *not* use the zng case. 7 #[cfg(not(zng))] 8 macro_rules! if_zng { 9 ($_zng:tt, $not_zng:tt) => { 10 $not_zng 11 }; 12 } 13 14 #[cfg(zng)] 15 macro_rules! if_zng { 16 ($zng:tt, $_not_zng:tt) => { 17 $zng 18 }; 19 } 20 21 // zlib uses unsigned long for various sizes; zlib-ng uses size_t. 22 type z_size = if_zng!(usize, c_ulong); 23 24 // zlib stores Adler-32 and CRC-32 checksums in unsigned long; zlib-ng uses uint32_t. 25 type z_checksum = if_zng!(u32, c_ulong); 26 27 pub type alloc_func = unsafe extern "C" fn(voidpf, uInt, uInt) -> voidpf; 28 pub type Bytef = u8; 29 pub type free_func = unsafe extern "C" fn(voidpf, voidpf); 30 #[cfg(any(zng, feature = "libc"))] 31 pub type gzFile = *mut gzFile_s; 32 pub type in_func = unsafe extern "C" fn(*mut c_void, *mut *const c_uchar) -> c_uint; 33 pub type out_func = unsafe extern "C" fn(*mut c_void, *mut c_uchar, c_uint) -> c_int; 34 pub type uInt = c_uint; 35 pub type uLong = c_ulong; 36 pub type uLongf = c_ulong; 37 pub type voidp = *mut c_void; 38 pub type voidpc = *const c_void; 39 pub type voidpf = *mut c_void; 40 41 #[cfg(any(zng, feature = "libc"))] 42 pub enum gzFile_s {} 43 pub enum internal_state {} 44 45 #[cfg(all( 46 not(zng), 47 feature = "libc", 48 not(all(target_family = "wasm", target_os = "unknown")) 49 ))] 50 pub type z_off_t = libc::off_t; 51 52 #[cfg(all( 53 not(zng), 54 feature = "libc", 55 all(target_family = "wasm", target_os = "unknown") 56 ))] 57 pub type z_off_t = c_long; 58 59 #[cfg(zng)] 60 pub type z_off_t = i64; 61 62 #[repr(C)] 63 #[derive(Copy, Clone)] 64 pub struct gz_header { 65 pub text: c_int, 66 pub time: uLong, 67 pub xflags: c_int, 68 pub os: c_int, 69 pub extra: *mut Bytef, 70 pub extra_len: uInt, 71 pub extra_max: uInt, 72 pub name: *mut Bytef, 73 pub name_max: uInt, 74 pub comment: *mut Bytef, 75 pub comm_max: uInt, 76 pub hcrc: c_int, 77 pub done: c_int, 78 } 79 pub type gz_headerp = *mut gz_header; 80 81 #[repr(C)] 82 #[derive(Copy, Clone)] 83 pub struct z_stream { 84 pub next_in: *mut Bytef, 85 pub avail_in: uInt, 86 pub total_in: z_size, 87 pub next_out: *mut Bytef, 88 pub avail_out: uInt, 89 pub total_out: z_size, 90 pub msg: *mut c_char, 91 pub state: *mut internal_state, 92 pub zalloc: alloc_func, 93 pub zfree: free_func, 94 pub opaque: voidpf, 95 pub data_type: c_int, 96 pub adler: z_checksum, 97 pub reserved: uLong, 98 } 99 pub type z_streamp = *mut z_stream; 100 101 // Ideally, this should instead use a macro that parses the whole block of externs, and generates 102 // the appropriate link_name attributes, without duplicating the function names. However, ctest2 103 // can't parse that. 104 #[cfg(not(zng))] 105 macro_rules! zng_prefix { 106 ($name:expr) => { stringify!($name) } 107 } 108 109 #[cfg(zng)] 110 macro_rules! zng_prefix { 111 ($name:expr) => { concat!("zng_", stringify!($name)) } 112 } 113 114 extern "C" { 115 #[link_name = zng_prefix!(adler32)] adler32(adler: z_checksum, buf: *const Bytef, len: uInt) -> z_checksum116 pub fn adler32(adler: z_checksum, buf: *const Bytef, len: uInt) -> z_checksum; 117 #[link_name = zng_prefix!(crc32)] crc32(crc: z_checksum, buf: *const Bytef, len: uInt) -> z_checksum118 pub fn crc32(crc: z_checksum, buf: *const Bytef, len: uInt) -> z_checksum; 119 #[link_name = zng_prefix!(deflate)] deflate(strm: z_streamp, flush: c_int) -> c_int120 pub fn deflate(strm: z_streamp, flush: c_int) -> c_int; 121 #[link_name = zng_prefix!(deflateBound)] deflateBound(strm: z_streamp, sourceLen: uLong) -> uLong122 pub fn deflateBound(strm: z_streamp, sourceLen: uLong) -> uLong; 123 #[link_name = zng_prefix!(deflateCopy)] deflateCopy(dest: z_streamp, source: z_streamp) -> c_int124 pub fn deflateCopy(dest: z_streamp, source: z_streamp) -> c_int; 125 #[link_name = zng_prefix!(deflateEnd)] deflateEnd(strm: z_streamp) -> c_int126 pub fn deflateEnd(strm: z_streamp) -> c_int; 127 #[link_name = zng_prefix!(deflateInit_)] deflateInit_( strm: z_streamp, level: c_int, version: *const c_char, stream_size: c_int, ) -> c_int128 pub fn deflateInit_( 129 strm: z_streamp, 130 level: c_int, 131 version: *const c_char, 132 stream_size: c_int, 133 ) -> c_int; 134 #[link_name = zng_prefix!(deflateInit2_)] deflateInit2_( strm: z_streamp, level: c_int, method: c_int, windowBits: c_int, memLevel: c_int, strategy: c_int, version: *const c_char, stream_size: c_int, ) -> c_int135 pub fn deflateInit2_( 136 strm: z_streamp, 137 level: c_int, 138 method: c_int, 139 windowBits: c_int, 140 memLevel: c_int, 141 strategy: c_int, 142 version: *const c_char, 143 stream_size: c_int, 144 ) -> c_int; 145 #[link_name = zng_prefix!(deflateParams)] deflateParams(strm: z_streamp, level: c_int, strategy: c_int) -> c_int146 pub fn deflateParams(strm: z_streamp, level: c_int, strategy: c_int) -> c_int; 147 #[link_name = zng_prefix!(deflatePrime)] deflatePrime(strm: z_streamp, bits: c_int, value: c_int) -> c_int148 pub fn deflatePrime(strm: z_streamp, bits: c_int, value: c_int) -> c_int; 149 #[link_name = zng_prefix!(deflateReset)] deflateReset(strm: z_streamp) -> c_int150 pub fn deflateReset(strm: z_streamp) -> c_int; 151 #[link_name = zng_prefix!(deflateSetDictionary)] deflateSetDictionary( strm: z_streamp, dictionary: *const Bytef, dictLength: uInt, ) -> c_int152 pub fn deflateSetDictionary( 153 strm: z_streamp, 154 dictionary: *const Bytef, 155 dictLength: uInt, 156 ) -> c_int; 157 #[link_name = zng_prefix!(deflateSetHeader)] deflateSetHeader(strm: z_streamp, head: gz_headerp) -> c_int158 pub fn deflateSetHeader(strm: z_streamp, head: gz_headerp) -> c_int; 159 #[link_name = zng_prefix!(deflateTune)] deflateTune( strm: z_streamp, good_length: c_int, max_lazy: c_int, nice_length: c_int, max_chain: c_int, ) -> c_int160 pub fn deflateTune( 161 strm: z_streamp, 162 good_length: c_int, 163 max_lazy: c_int, 164 nice_length: c_int, 165 max_chain: c_int, 166 ) -> c_int; 167 #[link_name = zng_prefix!(inflate)] inflate(strm: z_streamp, flush: c_int) -> c_int168 pub fn inflate(strm: z_streamp, flush: c_int) -> c_int; 169 #[link_name = zng_prefix!(inflateBack)] inflateBack( strm: z_streamp, _in: in_func, in_desc: *mut c_void, out: out_func, out_desc: *mut c_void, ) -> c_int170 pub fn inflateBack( 171 strm: z_streamp, 172 _in: in_func, 173 in_desc: *mut c_void, 174 out: out_func, 175 out_desc: *mut c_void, 176 ) -> c_int; 177 #[link_name = zng_prefix!(inflateBackEnd)] inflateBackEnd(strm: z_streamp) -> c_int178 pub fn inflateBackEnd(strm: z_streamp) -> c_int; 179 #[link_name = zng_prefix!(inflateBackInit_)] inflateBackInit_( strm: z_streamp, windowBits: c_int, window: *mut c_uchar, version: *const c_char, stream_size: c_int, ) -> c_int180 pub fn inflateBackInit_( 181 strm: z_streamp, 182 windowBits: c_int, 183 window: *mut c_uchar, 184 version: *const c_char, 185 stream_size: c_int, 186 ) -> c_int; 187 #[link_name = zng_prefix!(inflateCopy)] inflateCopy(dest: z_streamp, source: z_streamp) -> c_int188 pub fn inflateCopy(dest: z_streamp, source: z_streamp) -> c_int; 189 #[link_name = zng_prefix!(inflateEnd)] inflateEnd(strm: z_streamp) -> c_int190 pub fn inflateEnd(strm: z_streamp) -> c_int; 191 #[link_name = zng_prefix!(inflateGetHeader)] inflateGetHeader(strm: z_streamp, head: gz_headerp) -> c_int192 pub fn inflateGetHeader(strm: z_streamp, head: gz_headerp) -> c_int; 193 #[link_name = zng_prefix!(inflateInit_)] inflateInit_(strm: z_streamp, version: *const c_char, stream_size: c_int) -> c_int194 pub fn inflateInit_(strm: z_streamp, version: *const c_char, stream_size: c_int) -> c_int; 195 #[link_name = zng_prefix!(inflateInit2_)] inflateInit2_( strm: z_streamp, windowBits: c_int, version: *const c_char, stream_size: c_int, ) -> c_int196 pub fn inflateInit2_( 197 strm: z_streamp, 198 windowBits: c_int, 199 version: *const c_char, 200 stream_size: c_int, 201 ) -> c_int; 202 #[link_name = zng_prefix!(inflateMark)] inflateMark(strm: z_streamp) -> c_long203 pub fn inflateMark(strm: z_streamp) -> c_long; 204 #[link_name = zng_prefix!(inflatePrime)] inflatePrime(strm: z_streamp, bits: c_int, value: c_int) -> c_int205 pub fn inflatePrime(strm: z_streamp, bits: c_int, value: c_int) -> c_int; 206 #[link_name = zng_prefix!(inflateReset)] inflateReset(strm: z_streamp) -> c_int207 pub fn inflateReset(strm: z_streamp) -> c_int; 208 #[link_name = zng_prefix!(inflateReset2)] inflateReset2(strm: z_streamp, windowBits: c_int) -> c_int209 pub fn inflateReset2(strm: z_streamp, windowBits: c_int) -> c_int; 210 #[link_name = zng_prefix!(inflateSetDictionary)] inflateSetDictionary( strm: z_streamp, dictionary: *const Bytef, dictLength: uInt, ) -> c_int211 pub fn inflateSetDictionary( 212 strm: z_streamp, 213 dictionary: *const Bytef, 214 dictLength: uInt, 215 ) -> c_int; 216 #[link_name = zng_prefix!(inflateSync)] inflateSync(strm: z_streamp) -> c_int217 pub fn inflateSync(strm: z_streamp) -> c_int; 218 #[link_name = zng_prefix!(zlibCompileFlags)] zlibCompileFlags() -> uLong219 pub fn zlibCompileFlags() -> uLong; 220 221 // The above set of functions currently target 1.2.3.4 (what's present on Ubuntu 222 // 12.04, but there's some other APIs that were added later. Should figure out 223 // how to expose them... 224 // 225 // Added in 1.2.5.1 226 // 227 // pub fn deflatePending(strm: z_streamp, 228 // pending: *mut c_uint, 229 // bits: *mut c_int) -> c_int; 230 // 231 // Addedin 1.2.7.1 232 // pub fn inflateGetDictionary(strm: z_streamp, 233 // dictionary: *mut Bytef, 234 // dictLength: *mut uInt) -> c_int; 235 // 236 // Added in 1.2.3.5 237 // pub fn gzbuffer(file: gzFile, size: c_uint) -> c_int; 238 // pub fn gzclose_r(file: gzFile) -> c_int; 239 // pub fn gzclose_w(file: gzFile) -> c_int; 240 // pub fn gzoffset(file: gzFile) -> z_off_t; 241 } 242 243 extern "C" { 244 #[link_name = if_zng!("zlibng_version", "zlibVersion")] zlibVersion() -> *const c_char245 pub fn zlibVersion() -> *const c_char; 246 } 247 248 #[cfg(any(zng, feature = "libc"))] 249 extern "C" { 250 #[link_name = zng_prefix!(adler32_combine)] adler32_combine(adler1: z_checksum, adler2: z_checksum, len2: z_off_t) -> z_checksum251 pub fn adler32_combine(adler1: z_checksum, adler2: z_checksum, len2: z_off_t) -> z_checksum; 252 #[link_name = zng_prefix!(compress)] compress( dest: *mut Bytef, destLen: *mut z_size, source: *const Bytef, sourceLen: z_size, ) -> c_int253 pub fn compress( 254 dest: *mut Bytef, 255 destLen: *mut z_size, 256 source: *const Bytef, 257 sourceLen: z_size, 258 ) -> c_int; 259 #[link_name = zng_prefix!(compress2)] compress2( dest: *mut Bytef, destLen: *mut z_size, source: *const Bytef, sourceLen: z_size, level: c_int, ) -> c_int260 pub fn compress2( 261 dest: *mut Bytef, 262 destLen: *mut z_size, 263 source: *const Bytef, 264 sourceLen: z_size, 265 level: c_int, 266 ) -> c_int; 267 #[link_name = zng_prefix!(compressBound)] compressBound(sourceLen: z_size) -> z_size268 pub fn compressBound(sourceLen: z_size) -> z_size; 269 #[link_name = zng_prefix!(crc32_combine)] crc32_combine(crc1: z_checksum, crc2: z_checksum, len2: z_off_t) -> z_checksum270 pub fn crc32_combine(crc1: z_checksum, crc2: z_checksum, len2: z_off_t) -> z_checksum; 271 #[link_name = zng_prefix!(gzdirect)] gzdirect(file: gzFile) -> c_int272 pub fn gzdirect(file: gzFile) -> c_int; 273 #[link_name = zng_prefix!(gzdopen)] gzdopen(fd: c_int, mode: *const c_char) -> gzFile274 pub fn gzdopen(fd: c_int, mode: *const c_char) -> gzFile; 275 #[link_name = zng_prefix!(gzclearerr)] gzclearerr(file: gzFile)276 pub fn gzclearerr(file: gzFile); 277 #[link_name = zng_prefix!(gzclose)] gzclose(file: gzFile) -> c_int278 pub fn gzclose(file: gzFile) -> c_int; 279 #[link_name = zng_prefix!(gzeof)] gzeof(file: gzFile) -> c_int280 pub fn gzeof(file: gzFile) -> c_int; 281 #[link_name = zng_prefix!(gzerror)] gzerror(file: gzFile, errnum: *mut c_int) -> *const c_char282 pub fn gzerror(file: gzFile, errnum: *mut c_int) -> *const c_char; 283 #[link_name = zng_prefix!(gzflush)] gzflush(file: gzFile, flush: c_int) -> c_int284 pub fn gzflush(file: gzFile, flush: c_int) -> c_int; 285 #[link_name = zng_prefix!(gzgetc)] gzgetc(file: gzFile) -> c_int286 pub fn gzgetc(file: gzFile) -> c_int; 287 #[link_name = zng_prefix!(gzgets)] gzgets(file: gzFile, buf: *mut c_char, len: c_int) -> *mut c_char288 pub fn gzgets(file: gzFile, buf: *mut c_char, len: c_int) -> *mut c_char; 289 #[link_name = zng_prefix!(gzopen)] gzopen(path: *const c_char, mode: *const c_char) -> gzFile290 pub fn gzopen(path: *const c_char, mode: *const c_char) -> gzFile; 291 #[link_name = zng_prefix!(gzputc)] gzputc(file: gzFile, c: c_int) -> c_int292 pub fn gzputc(file: gzFile, c: c_int) -> c_int; 293 #[link_name = zng_prefix!(gzputs)] gzputs(file: gzFile, s: *const c_char) -> c_int294 pub fn gzputs(file: gzFile, s: *const c_char) -> c_int; 295 #[link_name = zng_prefix!(gzread)] gzread(file: gzFile, buf: voidp, len: c_uint) -> c_int296 pub fn gzread(file: gzFile, buf: voidp, len: c_uint) -> c_int; 297 #[link_name = zng_prefix!(gzrewind)] gzrewind(file: gzFile) -> c_int298 pub fn gzrewind(file: gzFile) -> c_int; 299 #[link_name = zng_prefix!(gzseek)] gzseek(file: gzFile, offset: z_off_t, whence: c_int) -> z_off_t300 pub fn gzseek(file: gzFile, offset: z_off_t, whence: c_int) -> z_off_t; 301 #[link_name = zng_prefix!(gzsetparams)] gzsetparams(file: gzFile, level: c_int, strategy: c_int) -> c_int302 pub fn gzsetparams(file: gzFile, level: c_int, strategy: c_int) -> c_int; 303 #[link_name = zng_prefix!(gztell)] gztell(file: gzFile) -> z_off_t304 pub fn gztell(file: gzFile) -> z_off_t; 305 #[link_name = zng_prefix!(gzungetc)] gzungetc(c: c_int, file: gzFile) -> c_int306 pub fn gzungetc(c: c_int, file: gzFile) -> c_int; 307 #[link_name = zng_prefix!(gzwrite)] gzwrite(file: gzFile, buf: voidpc, len: c_uint) -> c_int308 pub fn gzwrite(file: gzFile, buf: voidpc, len: c_uint) -> c_int; 309 #[link_name = zng_prefix!(uncompress)] uncompress( dest: *mut Bytef, destLen: *mut z_size, source: *const Bytef, sourceLen: z_size, ) -> c_int310 pub fn uncompress( 311 dest: *mut Bytef, 312 destLen: *mut z_size, 313 source: *const Bytef, 314 sourceLen: z_size, 315 ) -> c_int; 316 } 317 318 pub const Z_NO_FLUSH: c_int = 0; 319 pub const Z_PARTIAL_FLUSH: c_int = 1; 320 pub const Z_SYNC_FLUSH: c_int = 2; 321 pub const Z_FULL_FLUSH: c_int = 3; 322 pub const Z_FINISH: c_int = 4; 323 pub const Z_BLOCK: c_int = 5; 324 pub const Z_TREES: c_int = 6; 325 326 pub const Z_OK: c_int = 0; 327 pub const Z_STREAM_END: c_int = 1; 328 pub const Z_NEED_DICT: c_int = 2; 329 pub const Z_ERRNO: c_int = -1; 330 pub const Z_STREAM_ERROR: c_int = -2; 331 pub const Z_DATA_ERROR: c_int = -3; 332 pub const Z_MEM_ERROR: c_int = -4; 333 pub const Z_BUF_ERROR: c_int = -5; 334 pub const Z_VERSION_ERROR: c_int = -6; 335 336 pub const Z_NO_COMPRESSION: c_int = 0; 337 pub const Z_BEST_SPEED: c_int = 1; 338 pub const Z_BEST_COMPRESSION: c_int = 9; 339 pub const Z_DEFAULT_COMPRESSION: c_int = -1; 340 341 pub const Z_FILTERED: c_int = 1; 342 pub const Z_HUFFMAN_ONLY: c_int = 2; 343 pub const Z_RLE: c_int = 3; 344 pub const Z_FIXED: c_int = 4; 345 pub const Z_DEFAULT_STRATEGY: c_int = 0; 346 347 pub const Z_BINARY: c_int = 0; 348 pub const Z_TEXT: c_int = 1; 349 pub const Z_ASCII: c_int = Z_TEXT; 350 pub const Z_UNKNOWN: c_int = 2; 351 352 pub const Z_DEFLATED: c_int = 8; 353