diff options
Diffstat (limited to 'inflate.c')
-rw-r--r-- | inflate.c | 31 |
1 files changed, 25 insertions, 6 deletions
@@ -117,6 +117,7 @@ z_streamp strm; | |||
117 | state->head = Z_NULL; | 117 | state->head = Z_NULL; |
118 | state->wsize = 0; | 118 | state->wsize = 0; |
119 | state->whave = 0; | 119 | state->whave = 0; |
120 | state->write = 0; | ||
120 | state->hold = 0; | 121 | state->hold = 0; |
121 | state->bits = 0; | 122 | state->bits = 0; |
122 | state->lencode = state->distcode = state->next = state->codes; | 123 | state->lencode = state->distcode = state->next = state->codes; |
@@ -124,6 +125,22 @@ z_streamp strm; | |||
124 | return Z_OK; | 125 | return Z_OK; |
125 | } | 126 | } |
126 | 127 | ||
128 | int ZEXPORT inflatePrime(strm, bits, value) | ||
129 | z_streamp strm; | ||
130 | int bits; | ||
131 | int value; | ||
132 | { | ||
133 | struct inflate_state FAR *state; | ||
134 | |||
135 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | ||
136 | state = (struct inflate_state FAR *)strm->state; | ||
137 | if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR; | ||
138 | value &= (1L << bits) - 1; | ||
139 | state->hold += value << state->bits; | ||
140 | state->bits += bits; | ||
141 | return Z_OK; | ||
142 | } | ||
143 | |||
127 | int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) | 144 | int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) |
128 | z_streamp strm; | 145 | z_streamp strm; |
129 | int windowBits; | 146 | int windowBits; |
@@ -146,7 +163,7 @@ int stream_size; | |||
146 | ZALLOC(strm, 1, sizeof(struct inflate_state)); | 163 | ZALLOC(strm, 1, sizeof(struct inflate_state)); |
147 | if (state == Z_NULL) return Z_MEM_ERROR; | 164 | if (state == Z_NULL) return Z_MEM_ERROR; |
148 | Tracev((stderr, "inflate: allocated\n")); | 165 | Tracev((stderr, "inflate: allocated\n")); |
149 | strm->state = (voidpf)state; | 166 | strm->state = (struct internal_state FAR *)state; |
150 | if (windowBits < 0) { | 167 | if (windowBits < 0) { |
151 | state->wrap = 0; | 168 | state->wrap = 0; |
152 | windowBits = -windowBits; | 169 | windowBits = -windowBits; |
@@ -1310,6 +1327,7 @@ z_streamp source; | |||
1310 | struct inflate_state FAR *state; | 1327 | struct inflate_state FAR *state; |
1311 | struct inflate_state FAR *copy; | 1328 | struct inflate_state FAR *copy; |
1312 | unsigned char FAR *window; | 1329 | unsigned char FAR *window; |
1330 | unsigned wsize; | ||
1313 | 1331 | ||
1314 | /* check input */ | 1332 | /* check input */ |
1315 | if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL || | 1333 | if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL || |
@@ -1335,15 +1353,16 @@ z_streamp source; | |||
1335 | zmemcpy(dest, source, sizeof(z_stream)); | 1353 | zmemcpy(dest, source, sizeof(z_stream)); |
1336 | zmemcpy(copy, state, sizeof(struct inflate_state)); | 1354 | zmemcpy(copy, state, sizeof(struct inflate_state)); |
1337 | if (state->lencode >= state->codes && | 1355 | if (state->lencode >= state->codes && |
1338 | state->lencode <= state->codes + ENOUGH - 1) | 1356 | state->lencode <= state->codes + ENOUGH - 1) { |
1339 | { | ||
1340 | copy->lencode = copy->codes + (state->lencode - state->codes); | 1357 | copy->lencode = copy->codes + (state->lencode - state->codes); |
1341 | copy->distcode = copy->codes + (state->distcode - state->codes); | 1358 | copy->distcode = copy->codes + (state->distcode - state->codes); |
1342 | } | 1359 | } |
1343 | copy->next = copy->codes + (state->next - state->codes); | 1360 | copy->next = copy->codes + (state->next - state->codes); |
1344 | if (window != Z_NULL) | 1361 | if (window != Z_NULL) { |
1345 | zmemcpy(window, state->window, (uInt)(1U << state->wbits)); | 1362 | wsize = 1U << state->wbits; |
1363 | zmemcpy(window, state->window, wsize); | ||
1364 | } | ||
1346 | copy->window = window; | 1365 | copy->window = window; |
1347 | dest->state = (voidpf)copy; | 1366 | dest->state = (struct internal_state FAR *)copy; |
1348 | return Z_OK; | 1367 | return Z_OK; |
1349 | } | 1368 | } |