Home | History | Annotate | Download | only in libxml2

Lines Matching refs:state

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