1*5e3eaea3SApple OSS Distributions /* 2*5e3eaea3SApple OSS Distributions * Copyright (c) 2008 Apple Inc. All rights reserved. 3*5e3eaea3SApple OSS Distributions * 4*5e3eaea3SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*5e3eaea3SApple OSS Distributions * 6*5e3eaea3SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*5e3eaea3SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*5e3eaea3SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*5e3eaea3SApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*5e3eaea3SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*5e3eaea3SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*5e3eaea3SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*5e3eaea3SApple OSS Distributions * terms of an Apple operating system software license agreement. 14*5e3eaea3SApple OSS Distributions * 15*5e3eaea3SApple OSS Distributions * Please obtain a copy of the License at 16*5e3eaea3SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*5e3eaea3SApple OSS Distributions * 18*5e3eaea3SApple OSS Distributions * The Original Code and all software distributed under the License are 19*5e3eaea3SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*5e3eaea3SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*5e3eaea3SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*5e3eaea3SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*5e3eaea3SApple OSS Distributions * Please see the License for the specific language governing rights and 24*5e3eaea3SApple OSS Distributions * limitations under the License. 25*5e3eaea3SApple OSS Distributions * 26*5e3eaea3SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*5e3eaea3SApple OSS Distributions */ 28*5e3eaea3SApple OSS Distributions /* zutil.h -- internal interface and configuration of the compression library 29*5e3eaea3SApple OSS Distributions * Copyright (C) 1995-2005 Jean-loup Gailly. 30*5e3eaea3SApple OSS Distributions * For conditions of distribution and use, see copyright notice in zlib.h 31*5e3eaea3SApple OSS Distributions */ 32*5e3eaea3SApple OSS Distributions 33*5e3eaea3SApple OSS Distributions /* WARNING: this file should *not* be used by applications. It is 34*5e3eaea3SApple OSS Distributions part of the implementation of the compression library and is 35*5e3eaea3SApple OSS Distributions subject to change. Applications should only use zlib.h. 36*5e3eaea3SApple OSS Distributions */ 37*5e3eaea3SApple OSS Distributions 38*5e3eaea3SApple OSS Distributions /* @(#) $Id$ */ 39*5e3eaea3SApple OSS Distributions 40*5e3eaea3SApple OSS Distributions #ifndef ZUTIL_H 41*5e3eaea3SApple OSS Distributions #define ZUTIL_H 42*5e3eaea3SApple OSS Distributions 43*5e3eaea3SApple OSS Distributions #define ZLIB_INTERNAL 44*5e3eaea3SApple OSS Distributions 45*5e3eaea3SApple OSS Distributions #if KERNEL 46*5e3eaea3SApple OSS Distributions # include <libkern/zlib.h> 47*5e3eaea3SApple OSS Distributions # include <string.h> 48*5e3eaea3SApple OSS Distributions # ifndef NO_ERRNO_H 49*5e3eaea3SApple OSS Distributions # define NO_ERRNO_H 1 50*5e3eaea3SApple OSS Distributions # endif 51*5e3eaea3SApple OSS Distributions # ifndef NO_ZCFUNCS 52*5e3eaea3SApple OSS Distributions # define NO_ZCFUNCS 1 53*5e3eaea3SApple OSS Distributions # endif 54*5e3eaea3SApple OSS Distributions #else 55*5e3eaea3SApple OSS Distributions # include "zlib.h" 56*5e3eaea3SApple OSS Distributions # ifdef STDC 57*5e3eaea3SApple OSS Distributions # ifndef _WIN32_WCE 58*5e3eaea3SApple OSS Distributions # include <stddef.h> 59*5e3eaea3SApple OSS Distributions # endif 60*5e3eaea3SApple OSS Distributions # include <string.h> 61*5e3eaea3SApple OSS Distributions # include <stdlib.h> 62*5e3eaea3SApple OSS Distributions # endif 63*5e3eaea3SApple OSS Distributions #endif /* KERNEL */ 64*5e3eaea3SApple OSS Distributions 65*5e3eaea3SApple OSS Distributions #ifdef NO_ERRNO_H 66*5e3eaea3SApple OSS Distributions # ifdef _WIN32_WCE 67*5e3eaea3SApple OSS Distributions /* The Microsoft C Run-Time Library for Windows CE doesn't have 68*5e3eaea3SApple OSS Distributions * errno. We define it as a global variable to simplify porting. 69*5e3eaea3SApple OSS Distributions * Its value is always 0 and should not be used. We rename it to 70*5e3eaea3SApple OSS Distributions * avoid conflict with other libraries that use the same workaround. 71*5e3eaea3SApple OSS Distributions */ 72*5e3eaea3SApple OSS Distributions # define errno z_errno 73*5e3eaea3SApple OSS Distributions # endif 74*5e3eaea3SApple OSS Distributions extern int errno; 75*5e3eaea3SApple OSS Distributions #else 76*5e3eaea3SApple OSS Distributions # ifndef _WIN32_WCE 77*5e3eaea3SApple OSS Distributions # include <errno.h> 78*5e3eaea3SApple OSS Distributions # endif 79*5e3eaea3SApple OSS Distributions #endif 80*5e3eaea3SApple OSS Distributions 81*5e3eaea3SApple OSS Distributions #ifndef local 82*5e3eaea3SApple OSS Distributions # define local static 83*5e3eaea3SApple OSS Distributions #endif 84*5e3eaea3SApple OSS Distributions /* compile with -Dlocal if your debugger can't find static symbols */ 85*5e3eaea3SApple OSS Distributions 86*5e3eaea3SApple OSS Distributions typedef unsigned char uch; 87*5e3eaea3SApple OSS Distributions typedef uch FAR uchf; 88*5e3eaea3SApple OSS Distributions typedef unsigned short ush; 89*5e3eaea3SApple OSS Distributions typedef ush FAR ushf; 90*5e3eaea3SApple OSS Distributions typedef unsigned long ulg; 91*5e3eaea3SApple OSS Distributions 92*5e3eaea3SApple OSS Distributions extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 93*5e3eaea3SApple OSS Distributions /* (size given to avoid silly warnings with Visual C++) */ 94*5e3eaea3SApple OSS Distributions 95*5e3eaea3SApple OSS Distributions #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 96*5e3eaea3SApple OSS Distributions 97*5e3eaea3SApple OSS Distributions #define ERR_RETURN(strm,err) \ 98*5e3eaea3SApple OSS Distributions return (strm->msg = (char*)ERR_MSG(err), (err)) 99*5e3eaea3SApple OSS Distributions /* To be used only when the state is known to be valid */ 100*5e3eaea3SApple OSS Distributions 101*5e3eaea3SApple OSS Distributions /* common constants */ 102*5e3eaea3SApple OSS Distributions 103*5e3eaea3SApple OSS Distributions #ifndef DEF_WBITS 104*5e3eaea3SApple OSS Distributions # define DEF_WBITS MAX_WBITS 105*5e3eaea3SApple OSS Distributions #endif 106*5e3eaea3SApple OSS Distributions /* default windowBits for decompression. MAX_WBITS is for compression only */ 107*5e3eaea3SApple OSS Distributions 108*5e3eaea3SApple OSS Distributions #if MAX_MEM_LEVEL >= 8 109*5e3eaea3SApple OSS Distributions # define DEF_MEM_LEVEL 8 110*5e3eaea3SApple OSS Distributions #else 111*5e3eaea3SApple OSS Distributions # define DEF_MEM_LEVEL MAX_MEM_LEVEL 112*5e3eaea3SApple OSS Distributions #endif 113*5e3eaea3SApple OSS Distributions /* default memLevel */ 114*5e3eaea3SApple OSS Distributions 115*5e3eaea3SApple OSS Distributions #define STORED_BLOCK 0 116*5e3eaea3SApple OSS Distributions #define STATIC_TREES 1 117*5e3eaea3SApple OSS Distributions #define DYN_TREES 2 118*5e3eaea3SApple OSS Distributions /* The three kinds of block type */ 119*5e3eaea3SApple OSS Distributions 120*5e3eaea3SApple OSS Distributions #define MIN_MATCH 3 121*5e3eaea3SApple OSS Distributions #define MAX_MATCH 258 122*5e3eaea3SApple OSS Distributions /* The minimum and maximum match lengths */ 123*5e3eaea3SApple OSS Distributions 124*5e3eaea3SApple OSS Distributions #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 125*5e3eaea3SApple OSS Distributions 126*5e3eaea3SApple OSS Distributions /* target dependencies */ 127*5e3eaea3SApple OSS Distributions 128*5e3eaea3SApple OSS Distributions #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 129*5e3eaea3SApple OSS Distributions # define OS_CODE 0x00 130*5e3eaea3SApple OSS Distributions # if defined(__TURBOC__) || defined(__BORLANDC__) 131*5e3eaea3SApple OSS Distributions # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 132*5e3eaea3SApple OSS Distributions /* Allow compilation with ANSI keywords only enabled */ 133*5e3eaea3SApple OSS Distributions void _Cdecl farfree( void *block ); 134*5e3eaea3SApple OSS Distributions void *_Cdecl farmalloc( unsigned long nbytes ); 135*5e3eaea3SApple OSS Distributions # else 136*5e3eaea3SApple OSS Distributions # include <alloc.h> 137*5e3eaea3SApple OSS Distributions # endif 138*5e3eaea3SApple OSS Distributions # else /* MSC or DJGPP */ 139*5e3eaea3SApple OSS Distributions # include <malloc.h> 140*5e3eaea3SApple OSS Distributions # endif 141*5e3eaea3SApple OSS Distributions #endif 142*5e3eaea3SApple OSS Distributions 143*5e3eaea3SApple OSS Distributions #ifdef AMIGA 144*5e3eaea3SApple OSS Distributions # define OS_CODE 0x01 145*5e3eaea3SApple OSS Distributions #endif 146*5e3eaea3SApple OSS Distributions 147*5e3eaea3SApple OSS Distributions #if defined(VAXC) || defined(VMS) 148*5e3eaea3SApple OSS Distributions # define OS_CODE 0x02 149*5e3eaea3SApple OSS Distributions # define F_OPEN(name, mode) \ 150*5e3eaea3SApple OSS Distributions fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 151*5e3eaea3SApple OSS Distributions #endif 152*5e3eaea3SApple OSS Distributions 153*5e3eaea3SApple OSS Distributions #if defined(ATARI) || defined(atarist) 154*5e3eaea3SApple OSS Distributions # define OS_CODE 0x05 155*5e3eaea3SApple OSS Distributions #endif 156*5e3eaea3SApple OSS Distributions 157*5e3eaea3SApple OSS Distributions #ifdef OS2 158*5e3eaea3SApple OSS Distributions # define OS_CODE 0x06 159*5e3eaea3SApple OSS Distributions # ifdef M_I86 160*5e3eaea3SApple OSS Distributions #include <malloc.h> 161*5e3eaea3SApple OSS Distributions # endif 162*5e3eaea3SApple OSS Distributions #endif 163*5e3eaea3SApple OSS Distributions 164*5e3eaea3SApple OSS Distributions #if defined(MACOS) || defined(TARGET_OS_MAC) 165*5e3eaea3SApple OSS Distributions # define OS_CODE 0x07 166*5e3eaea3SApple OSS Distributions # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 167*5e3eaea3SApple OSS Distributions # include <unix.h> /* for fdopen */ 168*5e3eaea3SApple OSS Distributions # else 169*5e3eaea3SApple OSS Distributions # ifndef fdopen 170*5e3eaea3SApple OSS Distributions # define fdopen(fd,mode) NULL /* No fdopen() */ 171*5e3eaea3SApple OSS Distributions # endif 172*5e3eaea3SApple OSS Distributions # endif 173*5e3eaea3SApple OSS Distributions #endif 174*5e3eaea3SApple OSS Distributions 175*5e3eaea3SApple OSS Distributions #ifdef TOPS20 176*5e3eaea3SApple OSS Distributions # define OS_CODE 0x0a 177*5e3eaea3SApple OSS Distributions #endif 178*5e3eaea3SApple OSS Distributions 179*5e3eaea3SApple OSS Distributions #ifdef WIN32 180*5e3eaea3SApple OSS Distributions # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ 181*5e3eaea3SApple OSS Distributions # define OS_CODE 0x0b 182*5e3eaea3SApple OSS Distributions # endif 183*5e3eaea3SApple OSS Distributions #endif 184*5e3eaea3SApple OSS Distributions 185*5e3eaea3SApple OSS Distributions #ifdef __50SERIES /* Prime/PRIMOS */ 186*5e3eaea3SApple OSS Distributions # define OS_CODE 0x0f 187*5e3eaea3SApple OSS Distributions #endif 188*5e3eaea3SApple OSS Distributions 189*5e3eaea3SApple OSS Distributions #if defined(_BEOS_) || defined(RISCOS) 190*5e3eaea3SApple OSS Distributions # define fdopen(fd,mode) NULL /* No fdopen() */ 191*5e3eaea3SApple OSS Distributions #endif 192*5e3eaea3SApple OSS Distributions 193*5e3eaea3SApple OSS Distributions #if KERNEL 194*5e3eaea3SApple OSS Distributions typedef long ptrdiff_t; 195*5e3eaea3SApple OSS Distributions #elif (defined(_MSC_VER) && (_MSC_VER > 600)) 196*5e3eaea3SApple OSS Distributions # if defined(_WIN32_WCE) 197*5e3eaea3SApple OSS Distributions # define fdopen(fd,mode) NULL /* No fdopen() */ 198*5e3eaea3SApple OSS Distributions # ifndef _PTRDIFF_T_DEFINED 199*5e3eaea3SApple OSS Distributions typedef int ptrdiff_t; 200*5e3eaea3SApple OSS Distributions # define _PTRDIFF_T_DEFINED 201*5e3eaea3SApple OSS Distributions # endif 202*5e3eaea3SApple OSS Distributions # else 203*5e3eaea3SApple OSS Distributions # define fdopen(fd,type) _fdopen(fd,type) 204*5e3eaea3SApple OSS Distributions # endif 205*5e3eaea3SApple OSS Distributions #endif 206*5e3eaea3SApple OSS Distributions 207*5e3eaea3SApple OSS Distributions 208*5e3eaea3SApple OSS Distributions /* common defaults */ 209*5e3eaea3SApple OSS Distributions 210*5e3eaea3SApple OSS Distributions #ifndef OS_CODE 211*5e3eaea3SApple OSS Distributions # define OS_CODE 0x03 /* assume Unix */ 212*5e3eaea3SApple OSS Distributions #endif 213*5e3eaea3SApple OSS Distributions 214*5e3eaea3SApple OSS Distributions #ifndef F_OPEN 215*5e3eaea3SApple OSS Distributions # define F_OPEN(name, mode) fopen((name), (mode)) 216*5e3eaea3SApple OSS Distributions #endif 217*5e3eaea3SApple OSS Distributions 218*5e3eaea3SApple OSS Distributions /* functions */ 219*5e3eaea3SApple OSS Distributions 220*5e3eaea3SApple OSS Distributions #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) 221*5e3eaea3SApple OSS Distributions # ifndef HAVE_VSNPRINTF 222*5e3eaea3SApple OSS Distributions # define HAVE_VSNPRINTF 223*5e3eaea3SApple OSS Distributions # endif 224*5e3eaea3SApple OSS Distributions #endif 225*5e3eaea3SApple OSS Distributions #if defined(__CYGWIN__) 226*5e3eaea3SApple OSS Distributions # ifndef HAVE_VSNPRINTF 227*5e3eaea3SApple OSS Distributions # define HAVE_VSNPRINTF 228*5e3eaea3SApple OSS Distributions # endif 229*5e3eaea3SApple OSS Distributions #endif 230*5e3eaea3SApple OSS Distributions #ifndef HAVE_VSNPRINTF 231*5e3eaea3SApple OSS Distributions # ifdef MSDOS 232*5e3eaea3SApple OSS Distributions /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), 233*5e3eaea3SApple OSS Distributions but for now we just assume it doesn't. */ 234*5e3eaea3SApple OSS Distributions # define NO_vsnprintf 235*5e3eaea3SApple OSS Distributions # endif 236*5e3eaea3SApple OSS Distributions # ifdef __TURBOC__ 237*5e3eaea3SApple OSS Distributions # define NO_vsnprintf 238*5e3eaea3SApple OSS Distributions # endif 239*5e3eaea3SApple OSS Distributions # ifdef WIN32 240*5e3eaea3SApple OSS Distributions /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ 241*5e3eaea3SApple OSS Distributions # if !defined(vsnprintf) && !defined(NO_vsnprintf) 242*5e3eaea3SApple OSS Distributions # define vsnprintf _vsnprintf 243*5e3eaea3SApple OSS Distributions # endif 244*5e3eaea3SApple OSS Distributions # endif 245*5e3eaea3SApple OSS Distributions # ifdef __SASC 246*5e3eaea3SApple OSS Distributions # define NO_vsnprintf 247*5e3eaea3SApple OSS Distributions # endif 248*5e3eaea3SApple OSS Distributions #endif 249*5e3eaea3SApple OSS Distributions #ifdef VMS 250*5e3eaea3SApple OSS Distributions # define NO_vsnprintf 251*5e3eaea3SApple OSS Distributions #endif 252*5e3eaea3SApple OSS Distributions 253*5e3eaea3SApple OSS Distributions #if defined(pyr) 254*5e3eaea3SApple OSS Distributions # define NO_MEMCPY 255*5e3eaea3SApple OSS Distributions #endif 256*5e3eaea3SApple OSS Distributions #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 257*5e3eaea3SApple OSS Distributions /* Use our own functions for small and medium model with MSC <= 5.0. 258*5e3eaea3SApple OSS Distributions * You may have to use the same strategy for Borland C (untested). 259*5e3eaea3SApple OSS Distributions * The __SC__ check is for Symantec. 260*5e3eaea3SApple OSS Distributions */ 261*5e3eaea3SApple OSS Distributions # define NO_MEMCPY 262*5e3eaea3SApple OSS Distributions #endif 263*5e3eaea3SApple OSS Distributions #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 264*5e3eaea3SApple OSS Distributions # define HAVE_MEMCPY 265*5e3eaea3SApple OSS Distributions #endif 266*5e3eaea3SApple OSS Distributions #ifdef HAVE_MEMCPY 267*5e3eaea3SApple OSS Distributions # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 268*5e3eaea3SApple OSS Distributions # define zmemcpy _fmemcpy 269*5e3eaea3SApple OSS Distributions # define zmemcmp _fmemcmp 270*5e3eaea3SApple OSS Distributions # define zmemzero(dest, len) _fmemset(dest, 0, len) 271*5e3eaea3SApple OSS Distributions # else 272*5e3eaea3SApple OSS Distributions # define zmemcpy memcpy 273*5e3eaea3SApple OSS Distributions # define zmemcmp memcmp 274*5e3eaea3SApple OSS Distributions # define zmemzero(dest, len) memset(dest, 0, len) 275*5e3eaea3SApple OSS Distributions # endif 276*5e3eaea3SApple OSS Distributions #else 277*5e3eaea3SApple OSS Distributions extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 278*5e3eaea3SApple OSS Distributions extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); 279*5e3eaea3SApple OSS Distributions extern void zmemzero OF((Bytef* dest, uInt len)); 280*5e3eaea3SApple OSS Distributions #endif 281*5e3eaea3SApple OSS Distributions 282*5e3eaea3SApple OSS Distributions /* Diagnostic functions */ 283*5e3eaea3SApple OSS Distributions #if defined(DEBUG) && !defined(KERNEL) 284*5e3eaea3SApple OSS Distributions # include <stdio.h> 285*5e3eaea3SApple OSS Distributions extern int z_verbose; 286*5e3eaea3SApple OSS Distributions extern void z_error OF((char *m)); 287*5e3eaea3SApple OSS Distributions # define Assert(cond,msg) {if(!(cond)) z_error(msg);} 288*5e3eaea3SApple OSS Distributions # define Trace(x) {if (z_verbose>=0) fprintf x ;} 289*5e3eaea3SApple OSS Distributions # define Tracev(x) {if (z_verbose>0) fprintf x ;} 290*5e3eaea3SApple OSS Distributions # define Tracevv(x) {if (z_verbose>1) fprintf x ;} 291*5e3eaea3SApple OSS Distributions # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 292*5e3eaea3SApple OSS Distributions # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 293*5e3eaea3SApple OSS Distributions #else 294*5e3eaea3SApple OSS Distributions # define Assert(cond,msg) 295*5e3eaea3SApple OSS Distributions # define Trace(x) 296*5e3eaea3SApple OSS Distributions # define Tracev(x) 297*5e3eaea3SApple OSS Distributions # define Tracevv(x) 298*5e3eaea3SApple OSS Distributions # define Tracec(c,x) 299*5e3eaea3SApple OSS Distributions # define Tracecv(c,x) 300*5e3eaea3SApple OSS Distributions #endif 301*5e3eaea3SApple OSS Distributions #undef DEBUG 302*5e3eaea3SApple OSS Distributions 303*5e3eaea3SApple OSS Distributions #ifndef NO_ZCFUNCS 304*5e3eaea3SApple OSS Distributions voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); 305*5e3eaea3SApple OSS Distributions void zcfree OF((voidpf opaque, voidpf ptr)); 306*5e3eaea3SApple OSS Distributions #endif /* NO_ZCFUNCS */ 307*5e3eaea3SApple OSS Distributions 308*5e3eaea3SApple OSS Distributions #define ZALLOC(strm, items, size) \ 309*5e3eaea3SApple OSS Distributions (*((strm)->zalloc))((strm)->opaque, (items), (size)) 310*5e3eaea3SApple OSS Distributions #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 311*5e3eaea3SApple OSS Distributions #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 312*5e3eaea3SApple OSS Distributions 313*5e3eaea3SApple OSS Distributions #endif /* ZUTIL_H */ 314