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