kusano fc6ab3
/* zutil.h -- internal interface and configuration of the compression library
kusano fc6ab3
 * Copyright (C) 1995-2013 Jean-loup Gailly.
kusano fc6ab3
 * For conditions of distribution and use, see copyright notice in zlib.h
kusano fc6ab3
 */
kusano fc6ab3
kusano fc6ab3
/* WARNING: this file should *not* be used by applications. It is
kusano fc6ab3
   part of the implementation of the compression library and is
kusano fc6ab3
   subject to change. Applications should only use zlib.h.
kusano fc6ab3
 */
kusano fc6ab3
kusano fc6ab3
/* @(#) $Id$ */
kusano fc6ab3
kusano fc6ab3
#ifndef ZUTIL_H
kusano fc6ab3
#define ZUTIL_H
kusano fc6ab3
kusano fc6ab3
#ifdef HAVE_HIDDEN
kusano fc6ab3
#  define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
kusano fc6ab3
#else
kusano fc6ab3
#  define ZLIB_INTERNAL
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#include "zlib.h"
kusano fc6ab3
kusano fc6ab3
#if defined(STDC) && !defined(Z_SOLO)
kusano fc6ab3
#  if !(defined(_WIN32_WCE) && defined(_MSC_VER))
kusano fc6ab3
#    include <stddef.h></stddef.h>
kusano fc6ab3
#  endif
kusano fc6ab3
#  include <string.h></string.h>
kusano fc6ab3
#  include <stdlib.h></stdlib.h>
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#ifdef Z_SOLO
kusano fc6ab3
   typedef long ptrdiff_t;  /* guess -- will be caught if guess is wrong */
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#ifndef local
kusano fc6ab3
#  define local static
kusano fc6ab3
#endif
kusano fc6ab3
/* compile with -Dlocal if your debugger can't find static symbols */
kusano fc6ab3
kusano fc6ab3
typedef unsigned char  uch;
kusano fc6ab3
typedef uch FAR uchf;
kusano fc6ab3
typedef unsigned short ush;
kusano fc6ab3
typedef ush FAR ushf;
kusano fc6ab3
typedef unsigned long  ulg;
kusano fc6ab3
kusano fc6ab3
extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
kusano fc6ab3
/* (size given to avoid silly warnings with Visual C++) */
kusano fc6ab3
kusano fc6ab3
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
kusano fc6ab3
kusano fc6ab3
#define ERR_RETURN(strm,err) \
kusano fc6ab3
  return (strm->msg = ERR_MSG(err), (err))
kusano fc6ab3
/* To be used only when the state is known to be valid */
kusano fc6ab3
kusano fc6ab3
        /* common constants */
kusano fc6ab3
kusano fc6ab3
#ifndef DEF_WBITS
kusano fc6ab3
#  define DEF_WBITS MAX_WBITS
kusano fc6ab3
#endif
kusano fc6ab3
/* default windowBits for decompression. MAX_WBITS is for compression only */
kusano fc6ab3
kusano fc6ab3
#if MAX_MEM_LEVEL >= 8
kusano fc6ab3
#  define DEF_MEM_LEVEL 8
kusano fc6ab3
#else
kusano fc6ab3
#  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
kusano fc6ab3
#endif
kusano fc6ab3
/* default memLevel */
kusano fc6ab3
kusano fc6ab3
#define STORED_BLOCK 0
kusano fc6ab3
#define STATIC_TREES 1
kusano fc6ab3
#define DYN_TREES    2
kusano fc6ab3
/* The three kinds of block type */
kusano fc6ab3
kusano fc6ab3
#define MIN_MATCH  3
kusano fc6ab3
#define MAX_MATCH  258
kusano fc6ab3
/* The minimum and maximum match lengths */
kusano fc6ab3
kusano fc6ab3
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
kusano fc6ab3
kusano fc6ab3
        /* target dependencies */
kusano fc6ab3
kusano fc6ab3
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
kusano fc6ab3
#  define OS_CODE  0x00
kusano fc6ab3
#  ifndef Z_SOLO
kusano fc6ab3
#    if defined(__TURBOC__) || defined(__BORLANDC__)
kusano fc6ab3
#      if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
kusano fc6ab3
         /* Allow compilation with ANSI keywords only enabled */
kusano fc6ab3
         void _Cdecl farfree( void *block );
kusano fc6ab3
         void *_Cdecl farmalloc( unsigned long nbytes );
kusano fc6ab3
#      else
kusano fc6ab3
#        include <alloc.h></alloc.h>
kusano fc6ab3
#      endif
kusano fc6ab3
#    else /* MSC or DJGPP */
kusano fc6ab3
#      include <malloc.h></malloc.h>
kusano fc6ab3
#    endif
kusano fc6ab3
#  endif
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#ifdef AMIGA
kusano fc6ab3
#  define OS_CODE  0x01
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#if defined(VAXC) || defined(VMS)
kusano fc6ab3
#  define OS_CODE  0x02
kusano fc6ab3
#  define F_OPEN(name, mode) \
kusano fc6ab3
     fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#if defined(ATARI) || defined(atarist)
