|
version 1.1.1.1, 2012/02/21 16:23:02
|
version 1.1.1.2, 2013/07/22 10:46:14
|
|
Line 1
|
Line 1
|
| /* inflate.c -- zlib decompression |
/* inflate.c -- zlib decompression |
| * Copyright (C) 1995-2010 Mark Adler | * Copyright (C) 1995-2011 Mark Adler |
| * For conditions of distribution and use, see copyright notice in zlib.h |
* For conditions of distribution and use, see copyright notice in zlib.h |
| */ |
*/ |
| |
|
|
Line 100 local int updatewindow OF((z_streamp strm, unsigned ou
|
Line 100 local int updatewindow OF((z_streamp strm, unsigned ou
|
| local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf, |
local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf, |
| unsigned len)); |
unsigned len)); |
| |
|
| int ZEXPORT inflateReset(strm) | int ZEXPORT inflateResetKeep(strm) |
| z_streamp strm; |
z_streamp strm; |
| { |
{ |
| struct inflate_state FAR *state; |
struct inflate_state FAR *state; |
|
Line 109 z_streamp strm;
|
Line 109 z_streamp strm;
|
| state = (struct inflate_state FAR *)strm->state; |
state = (struct inflate_state FAR *)strm->state; |
| strm->total_in = strm->total_out = state->total = 0; |
strm->total_in = strm->total_out = state->total = 0; |
| strm->msg = Z_NULL; |
strm->msg = Z_NULL; |
| strm->adler = 1; /* to support ill-conceived Java test suite */ | if (state->wrap) /* to support ill-conceived Java test suite */ |
| | strm->adler = state->wrap & 1; |
| state->mode = HEAD; |
state->mode = HEAD; |
| state->last = 0; |
state->last = 0; |
| state->havedict = 0; |
state->havedict = 0; |
| state->dmax = 32768U; |
state->dmax = 32768U; |
| state->head = Z_NULL; |
state->head = Z_NULL; |
| state->wsize = 0; |
|
| state->whave = 0; |
|
| state->wnext = 0; |
|
| state->hold = 0; |
state->hold = 0; |
| state->bits = 0; |
state->bits = 0; |
| state->lencode = state->distcode = state->next = state->codes; |
state->lencode = state->distcode = state->next = state->codes; |
|
Line 127 z_streamp strm;
|
Line 125 z_streamp strm;
|
| return Z_OK; |
return Z_OK; |
| } |
} |
| |
|
| |
int ZEXPORT inflateReset(strm) |
| |
z_streamp strm; |
| |
{ |
| |
struct inflate_state FAR *state; |
| |
|
| |
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; |
| |
state = (struct inflate_state FAR *)strm->state; |
| |
state->wsize = 0; |
| |
state->whave = 0; |
| |
state->wnext = 0; |
| |
return inflateResetKeep(strm); |
| |
} |
| |
|
| int ZEXPORT inflateReset2(strm, windowBits) |
int ZEXPORT inflateReset2(strm, windowBits) |
| z_streamp strm; |
z_streamp strm; |
| int windowBits; |
int windowBits; |
|
Line 180 int stream_size;
|
Line 191 int stream_size;
|
| if (strm == Z_NULL) return Z_STREAM_ERROR; |
if (strm == Z_NULL) return Z_STREAM_ERROR; |
| strm->msg = Z_NULL; /* in case we return an error */ |
strm->msg = Z_NULL; /* in case we return an error */ |
| if (strm->zalloc == (alloc_func)0) { |
if (strm->zalloc == (alloc_func)0) { |
| |
#ifdef Z_SOLO |
| |
return Z_STREAM_ERROR; |
| |
#else |
| strm->zalloc = zcalloc; |
strm->zalloc = zcalloc; |
| strm->opaque = (voidpf)0; |
strm->opaque = (voidpf)0; |
| |
#endif |
| } |
} |
| if (strm->zfree == (free_func)0) strm->zfree = zcfree; | if (strm->zfree == (free_func)0) |
| | #ifdef Z_SOLO |
| | return Z_STREAM_ERROR; |
| | #else |
| | strm->zfree = zcfree; |
| | #endif |
| state = (struct inflate_state FAR *) |
state = (struct inflate_state FAR *) |
| ZALLOC(strm, 1, sizeof(struct inflate_state)); |
ZALLOC(strm, 1, sizeof(struct inflate_state)); |
| if (state == Z_NULL) return Z_MEM_ERROR; |
if (state == Z_NULL) return Z_MEM_ERROR; |
|
Line 321 void makefixed()
|
Line 341 void makefixed()
|
| low = 0; |
low = 0; |
| for (;;) { |
for (;;) { |
| if ((low % 7) == 0) printf("\n "); |
if ((low % 7) == 0) printf("\n "); |
| printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits, | printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op, |
| state.lencode[low].val); | state.lencode[low].bits, state.lencode[low].val); |
| if (++low == size) break; |
if (++low == size) break; |
| putchar(','); |
putchar(','); |
| } |
} |
|
Line 925 int flush;
|
Line 945 int flush;
|
| PULLBYTE(); |
PULLBYTE(); |
| } |
} |
| if (here.val < 16) { |
if (here.val < 16) { |
| NEEDBITS(here.bits); |
|
| DROPBITS(here.bits); |
DROPBITS(here.bits); |
| state->lens[state->have++] = here.val; |
state->lens[state->have++] = here.val; |
| } |
} |
|
Line 1214 int flush;
|
Line 1233 int flush;
|
| */ |
*/ |
| inf_leave: |
inf_leave: |
| RESTORE(); |
RESTORE(); |
| if (state->wsize || (state->mode < CHECK && out != strm->avail_out)) | if (state->wsize || (out != strm->avail_out && state->mode < BAD && |
| | (state->mode < CHECK || flush != Z_FINISH))) |
| if (updatewindow(strm, out)) { |
if (updatewindow(strm, out)) { |
| state->mode = MEM; |
state->mode = MEM; |
| return Z_MEM_ERROR; |
return Z_MEM_ERROR; |
|
Line 1256 uInt dictLength;
|
Line 1276 uInt dictLength;
|
| { |
{ |
| struct inflate_state FAR *state; |
struct inflate_state FAR *state; |
| unsigned long id; |
unsigned long id; |
| |
unsigned char *next; |
| |
unsigned avail; |
| |
int ret; |
| |
|
| /* check state */ |
/* check state */ |
| if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; |
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; |
|
Line 1271 uInt dictLength;
|
Line 1294 uInt dictLength;
|
| return Z_DATA_ERROR; |
return Z_DATA_ERROR; |
| } |
} |
| |
|
| /* copy dictionary to window */ | /* copy dictionary to window using updatewindow(), which will amend the |
| if (updatewindow(strm, strm->avail_out)) { | existing dictionary if appropriate */ |
| | next = strm->next_out; |
| | avail = strm->avail_out; |
| | strm->next_out = (Bytef *)dictionary + dictLength; |
| | strm->avail_out = 0; |
| | ret = updatewindow(strm, dictLength); |
| | strm->avail_out = avail; |
| | strm->next_out = next; |
| | if (ret) { |
| state->mode = MEM; |
state->mode = MEM; |
| return Z_MEM_ERROR; |
return Z_MEM_ERROR; |
| } |
} |
| if (dictLength > state->wsize) { |
|
| zmemcpy(state->window, dictionary + dictLength - state->wsize, |
|
| state->wsize); |
|
| state->whave = state->wsize; |
|
| } |
|
| else { |
|
| zmemcpy(state->window + state->wsize - dictLength, dictionary, |
|
| dictLength); |
|
| state->whave = dictLength; |
|
| } |
|
| state->havedict = 1; |
state->havedict = 1; |
| Tracev((stderr, "inflate: dictionary set\n")); |
Tracev((stderr, "inflate: dictionary set\n")); |
| return Z_OK; |
return Z_OK; |
|
Line 1433 z_streamp source;
|
Line 1454 z_streamp source;
|
| } |
} |
| |
|
| /* copy state */ |
/* copy state */ |
| zmemcpy(dest, source, sizeof(z_stream)); | zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); |
| zmemcpy(copy, state, sizeof(struct inflate_state)); | zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state)); |
| if (state->lencode >= state->codes && |
if (state->lencode >= state->codes && |
| state->lencode <= state->codes + ENOUGH - 1) { |
state->lencode <= state->codes + ENOUGH - 1) { |
| copy->lencode = copy->codes + (state->lencode - state->codes); |
copy->lencode = copy->codes + (state->lencode - state->codes); |