• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt/router/zlib/

Lines Matching refs:state

18    state->fd, and update state->eof, state->err, and state->msg as appropriate.
21 local int gz_load(state, buf, len, have)
22 gz_statep state;
31 ret = read(state->fd, buf + *have, len - *have);
37 gz_error(state, Z_ERRNO, zstrerror());
41 state->eof = 1;
50 local int gz_avail(state)
51 gz_statep state;
53 z_streamp strm = &(state->strm);
55 if (state->err != Z_OK)
57 if (state->eof == 0) {
58 if (gz_load(state, state->in, state->size,
61 strm->next_in = state->in;
67 #define NEXT() ((strm->avail_in == 0 && gz_avail(state) == -1) ? -1 : \
73 local int gz_next4(state, ret)
74 gz_statep state;
79 z_streamp strm = &(state->strm);
92 /* Look for gzip header, set up for inflate or copy. state->have must be zero.
93 If this is the first time in, allocate required memory. state->how will be
101 state and the check value will be initialized. gz_head() will return 0 on
104 local int gz_head(state)
105 gz_statep state;
107 z_streamp strm = &(state->strm);
112 if (state->size == 0) {
114 state->in = malloc(state->want);
115 state->out = malloc(state->want << 1);
116 if (state->in == NULL || state->out == NULL) {
117 if (state->out != NULL)
118 free(state->out);
119 if (state->in != NULL)
120 free(state->in);
121 gz_error(state, Z_MEM_ERROR, "out of memory");
124 state->size = state->want;
127 state->strm.zalloc = Z_NULL;
128 state->strm.zfree = Z_NULL;
129 state->strm.opaque = Z_NULL;
130 state->strm.avail_in = 0;
131 state->strm.next_in = Z_NULL;
132 if (inflateInit2(&(state->strm), -15) != Z_OK) { /* raw inflate */
133 free(state->out);
134 free(state->in);
135 state->size = 0;
136 gz_error(state, Z_MEM_ERROR, "out of memory");
143 if (gz_avail(state) == -1)
153 if (strm->avail_in == 0 && gz_avail(state) == -1)
162 gz_error(state, Z_DATA_ERROR, "unknown compression method");
167 gz_error(state, Z_DATA_ERROR, "unknown header flags set");
199 state->how = GZIP;
200 state->direct = 0;
205 state->out[0] = 31;
206 state->have = 1;
213 state->raw = state->pos;
214 state->next = state->out;
216 memcpy(state->next + state->have, strm->next_in, strm->avail_in);
217 state->have += strm->avail_in;
220 state->how = COPY;
221 state->direct = 1;
225 /* Decompress from input to the provided next_out and avail_out in the state.
227 check value and length (modulo 2^32). state->have and state->next are set
229 trailer is verified, state->how is reset to LOOK to look for the next gzip
230 stream or raw data, once state->have is depleted. Returns 0 on success, -1
233 local int gz_decomp(state)
234 gz_statep state;
239 z_streamp strm = &(state->strm);
245 if (strm->avail_in == 0 && gz_avail(state) == -1)
248 gz_error(state, Z_DATA_ERROR, "unexpected end of file");
255 gz_error(state, Z_STREAM_ERROR,
260 gz_error(state, Z_MEM_ERROR, "out of memory");
264 gz_error(state, Z_DATA_ERROR,
271 state->have = had - strm->avail_out;
272 state->next = strm->next_out - state->have;
273 strm->adler = crc32(strm->adler, state->next, state->have);
277 if (gz_next4(state, &crc) == -1 || gz_next4(state, &len) == -1) {
278 gz_error(state, Z_DATA_ERROR, "unexpected end of file");
282 gz_error(state, Z_DATA_ERROR, "incorrect data check");
286 gz_error(state, Z_DATA_ERROR, "incorrect length check");
289 state->how = LOOK; /* ready for next stream, once have is 0 (leave
290 state->direct unchanged to remember how) */
297 /* Make data and put in the output buffer. Assumes that state->have == 0.
299 file depending on state->how. If state->how is LOOK, then a gzip header is
301 Returns -1 on error, otherwise 0. gz_make() will leave state->have as COPY
304 local int gz_make(state)
305 gz_statep state;
307 z_streamp strm = &(state->strm);
309 if (state->how == LOOK) { /* look for gzip header */
310 if (gz_head(state) == -1)
312 if (state->have) /* got some data from gz_head() */
315 if (state->how == COPY) { /* straight copy */
316 if (gz_load(state, state->out, state->size << 1, &(state->have)) == -1)
318 state->next = state->out;
320 else if (state->how == GZIP) { /* decompress */
321 strm->avail_out = state->size << 1;
322 strm->next_out = state->out;
323 if (gz_decomp(state) == -1)
330 local int gz_skip(state, len)
331 gz_statep state;
339 if (state->have) {
340 n = GT_OFF(state->have) || (z_off64_t)state->have > len ?
341 (unsigned)len : state->have;
342 state->have -= n;
343 state->next += n;
344 state->pos += n;
349 else if (state->eof && state->strm.avail_in == 0)
355 if (gz_make(state) == -1)
368 gz_statep state;
374 state = (gz_statep)file;
375 strm = &(state->strm);
378 if (state->mode != GZ_READ || state->err != Z_OK)
384 gz_error(state, Z_BUF_ERROR, "requested length does not fit in int");
393 if (state->seek) {
394 state->seek = 0;
395 if (gz_skip(state, state->skip) == -1)
403 if (state->have) {
404 n = state->have > len ? len : state->have;
405 memcpy(buf, state->next, n);
406 state->next += n;
407 state->have -= n;
411 else if (state->eof && strm->avail_in == 0)
416 else if (state->how == LOOK || len < (state->size << 1)) {
418 if (gz_make(state) == -1)
426 else if (state->how == COPY) { /* read directly */
427 if (gz_load(state, buf, len, &n) == -1)
432 else { /* state->how == GZIP */
435 if (gz_decomp(state) == -1)
437 n = state->have;
438 state->have = 0;
445 state->pos += n;
458 gz_statep state;
463 state = (gz_statep)file;
466 if (state->mode != GZ_READ || state->err != Z_OK)
470 if (state->have) {
471 state->have--;
472 state->pos++;
473 return *(state->next)++;
486 gz_statep state;
491 state = (gz_statep)file;
494 if (state->mode != GZ_READ || state->err != Z_OK)
498 if (state->seek) {
499 state->seek = 0;
500 if (gz_skip(state, state->skip) == -1)
509 if (state->have == 0) {
510 state->have = 1;
511 state->next = state->out + (state->size << 1) - 1;
512 state->next[0] = c;
513 state->pos--;
518 if (state->have == (state->size << 1)) {
519 gz_error(state, Z_BUF_ERROR, "out of room to push characters");
524 if (state->next == state->out) {
525 unsigned char *src = state->out + state->have;
526 unsigned char *dest = state->out + (state->size << 1);
527 while (src > state->out)
529 state->next = dest;
531 state->have++;
532 state->next--;
533 state->next[0] = c;
534 state->pos--;
547 gz_statep state;
552 state = (gz_statep)file;
555 if (state->mode != GZ_READ || state->err != Z_OK)
559 if (state->seek) {
560 state->seek = 0;
561 if (gz_skip(state, state->skip) == -1)
572 if (state->have == 0) {
573 if (gz_make(state) == -1)
575 if (state->have == 0) { /* end of file */
583 n = state->have > left ? left : state->have;
584 eol = memchr(state->next, '\n', n);
586 n = (unsigned)(eol - state->next) + 1;
589 memcpy(buf, state->next, n);
590 state->have -= n;
591 state->next += n;
592 state->pos += n;
606 gz_statep state;
611 state = (gz_statep)file;
614 if (state->mode != GZ_READ)
617 /* if the state is not known, but we can find out, then do so (this is
619 if (state->how == LOOK && state->have == 0)
620 (void)gz_head(state);
623 return state->direct;
631 gz_statep state;
636 state = (gz_statep)file;
639 if (state->mode != GZ_READ)
643 if (state->size) {
644 inflateEnd(&(state->strm));
645 free(state->out);
646 free(state->in);
648 gz_error(state, Z_OK, NULL);
649 free(state->path);
650 ret = close(state->fd);
651 free(state);