Lines Matching refs:state

89 xz_error(xz_statep state, int err, const char *msg)  in xz_error()  argument
92 if (state->msg != NULL) { in xz_error()
93 if (state->err != LZMA_MEM_ERROR) in xz_error()
94 xmlFree(state->msg); in xz_error()
95 state->msg = NULL; in xz_error()
99 state->err = err; in xz_error()
105 state->msg = (char *) msg; in xz_error()
110 if ((state->msg = in xz_error()
111 xmlMalloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { in xz_error()
112 state->err = LZMA_MEM_ERROR; in xz_error()
113 state->msg = (char *) "out of memory"; in xz_error()
116 strcpy(state->msg, state->path); in xz_error()
117 strcat(state->msg, ": "); in xz_error()
118 strcat(state->msg, msg); in xz_error()
123 xz_reset(xz_statep state) in xz_reset() argument
125 state->have = 0; /* no output data available */ in xz_reset()
126 state->eof = 0; /* not at end of file */ in xz_reset()
127 state->how = LOOK; /* look for gzip header */ in xz_reset()
128 state->direct = 1; /* default for empty file */ in xz_reset()
129 state->seek = 0; /* no seek request pending */ in xz_reset()
130 xz_error(state, LZMA_OK, NULL); /* clear error */ in xz_reset()
131 state->pos = 0; /* no uncompressed data yet */ in xz_reset()
132 state->strm.avail_in = 0; /* no input data yet */ in xz_reset()
134 state->zstrm.avail_in = 0; /* no input data yet */ in xz_reset()
141 xz_statep state; in xz_open() local
144 state = xmlMalloc(sizeof(xz_state)); in xz_open()
145 if (state == NULL) in xz_open()
147 state->size = 0; /* no buffers allocated yet */ in xz_open()
148 state->want = BUFSIZ; /* requested buffer size */ in xz_open()
149 state->msg = NULL; /* no error message yet */ in xz_open()
150 state->init = 0; /* initialization of zlib data */ in xz_open()
153 state->path = xmlMalloc(strlen(path) + 1); in xz_open()
154 if (state->path == NULL) { in xz_open()
155 xmlFree(state); in xz_open()
158 strcpy(state->path, path); in xz_open()
161 state->fd = fd != -1 ? fd : open(path, in xz_open()
169 if (state->fd == -1) { in xz_open()
170 xmlFree(state->path); in xz_open()
171 xmlFree(state); in xz_open()
176 state->start = lseek(state->fd, 0, SEEK_CUR); in xz_open()
177 if (state->start == (uint64_t) - 1) in xz_open()
178 state->start = 0; in xz_open()
181 xz_reset(state); in xz_open()
184 return (xzFile) state; in xz_open()
189 xz_statep state; in xz_compressed() local
193 state = (xz_statep) f; in xz_compressed()
194 if (state->init <= 0) in xz_compressed()
197 switch (state->how) { in xz_compressed()
233 xz_load(xz_statep state, unsigned char *buf, unsigned int len, in xz_load() argument
240 ret = read(state->fd, buf + *have, len - *have); in xz_load()
246 xz_error(state, -1, strerror(errno)); in xz_load()
250 state->eof = 1; in xz_load()
255 xz_avail(xz_statep state) in xz_avail() argument
257 lzma_stream *strm = &(state->strm); in xz_avail()
259 if (state->err != LZMA_OK) in xz_avail()
261 if (state->eof == 0) { in xz_avail()
265 if (xz_load(state, state->in, state->size, &tmp) == -1) { in xz_avail()
270 strm->next_in = state->in; in xz_avail()
277 xz_avail_zstrm(xz_statep state) in xz_avail_zstrm() argument
280 state->strm.avail_in = state->zstrm.avail_in; in xz_avail_zstrm()
281 state->strm.next_in = state->zstrm.next_in; in xz_avail_zstrm()
282 ret = xz_avail(state); in xz_avail_zstrm()
283 state->zstrm.avail_in = (uInt) state->strm.avail_in; in xz_avail_zstrm()
284 state->zstrm.next_in = (Bytef *) state->strm.next_in; in xz_avail_zstrm()
290 is_format_xz(xz_statep state) in is_format_xz() argument
292 lzma_stream *strm = &(state->strm); in is_format_xz()
294 return strm->avail_in >= 6 && memcmp(state->in, "\3757zXZ", 6) == 0; in is_format_xz()
298 is_format_lzma(xz_statep state) in is_format_lzma() argument
300 lzma_stream *strm = &(state->strm); in is_format_lzma()
312 if (lzma_properties_decode(&filter, NULL, state->in, 5) != LZMA_OK) in is_format_lzma()
343 uncompressed_size |= (uint64_t) (state->in[5 + i]) << (i * 8); in is_format_lzma()
355 #define NEXT() ((strm->avail_in == 0 && xz_avail(state) == -1) ? -1 : \
359 #define NEXTZ() ((strm->avail_in == 0 && xz_avail_zstrm(state) == -1) ? -1 : \
366 gz_next4(xz_statep state, unsigned long *ret) in gz_next4() argument
370 z_streamp strm = &(state->zstrm); in gz_next4()
385 xz_head(xz_statep state) in xz_head() argument
387 lzma_stream *strm = &(state->strm); in xz_head()
393 if (state->size == 0) { in xz_head()
395 state->in = xmlMalloc(state->want); in xz_head()
396 state->out = xmlMalloc(state->want << 1); in xz_head()
397 if (state->in == NULL || state->out == NULL) { in xz_head()
398 if (state->out != NULL) in xz_head()
399 xmlFree(state->out); in xz_head()
400 if (state->in != NULL) in xz_head()
401 xmlFree(state->in); in xz_head()
402 xz_error(state, LZMA_MEM_ERROR, "out of memory"); in xz_head()
405 state->size = state->want; in xz_head()
408 state->strm = init; in xz_head()
409 state->strm.avail_in = 0; in xz_head()
410 state->strm.next_in = NULL; in xz_head()
411 if (lzma_auto_decoder(&state->strm, UINT64_MAX, 0) != LZMA_OK) { in xz_head()
412 xmlFree(state->out); in xz_head()
413 xmlFree(state->in); in xz_head()
414 state->size = 0; in xz_head()
415 xz_error(state, LZMA_MEM_ERROR, "out of memory"); in xz_head()
420 state->zstrm.zalloc = Z_NULL; in xz_head()
421 state->zstrm.zfree = Z_NULL; in xz_head()
422 state->zstrm.opaque = Z_NULL; in xz_head()
423 state->zstrm.avail_in = 0; in xz_head()
424 state->zstrm.next_in = Z_NULL; in xz_head()
425 if (state->init == 0) { in xz_head()
426 if (inflateInit2(&(state->zstrm), -15) != Z_OK) {/* raw inflate */ in xz_head()
427 xmlFree(state->out); in xz_head()
428 xmlFree(state->in); in xz_head()
429 state->size = 0; in xz_head()
430 xz_error(state, LZMA_MEM_ERROR, "out of memory"); in xz_head()
433 state->init = 1; in xz_head()
440 if (xz_avail(state) == -1) in xz_head()
447 if (is_format_xz(state) || is_format_lzma(state)) { in xz_head()
448 state->how = LZMA; in xz_head()
449 state->direct = 0; in xz_head()
457 if (strm->avail_in == 0 && xz_avail(state) == -1) in xz_head()
466 xz_error(state, LZMA_DATA_ERROR, in xz_head()
472 xz_error(state, LZMA_DATA_ERROR, in xz_head()
501 inflateReset(&state->zstrm); in xz_head()
502 state->zstrm.adler = crc32(0L, Z_NULL, 0); in xz_head()
503 state->how = GZIP; in xz_head()
504 state->direct = 0; in xz_head()
508 state->out[0] = 31; in xz_head()
509 state->have = 1; in xz_head()
517 state->raw = state->pos; in xz_head()
518 state->next = state->out; in xz_head()
520 memcpy(state->next + state->have, strm->next_in, strm->avail_in); in xz_head()
521 state->have += strm->avail_in; in xz_head()
524 state->how = COPY; in xz_head()
525 state->direct = 1; in xz_head()
530 xz_decomp(xz_statep state) in xz_decomp() argument
535 lzma_stream *strm = &(state->strm); in xz_decomp()
543 if (strm->avail_in == 0 && xz_avail(state) == -1) in xz_decomp()
546 xz_error(state, LZMA_DATA_ERROR, "unexpected end of file"); in xz_decomp()
549 if (state->eof) in xz_decomp()
554 if (state->how == GZIP) { in xz_decomp()
555 state->zstrm.avail_in = (uInt) state->strm.avail_in; in xz_decomp()
556 state->zstrm.next_in = (Bytef *) state->strm.next_in; in xz_decomp()
557 state->zstrm.avail_out = (uInt) state->strm.avail_out; in xz_decomp()
558 state->zstrm.next_out = (Bytef *) state->strm.next_out; in xz_decomp()
559 ret = inflate(&state->zstrm, Z_NO_FLUSH); in xz_decomp()
561 xz_error(state, Z_STREAM_ERROR, in xz_decomp()
571 state->strm.avail_in = state->zstrm.avail_in; in xz_decomp()
572 state->strm.next_in = state->zstrm.next_in; in xz_decomp()
573 state->strm.avail_out = state->zstrm.avail_out; in xz_decomp()
574 state->strm.next_out = state->zstrm.next_out; in xz_decomp()
579 xz_error(state, LZMA_MEM_ERROR, "out of memory"); in xz_decomp()
583 xz_error(state, LZMA_DATA_ERROR, "compressed data error"); in xz_decomp()
587 xz_error(state, LZMA_PROG_ERROR, "compression error"); in xz_decomp()
593 state->have = had - strm->avail_out; in xz_decomp()
594 state->next = strm->next_out - state->have; in xz_decomp()
596 state->zstrm.adler = in xz_decomp()
597 crc32(state->zstrm.adler, state->next, state->have); in xz_decomp()
602 if (state->how == GZIP) { in xz_decomp()
603 if (gz_next4(state, &crc) == -1 || gz_next4(state, &len) == -1) { in xz_decomp()
604 xz_error(state, LZMA_DATA_ERROR, "unexpected end of file"); in xz_decomp()
607 if (crc != state->zstrm.adler) { in xz_decomp()
608 xz_error(state, LZMA_DATA_ERROR, "incorrect data check"); in xz_decomp()
611 if (len != (state->zstrm.total_out & 0xffffffffL)) { in xz_decomp()
612 xz_error(state, LZMA_DATA_ERROR, "incorrect length check"); in xz_decomp()
615 state->strm.avail_in = 0; in xz_decomp()
616 state->strm.next_in = NULL; in xz_decomp()
617 state->strm.avail_out = 0; in xz_decomp()
618 state->strm.next_out = NULL; in xz_decomp()
621 if (strm->avail_in != 0 || !state->eof) { in xz_decomp()
622 xz_error(state, LZMA_DATA_ERROR, "trailing garbage"); in xz_decomp()
625 state->how = LOOK; /* ready for next stream, once have is 0 (leave in xz_decomp()
634 xz_make(xz_statep state) in xz_make() argument
636 lzma_stream *strm = &(state->strm); in xz_make()
638 if (state->how == LOOK) { /* look for lzma / gzip header */ in xz_make()
639 if (xz_head(state) == -1) in xz_make()
641 if (state->have) /* got some data from xz_head() */ in xz_make()
644 if (state->how == COPY) { /* straight copy */ in xz_make()
645 if (xz_load(state, state->out, state->size << 1, &(state->have)) == in xz_make()
648 state->next = state->out; in xz_make()
649 } else if (state->how == LZMA || state->how == GZIP) { /* decompress */ in xz_make()
650 strm->avail_out = state->size << 1; in xz_make()
651 strm->next_out = state->out; in xz_make()
652 if (xz_decomp(state) == -1) in xz_make()
659 xz_skip(xz_statep state, uint64_t len) in xz_skip() argument
666 if (state->have) { in xz_skip()
667 n = (uint64_t) state->have > len ? in xz_skip()
668 (unsigned) len : state->have; in xz_skip()
669 state->have -= n; in xz_skip()
670 state->next += n; in xz_skip()
671 state->pos += n; in xz_skip()
676 else if (state->eof && state->strm.avail_in == 0) in xz_skip()
682 if (xz_make(state) == -1) in xz_skip()
692 xz_statep state; in __libxml2_xzread() local
698 state = (xz_statep) file; in __libxml2_xzread()
699 strm = &(state->strm); in __libxml2_xzread()
702 if (state->err != LZMA_OK) in __libxml2_xzread()
708 xz_error(state, LZMA_BUF_ERROR, in __libxml2_xzread()
718 if (state->seek) { in __libxml2_xzread()
719 state->seek = 0; in __libxml2_xzread()
720 if (xz_skip(state, state->skip) == -1) in __libxml2_xzread()
728 if (state->have) { in __libxml2_xzread()
729 n = state->have > len ? len : state->have; in __libxml2_xzread()
730 memcpy(buf, state->next, n); in __libxml2_xzread()
731 state->next += n; in __libxml2_xzread()
732 state->have -= n; in __libxml2_xzread()
736 else if (state->eof && strm->avail_in == 0) in __libxml2_xzread()
741 else if (state->how == LOOK || len < (state->size << 1)) { in __libxml2_xzread()
743 if (xz_make(state) == -1) in __libxml2_xzread()
751 else if (state->how == COPY) { /* read directly */ in __libxml2_xzread()
752 if (xz_load(state, buf, len, &n) == -1) in __libxml2_xzread()
760 if (xz_decomp(state) == -1) in __libxml2_xzread()
762 n = state->have; in __libxml2_xzread()
763 state->have = 0; in __libxml2_xzread()
770 state->pos += n; in __libxml2_xzread()
781 xz_statep state; in __libxml2_xzclose() local
786 state = (xz_statep) file; in __libxml2_xzclose()
789 if (state->size) { in __libxml2_xzclose()
790 lzma_end(&(state->strm)); in __libxml2_xzclose()
792 if (state->init == 1) in __libxml2_xzclose()
793 inflateEnd(&(state->zstrm)); in __libxml2_xzclose()
794 state->init = 0; in __libxml2_xzclose()
796 xmlFree(state->out); in __libxml2_xzclose()
797 xmlFree(state->in); in __libxml2_xzclose()
799 xmlFree(state->path); in __libxml2_xzclose()
800 ret = close(state->fd); in __libxml2_xzclose()
801 xmlFree(state); in __libxml2_xzclose()