| OLD | NEW |
| 1 /** | 1 /** |
| 2 * xzlib.c: front end for the transparent suport of lzma compression | 2 * xzlib.c: front end for the transparent suport of lzma compression |
| 3 * at the I/O layer, based on an example file from lzma project | 3 * at the I/O layer, based on an example file from lzma project |
| 4 * | 4 * |
| 5 * See Copyright for the status of this software. | 5 * See Copyright for the status of this software. |
| 6 * | 6 * |
| 7 * Anders F Bjorklund <afb@users.sourceforge.net> | 7 * Anders F Bjorklund <afb@users.sourceforge.net> |
| 8 */ | 8 */ |
| 9 #define IN_LIBXML | 9 #define IN_LIBXML |
| 10 #include "libxml.h" | 10 #include "libxml.h" |
| 11 #ifdef HAVE_LZMA_H | 11 #ifdef LIBXML_LZMA_ENABLED |
| 12 | 12 |
| 13 #include <string.h> | 13 #include <string.h> |
| 14 #ifdef HAVE_ERRNO_H | 14 #ifdef HAVE_ERRNO_H |
| 15 #include <errno.h> | 15 #include <errno.h> |
| 16 #endif | 16 #endif |
| 17 | 17 |
| 18 | 18 |
| 19 #ifdef HAVE_SYS_TYPES_H | 19 #ifdef HAVE_SYS_TYPES_H |
| 20 #include <sys/types.h> | 20 #include <sys/types.h> |
| 21 #endif | 21 #endif |
| 22 #ifdef HAVE_SYS_STAT_H | 22 #ifdef HAVE_SYS_STAT_H |
| 23 #include <sys/stat.h> | 23 #include <sys/stat.h> |
| 24 #endif | 24 #endif |
| 25 #ifdef HAVE_FCNTL_H | 25 #ifdef HAVE_FCNTL_H |
| 26 #include <fcntl.h> | 26 #include <fcntl.h> |
| 27 #endif | 27 #endif |
| 28 #ifdef HAVE_UNISTD_H | 28 #ifdef HAVE_UNISTD_H |
| 29 #include <unistd.h> | 29 #include <unistd.h> |
| 30 #endif | 30 #endif |
| 31 #ifdef HAVE_STDLIB_H | 31 #ifdef HAVE_STDLIB_H |
| 32 #include <stdlib.h> | 32 #include <stdlib.h> |
| 33 #endif | 33 #endif |
| 34 #ifdef HAVE_ZLIB_H | 34 #ifdef HAVE_ZLIB_H |
| 35 #include <zlib.h> | 35 #include <zlib.h> |
| 36 #endif | 36 #endif |
| 37 #ifdef HAVE_LZMA_H |
| 37 #include <lzma.h> | 38 #include <lzma.h> |
| 39 #endif |
| 38 | 40 |
| 39 #include "xzlib.h" | 41 #include "xzlib.h" |
| 40 #include <libxml/xmlmemory.h> | 42 #include <libxml/xmlmemory.h> |
| 41 | 43 |
| 42 /* values for xz_state how */ | 44 /* values for xz_state how */ |
| 43 #define LOOK 0 /* look for a gzip/lzma header */ | 45 #define LOOK 0 /* look for a gzip/lzma header */ |
| 44 #define COPY 1 /* copy input directly */ | 46 #define COPY 1 /* copy input directly */ |
| 45 #define GZIP 2 /* decompress a gzip stream */ | 47 #define GZIP 2 /* decompress a gzip stream */ |
| 46 #define LZMA 3 /* decompress a lzma stream */ | 48 #define LZMA 3 /* decompress a lzma stream */ |
| 47 | 49 |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 #endif | 576 #endif |
| 575 ret = lzma_code(strm, action); | 577 ret = lzma_code(strm, action); |
| 576 if (ret == LZMA_MEM_ERROR) { | 578 if (ret == LZMA_MEM_ERROR) { |
| 577 xz_error(state, LZMA_MEM_ERROR, "out of memory"); | 579 xz_error(state, LZMA_MEM_ERROR, "out of memory"); |
| 578 return -1; | 580 return -1; |
| 579 } | 581 } |
| 580 if (ret == LZMA_DATA_ERROR) { | 582 if (ret == LZMA_DATA_ERROR) { |
| 581 xz_error(state, LZMA_DATA_ERROR, "compressed data error"); | 583 xz_error(state, LZMA_DATA_ERROR, "compressed data error"); |
| 582 return -1; | 584 return -1; |
| 583 } | 585 } |
| 586 if (ret == LZMA_PROG_ERROR) { |
| 587 xz_error(state, LZMA_PROG_ERROR, "compression error"); |
| 588 return -1; |
| 589 } |
| 584 } while (strm->avail_out && ret != LZMA_STREAM_END); | 590 } while (strm->avail_out && ret != LZMA_STREAM_END); |
| 585 | 591 |
| 586 /* update available output and crc check value */ | 592 /* update available output and crc check value */ |
| 587 state->have = had - strm->avail_out; | 593 state->have = had - strm->avail_out; |
| 588 state->next = strm->next_out - state->have; | 594 state->next = strm->next_out - state->have; |
| 589 #ifdef HAVE_ZLIB_H | 595 #ifdef HAVE_ZLIB_H |
| 590 state->zstrm.adler = | 596 state->zstrm.adler = |
| 591 crc32(state->zstrm.adler, state->next, state->have); | 597 crc32(state->zstrm.adler, state->next, state->have); |
| 592 #endif | 598 #endif |
| 593 | 599 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 state->init = 0; | 794 state->init = 0; |
| 789 #endif | 795 #endif |
| 790 xmlFree(state->out); | 796 xmlFree(state->out); |
| 791 xmlFree(state->in); | 797 xmlFree(state->in); |
| 792 } | 798 } |
| 793 xmlFree(state->path); | 799 xmlFree(state->path); |
| 794 ret = close(state->fd); | 800 ret = close(state->fd); |
| 795 xmlFree(state); | 801 xmlFree(state); |
| 796 return ret ? ret : LZMA_OK; | 802 return ret ? ret : LZMA_OK; |
| 797 } | 803 } |
| 798 #endif /* HAVE_LZMA_H */ | 804 #endif /* LIBXML_LZMA_ENABLED */ |
| OLD | NEW |