| 1 |
/* |
| 2 |
* This file is a part of the zlib compression module for NSIS. |
| 3 |
* |
| 4 |
* Copyright and license information can be found below. |
| 5 |
* Modifications Copyright (C) 1999-2026 Nullsoft and Contributors |
| 6 |
* |
| 7 |
* The original zlib source code is available at |
| 8 |
* http://www.zlib.net/ |
| 9 |
* |
| 10 |
* This software is provided 'as-is', without any express or implied |
| 11 |
* warranty. |
| 12 |
* |
| 13 |
* Unicode support by Jim Park -- 08/27/2007 |
| 14 |
*/ |
| 15 |
|
| 16 |
/* zlib.h -- interface of the 'zlib' general purpose compression library |
| 17 |
version 1.1.3, July 9th, 1998 |
| 18 |
|
| 19 |
Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler |
| 20 |
|
| 21 |
This software is provided 'as-is', without any express or implied |
| 22 |
warranty. In no event will the authors be held liable for any damages |
| 23 |
arising from the use of this software. |
| 24 |
|
| 25 |
Permission is granted to anyone to use this software for any purpose, |
| 26 |
including commercial applications, and to alter it and redistribute it |
| 27 |
freely, subject to the following restrictions: |
| 28 |
|
| 29 |
1. The origin of this software must not be misrepresented; you must not |
| 30 |
claim that you wrote the original software. If you use this software |
| 31 |
in a product, an acknowledgment in the product documentation would be |
| 32 |
appreciated but is not required. |
| 33 |
2. Altered source versions must be plainly marked as such, and must not be |
| 34 |
misrepresented as being the original software. |
| 35 |
3. This notice may not be removed or altered from any source distribution. |
| 36 |
|
| 37 |
Jean-loup Gailly Mark Adler |
| 38 |
[email protected] [email protected] |
| 39 |
|
| 40 |
|
| 41 |
*/ |
| 42 |
|
| 43 |
#ifndef _ZLIB_H |
| 44 |
#define _ZLIB_H |
| 45 |
|
| 46 |
#include "ZCONF.H" |
| 47 |
#include "ZUTIL.H" |
| 48 |
|
| 49 |
#ifdef __cplusplus |
| 50 |
extern "C" { |
| 51 |
#endif |
| 52 |
|
| 53 |
|
| 54 |
#ifdef EXEHEAD |
| 55 |
|
| 56 |
typedef struct inflate_huft_s FAR inflate_huft; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */ |
| 61 |
CODES_START, /* x: set up for LEN */ |
| 62 |
CODES_LEN, /* i: get length/literal/eob next */ |
| 63 |
CODES_LENEXT, /* i: getting length extra (have base) */ |
| 64 |
CODES_DIST, /* i: get distance next */ |
| 65 |
CODES_DISTEXT, /* i: getting distance extra */ |
| 66 |
CODES_COPY, /* o: copying bytes in window, waiting for space */ |
| 67 |
CODES_LIT, /* o: got literal, waiting for output space */ |
| 68 |
CODES_WASH, /* o: got eob, possibly still output waiting */ |
| 69 |
//CODES_END, /* x: got eob and all data flushed */ |
| 70 |
//CODES_BADCODE, /* x: got error */ |
| 71 |
|
| 72 |
TYPE, /* get type bits (3, including end bit) */ |
| 73 |
LENS, /* get lengths for stored */ |
| 74 |
STORED, /* processing stored block */ |
| 75 |
TABLE, /* get table lengths */ |
| 76 |
BTREE, /* get bit lengths tree for a dynamic block */ |
| 77 |
DTREE, /* get length, distance trees for a dynamic block */ |
| 78 |
CODES, /* processing fixed or dynamic block */ |
| 79 |
DRY, /* output remaining window bytes */ |
| 80 |
DONE, /* finished last block, done */ |
| 81 |
BAD /* got a data error--stuck here */ |
| 82 |
} inflate_mode; |
| 83 |
|
| 84 |
/* inflate codes private state */ |
| 85 |
struct inflate_codes_state { |
| 86 |
|
| 87 |
/* mode */ |
| 88 |
//inflate_mode mode; /* current inflate_codes mode */ |
| 89 |
|
| 90 |
/* mode dependent information */ |
| 91 |
uInt len; |
| 92 |
union { |
| 93 |
struct { |
| 94 |
inflate_huft *tree; /* pointer into tree */ |
| 95 |
uInt need; /* bits needed */ |
| 96 |
} code; /* if LEN or DIST, where in tree */ |
| 97 |
uInt lit; /* if LIT, literal */ |
| 98 |
struct { |
| 99 |
uInt get; /* bits to get for extra */ |
| 100 |
uInt dist; /* distance back to copy from */ |
| 101 |
} copy; /* if EXT or COPY, where and how much */ |
| 102 |
} sub; /* submode */ |
| 103 |
|
| 104 |
/* mode independent information */ |
| 105 |
Byte lbits; /* ltree bits decoded per branch */ |
| 106 |
Byte dbits; /* dtree bits decoder per branch */ |
| 107 |
inflate_huft *ltree; /* literal/length/eob tree */ |
| 108 |
inflate_huft *dtree; /* distance tree */ |
| 109 |
|
| 110 |
}; |
| 111 |
|
| 112 |
struct inflate_huft_s { |
| 113 |
union { |
| 114 |
struct { |
| 115 |
Byte Exop; /* number of extra bits or operation */ |
| 116 |
Byte Bits; /* number of bits in this code or subcode */ |
| 117 |
} what; |
| 118 |
} word; |
| 119 |
unsigned short base; /* literal, length base, distance base, |
| 120 |
or table offset */ |
| 121 |
}; |
| 122 |
|
| 123 |
#define MANY 1440 |
| 124 |
|
| 125 |
typedef struct inflate_codes_state inflate_codes_statef; |
| 126 |
|
| 127 |
struct inflate_blocks_state { |
| 128 |
|
| 129 |
/* mode */ |
| 130 |
inflate_mode mode; /* current inflate_block mode */ |
| 131 |
|
| 132 |
/* mode dependent information */ |
| 133 |
union { |
| 134 |
uInt left; /* if STORED, bytes left to copy */ |
| 135 |
struct { |
| 136 |
uInt table; /* table lengths (14 bits) */ |
| 137 |
uInt index; /* index into blens (or border) */ |
| 138 |
uIntf t_blens[258+31+31]; /* bit lengths of codes */ |
| 139 |
uInt bb; /* bit length tree depth */ |
| 140 |
inflate_huft *tb; /* bit length decoding tree */ |
| 141 |
} trees; /* if DTREE, decoding info for trees */ |
| 142 |
struct { |
| 143 |
inflate_codes_statef t_codes; |
| 144 |
} decode; /* if CODES, current state */ |
| 145 |
} sub; /* submode */ |
| 146 |
|
| 147 |
uInt last; /* DRY if this block is the last block, TYPE otherwise */ |
| 148 |
|
| 149 |
/* mode independent information */ |
| 150 |
uInt bitk; /* bits in bit buffer */ |
| 151 |
uLong bitb; /* bit buffer */ |
| 152 |
inflate_huft hufts[MANY]; /* single malloc for tree space */ |
| 153 |
Bytef window[1 << MAX_WBITS]; /* sliding window */ |
| 154 |
Bytef *end; /* one byte after sliding window */ |
| 155 |
Bytef *read; /* window read pointer */ |
| 156 |
Bytef *write; /* window write pointer */ |
| 157 |
uLong check; /* check on output */ |
| 158 |
|
| 159 |
}; |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
#else |
| 164 |
struct internal_state; |
| 165 |
#endif |
| 166 |
|
| 167 |
typedef struct z_stream_s { |
| 168 |
Bytef *next_in; /* next input byte */ |
| 169 |
uInt avail_in; /* number of bytes available at next_in */ |
| 170 |
#ifndef EXEHEAD |
| 171 |
uLong total_in; /* total nb of input bytes read so far */ |
| 172 |
#endif |
| 173 |
|
| 174 |
Bytef *next_out; /* next output byte should be put there */ |
| 175 |
uInt avail_out; /* remaining free space at next_out */ |
| 176 |
#ifndef EXEHEAD |
| 177 |
uLong total_out; /* total nb of bytes output so far */ |
| 178 |
#endif |
| 179 |
|
| 180 |
// TCHAR *msg; /* last error message, NULL if no error */ |
| 181 |
//struct internal_state FAR *state; /* not visible by applications */ |
| 182 |
#ifdef EXEHEAD |
| 183 |
struct inflate_blocks_state blocks; /* current inflate_blocks state */ |
| 184 |
#else |
| 185 |
struct internal_state *state; |
| 186 |
#endif |
| 187 |
|
| 188 |
} z_stream; |
| 189 |
|
| 190 |
typedef z_stream FAR *z_streamp; |
| 191 |
|
| 192 |
|
| 193 |
#define Z_NO_FLUSH 0 |
| 194 |
#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ |
| 195 |
#define Z_SYNC_FLUSH 2 |
| 196 |
#define Z_FULL_FLUSH 3 |
| 197 |
#define Z_FINISH 4 |
| 198 |
/* Allowed flush values; see deflate() below for details */ |
| 199 |
|
| 200 |
#define Z_OK 0 |
| 201 |
#define Z_STREAM_END 1 |
| 202 |
#define Z_NEED_DICT 2 |
| 203 |
#define Z_ERRNO (-1) |
| 204 |
|
| 205 |
#ifndef EXEHEAD |
| 206 |
|
| 207 |
#define Z_STREAM_ERROR (-2) |
| 208 |
#define Z_DATA_ERROR (-3) |
| 209 |
#define Z_MEM_ERROR (-4) |
| 210 |
#define Z_BUF_ERROR (-5) |
| 211 |
#define Z_VERSION_ERROR (-6) |
| 212 |
|
| 213 |
#else |
| 214 |
// EXEHEAD doesn't need a specific return code, just < 0 |
| 215 |
|
| 216 |
#define Z_STREAM_ERROR Z_ERRNO |
| 217 |
#define Z_DATA_ERROR Z_ERRNO |
| 218 |
#define Z_MEM_ERROR Z_ERRNO |
| 219 |
#define Z_BUF_ERROR Z_ERRNO |
| 220 |
#define Z_VERSION_ERROR Z_ERRNO |
| 221 |
|
| 222 |
#endif |
| 223 |
/* Return codes for the compression/decompression functions. Negative |
| 224 |
* values are errors, positive values are used for special but normal events. |
| 225 |
*/ |
| 226 |
|
| 227 |
#define Z_NO_COMPRESSION 0 |
| 228 |
#define Z_BEST_SPEED 1 |
| 229 |
#define Z_BEST_COMPRESSION 9 |
| 230 |
#define Z_DEFAULT_COMPRESSION (-1) |
| 231 |
/* compression levels */ |
| 232 |
|
| 233 |
#define Z_FILTERED 1 |
| 234 |
#define Z_HUFFMAN_ONLY 2 |
| 235 |
#define Z_DEFAULT_STRATEGY 0 |
| 236 |
/* compression strategy; see deflateInit2() below for details */ |
| 237 |
|
| 238 |
#define Z_BINARY 0 |
| 239 |
#define Z_ASCII 1 |
| 240 |
#define Z_UNKNOWN 2 |
| 241 |
/* Possible values of the data_type field */ |
| 242 |
|
| 243 |
#define Z_DEFLATED 8 |
| 244 |
/* The deflate compression method (the only one supported in this version) */ |
| 245 |
|
| 246 |
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ |
| 247 |
|
| 248 |
|
| 249 |
ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); |
| 250 |
|
| 251 |
ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); |
| 252 |
|
| 253 |
|
| 254 |
#define inflateInit(x) inflateReset(x) |
| 255 |
int ZEXPORT inflate(z_streamp z); |
| 256 |
ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); |
| 257 |
ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, |
| 258 |
int level, |
| 259 |
int method, |
| 260 |
int windowBits, |
| 261 |
int memLevel, |
| 262 |
int strategy)); |
| 263 |
|
| 264 |
|
| 265 |
ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); |
| 266 |
|
| 267 |
//void ZEXPORT inflateReset OF(( |
| 268 |
// z_streamp)); |
| 269 |
#define inflateReset(z) \ |
| 270 |
{ \ |
| 271 |
(z)->blocks.mode = TYPE; \ |
| 272 |
(z)->blocks.bitk = (z)->blocks.bitb = 0; \ |
| 273 |
(z)->blocks.read = (z)->blocks.write = (z)->blocks.window; \ |
| 274 |
(z)->blocks.end = (z)->blocks.window + (1 << DEF_WBITS); \ |
| 275 |
} |
| 276 |
|
| 277 |
/* various hacks, don't look :) */ |
| 278 |
|
| 279 |
/* deflateInit and inflateInit are macros to allow checking the zlib version |
| 280 |
* and the compiler's view of z_stream: |
| 281 |
*/ |
| 282 |
ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, |
| 283 |
const TCHAR *version, int stream_size)); |
| 284 |
//ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, |
| 285 |
// const TCHAR *version, int stream_size)); |
| 286 |
ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, |
| 287 |
int windowBits, int memLevel, |
| 288 |
int strategy, const TCHAR *version, |
| 289 |
int stream_size)); |
| 290 |
|
| 291 |
#define deflateInit(strm, level) \ |
| 292 |
deflateInit_((strm), (level), _T(""), sizeof(z_stream)) |
| 293 |
|
| 294 |
|
| 295 |
#ifdef __cplusplus |
| 296 |
} |
| 297 |
#endif |
| 298 |
|
| 299 |
#endif /* _ZLIB_H */ |