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