blob: ef19ae1654d82ffbb1744c958dd2f9e7434d6775 [file] [log] [blame]
Denis Vlasenko77f1ec12007-10-13 03:36:03 +00001/*
2 * bzip2 is written by Julian Seward <jseward@bzip.org>.
3 * Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>.
4 * See README and LICENSE files in this directory for more information.
5 */
6
7/*-------------------------------------------------------------*/
8/*--- Library top-level functions. ---*/
9/*--- bzlib.c ---*/
10/*-------------------------------------------------------------*/
11
12/* ------------------------------------------------------------------
13This file is part of bzip2/libbzip2, a program and library for
14lossless, block-sorting data compression.
15
16bzip2/libbzip2 version 1.0.4 of 20 December 2006
17Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
18
19Please read the WARNING, DISCLAIMER and PATENTS sections in the
20README file.
21
22This program is released under the terms of the license contained
23in the file LICENSE.
24------------------------------------------------------------------ */
25
26/* CHANGES
27 * 0.9.0 -- original version.
28 * 0.9.0a/b -- no changes in this file.
29 * 0.9.0c -- made zero-length BZ_FLUSH work correctly in bzCompress().
30 * fixed bzWrite/bzRead to ignore zero-length requests.
Denys Vlasenkofb132e42010-10-29 11:46:52 +020031 * fixed bzread to correctly handle read requests after EOF.
Denis Vlasenko77f1ec12007-10-13 03:36:03 +000032 * wrong parameter order in call to bzDecompressInit in
33 * bzBuffToBuffDecompress. Fixed.
34 */
35
36/* #include "bzlib_private.h" */
37
38/*---------------------------------------------------*/
39/*--- Compression stuff ---*/
40/*---------------------------------------------------*/
41
42/*---------------------------------------------------*/
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +000043#if BZ_LIGHT_DEBUG
44static
45void bz_assert_fail(int errcode)
Denis Vlasenko77f1ec12007-10-13 03:36:03 +000046{
47 /* if (errcode == 1007) bb_error_msg_and_die("probably bad RAM"); */
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +000048 bb_error_msg_and_die("internal error %d", errcode);
Denis Vlasenko77f1ec12007-10-13 03:36:03 +000049}
50#endif
51
Denis Vlasenko77f1ec12007-10-13 03:36:03 +000052/*---------------------------------------------------*/
53static
54void prepare_new_block(EState* s)
55{
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +000056 int i;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +000057 s->nblock = 0;
Denys Vlasenkofeafb342018-02-03 04:43:46 +010058 //indexes into s->zbits[], initialzation moved to init of s->zbits
Denys Vlasenkoe594fb22018-02-03 01:30:12 +010059 //s->posZ = s->zbits; // was: s->numZ = 0;
60 //s->state_out_pos = s->zbits;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +000061 BZ_INITIALISE_CRC(s->blockCRC);
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +000062 /* inlined memset would be nice to have here */
63 for (i = 0; i < 256; i++)
64 s->inUse[i] = 0;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +000065 s->blockNo++;
66}
67
68
69/*---------------------------------------------------*/
70static
71ALWAYS_INLINE
72void init_RL(EState* s)
73{
74 s->state_in_ch = 256;
75 s->state_in_len = 0;
76}
77
78
79static
Denis Vlasenko31acd1b2007-10-17 10:14:11 +000080int isempty_RL(EState* s)
Denis Vlasenko77f1ec12007-10-13 03:36:03 +000081{
Denis Vlasenko31acd1b2007-10-17 10:14:11 +000082 return (s->state_in_ch >= 256 || s->state_in_len <= 0);
Denis Vlasenko77f1ec12007-10-13 03:36:03 +000083}
84
85
86/*---------------------------------------------------*/
87static
88void BZ2_bzCompressInit(bz_stream *strm, int blockSize100k)
89{
Denys Vlasenkoc9ae8d72018-02-03 20:19:51 +010090 unsigned n;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +000091 EState* s;
92
93 s = xzalloc(sizeof(EState));
94 s->strm = strm;
95
96 n = 100000 * blockSize100k;
97 s->arr1 = xmalloc(n * sizeof(uint32_t));
98 s->mtfv = (uint16_t*)s->arr1;
99 s->ptr = (uint32_t*)s->arr1;
100 s->arr2 = xmalloc((n + BZ_N_OVERSHOOT) * sizeof(uint32_t));
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000101 s->block = (uint8_t*)s->arr2;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000102
Denys Vlasenko6d3da732021-08-29 15:32:42 +0200103 crc32_filltable(s->crc32table, 1);
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000104
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000105 s->state = BZ_S_INPUT;
106 s->mode = BZ_M_RUNNING;
107 s->blockSize100k = blockSize100k;
108 s->nblockMAX = n - 19;
109
110 strm->state = s;
111 /*strm->total_in = 0;*/
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000112 strm->total_out = 0;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000113 init_RL(s);
114 prepare_new_block(s);
115}
116
117
118/*---------------------------------------------------*/
119static
120void add_pair_to_block(EState* s)
121{
122 int32_t i;
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000123 uint8_t ch = (uint8_t)(s->state_in_ch);
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000124 for (i = 0; i < s->state_in_len; i++) {
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000125 BZ_UPDATE_CRC(s, s->blockCRC, ch);
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000126 }
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000127 s->inUse[s->state_in_ch] = 1;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000128 switch (s->state_in_len) {
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000129 case 3:
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000130 s->block[s->nblock] = (uint8_t)ch; s->nblock++;
131 /* fall through */
132 case 2:
133 s->block[s->nblock] = (uint8_t)ch; s->nblock++;
134 /* fall through */
135 case 1:
136 s->block[s->nblock] = (uint8_t)ch; s->nblock++;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000137 break;
138 default:
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000139 s->inUse[s->state_in_len - 4] = 1;
140 s->block[s->nblock] = (uint8_t)ch; s->nblock++;
141 s->block[s->nblock] = (uint8_t)ch; s->nblock++;
142 s->block[s->nblock] = (uint8_t)ch; s->nblock++;
143 s->block[s->nblock] = (uint8_t)ch; s->nblock++;
144 s->block[s->nblock] = (uint8_t)(s->state_in_len - 4);
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000145 s->nblock++;
146 break;
147 }
148}
149
150
151/*---------------------------------------------------*/
152static
153void flush_RL(EState* s)
154{
155 if (s->state_in_ch < 256) add_pair_to_block(s);
156 init_RL(s);
157}
158
159
160/*---------------------------------------------------*/
161#define ADD_CHAR_TO_BLOCK(zs, zchh0) \
162{ \
163 uint32_t zchh = (uint32_t)(zchh0); \
164 /*-- fast track the common case --*/ \
165 if (zchh != zs->state_in_ch && zs->state_in_len == 1) { \
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000166 uint8_t ch = (uint8_t)(zs->state_in_ch); \
167 BZ_UPDATE_CRC(zs, zs->blockCRC, ch); \
168 zs->inUse[zs->state_in_ch] = 1; \
169 zs->block[zs->nblock] = (uint8_t)ch; \
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000170 zs->nblock++; \
171 zs->state_in_ch = zchh; \
172 } \
173 else \
174 /*-- general, uncommon cases --*/ \
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000175 if (zchh != zs->state_in_ch || zs->state_in_len == 255) { \
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000176 if (zs->state_in_ch < 256) \
177 add_pair_to_block(zs); \
178 zs->state_in_ch = zchh; \
179 zs->state_in_len = 1; \
180 } else { \
181 zs->state_in_len++; \
182 } \
183}
184
185
186/*---------------------------------------------------*/
187static
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000188void /*Bool*/ copy_input_until_stop(EState* s)
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000189{
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000190 /*Bool progress_in = False;*/
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000191
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000192#ifdef SAME_CODE_AS_BELOW
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000193 if (s->mode == BZ_M_RUNNING) {
194 /*-- fast track the common case --*/
195 while (1) {
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000196 /*-- no input? --*/
197 if (s->strm->avail_in == 0) break;
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000198 /*-- block full? --*/
199 if (s->nblock >= s->nblockMAX) break;
200 /*progress_in = True;*/
201 ADD_CHAR_TO_BLOCK(s, (uint32_t)(*(uint8_t*)(s->strm->next_in)));
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000202 s->strm->next_in++;
203 s->strm->avail_in--;
204 /*s->strm->total_in++;*/
205 }
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000206 } else
207#endif
208 {
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000209 /*-- general, uncommon case --*/
210 while (1) {
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000211 /*-- no input? --*/
212 if (s->strm->avail_in == 0) break;
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000213 /*-- block full? --*/
214 if (s->nblock >= s->nblockMAX) break;
215 //# /*-- flush/finish end? --*/
216 //# if (s->avail_in_expect == 0) break;
217 /*progress_in = True;*/
218 ADD_CHAR_TO_BLOCK(s, *(uint8_t*)(s->strm->next_in));
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000219 s->strm->next_in++;
220 s->strm->avail_in--;
221 /*s->strm->total_in++;*/
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000222 //# s->avail_in_expect--;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000223 }
224 }
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000225 /*return progress_in;*/
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000226}
227
228
229/*---------------------------------------------------*/
230static
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000231void /*Bool*/ copy_output_until_stop(EState* s)
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000232{
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000233 /*Bool progress_out = False;*/
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000234
235 while (1) {
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000236 /*-- no output space? --*/
237 if (s->strm->avail_out == 0) break;
238
239 /*-- block done? --*/
Denys Vlasenkoe594fb22018-02-03 01:30:12 +0100240 if (s->state_out_pos >= s->posZ) break;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000241
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000242 /*progress_out = True;*/
Denys Vlasenkoe594fb22018-02-03 01:30:12 +0100243 *(s->strm->next_out) = *s->state_out_pos++;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000244 s->strm->avail_out--;
245 s->strm->next_out++;
246 s->strm->total_out++;
247 }
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000248 /*return progress_out;*/
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000249}
250
251
252/*---------------------------------------------------*/
253static
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000254void /*Bool*/ handle_compress(bz_stream *strm)
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000255{
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000256 /*Bool progress_in = False;*/
257 /*Bool progress_out = False;*/
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000258 EState* s = strm->state;
Denis Vlasenko3f5fdc72007-10-14 04:55:59 +0000259
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000260 while (1) {
261 if (s->state == BZ_S_OUTPUT) {
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000262 /*progress_out |=*/ copy_output_until_stop(s);
Denys Vlasenkoe594fb22018-02-03 01:30:12 +0100263 if (s->state_out_pos < s->posZ) break;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000264 if (s->mode == BZ_M_FINISHING
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000265 //# && s->avail_in_expect == 0
266 && s->strm->avail_in == 0
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000267 && isempty_RL(s))
268 break;
269 prepare_new_block(s);
270 s->state = BZ_S_INPUT;
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000271#ifdef FLUSH_IS_UNUSED
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000272 if (s->mode == BZ_M_FLUSHING
273 && s->avail_in_expect == 0
274 && isempty_RL(s))
275 break;
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000276#endif
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000277 }
278
279 if (s->state == BZ_S_INPUT) {
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000280 /*progress_in |=*/ copy_input_until_stop(s);
281 //#if (s->mode != BZ_M_RUNNING && s->avail_in_expect == 0) {
282 if (s->mode != BZ_M_RUNNING && s->strm->avail_in == 0) {
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000283 flush_RL(s);
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000284 BZ2_compressBlock(s, (s->mode == BZ_M_FINISHING));
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000285 s->state = BZ_S_OUTPUT;
286 } else
287 if (s->nblock >= s->nblockMAX) {
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000288 BZ2_compressBlock(s, 0);
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000289 s->state = BZ_S_OUTPUT;
290 } else
291 if (s->strm->avail_in == 0) {
292 break;
293 }
294 }
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000295 }
296
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000297 /*return progress_in || progress_out;*/
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000298}
299
300
301/*---------------------------------------------------*/
302static
303int BZ2_bzCompress(bz_stream *strm, int action)
304{
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000305 /*Bool progress;*/
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000306 EState* s;
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000307
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000308 s = strm->state;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000309
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000310 switch (s->mode) {
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000311 case BZ_M_RUNNING:
312 if (action == BZ_RUN) {
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000313 /*progress =*/ handle_compress(strm);
314 /*return progress ? BZ_RUN_OK : BZ_PARAM_ERROR;*/
315 return BZ_RUN_OK;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000316 }
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000317#ifdef FLUSH_IS_UNUSED
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000318 else
319 if (action == BZ_FLUSH) {
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000320 //#s->avail_in_expect = strm->avail_in;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000321 s->mode = BZ_M_FLUSHING;
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000322 goto case_BZ_M_FLUSHING;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000323 }
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000324#endif
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000325 else
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000326 /*if (action == BZ_FINISH)*/ {
327 //#s->avail_in_expect = strm->avail_in;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000328 s->mode = BZ_M_FINISHING;
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000329 goto case_BZ_M_FINISHING;
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000330 }
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000331
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000332#ifdef FLUSH_IS_UNUSED
Denis Vlasenko31acd1b2007-10-17 10:14:11 +0000333 case_BZ_M_FLUSHING:
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000334 case BZ_M_FLUSHING:
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000335 /*if (s->avail_in_expect != s->strm->avail_in)
336 return BZ_SEQUENCE_ERROR;*/
337 /*progress =*/ handle_compress(strm);
Denys Vlasenkoe594fb22018-02-03 01:30:12 +0100338 if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->posZ)
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000339 return BZ_FLUSH_OK;
340 s->mode = BZ_M_RUNNING;
341 return BZ_RUN_OK;
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000342#endif
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000343
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000344 case_BZ_M_FINISHING:
345 /*case BZ_M_FINISHING:*/
346 default:
347 /*if (s->avail_in_expect != s->strm->avail_in)
348 return BZ_SEQUENCE_ERROR;*/
349 /*progress =*/ handle_compress(strm);
350 /*if (!progress) return BZ_SEQUENCE_ERROR;*/
Denys Vlasenkoe594fb22018-02-03 01:30:12 +0100351 //#if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->posZ)
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000352 //# return BZ_FINISH_OK;
Denys Vlasenkoe594fb22018-02-03 01:30:12 +0100353 if (s->strm->avail_in > 0 || !isempty_RL(s) || s->state_out_pos < s->posZ)
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000354 return BZ_FINISH_OK;
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000355 /*s->mode = BZ_M_IDLE;*/
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000356 return BZ_STREAM_END;
357 }
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000358 /* return BZ_OK; --not reached--*/
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000359}
360
361
362/*---------------------------------------------------*/
363static
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000364void BZ2_bzCompressEnd(bz_stream *strm)
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000365{
366 EState* s;
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000367
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000368 s = strm->state;
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000369 free(s->arr1);
370 free(s->arr2);
Denys Vlasenko6d3da732021-08-29 15:32:42 +0200371 //free(s->ftab); // made it array member of s
372 //free(s->crc32table); // ditto
Denys Vlasenkoed9b08d2010-12-30 04:43:35 +0100373 free(s);
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000374}
375
376
377/*---------------------------------------------------*/
378/*--- Misc convenience stuff ---*/
379/*---------------------------------------------------*/
380
381/*---------------------------------------------------*/
382#ifdef EXAMPLE_CODE_FOR_MEM_TO_MEM_COMPRESSION
383static
384int BZ2_bzBuffToBuffCompress(char* dest,
385 unsigned int* destLen,
386 char* source,
387 unsigned int sourceLen,
388 int blockSize100k)
389{
390 bz_stream strm;
391 int ret;
392
Denys Vlasenko6b9f1632010-01-28 02:24:24 +0100393 if (dest == NULL || destLen == NULL
394 || source == NULL
395 || blockSize100k < 1 || blockSize100k > 9
396 ) {
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000397 return BZ_PARAM_ERROR;
Denys Vlasenko6b9f1632010-01-28 02:24:24 +0100398 }
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000399
400 BZ2_bzCompressInit(&strm, blockSize100k);
401
402 strm.next_in = source;
403 strm.next_out = dest;
404 strm.avail_in = sourceLen;
405 strm.avail_out = *destLen;
406
407 ret = BZ2_bzCompress(&strm, BZ_FINISH);
408 if (ret == BZ_FINISH_OK) goto output_overflow;
409 if (ret != BZ_STREAM_END) goto errhandler;
410
411 /* normal termination */
412 *destLen -= strm.avail_out;
413 BZ2_bzCompressEnd(&strm);
414 return BZ_OK;
415
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000416 output_overflow:
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000417 BZ2_bzCompressEnd(&strm);
418 return BZ_OUTBUFF_FULL;
419
Denis Vlasenkoef3aabe2007-10-14 00:43:01 +0000420 errhandler:
Denis Vlasenko77f1ec12007-10-13 03:36:03 +0000421 BZ2_bzCompressEnd(&strm);
422 return ret;
423}
424#endif
425
426/*-------------------------------------------------------------*/
427/*--- end bzlib.c ---*/
428/*-------------------------------------------------------------*/