OLD | NEW |
1 /* infback.c -- inflate using a call-back interface | 1 /* infback.c -- inflate using a call-back interface |
2 * Copyright (C) 1995-2011 Mark Adler | 2 * Copyright (C) 1995-2009 Mark Adler |
3 * For conditions of distribution and use, see copyright notice in zlib.h | 3 * For conditions of distribution and use, see copyright notice in zlib.h |
4 */ | 4 */ |
5 | 5 |
6 /* | 6 /* |
7 This code is largely copied from inflate.c. Normally either infback.o or | 7 This code is largely copied from inflate.c. Normally either infback.o or |
8 inflate.o would be linked into an application--not both. The interface | 8 inflate.o would be linked into an application--not both. The interface |
9 with inffast.c is retained so that optimized assembler-coded versions of | 9 with inffast.c is retained so that optimized assembler-coded versions of |
10 inflate_fast() can be used with either inflate.c or infback.c. | 10 inflate_fast() can be used with either inflate.c or infback.c. |
11 */ | 11 */ |
12 | 12 |
(...skipping 22 matching lines...) Expand all Loading... |
35 struct inflate_state FAR *state; | 35 struct inflate_state FAR *state; |
36 | 36 |
37 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || | 37 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || |
38 stream_size != (int)(sizeof(z_stream))) | 38 stream_size != (int)(sizeof(z_stream))) |
39 return Z_VERSION_ERROR; | 39 return Z_VERSION_ERROR; |
40 if (strm == Z_NULL || window == Z_NULL || | 40 if (strm == Z_NULL || window == Z_NULL || |
41 windowBits < 8 || windowBits > 15) | 41 windowBits < 8 || windowBits > 15) |
42 return Z_STREAM_ERROR; | 42 return Z_STREAM_ERROR; |
43 strm->msg = Z_NULL; /* in case we return an error */ | 43 strm->msg = Z_NULL; /* in case we return an error */ |
44 if (strm->zalloc == (alloc_func)0) { | 44 if (strm->zalloc == (alloc_func)0) { |
45 #ifdef Z_SOLO | |
46 return Z_STREAM_ERROR; | |
47 #else | |
48 strm->zalloc = zcalloc; | 45 strm->zalloc = zcalloc; |
49 strm->opaque = (voidpf)0; | 46 strm->opaque = (voidpf)0; |
50 #endif | |
51 } | 47 } |
52 if (strm->zfree == (free_func)0) | 48 if (strm->zfree == (free_func)0) strm->zfree = zcfree; |
53 #ifdef Z_SOLO | |
54 return Z_STREAM_ERROR; | |
55 #else | |
56 strm->zfree = zcfree; | |
57 #endif | |
58 state = (struct inflate_state FAR *)ZALLOC(strm, 1, | 49 state = (struct inflate_state FAR *)ZALLOC(strm, 1, |
59 sizeof(struct inflate_state)); | 50 sizeof(struct inflate_state)); |
60 if (state == Z_NULL) return Z_MEM_ERROR; | 51 if (state == Z_NULL) return Z_MEM_ERROR; |
61 Tracev((stderr, "inflate: allocated\n")); | 52 Tracev((stderr, "inflate: allocated\n")); |
62 strm->state = (struct internal_state FAR *)state; | 53 strm->state = (struct internal_state FAR *)state; |
63 state->dmax = 32768U; | 54 state->dmax = 32768U; |
64 state->wbits = windowBits; | 55 state->wbits = windowBits; |
65 state->wsize = 1U << windowBits; | 56 state->wsize = 1U << windowBits; |
66 state->window = window; | 57 state->window = window; |
67 state->wnext = 0; | 58 state->wnext = 0; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 are not correct, i.e. strm is Z_NULL or the state was not initialized. | 239 are not correct, i.e. strm is Z_NULL or the state was not initialized. |
249 */ | 240 */ |
250 int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc) | 241 int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc) |
251 z_streamp strm; | 242 z_streamp strm; |
252 in_func in; | 243 in_func in; |
253 void FAR *in_desc; | 244 void FAR *in_desc; |
254 out_func out; | 245 out_func out; |
255 void FAR *out_desc; | 246 void FAR *out_desc; |
256 { | 247 { |
257 struct inflate_state FAR *state; | 248 struct inflate_state FAR *state; |
258 z_const unsigned char FAR *next; /* next input */ | 249 unsigned char FAR *next; /* next input */ |
259 unsigned char FAR *put; /* next output */ | 250 unsigned char FAR *put; /* next output */ |
260 unsigned have, left; /* available input and output */ | 251 unsigned have, left; /* available input and output */ |
261 unsigned long hold; /* bit buffer */ | 252 unsigned long hold; /* bit buffer */ |
262 unsigned bits; /* bits in bit buffer */ | 253 unsigned bits; /* bits in bit buffer */ |
263 unsigned copy; /* number of stored or match bytes to copy */ | 254 unsigned copy; /* number of stored or match bytes to copy */ |
264 unsigned char FAR *from; /* where to copy match bytes from */ | 255 unsigned char FAR *from; /* where to copy match bytes from */ |
265 code here; /* current decoding table entry */ | 256 code here; /* current decoding table entry */ |
266 code last; /* parent table entry */ | 257 code last; /* parent table entry */ |
267 unsigned len; /* length to copy for repeats, bits to drop */ | 258 unsigned len; /* length to copy for repeats, bits to drop */ |
268 int ret; /* return code */ | 259 int ret; /* return code */ |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 387 |
397 /* get length and distance code code lengths */ | 388 /* get length and distance code code lengths */ |
398 state->have = 0; | 389 state->have = 0; |
399 while (state->have < state->nlen + state->ndist) { | 390 while (state->have < state->nlen + state->ndist) { |
400 for (;;) { | 391 for (;;) { |
401 here = state->lencode[BITS(state->lenbits)]; | 392 here = state->lencode[BITS(state->lenbits)]; |
402 if ((unsigned)(here.bits) <= bits) break; | 393 if ((unsigned)(here.bits) <= bits) break; |
403 PULLBYTE(); | 394 PULLBYTE(); |
404 } | 395 } |
405 if (here.val < 16) { | 396 if (here.val < 16) { |
| 397 NEEDBITS(here.bits); |
406 DROPBITS(here.bits); | 398 DROPBITS(here.bits); |
407 state->lens[state->have++] = here.val; | 399 state->lens[state->have++] = here.val; |
408 } | 400 } |
409 else { | 401 else { |
410 if (here.val == 16) { | 402 if (here.val == 16) { |
411 NEEDBITS(here.bits + 2); | 403 NEEDBITS(here.bits + 2); |
412 DROPBITS(here.bits); | 404 DROPBITS(here.bits); |
413 if (state->have == 0) { | 405 if (state->have == 0) { |
414 strm->msg = (char *)"invalid bit length repeat"; | 406 strm->msg = (char *)"invalid bit length repeat"; |
415 state->mode = BAD; | 407 state->mode = BAD; |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 int ZEXPORT inflateBackEnd(strm) | 623 int ZEXPORT inflateBackEnd(strm) |
632 z_streamp strm; | 624 z_streamp strm; |
633 { | 625 { |
634 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) | 626 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) |
635 return Z_STREAM_ERROR; | 627 return Z_STREAM_ERROR; |
636 ZFREE(strm, strm->state); | 628 ZFREE(strm, strm->state); |
637 strm->state = Z_NULL; | 629 strm->state = Z_NULL; |
638 Tracev((stderr, "inflate: end\n")); | 630 Tracev((stderr, "inflate: end\n")); |
639 return Z_OK; | 631 return Z_OK; |
640 } | 632 } |
OLD | NEW |