Load up input buffer and set eof flag if last data loaded -- return -1 on 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 b
(state)
| 57 | the input buffer, and then the remainder of the buffer is loaded with the |
| 58 | available data from the input file. */ |
| 59 | local int gz_avail(state) |
| 60 | gz_statep state; |
| 61 | { |
| 62 | unsigned got; |
| 63 | z_streamp strm = &(state->strm); |
| 64 | |
| 65 | if (state->err != Z_OK && state->err != Z_BUF_ERROR) |
| 66 | return -1; |
| 67 | if (state->eof == 0) { |
| 68 | if (strm->avail_in) { /* copy what's there to the start */ |
| 69 | unsigned char *p = state->in; |
| 70 | unsigned const char *q = strm->next_in; |
| 71 | unsigned n = strm->avail_in; |
| 72 | do { |
| 73 | *p++ = *q++; |
| 74 | } while (--n); |
| 75 | } |
| 76 | if (gz_load(state, state->in + strm->avail_in, |
| 77 | state->size - strm->avail_in, &got) == -1) |
| 78 | return -1; |
| 79 | strm->avail_in += got; |
| 80 | strm->next_in = state->in; |
| 81 | } |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | /* Look for gzip header, set up for inflate or copy. state->x.have must be 0. |
| 86 | If this is the first time in, allocate required memory. state->how will be |