2 |
- |
1 |
/*
|
|
|
2 |
* THIS FILE IS NOT IDENTICAL TO THE ORIGINAL
|
|
|
3 |
* FROM THE BZIP2 DISTRIBUTION.
|
|
|
4 |
*
|
|
|
5 |
* It has been modified, mainly to break the library
|
|
|
6 |
* into smaller pieces.
|
|
|
7 |
*
|
|
|
8 |
* Russ Cox
|
|
|
9 |
* rsc@plan9.bell-labs.com
|
|
|
10 |
* July 2000
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
/*-------------------------------------------------------------*/
|
|
|
14 |
/*--- Library top-level functions. ---*/
|
|
|
15 |
/*--- bzlib.c ---*/
|
|
|
16 |
/*-------------------------------------------------------------*/
|
|
|
17 |
|
|
|
18 |
/*--
|
|
|
19 |
This file is a part of bzip2 and/or libbzip2, a program and
|
|
|
20 |
library for lossless, block-sorting data compression.
|
|
|
21 |
|
|
|
22 |
Copyright (C) 1996-2000 Julian R Seward. All rights reserved.
|
|
|
23 |
|
|
|
24 |
Redistribution and use in source and binary forms, with or without
|
|
|
25 |
modification, are permitted provided that the following conditions
|
|
|
26 |
are met:
|
|
|
27 |
|
|
|
28 |
1. Redistributions of source code must retain the above copyright
|
|
|
29 |
notice, this list of conditions and the following disclaimer.
|
|
|
30 |
|
|
|
31 |
2. The origin of this software must not be misrepresented; you must
|
|
|
32 |
not claim that you wrote the original software. If you use this
|
|
|
33 |
software in a product, an acknowledgment in the product
|
|
|
34 |
documentation would be appreciated but is not required.
|
|
|
35 |
|
|
|
36 |
3. Altered source versions must be plainly marked as such, and must
|
|
|
37 |
not be misrepresented as being the original software.
|
|
|
38 |
|
|
|
39 |
4. The name of the author may not be used to endorse or promote
|
|
|
40 |
products derived from this software without specific prior written
|
|
|
41 |
permission.
|
|
|
42 |
|
|
|
43 |
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
|
|
44 |
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
45 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
46 |
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
47 |
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
48 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
|
|
49 |
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
50 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
51 |
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
52 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
53 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
54 |
|
|
|
55 |
Julian Seward, Cambridge, UK.
|
|
|
56 |
jseward@acm.org
|
|
|
57 |
bzip2/libbzip2 version 1.0 of 21 March 2000
|
|
|
58 |
|
|
|
59 |
This program is based on (at least) the work of:
|
|
|
60 |
Mike Burrows
|
|
|
61 |
David Wheeler
|
|
|
62 |
Peter Fenwick
|
|
|
63 |
Alistair Moffat
|
|
|
64 |
Radford Neal
|
|
|
65 |
Ian H. Witten
|
|
|
66 |
Robert Sedgewick
|
|
|
67 |
Jon L. Bentley
|
|
|
68 |
|
|
|
69 |
For more information on these sources, see the manual.
|
|
|
70 |
--*/
|
|
|
71 |
|
|
|
72 |
/*--
|
|
|
73 |
CHANGES
|
|
|
74 |
~~~~~~~
|
|
|
75 |
0.9.0 -- original version.
|
|
|
76 |
|
|
|
77 |
0.9.0a/b -- no changes in this file.
|
|
|
78 |
|
|
|
79 |
0.9.0c
|
|
|
80 |
* made zero-length BZ_FLUSH work correctly in bzCompress().
|
|
|
81 |
* fixed bzWrite/bzRead to ignore zero-length requests.
|
|
|
82 |
* fixed bzread to correctly handle read requests after EOF.
|
|
|
83 |
* wrong parameter order in call to bzDecompressInit in
|
|
|
84 |
bzBuffToBuffDecompress. Fixed.
|
|
|
85 |
--*/
|
|
|
86 |
|
|
|
87 |
#include "os.h"
|
|
|
88 |
#include "bzlib.h"
|
|
|
89 |
#include "bzlib_private.h"
|
|
|
90 |
|
|
|
91 |
/*---------------------------------------------------*/
|
|
|
92 |
int BZ_API(BZ2_bzBuffToBuffDecompress)
|
|
|
93 |
( char* dest,
|
|
|
94 |
unsigned int* destLen,
|
|
|
95 |
char* source,
|
|
|
96 |
unsigned int sourceLen,
|
|
|
97 |
int small,
|
|
|
98 |
int verbosity )
|
|
|
99 |
{
|
|
|
100 |
bz_stream strm;
|
|
|
101 |
int ret;
|
|
|
102 |
|
|
|
103 |
if (dest == NULL || destLen == NULL ||
|
|
|
104 |
source == NULL ||
|
|
|
105 |
(small != 0 && small != 1) ||
|
|
|
106 |
verbosity < 0 || verbosity > 4)
|
|
|
107 |
return BZ_PARAM_ERROR;
|
|
|
108 |
|
|
|
109 |
strm.bzalloc = NULL;
|
|
|
110 |
strm.bzfree = NULL;
|
|
|
111 |
strm.opaque = NULL;
|
|
|
112 |
ret = BZ2_bzDecompressInit ( &strm, verbosity, small );
|
|
|
113 |
if (ret != BZ_OK) return ret;
|
|
|
114 |
|
|
|
115 |
strm.next_in = source;
|
|
|
116 |
strm.next_out = dest;
|
|
|
117 |
strm.avail_in = sourceLen;
|
|
|
118 |
strm.avail_out = *destLen;
|
|
|
119 |
|
|
|
120 |
ret = BZ2_bzDecompress ( &strm );
|
|
|
121 |
if (ret == BZ_OK) goto output_overflow_or_eof;
|
|
|
122 |
if (ret != BZ_STREAM_END) goto errhandler;
|
|
|
123 |
|
|
|
124 |
/* normal termination */
|
|
|
125 |
*destLen -= strm.avail_out;
|
|
|
126 |
BZ2_bzDecompressEnd ( &strm );
|
|
|
127 |
return BZ_OK;
|
|
|
128 |
|
|
|
129 |
output_overflow_or_eof:
|
|
|
130 |
if (strm.avail_out > 0) {
|
|
|
131 |
BZ2_bzDecompressEnd ( &strm );
|
|
|
132 |
return BZ_UNEXPECTED_EOF;
|
|
|
133 |
} else {
|
|
|
134 |
BZ2_bzDecompressEnd ( &strm );
|
|
|
135 |
return BZ_OUTBUFF_FULL;
|
|
|
136 |
};
|
|
|
137 |
|
|
|
138 |
errhandler:
|
|
|
139 |
BZ2_bzDecompressEnd ( &strm );
|
|
|
140 |
return ret;
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
|