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