Home | History | Annotate | Line # | Download | only in zlib
zutil.h revision 1.6
      1  1.6  christos /*	$NetBSD: zutil.h,v 1.6 2022/10/15 19:49:32 christos Exp $	*/
      2  1.1  christos 
      3  1.1  christos /* zutil.h -- internal interface and configuration of the compression library
      4  1.6  christos  * Copyright (C) 1995-2022 Jean-loup Gailly, Mark Adler
      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.6  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.5  christos #ifdef HAVE_HIDDEN
     19  1.5  christos #  define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
     20  1.5  christos #else
     21  1.5  christos #  define ZLIB_INTERNAL
     22  1.5  christos #endif
     23  1.5  christos 
     24  1.1  christos #include "zlib.h"
     25  1.1  christos 
     26  1.5  christos #if defined(STDC) && !defined(Z_SOLO)
     27  1.5  christos #  if defined(_KERNEL) || defined(_STANDALONE)
     28  1.5  christos #    include <lib/libkern/libkern.h>
     29  1.5  christos #  else
     30  1.5  christos #    if !(defined(_WIN32_WCE) && defined(_MSC_VER))
     31  1.5  christos #      include <stddef.h>
     32  1.5  christos #    endif
     33  1.5  christos #    include <string.h>
     34  1.5  christos #    include <stdlib.h>
     35  1.1  christos #  endif
     36  1.1  christos #endif
     37  1.5  christos 
     38  1.1  christos #ifndef local
     39  1.1  christos #  define local static
     40  1.1  christos #endif
     41  1.5  christos /* since "static" is used to mean two completely different things in C, we
     42  1.5  christos    define "local" for the non-static meaning of "static", for readability
     43  1.5  christos    (compile with -Dlocal if your debugger can't find static symbols) */
     44  1.1  christos 
     45  1.1  christos typedef unsigned char  uch;
     46  1.1  christos typedef uch FAR uchf;
     47  1.1  christos typedef unsigned short ush;
     48  1.1  christos typedef ush FAR ushf;
     49  1.1  christos typedef unsigned long  ulg;
     50  1.1  christos 
     51  1.6  christos #if !defined(Z_U8) && !defined(Z_SOLO) && defined(STDC)
     52  1.6  christos #  include <limits.h>
     53  1.6  christos #  if (ULONG_MAX == 0xffffffffffffffff)
     54  1.6  christos #    define Z_U8 unsigned long
     55  1.6  christos #  elif (ULLONG_MAX == 0xffffffffffffffff)
     56  1.6  christos #    define Z_U8 unsigned long long
     57  1.6  christos #  elif (UINT_MAX == 0xffffffffffffffff)
     58  1.6  christos #    define Z_U8 unsigned
     59  1.6  christos #  endif
     60  1.6  christos #endif
     61  1.6  christos 
     62  1.5  christos extern z_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.4  christos   return (strm->msg = __UNCONST(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.5  christos #  ifndef Z_SOLO
    101  1.5  christos #    if defined(__TURBOC__) || defined(__BORLANDC__)
    102  1.5  christos #      if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
    103  1.5  christos          /* Allow compilation with ANSI keywords only enabled */
    104  1.5  christos          void _Cdecl farfree( void *block );
    105  1.5  christos          void *_Cdecl farmalloc( unsigned long nbytes );
    106  1.5  christos #      else
    107  1.5  christos #        include <alloc.h>
    108  1.5  christos #      endif
    109  1.5  christos #    else /* MSC or DJGPP */
    110  1.5  christos #      include <malloc.h>
    111  1.1  christos #    endif
    112  1.1  christos #  endif
    113  1.1  christos #endif
    114  1.1  christos 
    115  1.1  christos #ifdef AMIGA
    116  1.5  christos #  define OS_CODE  1
    117  1.1  christos #endif
    118  1.1  christos 
    119  1.1  christos #if defined(VAXC) || defined(VMS)
    120  1.5  christos #  define OS_CODE  2
    121  1.1  christos #  define F_OPEN(name, mode) \
    122  1.1  christos      fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
    123  1.1  christos #endif
    124  1.1  christos 
    125  1.5  christos #ifdef __370__
    126  1.5  christos #  if __TARGET_LIB__ < 0x20000000
    127  1.5  christos #    define OS_CODE 4
    128  1.5  christos #  elif __TARGET_LIB__ < 0x40000000
    129  1.5  christos #    define OS_CODE 11
    130  1.5  christos #  else
    131  1.5  christos #    define OS_CODE 8
    132  1.5  christos #  endif
    133  1.5  christos #endif
    134  1.5  christos 
    135  1.1  christos #if defined(ATARI) || defined(atarist)
    136  1.5  christos #  define OS_CODE  5
    137  1.1  christos #endif
    138  1.1  christos 
    139  1.1  christos #ifdef OS2
    140  1.5  christos #  define OS_CODE  6
    141  1.5  christos #  if defined(M_I86) && !defined(Z_SOLO)
    142  1.5  christos #    include <malloc.h>
    143  1.1  christos #  endif
    144  1.1  christos #endif
    145  1.1  christos 
    146  1.1  christos #if defined(MACOS) || defined(TARGET_OS_MAC)
    147  1.5  christos #  define OS_CODE  7
    148  1.5  christos #  ifndef Z_SOLO
    149  1.5  christos #    if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
    150  1.5  christos #      include <unix.h> /* for fdopen */
    151  1.5  christos #    else
    152  1.5  christos #      ifndef fdopen
    153  1.5  christos #        define fdopen(fd,mode) NULL /* No fdopen() */
    154  1.5  christos #      endif
    155  1.1  christos #    endif
    156  1.1  christos #  endif
    157  1.1  christos #endif
    158  1.1  christos 
    159  1.5  christos #ifdef __acorn
    160  1.5  christos #  define OS_CODE 13
    161  1.5  christos #endif
    162  1.5  christos 
    163  1.5  christos #if defined(WIN32) && !defined(__CYGWIN__)
    164  1.5  christos #  define OS_CODE  10
    165  1.1  christos #endif
    166  1.1  christos 
    167  1.5  christos #ifdef _BEOS_
    168  1.5  christos #  define OS_CODE  16
    169  1.5  christos #endif
    170  1.5  christos 
    171  1.5  christos #ifdef __TOS_OS400__
    172  1.5  christos #  define OS_CODE 18
    173  1.1  christos #endif
    174  1.1  christos 
    175  1.5  christos #ifdef __APPLE__
    176  1.5  christos #  define OS_CODE 19
    177  1.1  christos #endif
    178  1.1  christos 
    179  1.1  christos #if defined(_BEOS_) || defined(RISCOS)
    180  1.1  christos #  define fdopen(fd,mode) NULL /* No fdopen() */
    181  1.1  christos #endif
    182  1.1  christos 
    183  1.5  christos #if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX
    184  1.1  christos #  if defined(_WIN32_WCE)
    185  1.1  christos #    define fdopen(fd,mode) NULL /* No fdopen() */
    186  1.1  christos #  else
    187  1.1  christos #    define fdopen(fd,type)  _fdopen(fd,type)
    188  1.1  christos #  endif
    189  1.1  christos #endif
    190  1.1  christos 
    191  1.5  christos #if defined(__BORLANDC__) && !defined(MSDOS)
    192  1.5  christos   #pragma warn -8004
    193  1.5  christos   #pragma warn -8008
    194  1.5  christos   #pragma warn -8066
    195  1.5  christos #endif
    196  1.5  christos 
    197  1.5  christos /* provide prototypes for these when building zlib without LFS */
    198  1.5  christos #if !defined(_WIN32) && \
    199  1.5  christos     (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
    200  1.5  christos     ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
    201  1.5  christos     ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
    202  1.6  christos     ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t));
    203  1.5  christos #endif
    204  1.5  christos 
    205  1.1  christos         /* common defaults */
    206  1.1  christos 
    207  1.1  christos #ifndef OS_CODE
    208  1.5  christos #  define OS_CODE  3     /* assume Unix */
    209  1.1  christos #endif
    210  1.1  christos 
    211  1.1  christos #ifndef F_OPEN
    212  1.1  christos #  define F_OPEN(name, mode) fopen((name), (mode))
    213  1.1  christos #endif
    214  1.1  christos 
    215  1.1  christos          /* functions */
    216  1.1  christos 
    217  1.5  christos #if defined(pyr) || defined(Z_SOLO)
    218  1.1  christos #  define NO_MEMCPY
    219  1.1  christos #endif
    220  1.1  christos #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
    221  1.1  christos  /* Use our own functions for small and medium model with MSC <= 5.0.
    222  1.1  christos   * You may have to use the same strategy for Borland C (untested).
    223  1.1  christos   * The __SC__ check is for Symantec.
    224  1.1  christos   */
    225  1.1  christos #  define NO_MEMCPY
    226  1.1  christos #endif
    227  1.1  christos #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
    228  1.1  christos #  define HAVE_MEMCPY
    229  1.1  christos #endif
    230  1.1  christos #ifdef HAVE_MEMCPY
    231  1.1  christos #  ifdef SMALL_MEDIUM /* MSDOS small or medium model */
    232  1.1  christos #    define zmemcpy _fmemcpy
    233  1.1  christos #    define zmemcmp _fmemcmp
    234  1.1  christos #    define zmemzero(dest, len) _fmemset(dest, 0, len)
    235  1.1  christos #  else
    236  1.1  christos #    define zmemcpy memcpy
    237  1.1  christos #    define zmemcmp memcmp
    238  1.1  christos #    define zmemzero(dest, len) memset(dest, 0, len)
    239  1.1  christos #  endif
    240  1.1  christos #else
    241  1.5  christos    void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
    242  1.5  christos    int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
    243  1.5  christos    void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));
    244  1.1  christos #endif
    245  1.1  christos 
    246  1.1  christos /* Diagnostic functions */
    247  1.5  christos #ifdef ZLIB_DEBUG
    248  1.1  christos #  include <stdio.h>
    249  1.5  christos    extern int ZLIB_INTERNAL z_verbose;
    250  1.5  christos    extern void ZLIB_INTERNAL z_error OF((char *m));
    251  1.1  christos #  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
    252  1.1  christos #  define Trace(x) {if (z_verbose>=0) fprintf x ;}
    253  1.1  christos #  define Tracev(x) {if (z_verbose>0) fprintf x ;}
    254  1.1  christos #  define Tracevv(x) {if (z_verbose>1) fprintf x ;}
    255  1.1  christos #  define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
    256  1.1  christos #  define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
    257  1.1  christos #else
    258  1.1  christos #  define Assert(cond,msg)
    259  1.1  christos #  define Trace(x)
    260  1.1  christos #  define Tracev(x)
    261  1.1  christos #  define Tracevv(x)
    262  1.1  christos #  define Tracec(c,x)
    263  1.1  christos #  define Tracecv(c,x)
    264  1.1  christos #endif
    265  1.1  christos 
    266  1.5  christos #ifndef Z_SOLO
    267  1.5  christos    voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
    268  1.5  christos                                     unsigned size));
    269  1.5  christos    void ZLIB_INTERNAL zcfree  OF((voidpf opaque, voidpf ptr));
    270  1.5  christos #endif
    271  1.1  christos 
    272  1.1  christos #define ZALLOC(strm, items, size) \
    273  1.1  christos            (*((strm)->zalloc))((strm)->opaque, (items), (size))
    274  1.1  christos #define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
    275  1.1  christos #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
    276  1.1  christos 
    277  1.5  christos /* Reverse the bytes in a 32-bit value */
    278  1.5  christos #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
    279  1.5  christos                     (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
    280  1.5  christos 
    281  1.1  christos #endif /* ZUTIL_H */
    282