| Index: third_party/zlib/gzread.c
|
| diff --git a/third_party/zlib/gzread.c b/third_party/zlib/gzread.c
|
| index 4e11246d8756a1c36ca8e59c3202f64bc4f2d505..548201ab0099b51556da32c4873d1dbb2d211b5a 100644
|
| --- a/third_party/zlib/gzread.c
|
| +++ b/third_party/zlib/gzread.c
|
| @@ -1,5 +1,5 @@
|
| /* gzread.c -- zlib functions for reading gzip files
|
| - * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
|
| + * Copyright (C) 2004, 2005, 2010 Mark Adler
|
| * For conditions of distribution and use, see copyright notice in zlib.h
|
| */
|
|
|
| @@ -8,9 +8,10 @@
|
| /* Local functions */
|
| local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
|
| local int gz_avail OF((gz_statep));
|
| -local int gz_look OF((gz_statep));
|
| +local int gz_next4 OF((gz_statep, unsigned long *));
|
| +local int gz_head OF((gz_statep));
|
| local int gz_decomp OF((gz_statep));
|
| -local int gz_fetch OF((gz_statep));
|
| +local int gz_make OF((gz_statep));
|
| local int gz_skip OF((gz_statep, z_off64_t));
|
|
|
| /* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
|
| @@ -45,54 +46,73 @@
|
| error, 0 otherwise. Note that the eof flag is set when the end of the input
|
| file is reached, even though there may be unused data in the buffer. Once
|
| that data has been used, no more attempts will be made to read the file.
|
| - If strm->avail_in != 0, then the current data is moved to the beginning of
|
| - the input buffer, and then the remainder of the buffer is loaded with the
|
| - available data from the input file. */
|
| + gz_avail() assumes that strm->avail_in == 0. */
|
| local int gz_avail(state)
|
| gz_statep state;
|
| {
|
| - unsigned got;
|
| z_streamp strm = &(state->strm);
|
|
|
| - if (state->err != Z_OK && state->err != Z_BUF_ERROR)
|
| + if (state->err != Z_OK)
|
| return -1;
|
| if (state->eof == 0) {
|
| - if (strm->avail_in) { /* copy what's there to the start */
|
| - unsigned char *p = state->in;
|
| - unsigned const char *q = strm->next_in;
|
| - unsigned n = strm->avail_in;
|
| - do {
|
| - *p++ = *q++;
|
| - } while (--n);
|
| - }
|
| - if (gz_load(state, state->in + strm->avail_in,
|
| - state->size - strm->avail_in, &got) == -1)
|
| - return -1;
|
| - strm->avail_in += got;
|
| + if (gz_load(state, state->in, state->size,
|
| + (unsigned *)&(strm->avail_in)) == -1)
|
| + return -1;
|
| strm->next_in = state->in;
|
| }
|
| return 0;
|
| }
|
|
|
| -/* Look for gzip header, set up for inflate or copy. state->x.have must be 0.
|
| +/* Get next byte from input, or -1 if end or error. */
|
| +#define NEXT() ((strm->avail_in == 0 && gz_avail(state) == -1) ? -1 : \
|
| + (strm->avail_in == 0 ? -1 : \
|
| + (strm->avail_in--, *(strm->next_in)++)))
|
| +
|
| +/* Get a four-byte little-endian integer and return 0 on success and the value
|
| + in *ret. Otherwise -1 is returned and *ret is not modified. */
|
| +local int gz_next4(state, ret)
|
| + gz_statep state;
|
| + unsigned long *ret;
|
| +{
|
| + int ch;
|
| + unsigned long val;
|
| + z_streamp strm = &(state->strm);
|
| +
|
| + val = NEXT();
|
| + val += (unsigned)NEXT() << 8;
|
| + val += (unsigned long)NEXT() << 16;
|
| + ch = NEXT();
|
| + if (ch == -1)
|
| + return -1;
|
| + val += (unsigned long)ch << 24;
|
| + *ret = val;
|
| + return 0;
|
| +}
|
| +
|
| +/* Look for gzip header, set up for inflate or copy. state->have must be zero.
|
| If this is the first time in, allocate required memory. state->how will be
|
| left unchanged if there is no more input data available, will be set to COPY
|
| if there is no gzip header and direct copying will be performed, or it will
|
| - be set to GZIP for decompression. If direct copying, then leftover input
|
| - data from the input buffer will be copied to the output buffer. In that
|
| - case, all further file reads will be directly to either the output buffer or
|
| - a user buffer. If decompressing, the inflate state will be initialized.
|
| - gz_look() will return 0 on success or -1 on failure. */
|
| -local int gz_look(state)
|
| + be set to GZIP for decompression, and the gzip header will be skipped so
|
| + that the next available input data is the raw deflate stream. If direct
|
| + copying, then leftover input data from the input buffer will be copied to
|
| + the output buffer. In that case, all further file reads will be directly to
|
| + either the output buffer or a user buffer. If decompressing, the inflate
|
| + state and the check value will be initialized. gz_head() will return 0 on
|
| + success or -1 on failure. Failures may include read errors or gzip header
|
| + errors. */
|
| +local int gz_head(state)
|
| gz_statep state;
|
| {
|
| z_streamp strm = &(state->strm);
|
| + int flags;
|
| + unsigned len;
|
|
|
| /* allocate read buffers and inflate memory */
|
| if (state->size == 0) {
|
| /* allocate buffers */
|
| - state->in = (unsigned char *)malloc(state->want);
|
| - state->out = (unsigned char *)malloc(state->want << 1);
|
| + state->in = malloc(state->want);
|
| + state->out = malloc(state->want << 1);
|
| if (state->in == NULL || state->out == NULL) {
|
| if (state->out != NULL)
|
| free(state->out);
|
| @@ -109,7 +129,7 @@
|
| state->strm.opaque = Z_NULL;
|
| state->strm.avail_in = 0;
|
| state->strm.next_in = Z_NULL;
|
| - if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */
|
| + if (inflateInit2(&(state->strm), -15) != Z_OK) { /* raw inflate */
|
| free(state->out);
|
| free(state->in);
|
| state->size = 0;
|
| @@ -118,45 +138,83 @@
|
| }
|
| }
|
|
|
| - /* get at least the magic bytes in the input buffer */
|
| - if (strm->avail_in < 2) {
|
| + /* get some data in the input buffer */
|
| + if (strm->avail_in == 0) {
|
| if (gz_avail(state) == -1)
|
| return -1;
|
| if (strm->avail_in == 0)
|
| return 0;
|
| }
|
|
|
| - /* look for gzip magic bytes -- if there, do gzip decoding (note: there is
|
| - a logical dilemma here when considering the case of a partially written
|
| - gzip file, to wit, if a single 31 byte is written, then we cannot tell
|
| - whether this is a single-byte file, or just a partially written gzip
|
| - file -- for here we assume that if a gzip file is being written, then
|
| - the header will be written in a single operation, so that reading a
|
| - single byte is sufficient indication that it is not a gzip file) */
|
| - if (strm->avail_in > 1 &&
|
| - strm->next_in[0] == 31 && strm->next_in[1] == 139) {
|
| - inflateReset(strm);
|
| - state->how = GZIP;
|
| - state->direct = 0;
|
| - return 0;
|
| - }
|
| -
|
| - /* no gzip header -- if we were decoding gzip before, then this is trailing
|
| - garbage. Ignore the trailing garbage and finish. */
|
| - if (state->direct == 0) {
|
| - strm->avail_in = 0;
|
| - state->eof = 1;
|
| - state->x.have = 0;
|
| - return 0;
|
| - }
|
| -
|
| - /* doing raw i/o, copy any leftover input to output -- this assumes that
|
| - the output buffer is larger than the input buffer, which also assures
|
| - space for gzungetc() */
|
| - state->x.next = state->out;
|
| + /* look for the gzip magic header bytes 31 and 139 */
|
| + if (strm->next_in[0] == 31) {
|
| + strm->avail_in--;
|
| + strm->next_in++;
|
| + if (strm->avail_in == 0 && gz_avail(state) == -1)
|
| + return -1;
|
| + if (strm->avail_in && strm->next_in[0] == 139) {
|
| + /* we have a gzip header, woo hoo! */
|
| + strm->avail_in--;
|
| + strm->next_in++;
|
| +
|
| + /* skip rest of header */
|
| + if (NEXT() != 8) { /* compression method */
|
| + gz_error(state, Z_DATA_ERROR, "unknown compression method");
|
| + return -1;
|
| + }
|
| + flags = NEXT();
|
| + if (flags & 0xe0) { /* reserved flag bits */
|
| + gz_error(state, Z_DATA_ERROR, "unknown header flags set");
|
| + return -1;
|
| + }
|
| + NEXT(); /* modification time */
|
| + NEXT();
|
| + NEXT();
|
| + NEXT();
|
| + NEXT(); /* extra flags */
|
| + NEXT(); /* operating system */
|
| + if (flags & 4) { /* extra field */
|
| + len = (unsigned)NEXT();
|
| + len += (unsigned)NEXT() << 8;
|
| + while (len--)
|
| + if (NEXT() < 0)
|
| + break;
|
| + }
|
| + if (flags & 8) /* file name */
|
| + while (NEXT() > 0)
|
| + ;
|
| + if (flags & 16) /* comment */
|
| + while (NEXT() > 0)
|
| + ;
|
| + if (flags & 2) { /* header crc */
|
| + NEXT();
|
| + NEXT();
|
| + }
|
| + /* an unexpected end of file is not checked for here -- it will be
|
| + noticed on the first request for uncompressed data */
|
| +
|
| + /* set up for decompression */
|
| + inflateReset(strm);
|
| + strm->adler = crc32(0L, Z_NULL, 0);
|
| + state->how = GZIP;
|
| + state->direct = 0;
|
| + return 0;
|
| + }
|
| + else {
|
| + /* not a gzip file -- save first byte (31) and fall to raw i/o */
|
| + state->out[0] = 31;
|
| + state->have = 1;
|
| + }
|
| + }
|
| +
|
| + /* doing raw i/o, save start of raw data for seeking, copy any leftover
|
| + input to output -- this assumes that the output buffer is larger than
|
| + the input buffer, which also assures space for gzungetc() */
|
| + state->raw = state->pos;
|
| + state->next = state->out;
|
| if (strm->avail_in) {
|
| - memcpy(state->x.next, strm->next_in, strm->avail_in);
|
| - state->x.have = strm->avail_in;
|
| + memcpy(state->next + state->have, strm->next_in, strm->avail_in);
|
| + state->have += strm->avail_in;
|
| strm->avail_in = 0;
|
| }
|
| state->how = COPY;
|
| @@ -165,15 +223,19 @@
|
| }
|
|
|
| /* Decompress from input to the provided next_out and avail_out in the state.
|
| - On return, state->x.have and state->x.next point to the just decompressed
|
| - data. If the gzip stream completes, state->how is reset to LOOK to look for
|
| - the next gzip stream or raw data, once state->x.have is depleted. Returns 0
|
| - on success, -1 on failure. */
|
| + If the end of the compressed data is reached, then verify the gzip trailer
|
| + check value and length (modulo 2^32). state->have and state->next are set
|
| + to point to the just decompressed data, and the crc is updated. If the
|
| + trailer is verified, state->how is reset to LOOK to look for the next gzip
|
| + stream or raw data, once state->have is depleted. Returns 0 on success, -1
|
| + on failure. Failures may include invalid compressed data or a failed gzip
|
| + trailer verification. */
|
| local int gz_decomp(state)
|
| gz_statep state;
|
| {
|
| - int ret = Z_OK;
|
| + int ret;
|
| unsigned had;
|
| + unsigned long crc, len;
|
| z_streamp strm = &(state->strm);
|
|
|
| /* fill output buffer up to end of deflate stream */
|
| @@ -183,15 +245,15 @@
|
| if (strm->avail_in == 0 && gz_avail(state) == -1)
|
| return -1;
|
| if (strm->avail_in == 0) {
|
| - gz_error(state, Z_BUF_ERROR, "unexpected end of file");
|
| - break;
|
| + gz_error(state, Z_DATA_ERROR, "unexpected end of file");
|
| + return -1;
|
| }
|
|
|
| /* decompress and handle errors */
|
| ret = inflate(strm, Z_NO_FLUSH);
|
| if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
|
| gz_error(state, Z_STREAM_ERROR,
|
| - "internal error: inflate stream corrupt");
|
| + "internal error: inflate stream corrupt");
|
| return -1;
|
| }
|
| if (ret == Z_MEM_ERROR) {
|
| @@ -200,55 +262,67 @@
|
| }
|
| if (ret == Z_DATA_ERROR) { /* deflate stream invalid */
|
| gz_error(state, Z_DATA_ERROR,
|
| - strm->msg == NULL ? "compressed data error" : strm->msg);
|
| + strm->msg == NULL ? "compressed data error" : strm->msg);
|
| return -1;
|
| }
|
| } while (strm->avail_out && ret != Z_STREAM_END);
|
|
|
| - /* update available output */
|
| - state->x.have = had - strm->avail_out;
|
| - state->x.next = strm->next_out - state->x.have;
|
| -
|
| - /* if the gzip stream completed successfully, look for another */
|
| - if (ret == Z_STREAM_END)
|
| - state->how = LOOK;
|
| + /* update available output and crc check value */
|
| + state->have = had - strm->avail_out;
|
| + state->next = strm->next_out - state->have;
|
| + strm->adler = crc32(strm->adler, state->next, state->have);
|
| +
|
| + /* check gzip trailer if at end of deflate stream */
|
| + if (ret == Z_STREAM_END) {
|
| + if (gz_next4(state, &crc) == -1 || gz_next4(state, &len) == -1) {
|
| + gz_error(state, Z_DATA_ERROR, "unexpected end of file");
|
| + return -1;
|
| + }
|
| + if (crc != strm->adler) {
|
| + gz_error(state, Z_DATA_ERROR, "incorrect data check");
|
| + return -1;
|
| + }
|
| + if (len != (strm->total_out & 0xffffffffL)) {
|
| + gz_error(state, Z_DATA_ERROR, "incorrect length check");
|
| + return -1;
|
| + }
|
| + state->how = LOOK; /* ready for next stream, once have is 0 (leave
|
| + state->direct unchanged to remember how) */
|
| + }
|
|
|
| /* good decompression */
|
| return 0;
|
| }
|
|
|
| -/* Fetch data and put it in the output buffer. Assumes state->x.have is 0.
|
| +/* Make data and put in the output buffer. Assumes that state->have == 0.
|
| Data is either copied from the input file or decompressed from the input
|
| file depending on state->how. If state->how is LOOK, then a gzip header is
|
| - looked for to determine whether to copy or decompress. Returns -1 on error,
|
| - otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the
|
| - end of the input file has been reached and all data has been processed. */
|
| -local int gz_fetch(state)
|
| + looked for (and skipped if found) to determine wither to copy or decompress.
|
| + Returns -1 on error, otherwise 0. gz_make() will leave state->have as COPY
|
| + or GZIP unless the end of the input file has been reached and all data has
|
| + been processed. */
|
| +local int gz_make(state)
|
| gz_statep state;
|
| {
|
| z_streamp strm = &(state->strm);
|
|
|
| - do {
|
| - switch(state->how) {
|
| - case LOOK: /* -> LOOK, COPY (only if never GZIP), or GZIP */
|
| - if (gz_look(state) == -1)
|
| - return -1;
|
| - if (state->how == LOOK)
|
| - return 0;
|
| - break;
|
| - case COPY: /* -> COPY */
|
| - if (gz_load(state, state->out, state->size << 1, &(state->x.have))
|
| - == -1)
|
| - return -1;
|
| - state->x.next = state->out;
|
| + if (state->how == LOOK) { /* look for gzip header */
|
| + if (gz_head(state) == -1)
|
| + return -1;
|
| + if (state->have) /* got some data from gz_head() */
|
| return 0;
|
| - case GZIP: /* -> GZIP or LOOK (if end of gzip stream) */
|
| - strm->avail_out = state->size << 1;
|
| - strm->next_out = state->out;
|
| - if (gz_decomp(state) == -1)
|
| - return -1;
|
| - }
|
| - } while (state->x.have == 0 && (!state->eof || strm->avail_in));
|
| + }
|
| + if (state->how == COPY) { /* straight copy */
|
| + if (gz_load(state, state->out, state->size << 1, &(state->have)) == -1)
|
| + return -1;
|
| + state->next = state->out;
|
| + }
|
| + else if (state->how == GZIP) { /* decompress */
|
| + strm->avail_out = state->size << 1;
|
| + strm->next_out = state->out;
|
| + if (gz_decomp(state) == -1)
|
| + return -1;
|
| + }
|
| return 0;
|
| }
|
|
|
| @@ -262,12 +336,12 @@
|
| /* skip over len bytes or reach end-of-file, whichever comes first */
|
| while (len)
|
| /* skip over whatever is in output buffer */
|
| - if (state->x.have) {
|
| - n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
|
| - (unsigned)len : state->x.have;
|
| - state->x.have -= n;
|
| - state->x.next += n;
|
| - state->x.pos += n;
|
| + if (state->have) {
|
| + n = GT_OFF(state->have) || (z_off64_t)state->have > len ?
|
| + (unsigned)len : state->have;
|
| + state->have -= n;
|
| + state->next += n;
|
| + state->pos += n;
|
| len -= n;
|
| }
|
|
|
| @@ -278,7 +352,7 @@
|
| /* need more data to skip -- load up output buffer */
|
| else {
|
| /* get more output, looking for header if required */
|
| - if (gz_fetch(state) == -1)
|
| + if (gz_make(state) == -1)
|
| return -1;
|
| }
|
| return 0;
|
| @@ -300,15 +374,14 @@
|
| state = (gz_statep)file;
|
| strm = &(state->strm);
|
|
|
| - /* check that we're reading and that there's no (serious) error */
|
| - if (state->mode != GZ_READ ||
|
| - (state->err != Z_OK && state->err != Z_BUF_ERROR))
|
| + /* check that we're reading and that there's no error */
|
| + if (state->mode != GZ_READ || state->err != Z_OK)
|
| return -1;
|
|
|
| /* since an int is returned, make sure len fits in one, otherwise return
|
| with an error (this avoids the flaw in the interface) */
|
| if ((int)len < 0) {
|
| - gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
|
| + gz_error(state, Z_BUF_ERROR, "requested length does not fit in int");
|
| return -1;
|
| }
|
|
|
| @@ -327,51 +400,49 @@
|
| got = 0;
|
| do {
|
| /* first just try copying data from the output buffer */
|
| - if (state->x.have) {
|
| - n = state->x.have > len ? len : state->x.have;
|
| - memcpy(buf, state->x.next, n);
|
| - state->x.next += n;
|
| - state->x.have -= n;
|
| + if (state->have) {
|
| + n = state->have > len ? len : state->have;
|
| + memcpy(buf, state->next, n);
|
| + state->next += n;
|
| + state->have -= n;
|
| }
|
|
|
| /* output buffer empty -- return if we're at the end of the input */
|
| - else if (state->eof && strm->avail_in == 0) {
|
| - state->past = 1; /* tried to read past end */
|
| + else if (state->eof && strm->avail_in == 0)
|
| break;
|
| - }
|
|
|
| /* need output data -- for small len or new stream load up our output
|
| buffer */
|
| else if (state->how == LOOK || len < (state->size << 1)) {
|
| /* get more output, looking for header if required */
|
| - if (gz_fetch(state) == -1)
|
| + if (gz_make(state) == -1)
|
| return -1;
|
| - continue; /* no progress yet -- go back to copy above */
|
| + continue; /* no progress yet -- go back to memcpy() above */
|
| /* the copy above assures that we will leave with space in the
|
| output buffer, allowing at least one gzungetc() to succeed */
|
| }
|
|
|
| /* large len -- read directly into user buffer */
|
| else if (state->how == COPY) { /* read directly */
|
| - if (gz_load(state, (unsigned char *)buf, len, &n) == -1)
|
| + if (gz_load(state, buf, len, &n) == -1)
|
| return -1;
|
| }
|
|
|
| /* large len -- decompress directly into user buffer */
|
| else { /* state->how == GZIP */
|
| strm->avail_out = len;
|
| - strm->next_out = (unsigned char *)buf;
|
| + strm->next_out = buf;
|
| if (gz_decomp(state) == -1)
|
| return -1;
|
| - n = state->x.have;
|
| - state->x.have = 0;
|
| + n = state->have;
|
| + state->have = 0;
|
| }
|
|
|
| /* update progress */
|
| len -= n;
|
| buf = (char *)buf + n;
|
| got += n;
|
| - state->x.pos += n;
|
| + state->pos += n;
|
| } while (len);
|
|
|
| /* return number of bytes read into user buffer (will fit in int) */
|
| @@ -379,15 +450,6 @@
|
| }
|
|
|
| /* -- see zlib.h -- */
|
| -#ifdef Z_PREFIX_SET
|
| -# undef z_gzgetc
|
| -#else
|
| -# undef gzgetc
|
| -# ifdef MOZZCONF_H
|
| -# define gzgetc MOZ_Z_gzgetc
|
| -# endif
|
| -#endif
|
| -
|
| int ZEXPORT gzgetc(file)
|
| gzFile file;
|
| {
|
| @@ -400,27 +462,20 @@
|
| return -1;
|
| state = (gz_statep)file;
|
|
|
| - /* check that we're reading and that there's no (serious) error */
|
| - if (state->mode != GZ_READ ||
|
| - (state->err != Z_OK && state->err != Z_BUF_ERROR))
|
| + /* check that we're reading and that there's no error */
|
| + if (state->mode != GZ_READ || state->err != Z_OK)
|
| return -1;
|
|
|
| /* try output buffer (no need to check for skip request) */
|
| - if (state->x.have) {
|
| - state->x.have--;
|
| - state->x.pos++;
|
| - return *(state->x.next)++;
|
| + if (state->have) {
|
| + state->have--;
|
| + state->pos++;
|
| + return *(state->next)++;
|
| }
|
|
|
| /* nothing there -- try gzread() */
|
| ret = gzread(file, buf, 1);
|
| return ret < 1 ? -1 : buf[0];
|
| -}
|
| -
|
| -int ZEXPORT gzgetc_(file)
|
| -gzFile file;
|
| -{
|
| - return gzgetc(file);
|
| }
|
|
|
| /* -- see zlib.h -- */
|
| @@ -435,9 +490,8 @@
|
| return -1;
|
| state = (gz_statep)file;
|
|
|
| - /* check that we're reading and that there's no (serious) error */
|
| - if (state->mode != GZ_READ ||
|
| - (state->err != Z_OK && state->err != Z_BUF_ERROR))
|
| + /* check that we're reading and that there's no error */
|
| + if (state->mode != GZ_READ || state->err != Z_OK)
|
| return -1;
|
|
|
| /* process a skip request */
|
| @@ -452,34 +506,32 @@
|
| return -1;
|
|
|
| /* if output buffer empty, put byte at end (allows more pushing) */
|
| - if (state->x.have == 0) {
|
| - state->x.have = 1;
|
| - state->x.next = state->out + (state->size << 1) - 1;
|
| - state->x.next[0] = c;
|
| - state->x.pos--;
|
| - state->past = 0;
|
| + if (state->have == 0) {
|
| + state->have = 1;
|
| + state->next = state->out + (state->size << 1) - 1;
|
| + state->next[0] = c;
|
| + state->pos--;
|
| return c;
|
| }
|
|
|
| /* if no room, give up (must have already done a gzungetc()) */
|
| - if (state->x.have == (state->size << 1)) {
|
| - gz_error(state, Z_DATA_ERROR, "out of room to push characters");
|
| + if (state->have == (state->size << 1)) {
|
| + gz_error(state, Z_BUF_ERROR, "out of room to push characters");
|
| return -1;
|
| }
|
|
|
| /* slide output data if needed and insert byte before existing data */
|
| - if (state->x.next == state->out) {
|
| - unsigned char *src = state->out + state->x.have;
|
| + if (state->next == state->out) {
|
| + unsigned char *src = state->out + state->have;
|
| unsigned char *dest = state->out + (state->size << 1);
|
| while (src > state->out)
|
| *--dest = *--src;
|
| - state->x.next = dest;
|
| - }
|
| - state->x.have++;
|
| - state->x.next--;
|
| - state->x.next[0] = c;
|
| - state->x.pos--;
|
| - state->past = 0;
|
| + state->next = dest;
|
| + }
|
| + state->have++;
|
| + state->next--;
|
| + state->next[0] = c;
|
| + state->pos--;
|
| return c;
|
| }
|
|
|
| @@ -499,9 +551,8 @@
|
| return NULL;
|
| state = (gz_statep)file;
|
|
|
| - /* check that we're reading and that there's no (serious) error */
|
| - if (state->mode != GZ_READ ||
|
| - (state->err != Z_OK && state->err != Z_BUF_ERROR))
|
| + /* check that we're reading and that there's no error */
|
| + if (state->mode != GZ_READ || state->err != Z_OK)
|
| return NULL;
|
|
|
| /* process a skip request */
|
| @@ -518,31 +569,32 @@
|
| left = (unsigned)len - 1;
|
| if (left) do {
|
| /* assure that something is in the output buffer */
|
| - if (state->x.have == 0 && gz_fetch(state) == -1)
|
| - return NULL; /* error */
|
| - if (state->x.have == 0) { /* end of file */
|
| - state->past = 1; /* read past end */
|
| - break; /* return what we have */
|
| + if (state->have == 0) {
|
| + if (gz_make(state) == -1)
|
| + return NULL; /* error */
|
| + if (state->have == 0) { /* end of file */
|
| + if (buf == str) /* got bupkus */
|
| + return NULL;
|
| + break; /* got something -- return it */
|
| + }
|
| }
|
|
|
| /* look for end-of-line in current output buffer */
|
| - n = state->x.have > left ? left : state->x.have;
|
| - eol = (unsigned char *)memchr(state->x.next, '\n', n);
|
| + n = state->have > left ? left : state->have;
|
| + eol = memchr(state->next, '\n', n);
|
| if (eol != NULL)
|
| - n = (unsigned)(eol - state->x.next) + 1;
|
| + n = (unsigned)(eol - state->next) + 1;
|
|
|
| /* copy through end-of-line, or remainder if not found */
|
| - memcpy(buf, state->x.next, n);
|
| - state->x.have -= n;
|
| - state->x.next += n;
|
| - state->x.pos += n;
|
| + memcpy(buf, state->next, n);
|
| + state->have -= n;
|
| + state->next += n;
|
| + state->pos += n;
|
| left -= n;
|
| buf += n;
|
| } while (left && eol == NULL);
|
|
|
| - /* return terminated string, or if nothing, end of file */
|
| - if (buf == str)
|
| - return NULL;
|
| + /* found end-of-line or out of space -- terminate string and return it */
|
| buf[0] = 0;
|
| return str;
|
| }
|
| @@ -558,12 +610,16 @@
|
| return 0;
|
| state = (gz_statep)file;
|
|
|
| + /* check that we're reading */
|
| + if (state->mode != GZ_READ)
|
| + return 0;
|
| +
|
| /* if the state is not known, but we can find out, then do so (this is
|
| mainly for right after a gzopen() or gzdopen()) */
|
| - if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
|
| - (void)gz_look(state);
|
| -
|
| - /* return 1 if transparent, 0 if processing a gzip stream */
|
| + if (state->how == LOOK && state->have == 0)
|
| + (void)gz_head(state);
|
| +
|
| + /* return 1 if reading direct, 0 if decompressing a gzip stream */
|
| return state->direct;
|
| }
|
|
|
| @@ -571,7 +627,7 @@
|
| int ZEXPORT gzclose_r(file)
|
| gzFile file;
|
| {
|
| - int ret, err;
|
| + int ret;
|
| gz_statep state;
|
|
|
| /* get internal structure */
|
| @@ -589,10 +645,9 @@
|
| free(state->out);
|
| free(state->in);
|
| }
|
| - err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
|
| gz_error(state, Z_OK, NULL);
|
| free(state->path);
|
| ret = close(state->fd);
|
| free(state);
|
| - return ret ? Z_ERRNO : err;
|
| -}
|
| + return ret ? Z_ERRNO : Z_OK;
|
| +}
|
|
|