kusano fc6ab3
#  define OS_CODE  0x05
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#ifdef OS2
kusano fc6ab3
#  define OS_CODE  0x06
kusano fc6ab3
#  if defined(M_I86) && !defined(Z_SOLO)
kusano fc6ab3
#    include <malloc.h></malloc.h>
kusano fc6ab3
#  endif
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#if defined(MACOS) || defined(TARGET_OS_MAC)
kusano fc6ab3
#  define OS_CODE  0x07
kusano fc6ab3
#  ifndef Z_SOLO
kusano fc6ab3
#    if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
kusano fc6ab3
#      include <unix.h> /* for fdopen */</unix.h>
kusano fc6ab3
#    else
kusano fc6ab3
#      ifndef fdopen
kusano fc6ab3
#        define fdopen(fd,mode) NULL /* No fdopen() */
kusano fc6ab3
#      endif
kusano fc6ab3
#    endif
kusano fc6ab3
#  endif
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#ifdef TOPS20
kusano fc6ab3
#  define OS_CODE  0x0a
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#ifdef WIN32
kusano fc6ab3
#  ifndef __CYGWIN__  /* Cygwin is Unix, not Win32 */
kusano fc6ab3
#    define OS_CODE  0x0b
kusano fc6ab3
#  endif
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#ifdef __50SERIES /* Prime/PRIMOS */
kusano fc6ab3
#  define OS_CODE  0x0f
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#if defined(_BEOS_) || defined(RISCOS)
kusano fc6ab3
#  define fdopen(fd,mode) NULL /* No fdopen() */
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX
kusano fc6ab3
#  if defined(_WIN32_WCE)
kusano fc6ab3
#    define fdopen(fd,mode) NULL /* No fdopen() */
kusano fc6ab3
#    ifndef _PTRDIFF_T_DEFINED
kusano fc6ab3
       typedef int ptrdiff_t;
kusano fc6ab3
#      define _PTRDIFF_T_DEFINED
kusano fc6ab3
#    endif
kusano fc6ab3
#  else
kusano fc6ab3
#    define fdopen(fd,type)  _fdopen(fd,type)
kusano fc6ab3
#  endif
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#if defined(__BORLANDC__) && !defined(MSDOS)
kusano fc6ab3
  #pragma warn -8004
kusano fc6ab3
  #pragma warn -8008
kusano fc6ab3
  #pragma warn -8066
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
/* provide prototypes for these when building zlib without LFS */
kusano fc6ab3
#if !defined(_WIN32) && \
kusano fc6ab3
    (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
kusano fc6ab3
    ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
kusano fc6ab3
    ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
        /* common defaults */
kusano fc6ab3
kusano fc6ab3
#ifndef OS_CODE
kusano fc6ab3
#  define OS_CODE  0x03  /* assume Unix */
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#ifndef F_OPEN
kusano fc6ab3
#  define F_OPEN(name, mode) fopen((name), (mode))
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
         /* functions */
kusano fc6ab3
kusano fc6ab3
#if defined(pyr) || defined(Z_SOLO)
kusano fc6ab3
#  define NO_MEMCPY
kusano fc6ab3
#endif
kusano fc6ab3
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
kusano fc6ab3
 /* Use our own functions for small and medium model with MSC <= 5.0.
kusano fc6ab3
  * You may have to use the same strategy for Borland C (untested).
kusano fc6ab3
  * The __SC__ check is for Symantec.
kusano fc6ab3
  */
kusano fc6ab3
#  define NO_MEMCPY
kusano fc6ab3
#endif
kusano fc6ab3
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
kusano fc6ab3
#  define HAVE_MEMCPY
kusano fc6ab3
#endif
kusano fc6ab3
#ifdef HAVE_MEMCPY
kusano fc6ab3
#  ifdef SMALL_MEDIUM /* MSDOS small or medium model */
kusano fc6ab3
#    define zmemcpy _fmemcpy
kusano fc6ab3
#    define zmemcmp _fmemcmp
kusano fc6ab3
#    define zmemzero(dest, len) _fmemset(dest, 0, len)
kusano fc6ab3
#  else
kusano fc6ab3
#    define zmemcpy memcpy
kusano fc6ab3
#    define zmemcmp memcmp
kusano fc6ab3
#    define zmemzero(dest, len) memset(dest, 0, len)
kusano fc6ab3
#  endif
kusano fc6ab3
#else
kusano fc6ab3
   void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
kusano fc6ab3
   int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
kusano fc6ab3
   void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
/* Diagnostic functions */
kusano fc6ab3
#ifdef DEBUG
kusano fc6ab3
#  include <stdio.h></stdio.h>
kusano fc6ab3
   extern int ZLIB_INTERNAL z_verbose;
kusano fc6ab3
   extern void ZLIB_INTERNAL z_error OF((char *m));
kusano fc6ab3
#  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
kusano fc6ab3
#  define Trace(x) {if (z_verbose>=0) fprintf x ;}
kusano fc6ab3
#  define Tracev(x) {if (z_verbose>0) fprintf x ;}
kusano fc6ab3
#  define Tracevv(x) {if (z_verbose>1) fprintf x ;}
kusano fc6ab3
#  define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
kusano fc6ab3
#  define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
kusano fc6ab3
#else
kusano fc6ab3
#  define Assert(cond,msg)
kusano fc6ab3
#  define Trace(x)
kusano fc6ab3
#  define Tracev(x)
kusano fc6ab3
#  define Tracevv(x)
kusano fc6ab3
#  define Tracec(c,x)
kusano fc6ab3
#  define Tracecv(c,x)
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#ifndef Z_SOLO
kusano fc6ab3
   voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
kusano fc6ab3
                                    unsigned size));
kusano fc6ab3
   void ZLIB_INTERNAL zcfree  OF((voidpf opaque, voidpf ptr));
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#define ZALLOC(strm, items, size) \
kusano fc6ab3
           (*((strm)->zalloc))((strm)->opaque, (items), (size))
kusano fc6ab3
#define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
kusano fc6ab3
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
kusano fc6ab3
kusano fc6ab3
/* Reverse the bytes in a 32-bit value */
kusano fc6ab3
#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
kusano fc6ab3
                    (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
kusano fc6ab3
kusano fc6ab3
#endif /* ZUTIL_H */