1 /* zutil.h -- internal interface and configuration of the compression library
2  * Copyright (C) 1995-2013 Jean-loup Gailly.
3  * For conditions of distribution and use, see copyright notice in zlib.h
4  */
5 
6 /* WARNING: this file should *not* be used by applications. It is
7    part of the implementation of the compression library and is
8    subject to change. Applications should only use zlib.h.
9  */
10 
11 /* @(#) $Id$ */
12 
13 #ifndef ZUTIL_H
14 #define ZUTIL_H
15 
16 #ifdef HAVE_HIDDEN
17 #  define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
18 #else
19 #  define ZLIB_INTERNAL
20 #endif
21 
22 #include <sys/param.h> /* for panic() */
23 #include "hammer2_zlib.h"
24 
25 #ifndef local
26 #  define local static
27 #endif
28 /* compile with -Dlocal if your debugger can't find static symbols */
29 
30 typedef unsigned char  uch;
31 typedef uch FAR uchf;
32 typedef unsigned short ush;
33 typedef ush FAR ushf;
34 typedef unsigned long  ulg;
35 
36 extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
37 /* (size given to avoid silly warnings with Visual C++) */
38 
39 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
40 
41 #define ERR_RETURN(strm,err) \
42   return (strm->msg = ERR_MSG(err), (err))
43 /* To be used only when the state is known to be valid */
44 
45         /* common constants */
46 
47 #ifndef DEF_WBITS
48 #  define DEF_WBITS MAX_WBITS
49 #endif
50 /* default windowBits for decompression. MAX_WBITS is for compression only */
51 
52 #if MAX_MEM_LEVEL >= 8
53 #  define DEF_MEM_LEVEL 8
54 #else
55 #  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
56 #endif
57 /* default memLevel */
58 
59 #define STORED_BLOCK 0
60 #define STATIC_TREES 1
61 #define DYN_TREES    2
62 /* The three kinds of block type */
63 
64 #define MIN_MATCH  3
65 #define MAX_MATCH  258
66 /* The minimum and maximum match lengths */
67 
68 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
69 
70         /* target dependencies */
71 
72 #if defined(__BORLANDC__) && !defined(MSDOS)
73   #pragma warn -8004
74   #pragma warn -8008
75   #pragma warn -8066
76 #endif
77 
78 /* provide prototypes for these when building zlib without LFS */
79 #if !defined(_WIN32) && \
80     (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
81     uLong adler32_combine64(uLong, uLong, z_off_t);
82 #endif
83 
84         /* common defaults */
85 
86 #ifndef OS_CODE
87 #  define OS_CODE  0x03  /* assume Unix */
88 #endif
89 
90 #ifndef F_OPEN
91 #  define F_OPEN(name, mode) fopen((name), (mode))
92 #endif
93 
94          /* functions */
95 
96 #if defined(pyr) || defined(Z_SOLO)
97 #  define NO_MEMCPY
98 #endif
99 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
100  /* Use our own functions for small and medium model with MSC <= 5.0.
101   * You may have to use the same strategy for Borland C (untested).
102   * The __SC__ check is for Symantec.
103   */
104 #  define NO_MEMCPY
105 #endif
106 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
107 #  define HAVE_MEMCPY
108 #endif
109 #ifdef HAVE_MEMCPY
110 #  ifdef SMALL_MEDIUM /* MSDOS small or medium model */
111 #    define zmemcpy _fmemcpy
112 #    define zmemcmp _fmemcmp
113 #    define zmemzero(dest, len) _fmemset(dest, 0, len)
114 #  else
115 #    define zmemcpy memcpy
116 #    define zmemcmp memcmp
117 #    define zmemzero(dest, len) memset(dest, 0, len)
118 #  endif
119 #else
120    void ZLIB_INTERNAL zmemcpy((Bytef* dest, const Bytef* source, uInt len));
121    int ZLIB_INTERNAL zmemcmp((const Bytef* s1, const Bytef* s2, uInt len));
122    void ZLIB_INTERNAL zmemzero((Bytef* dest, uInt len));
123 #endif
124 
125 /* Diagnostic functions */
126 #ifdef H2_ZLIB_DEBUG
127 #  include <stdio.h>
128    extern int ZLIB_INTERNAL z_verbose;
129    extern void ZLIB_INTERNAL z_error(char *m);
130 #  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
131 #  define Trace(x) {if (z_verbose>=0) fprintf x ;}
132 #  define Tracev(x) {if (z_verbose>0) fprintf x ;}
133 #  define Tracevv(x) {if (z_verbose>1) fprintf x ;}
134 #  define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
135 #  define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
136 #else
137 #  define Assert(cond,msg)
138 #  define Trace(x)
139 #  define Tracev(x)
140 #  define Tracevv(x)
141 #  define Tracec(c,x)
142 #  define Tracecv(c,x)
143 #endif
144 
145 /* Reverse the bytes in a 32-bit value */
146 #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
147                     (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
148 
149 #endif /* ZUTIL_H */
150