1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/modules/zlib/src/infback.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,640 @@ 1.4 +/* infback.c -- inflate using a call-back interface 1.5 + * Copyright (C) 1995-2011 Mark Adler 1.6 + * For conditions of distribution and use, see copyright notice in zlib.h 1.7 + */ 1.8 + 1.9 +/* 1.10 + This code is largely copied from inflate.c. Normally either infback.o or 1.11 + inflate.o would be linked into an application--not both. The interface 1.12 + with inffast.c is retained so that optimized assembler-coded versions of 1.13 + inflate_fast() can be used with either inflate.c or infback.c. 1.14 + */ 1.15 + 1.16 +#include "zutil.h" 1.17 +#include "inftrees.h" 1.18 +#include "inflate.h" 1.19 +#include "inffast.h" 1.20 + 1.21 +/* function prototypes */ 1.22 +local void fixedtables OF((struct inflate_state FAR *state)); 1.23 + 1.24 +/* 1.25 + strm provides memory allocation functions in zalloc and zfree, or 1.26 + Z_NULL to use the library memory allocation functions. 1.27 + 1.28 + windowBits is in the range 8..15, and window is a user-supplied 1.29 + window and output buffer that is 2**windowBits bytes. 1.30 + */ 1.31 +int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size) 1.32 +z_streamp strm; 1.33 +int windowBits; 1.34 +unsigned char FAR *window; 1.35 +const char *version; 1.36 +int stream_size; 1.37 +{ 1.38 + struct inflate_state FAR *state; 1.39 + 1.40 + if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || 1.41 + stream_size != (int)(sizeof(z_stream))) 1.42 + return Z_VERSION_ERROR; 1.43 + if (strm == Z_NULL || window == Z_NULL || 1.44 + windowBits < 8 || windowBits > 15) 1.45 + return Z_STREAM_ERROR; 1.46 + strm->msg = Z_NULL; /* in case we return an error */ 1.47 + if (strm->zalloc == (alloc_func)0) { 1.48 +#ifdef Z_SOLO 1.49 + return Z_STREAM_ERROR; 1.50 +#else 1.51 + strm->zalloc = zcalloc; 1.52 + strm->opaque = (voidpf)0; 1.53 +#endif 1.54 + } 1.55 + if (strm->zfree == (free_func)0) 1.56 +#ifdef Z_SOLO 1.57 + return Z_STREAM_ERROR; 1.58 +#else 1.59 + strm->zfree = zcfree; 1.60 +#endif 1.61 + state = (struct inflate_state FAR *)ZALLOC(strm, 1, 1.62 + sizeof(struct inflate_state)); 1.63 + if (state == Z_NULL) return Z_MEM_ERROR; 1.64 + Tracev((stderr, "inflate: allocated\n")); 1.65 + strm->state = (struct internal_state FAR *)state; 1.66 + state->dmax = 32768U; 1.67 + state->wbits = windowBits; 1.68 + state->wsize = 1U << windowBits; 1.69 + state->window = window; 1.70 + state->wnext = 0; 1.71 + state->whave = 0; 1.72 + return Z_OK; 1.73 +} 1.74 + 1.75 +/* 1.76 + Return state with length and distance decoding tables and index sizes set to 1.77 + fixed code decoding. Normally this returns fixed tables from inffixed.h. 1.78 + If BUILDFIXED is defined, then instead this routine builds the tables the 1.79 + first time it's called, and returns those tables the first time and 1.80 + thereafter. This reduces the size of the code by about 2K bytes, in 1.81 + exchange for a little execution time. However, BUILDFIXED should not be 1.82 + used for threaded applications, since the rewriting of the tables and virgin 1.83 + may not be thread-safe. 1.84 + */ 1.85 +local void fixedtables(state) 1.86 +struct inflate_state FAR *state; 1.87 +{ 1.88 +#ifdef BUILDFIXED 1.89 + static int virgin = 1; 1.90 + static code *lenfix, *distfix; 1.91 + static code fixed[544]; 1.92 + 1.93 + /* build fixed huffman tables if first call (may not be thread safe) */ 1.94 + if (virgin) { 1.95 + unsigned sym, bits; 1.96 + static code *next; 1.97 + 1.98 + /* literal/length table */ 1.99 + sym = 0; 1.100 + while (sym < 144) state->lens[sym++] = 8; 1.101 + while (sym < 256) state->lens[sym++] = 9; 1.102 + while (sym < 280) state->lens[sym++] = 7; 1.103 + while (sym < 288) state->lens[sym++] = 8; 1.104 + next = fixed; 1.105 + lenfix = next; 1.106 + bits = 9; 1.107 + inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); 1.108 + 1.109 + /* distance table */ 1.110 + sym = 0; 1.111 + while (sym < 32) state->lens[sym++] = 5; 1.112 + distfix = next; 1.113 + bits = 5; 1.114 + inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); 1.115 + 1.116 + /* do this just once */ 1.117 + virgin = 0; 1.118 + } 1.119 +#else /* !BUILDFIXED */ 1.120 +# include "inffixed.h" 1.121 +#endif /* BUILDFIXED */ 1.122 + state->lencode = lenfix; 1.123 + state->lenbits = 9; 1.124 + state->distcode = distfix; 1.125 + state->distbits = 5; 1.126 +} 1.127 + 1.128 +/* Macros for inflateBack(): */ 1.129 + 1.130 +/* Load returned state from inflate_fast() */ 1.131 +#define LOAD() \ 1.132 + do { \ 1.133 + put = strm->next_out; \ 1.134 + left = strm->avail_out; \ 1.135 + next = strm->next_in; \ 1.136 + have = strm->avail_in; \ 1.137 + hold = state->hold; \ 1.138 + bits = state->bits; \ 1.139 + } while (0) 1.140 + 1.141 +/* Set state from registers for inflate_fast() */ 1.142 +#define RESTORE() \ 1.143 + do { \ 1.144 + strm->next_out = put; \ 1.145 + strm->avail_out = left; \ 1.146 + strm->next_in = next; \ 1.147 + strm->avail_in = have; \ 1.148 + state->hold = hold; \ 1.149 + state->bits = bits; \ 1.150 + } while (0) 1.151 + 1.152 +/* Clear the input bit accumulator */ 1.153 +#define INITBITS() \ 1.154 + do { \ 1.155 + hold = 0; \ 1.156 + bits = 0; \ 1.157 + } while (0) 1.158 + 1.159 +/* Assure that some input is available. If input is requested, but denied, 1.160 + then return a Z_BUF_ERROR from inflateBack(). */ 1.161 +#define PULL() \ 1.162 + do { \ 1.163 + if (have == 0) { \ 1.164 + have = in(in_desc, &next); \ 1.165 + if (have == 0) { \ 1.166 + next = Z_NULL; \ 1.167 + ret = Z_BUF_ERROR; \ 1.168 + goto inf_leave; \ 1.169 + } \ 1.170 + } \ 1.171 + } while (0) 1.172 + 1.173 +/* Get a byte of input into the bit accumulator, or return from inflateBack() 1.174 + with an error if there is no input available. */ 1.175 +#define PULLBYTE() \ 1.176 + do { \ 1.177 + PULL(); \ 1.178 + have--; \ 1.179 + hold += (unsigned long)(*next++) << bits; \ 1.180 + bits += 8; \ 1.181 + } while (0) 1.182 + 1.183 +/* Assure that there are at least n bits in the bit accumulator. If there is 1.184 + not enough available input to do that, then return from inflateBack() with 1.185 + an error. */ 1.186 +#define NEEDBITS(n) \ 1.187 + do { \ 1.188 + while (bits < (unsigned)(n)) \ 1.189 + PULLBYTE(); \ 1.190 + } while (0) 1.191 + 1.192 +/* Return the low n bits of the bit accumulator (n < 16) */ 1.193 +#define BITS(n) \ 1.194 + ((unsigned)hold & ((1U << (n)) - 1)) 1.195 + 1.196 +/* Remove n bits from the bit accumulator */ 1.197 +#define DROPBITS(n) \ 1.198 + do { \ 1.199 + hold >>= (n); \ 1.200 + bits -= (unsigned)(n); \ 1.201 + } while (0) 1.202 + 1.203 +/* Remove zero to seven bits as needed to go to a byte boundary */ 1.204 +#define BYTEBITS() \ 1.205 + do { \ 1.206 + hold >>= bits & 7; \ 1.207 + bits -= bits & 7; \ 1.208 + } while (0) 1.209 + 1.210 +/* Assure that some output space is available, by writing out the window 1.211 + if it's full. If the write fails, return from inflateBack() with a 1.212 + Z_BUF_ERROR. */ 1.213 +#define ROOM() \ 1.214 + do { \ 1.215 + if (left == 0) { \ 1.216 + put = state->window; \ 1.217 + left = state->wsize; \ 1.218 + state->whave = left; \ 1.219 + if (out(out_desc, put, left)) { \ 1.220 + ret = Z_BUF_ERROR; \ 1.221 + goto inf_leave; \ 1.222 + } \ 1.223 + } \ 1.224 + } while (0) 1.225 + 1.226 +/* 1.227 + strm provides the memory allocation functions and window buffer on input, 1.228 + and provides information on the unused input on return. For Z_DATA_ERROR 1.229 + returns, strm will also provide an error message. 1.230 + 1.231 + in() and out() are the call-back input and output functions. When 1.232 + inflateBack() needs more input, it calls in(). When inflateBack() has 1.233 + filled the window with output, or when it completes with data in the 1.234 + window, it calls out() to write out the data. The application must not 1.235 + change the provided input until in() is called again or inflateBack() 1.236 + returns. The application must not change the window/output buffer until 1.237 + inflateBack() returns. 1.238 + 1.239 + in() and out() are called with a descriptor parameter provided in the 1.240 + inflateBack() call. This parameter can be a structure that provides the 1.241 + information required to do the read or write, as well as accumulated 1.242 + information on the input and output such as totals and check values. 1.243 + 1.244 + in() should return zero on failure. out() should return non-zero on 1.245 + failure. If either in() or out() fails, than inflateBack() returns a 1.246 + Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it 1.247 + was in() or out() that caused in the error. Otherwise, inflateBack() 1.248 + returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format 1.249 + error, or Z_MEM_ERROR if it could not allocate memory for the state. 1.250 + inflateBack() can also return Z_STREAM_ERROR if the input parameters 1.251 + are not correct, i.e. strm is Z_NULL or the state was not initialized. 1.252 + */ 1.253 +int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc) 1.254 +z_streamp strm; 1.255 +in_func in; 1.256 +void FAR *in_desc; 1.257 +out_func out; 1.258 +void FAR *out_desc; 1.259 +{ 1.260 + struct inflate_state FAR *state; 1.261 + z_const unsigned char FAR *next; /* next input */ 1.262 + unsigned char FAR *put; /* next output */ 1.263 + unsigned have, left; /* available input and output */ 1.264 + unsigned long hold; /* bit buffer */ 1.265 + unsigned bits; /* bits in bit buffer */ 1.266 + unsigned copy; /* number of stored or match bytes to copy */ 1.267 + unsigned char FAR *from; /* where to copy match bytes from */ 1.268 + code here; /* current decoding table entry */ 1.269 + code last; /* parent table entry */ 1.270 + unsigned len; /* length to copy for repeats, bits to drop */ 1.271 + int ret; /* return code */ 1.272 + static const unsigned short order[19] = /* permutation of code lengths */ 1.273 + {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; 1.274 + 1.275 + /* Check that the strm exists and that the state was initialized */ 1.276 + if (strm == Z_NULL || strm->state == Z_NULL) 1.277 + return Z_STREAM_ERROR; 1.278 + state = (struct inflate_state FAR *)strm->state; 1.279 + 1.280 + /* Reset the state */ 1.281 + strm->msg = Z_NULL; 1.282 + state->mode = TYPE; 1.283 + state->last = 0; 1.284 + state->whave = 0; 1.285 + next = strm->next_in; 1.286 + have = next != Z_NULL ? strm->avail_in : 0; 1.287 + hold = 0; 1.288 + bits = 0; 1.289 + put = state->window; 1.290 + left = state->wsize; 1.291 + 1.292 + /* Inflate until end of block marked as last */ 1.293 + for (;;) 1.294 + switch (state->mode) { 1.295 + case TYPE: 1.296 + /* determine and dispatch block type */ 1.297 + if (state->last) { 1.298 + BYTEBITS(); 1.299 + state->mode = DONE; 1.300 + break; 1.301 + } 1.302 + NEEDBITS(3); 1.303 + state->last = BITS(1); 1.304 + DROPBITS(1); 1.305 + switch (BITS(2)) { 1.306 + case 0: /* stored block */ 1.307 + Tracev((stderr, "inflate: stored block%s\n", 1.308 + state->last ? " (last)" : "")); 1.309 + state->mode = STORED; 1.310 + break; 1.311 + case 1: /* fixed block */ 1.312 + fixedtables(state); 1.313 + Tracev((stderr, "inflate: fixed codes block%s\n", 1.314 + state->last ? " (last)" : "")); 1.315 + state->mode = LEN; /* decode codes */ 1.316 + break; 1.317 + case 2: /* dynamic block */ 1.318 + Tracev((stderr, "inflate: dynamic codes block%s\n", 1.319 + state->last ? " (last)" : "")); 1.320 + state->mode = TABLE; 1.321 + break; 1.322 + case 3: 1.323 + strm->msg = (char *)"invalid block type"; 1.324 + state->mode = BAD; 1.325 + } 1.326 + DROPBITS(2); 1.327 + break; 1.328 + 1.329 + case STORED: 1.330 + /* get and verify stored block length */ 1.331 + BYTEBITS(); /* go to byte boundary */ 1.332 + NEEDBITS(32); 1.333 + if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { 1.334 + strm->msg = (char *)"invalid stored block lengths"; 1.335 + state->mode = BAD; 1.336 + break; 1.337 + } 1.338 + state->length = (unsigned)hold & 0xffff; 1.339 + Tracev((stderr, "inflate: stored length %u\n", 1.340 + state->length)); 1.341 + INITBITS(); 1.342 + 1.343 + /* copy stored block from input to output */ 1.344 + while (state->length != 0) { 1.345 + copy = state->length; 1.346 + PULL(); 1.347 + ROOM(); 1.348 + if (copy > have) copy = have; 1.349 + if (copy > left) copy = left; 1.350 + zmemcpy(put, next, copy); 1.351 + have -= copy; 1.352 + next += copy; 1.353 + left -= copy; 1.354 + put += copy; 1.355 + state->length -= copy; 1.356 + } 1.357 + Tracev((stderr, "inflate: stored end\n")); 1.358 + state->mode = TYPE; 1.359 + break; 1.360 + 1.361 + case TABLE: 1.362 + /* get dynamic table entries descriptor */ 1.363 + NEEDBITS(14); 1.364 + state->nlen = BITS(5) + 257; 1.365 + DROPBITS(5); 1.366 + state->ndist = BITS(5) + 1; 1.367 + DROPBITS(5); 1.368 + state->ncode = BITS(4) + 4; 1.369 + DROPBITS(4); 1.370 +#ifndef PKZIP_BUG_WORKAROUND 1.371 + if (state->nlen > 286 || state->ndist > 30) { 1.372 + strm->msg = (char *)"too many length or distance symbols"; 1.373 + state->mode = BAD; 1.374 + break; 1.375 + } 1.376 +#endif 1.377 + Tracev((stderr, "inflate: table sizes ok\n")); 1.378 + 1.379 + /* get code length code lengths (not a typo) */ 1.380 + state->have = 0; 1.381 + while (state->have < state->ncode) { 1.382 + NEEDBITS(3); 1.383 + state->lens[order[state->have++]] = (unsigned short)BITS(3); 1.384 + DROPBITS(3); 1.385 + } 1.386 + while (state->have < 19) 1.387 + state->lens[order[state->have++]] = 0; 1.388 + state->next = state->codes; 1.389 + state->lencode = (code const FAR *)(state->next); 1.390 + state->lenbits = 7; 1.391 + ret = inflate_table(CODES, state->lens, 19, &(state->next), 1.392 + &(state->lenbits), state->work); 1.393 + if (ret) { 1.394 + strm->msg = (char *)"invalid code lengths set"; 1.395 + state->mode = BAD; 1.396 + break; 1.397 + } 1.398 + Tracev((stderr, "inflate: code lengths ok\n")); 1.399 + 1.400 + /* get length and distance code code lengths */ 1.401 + state->have = 0; 1.402 + while (state->have < state->nlen + state->ndist) { 1.403 + for (;;) { 1.404 + here = state->lencode[BITS(state->lenbits)]; 1.405 + if ((unsigned)(here.bits) <= bits) break; 1.406 + PULLBYTE(); 1.407 + } 1.408 + if (here.val < 16) { 1.409 + DROPBITS(here.bits); 1.410 + state->lens[state->have++] = here.val; 1.411 + } 1.412 + else { 1.413 + if (here.val == 16) { 1.414 + NEEDBITS(here.bits + 2); 1.415 + DROPBITS(here.bits); 1.416 + if (state->have == 0) { 1.417 + strm->msg = (char *)"invalid bit length repeat"; 1.418 + state->mode = BAD; 1.419 + break; 1.420 + } 1.421 + len = (unsigned)(state->lens[state->have - 1]); 1.422 + copy = 3 + BITS(2); 1.423 + DROPBITS(2); 1.424 + } 1.425 + else if (here.val == 17) { 1.426 + NEEDBITS(here.bits + 3); 1.427 + DROPBITS(here.bits); 1.428 + len = 0; 1.429 + copy = 3 + BITS(3); 1.430 + DROPBITS(3); 1.431 + } 1.432 + else { 1.433 + NEEDBITS(here.bits + 7); 1.434 + DROPBITS(here.bits); 1.435 + len = 0; 1.436 + copy = 11 + BITS(7); 1.437 + DROPBITS(7); 1.438 + } 1.439 + if (state->have + copy > state->nlen + state->ndist) { 1.440 + strm->msg = (char *)"invalid bit length repeat"; 1.441 + state->mode = BAD; 1.442 + break; 1.443 + } 1.444 + while (copy--) 1.445 + state->lens[state->have++] = (unsigned short)len; 1.446 + } 1.447 + } 1.448 + 1.449 + /* handle error breaks in while */ 1.450 + if (state->mode == BAD) break; 1.451 + 1.452 + /* check for end-of-block code (better have one) */ 1.453 + if (state->lens[256] == 0) { 1.454 + strm->msg = (char *)"invalid code -- missing end-of-block"; 1.455 + state->mode = BAD; 1.456 + break; 1.457 + } 1.458 + 1.459 + /* build code tables -- note: do not change the lenbits or distbits 1.460 + values here (9 and 6) without reading the comments in inftrees.h 1.461 + concerning the ENOUGH constants, which depend on those values */ 1.462 + state->next = state->codes; 1.463 + state->lencode = (code const FAR *)(state->next); 1.464 + state->lenbits = 9; 1.465 + ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), 1.466 + &(state->lenbits), state->work); 1.467 + if (ret) { 1.468 + strm->msg = (char *)"invalid literal/lengths set"; 1.469 + state->mode = BAD; 1.470 + break; 1.471 + } 1.472 + state->distcode = (code const FAR *)(state->next); 1.473 + state->distbits = 6; 1.474 + ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, 1.475 + &(state->next), &(state->distbits), state->work); 1.476 + if (ret) { 1.477 + strm->msg = (char *)"invalid distances set"; 1.478 + state->mode = BAD; 1.479 + break; 1.480 + } 1.481 + Tracev((stderr, "inflate: codes ok\n")); 1.482 + state->mode = LEN; 1.483 + 1.484 + case LEN: 1.485 + /* use inflate_fast() if we have enough input and output */ 1.486 + if (have >= 6 && left >= 258) { 1.487 + RESTORE(); 1.488 + if (state->whave < state->wsize) 1.489 + state->whave = state->wsize - left; 1.490 + inflate_fast(strm, state->wsize); 1.491 + LOAD(); 1.492 + break; 1.493 + } 1.494 + 1.495 + /* get a literal, length, or end-of-block code */ 1.496 + for (;;) { 1.497 + here = state->lencode[BITS(state->lenbits)]; 1.498 + if ((unsigned)(here.bits) <= bits) break; 1.499 + PULLBYTE(); 1.500 + } 1.501 + if (here.op && (here.op & 0xf0) == 0) { 1.502 + last = here; 1.503 + for (;;) { 1.504 + here = state->lencode[last.val + 1.505 + (BITS(last.bits + last.op) >> last.bits)]; 1.506 + if ((unsigned)(last.bits + here.bits) <= bits) break; 1.507 + PULLBYTE(); 1.508 + } 1.509 + DROPBITS(last.bits); 1.510 + } 1.511 + DROPBITS(here.bits); 1.512 + state->length = (unsigned)here.val; 1.513 + 1.514 + /* process literal */ 1.515 + if (here.op == 0) { 1.516 + Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? 1.517 + "inflate: literal '%c'\n" : 1.518 + "inflate: literal 0x%02x\n", here.val)); 1.519 + ROOM(); 1.520 + *put++ = (unsigned char)(state->length); 1.521 + left--; 1.522 + state->mode = LEN; 1.523 + break; 1.524 + } 1.525 + 1.526 + /* process end of block */ 1.527 + if (here.op & 32) { 1.528 + Tracevv((stderr, "inflate: end of block\n")); 1.529 + state->mode = TYPE; 1.530 + break; 1.531 + } 1.532 + 1.533 + /* invalid code */ 1.534 + if (here.op & 64) { 1.535 + strm->msg = (char *)"invalid literal/length code"; 1.536 + state->mode = BAD; 1.537 + break; 1.538 + } 1.539 + 1.540 + /* length code -- get extra bits, if any */ 1.541 + state->extra = (unsigned)(here.op) & 15; 1.542 + if (state->extra != 0) { 1.543 + NEEDBITS(state->extra); 1.544 + state->length += BITS(state->extra); 1.545 + DROPBITS(state->extra); 1.546 + } 1.547 + Tracevv((stderr, "inflate: length %u\n", state->length)); 1.548 + 1.549 + /* get distance code */ 1.550 + for (;;) { 1.551 + here = state->distcode[BITS(state->distbits)]; 1.552 + if ((unsigned)(here.bits) <= bits) break; 1.553 + PULLBYTE(); 1.554 + } 1.555 + if ((here.op & 0xf0) == 0) { 1.556 + last = here; 1.557 + for (;;) { 1.558 + here = state->distcode[last.val + 1.559 + (BITS(last.bits + last.op) >> last.bits)]; 1.560 + if ((unsigned)(last.bits + here.bits) <= bits) break; 1.561 + PULLBYTE(); 1.562 + } 1.563 + DROPBITS(last.bits); 1.564 + } 1.565 + DROPBITS(here.bits); 1.566 + if (here.op & 64) { 1.567 + strm->msg = (char *)"invalid distance code"; 1.568 + state->mode = BAD; 1.569 + break; 1.570 + } 1.571 + state->offset = (unsigned)here.val; 1.572 + 1.573 + /* get distance extra bits, if any */ 1.574 + state->extra = (unsigned)(here.op) & 15; 1.575 + if (state->extra != 0) { 1.576 + NEEDBITS(state->extra); 1.577 + state->offset += BITS(state->extra); 1.578 + DROPBITS(state->extra); 1.579 + } 1.580 + if (state->offset > state->wsize - (state->whave < state->wsize ? 1.581 + left : 0)) { 1.582 + strm->msg = (char *)"invalid distance too far back"; 1.583 + state->mode = BAD; 1.584 + break; 1.585 + } 1.586 + Tracevv((stderr, "inflate: distance %u\n", state->offset)); 1.587 + 1.588 + /* copy match from window to output */ 1.589 + do { 1.590 + ROOM(); 1.591 + copy = state->wsize - state->offset; 1.592 + if (copy < left) { 1.593 + from = put + copy; 1.594 + copy = left - copy; 1.595 + } 1.596 + else { 1.597 + from = put - state->offset; 1.598 + copy = left; 1.599 + } 1.600 + if (copy > state->length) copy = state->length; 1.601 + state->length -= copy; 1.602 + left -= copy; 1.603 + do { 1.604 + *put++ = *from++; 1.605 + } while (--copy); 1.606 + } while (state->length != 0); 1.607 + break; 1.608 + 1.609 + case DONE: 1.610 + /* inflate stream terminated properly -- write leftover output */ 1.611 + ret = Z_STREAM_END; 1.612 + if (left < state->wsize) { 1.613 + if (out(out_desc, state->window, state->wsize - left)) 1.614 + ret = Z_BUF_ERROR; 1.615 + } 1.616 + goto inf_leave; 1.617 + 1.618 + case BAD: 1.619 + ret = Z_DATA_ERROR; 1.620 + goto inf_leave; 1.621 + 1.622 + default: /* can't happen, but makes compilers happy */ 1.623 + ret = Z_STREAM_ERROR; 1.624 + goto inf_leave; 1.625 + } 1.626 + 1.627 + /* Return unused input */ 1.628 + inf_leave: 1.629 + strm->next_in = next; 1.630 + strm->avail_in = have; 1.631 + return ret; 1.632 +} 1.633 + 1.634 +int ZEXPORT inflateBackEnd(strm) 1.635 +z_streamp strm; 1.636 +{ 1.637 + if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) 1.638 + return Z_STREAM_ERROR; 1.639 + ZFREE(strm, strm->state); 1.640 + strm->state = Z_NULL; 1.641 + Tracev((stderr, "inflate: end\n")); 1.642 + return Z_OK; 1.643 +}