2 /*-------------------------------------------------------------*/
3 /*--- Library top-level functions. ---*/
5 /*-------------------------------------------------------------*/
8 This file is a part of bzip2 and/or libbzip2, a program and
9 library for lossless, block-sorting data compression.
11 Copyright (C) 1996-2002 Julian R Seward. All rights reserved.
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions
17 1. Redistributions of source code must retain the above copyright
18 notice, this list of conditions and the following disclaimer.
20 2. The origin of this software must not be misrepresented; you must
21 not claim that you wrote the original software. If you use this
22 software in a product, an acknowledgment in the product
23 documentation would be appreciated but is not required.
25 3. Altered source versions must be plainly marked as such, and must
26 not be misrepresented as being the original software.
28 4. The name of the author may not be used to endorse or promote
29 products derived from this software without specific prior written
32 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
33 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
36 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
38 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
40 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 Julian Seward, Cambridge, UK.
46 bzip2/libbzip2 version 1.0 of 21 March 2000
48 This program is based on (at least) the work of:
58 For more information on these sources, see the manual.
64 0.9.0 -- original version.
66 0.9.0a/b -- no changes in this file.
69 * made zero-length BZ_FLUSH work correctly in bzCompress().
70 * fixed bzWrite/bzRead to ignore zero-length requests.
71 * fixed bzread to correctly handle read requests after EOF.
72 * wrong parameter order in call to bzDecompressInit in
73 bzBuffToBuffDecompress. Fixed.
76 #include "bzlib_private.h"
79 /*---------------------------------------------------*/
80 /*--- Compression stuff ---*/
81 /*---------------------------------------------------*/
84 /*---------------------------------------------------*/
86 void BZ2_bz__AssertH__fail ( int errcode
)
89 "\n\nbzip2/libbzip2: internal error number %d.\n"
90 "This is a bug in bzip2/libbzip2, %s.\n"
91 "Please report it to me at: jseward@acm.org. If this happened\n"
92 "when you were using some program which uses libbzip2 as a\n"
93 "component, you should also report this bug to the author(s)\n"
94 "of that program. Please make an effort to report this bug;\n"
95 "timely and accurate bug reports eventually lead to higher\n"
96 "quality software. Thanks. Julian Seward, 30 December 2001.\n\n",
101 if (errcode
== 1007) {
103 "\n*** A special note about internal error number 1007 ***\n"
105 "Experience suggests that a common cause of i.e. 1007\n"
106 "is unreliable memory or other hardware. The 1007 assertion\n"
107 "just happens to cross-check the results of huge numbers of\n"
108 "memory reads/writes, and so acts (unintendedly) as a stress\n"
109 "test of your memory system.\n"
113 "I suggest the following: try compressing the file again,\n"
114 "possibly monitoring progress in detail with the -vv flag.\n"
116 "* If the error cannot be reproduced, and/or happens at different\n"
117 " points in compression, you may have a flaky memory system.\n"
118 " Try a memory-test program. I have used Memtest86\n"
119 " (www.memtest86.com). At the time of writing it is free (GPLd).\n"
120 " Memtest86 tests memory much more thorougly than your BIOSs\n"
121 " power-on test, and may find failures that the BIOS doesn't.\n"
125 "* If the error can be repeatably reproduced, this is a bug in\n"
126 " bzip2, and I would very much like to hear about it. Please\n"
127 " let me know, and, ideally, save a copy of the file causing the\n"
128 " problem -- without which I will be unable to investigate it.\n"
138 /*---------------------------------------------------*/
140 int bz_config_ok ( void )
142 if (sizeof(int) != 4) return 0;
143 if (sizeof(short) != 2) return 0;
144 if (sizeof(char) != 1) return 0;
149 /*---------------------------------------------------*/
151 void* default_bzalloc ( void* opaque
, Int32 items
, Int32 size
)
153 void* v
= malloc ( items
* size
);
158 void default_bzfree ( void* opaque
, void* addr
)
160 if (addr
!= NULL
) free ( addr
);
164 /*---------------------------------------------------*/
166 void prepare_new_block ( EState
* s
)
171 s
->state_out_pos
= 0;
172 BZ_INITIALISE_CRC ( s
->blockCRC
);
173 for (i
= 0; i
< 256; i
++) s
->inUse
[i
] = False
;
178 /*---------------------------------------------------*/
180 void init_RL ( EState
* s
)
182 s
->state_in_ch
= 256;
188 Bool
isempty_RL ( EState
* s
)
190 if (s
->state_in_ch
< 256 && s
->state_in_len
> 0)
196 /*---------------------------------------------------*/
197 int BZ_API(BZ2_bzCompressInit
)
206 if (!bz_config_ok()) return BZ_CONFIG_ERROR
;
209 blockSize100k
< 1 || blockSize100k
> 9 ||
210 workFactor
< 0 || workFactor
> 250)
211 return BZ_PARAM_ERROR
;
213 if (workFactor
== 0) workFactor
= 30;
214 if (strm
->bzalloc
== NULL
) strm
->bzalloc
= default_bzalloc
;
215 if (strm
->bzfree
== NULL
) strm
->bzfree
= default_bzfree
;
217 s
= BZALLOC( sizeof(EState
) );
218 if (s
== NULL
) return BZ_MEM_ERROR
;
225 n
= 100000 * blockSize100k
;
226 s
->arr1
= BZALLOC( n
* sizeof(UInt32
) );
227 s
->arr2
= BZALLOC( (n
+BZ_N_OVERSHOOT
) * sizeof(UInt32
) );
228 s
->ftab
= BZALLOC( 65537 * sizeof(UInt32
) );
230 if (s
->arr1
== NULL
|| s
->arr2
== NULL
|| s
->ftab
== NULL
) {
231 if (s
->arr1
!= NULL
) BZFREE(s
->arr1
);
232 if (s
->arr2
!= NULL
) BZFREE(s
->arr2
);
233 if (s
->ftab
!= NULL
) BZFREE(s
->ftab
);
234 if (s
!= NULL
) BZFREE(s
);
239 s
->state
= BZ_S_INPUT
;
240 s
->mode
= BZ_M_RUNNING
;
242 s
->blockSize100k
= blockSize100k
;
243 s
->nblockMAX
= 100000 * blockSize100k
- 19;
244 s
->verbosity
= verbosity
;
245 s
->workFactor
= workFactor
;
247 s
->block
= (UChar
*)s
->arr2
;
248 s
->mtfv
= (UInt16
*)s
->arr1
;
250 s
->ptr
= (UInt32
*)s
->arr1
;
253 strm
->total_in_lo32
= 0;
254 strm
->total_in_hi32
= 0;
255 strm
->total_out_lo32
= 0;
256 strm
->total_out_hi32
= 0;
258 prepare_new_block ( s
);
263 /*---------------------------------------------------*/
265 void add_pair_to_block ( EState
* s
)
268 UChar ch
= (UChar
)(s
->state_in_ch
);
269 for (i
= 0; i
< s
->state_in_len
; i
++) {
270 BZ_UPDATE_CRC( s
->blockCRC
, ch
);
272 s
->inUse
[s
->state_in_ch
] = True
;
273 switch (s
->state_in_len
) {
275 s
->block
[s
->nblock
] = (UChar
)ch
; s
->nblock
++;
278 s
->block
[s
->nblock
] = (UChar
)ch
; s
->nblock
++;
279 s
->block
[s
->nblock
] = (UChar
)ch
; s
->nblock
++;
282 s
->block
[s
->nblock
] = (UChar
)ch
; s
->nblock
++;
283 s
->block
[s
->nblock
] = (UChar
)ch
; s
->nblock
++;
284 s
->block
[s
->nblock
] = (UChar
)ch
; s
->nblock
++;
287 s
->inUse
[s
->state_in_len
-4] = True
;
288 s
->block
[s
->nblock
] = (UChar
)ch
; s
->nblock
++;
289 s
->block
[s
->nblock
] = (UChar
)ch
; s
->nblock
++;
290 s
->block
[s
->nblock
] = (UChar
)ch
; s
->nblock
++;
291 s
->block
[s
->nblock
] = (UChar
)ch
; s
->nblock
++;
292 s
->block
[s
->nblock
] = ((UChar
)(s
->state_in_len
-4));
299 /*---------------------------------------------------*/
301 void flush_RL ( EState
* s
)
303 if (s
->state_in_ch
< 256) add_pair_to_block ( s
);
308 /*---------------------------------------------------*/
309 #define ADD_CHAR_TO_BLOCK(zs,zchh0) \
311 UInt32 zchh = (UInt32)(zchh0); \
312 /*-- fast track the common case --*/ \
313 if (zchh != zs->state_in_ch && \
314 zs->state_in_len == 1) { \
315 UChar ch = (UChar)(zs->state_in_ch); \
316 BZ_UPDATE_CRC( zs->blockCRC, ch ); \
317 zs->inUse[zs->state_in_ch] = True; \
318 zs->block[zs->nblock] = (UChar)ch; \
320 zs->state_in_ch = zchh; \
323 /*-- general, uncommon cases --*/ \
324 if (zchh != zs->state_in_ch || \
325 zs->state_in_len == 255) { \
326 if (zs->state_in_ch < 256) \
327 add_pair_to_block ( zs ); \
328 zs->state_in_ch = zchh; \
329 zs->state_in_len = 1; \
331 zs->state_in_len++; \
336 /*---------------------------------------------------*/
338 Bool
copy_input_until_stop ( EState
* s
)
340 Bool progress_in
= False
;
342 if (s
->mode
== BZ_M_RUNNING
) {
344 /*-- fast track the common case --*/
346 /*-- block full? --*/
347 if (s
->nblock
>= s
->nblockMAX
) break;
349 if (s
->strm
->avail_in
== 0) break;
351 ADD_CHAR_TO_BLOCK ( s
, (UInt32
)(*((UChar
*)(s
->strm
->next_in
))) );
354 s
->strm
->total_in_lo32
++;
355 if (s
->strm
->total_in_lo32
== 0) s
->strm
->total_in_hi32
++;
360 /*-- general, uncommon case --*/
362 /*-- block full? --*/
363 if (s
->nblock
>= s
->nblockMAX
) break;
365 if (s
->strm
->avail_in
== 0) break;
366 /*-- flush/finish end? --*/
367 if (s
->avail_in_expect
== 0) break;
369 ADD_CHAR_TO_BLOCK ( s
, (UInt32
)(*((UChar
*)(s
->strm
->next_in
))) );
372 s
->strm
->total_in_lo32
++;
373 if (s
->strm
->total_in_lo32
== 0) s
->strm
->total_in_hi32
++;
374 s
->avail_in_expect
--;
381 /*---------------------------------------------------*/
383 Bool
copy_output_until_stop ( EState
* s
)
385 Bool progress_out
= False
;
389 /*-- no output space? --*/
390 if (s
->strm
->avail_out
== 0) break;
392 /*-- block done? --*/
393 if (s
->state_out_pos
>= s
->numZ
) break;
396 *(s
->strm
->next_out
) = s
->zbits
[s
->state_out_pos
];
398 s
->strm
->avail_out
--;
400 s
->strm
->total_out_lo32
++;
401 if (s
->strm
->total_out_lo32
== 0) s
->strm
->total_out_hi32
++;
408 /*---------------------------------------------------*/
410 Bool
handle_compress ( bz_stream
* strm
)
412 Bool progress_in
= False
;
413 Bool progress_out
= False
;
414 EState
* s
= strm
->state
;
418 if (s
->state
== BZ_S_OUTPUT
) {
419 progress_out
|= copy_output_until_stop ( s
);
420 if (s
->state_out_pos
< s
->numZ
) break;
421 if (s
->mode
== BZ_M_FINISHING
&&
422 s
->avail_in_expect
== 0 &&
423 isempty_RL(s
)) break;
424 prepare_new_block ( s
);
425 s
->state
= BZ_S_INPUT
;
426 if (s
->mode
== BZ_M_FLUSHING
&&
427 s
->avail_in_expect
== 0 &&
428 isempty_RL(s
)) break;
431 if (s
->state
== BZ_S_INPUT
) {
432 progress_in
|= copy_input_until_stop ( s
);
433 if (s
->mode
!= BZ_M_RUNNING
&& s
->avail_in_expect
== 0) {
435 BZ2_compressBlock ( s
, (Bool
)(s
->mode
== BZ_M_FINISHING
) );
436 s
->state
= BZ_S_OUTPUT
;
439 if (s
->nblock
>= s
->nblockMAX
) {
440 BZ2_compressBlock ( s
, False
);
441 s
->state
= BZ_S_OUTPUT
;
444 if (s
->strm
->avail_in
== 0) {
451 return progress_in
|| progress_out
;
455 /*---------------------------------------------------*/
456 int BZ_API(BZ2_bzCompress
) ( bz_stream
*strm
, int action
)
460 if (strm
== NULL
) return BZ_PARAM_ERROR
;
462 if (s
== NULL
) return BZ_PARAM_ERROR
;
463 if (s
->strm
!= strm
) return BZ_PARAM_ERROR
;
469 return BZ_SEQUENCE_ERROR
;
472 if (action
== BZ_RUN
) {
473 progress
= handle_compress ( strm
);
474 return progress
? BZ_RUN_OK
: BZ_PARAM_ERROR
;
477 if (action
== BZ_FLUSH
) {
478 s
->avail_in_expect
= strm
->avail_in
;
479 s
->mode
= BZ_M_FLUSHING
;
483 if (action
== BZ_FINISH
) {
484 s
->avail_in_expect
= strm
->avail_in
;
485 s
->mode
= BZ_M_FINISHING
;
489 return BZ_PARAM_ERROR
;
492 if (action
!= BZ_FLUSH
) return BZ_SEQUENCE_ERROR
;
493 if (s
->avail_in_expect
!= s
->strm
->avail_in
)
494 return BZ_SEQUENCE_ERROR
;
495 progress
= handle_compress ( strm
);
496 if (s
->avail_in_expect
> 0 || !isempty_RL(s
) ||
497 s
->state_out_pos
< s
->numZ
) return BZ_FLUSH_OK
;
498 s
->mode
= BZ_M_RUNNING
;
502 if (action
!= BZ_FINISH
) return BZ_SEQUENCE_ERROR
;
503 if (s
->avail_in_expect
!= s
->strm
->avail_in
)
504 return BZ_SEQUENCE_ERROR
;
505 progress
= handle_compress ( strm
);
506 if (!progress
) return BZ_SEQUENCE_ERROR
;
507 if (s
->avail_in_expect
> 0 || !isempty_RL(s
) ||
508 s
->state_out_pos
< s
->numZ
) return BZ_FINISH_OK
;
510 return BZ_STREAM_END
;
512 return BZ_OK
; /*--not reached--*/
516 /*---------------------------------------------------*/
517 int BZ_API(BZ2_bzCompressEnd
) ( bz_stream
*strm
)
520 if (strm
== NULL
) return BZ_PARAM_ERROR
;
522 if (s
== NULL
) return BZ_PARAM_ERROR
;
523 if (s
->strm
!= strm
) return BZ_PARAM_ERROR
;
525 if (s
->arr1
!= NULL
) BZFREE(s
->arr1
);
526 if (s
->arr2
!= NULL
) BZFREE(s
->arr2
);
527 if (s
->ftab
!= NULL
) BZFREE(s
->ftab
);
536 /*---------------------------------------------------*/
537 /*--- Decompression stuff ---*/
538 /*---------------------------------------------------*/
540 /*---------------------------------------------------*/
541 int BZ_API(BZ2_bzDecompressInit
)
548 if (!bz_config_ok()) return BZ_CONFIG_ERROR
;
550 if (strm
== NULL
) return BZ_PARAM_ERROR
;
551 if (small
!= 0 && small
!= 1) return BZ_PARAM_ERROR
;
552 if (verbosity
< 0 || verbosity
> 4) return BZ_PARAM_ERROR
;
554 if (strm
->bzalloc
== NULL
) strm
->bzalloc
= default_bzalloc
;
555 if (strm
->bzfree
== NULL
) strm
->bzfree
= default_bzfree
;
557 s
= BZALLOC( sizeof(DState
) );
558 if (s
== NULL
) return BZ_MEM_ERROR
;
561 s
->state
= BZ_X_MAGIC_1
;
564 s
->calculatedCombinedCRC
= 0;
565 strm
->total_in_lo32
= 0;
566 strm
->total_in_hi32
= 0;
567 strm
->total_out_lo32
= 0;
568 strm
->total_out_hi32
= 0;
569 s
->smallDecompress
= (Bool
)small
;
574 s
->verbosity
= verbosity
;
580 /*---------------------------------------------------*/
582 void unRLE_obuf_to_output_FAST ( DState
* s
)
586 if (s
->blockRandomised
) {
589 /* try to finish existing run */
591 if (s
->strm
->avail_out
== 0) return;
592 if (s
->state_out_len
== 0) break;
593 *( (UChar
*)(s
->strm
->next_out
) ) = s
->state_out_ch
;
594 BZ_UPDATE_CRC ( s
->calculatedBlockCRC
, s
->state_out_ch
);
597 s
->strm
->avail_out
--;
598 s
->strm
->total_out_lo32
++;
599 if (s
->strm
->total_out_lo32
== 0) s
->strm
->total_out_hi32
++;
602 /* can a new run be started? */
603 if (s
->nblock_used
== s
->save_nblock
+1) return;
606 s
->state_out_len
= 1;
607 s
->state_out_ch
= s
->k0
;
608 BZ_GET_FAST(k1
); BZ_RAND_UPD_MASK
;
609 k1
^= BZ_RAND_MASK
; s
->nblock_used
++;
610 if (s
->nblock_used
== s
->save_nblock
+1) continue;
611 if (k1
!= s
->k0
) { s
->k0
= k1
; continue; };
613 s
->state_out_len
= 2;
614 BZ_GET_FAST(k1
); BZ_RAND_UPD_MASK
;
615 k1
^= BZ_RAND_MASK
; s
->nblock_used
++;
616 if (s
->nblock_used
== s
->save_nblock
+1) continue;
617 if (k1
!= s
->k0
) { s
->k0
= k1
; continue; };
619 s
->state_out_len
= 3;
620 BZ_GET_FAST(k1
); BZ_RAND_UPD_MASK
;
621 k1
^= BZ_RAND_MASK
; s
->nblock_used
++;
622 if (s
->nblock_used
== s
->save_nblock
+1) continue;
623 if (k1
!= s
->k0
) { s
->k0
= k1
; continue; };
625 BZ_GET_FAST(k1
); BZ_RAND_UPD_MASK
;
626 k1
^= BZ_RAND_MASK
; s
->nblock_used
++;
627 s
->state_out_len
= ((Int32
)k1
) + 4;
628 BZ_GET_FAST(s
->k0
); BZ_RAND_UPD_MASK
;
629 s
->k0
^= BZ_RAND_MASK
; s
->nblock_used
++;
635 UInt32 c_calculatedBlockCRC
= s
->calculatedBlockCRC
;
636 UChar c_state_out_ch
= s
->state_out_ch
;
637 Int32 c_state_out_len
= s
->state_out_len
;
638 Int32 c_nblock_used
= s
->nblock_used
;
640 UInt32
* c_tt
= s
->tt
;
641 UInt32 c_tPos
= s
->tPos
;
642 char* cs_next_out
= s
->strm
->next_out
;
643 unsigned int cs_avail_out
= s
->strm
->avail_out
;
646 UInt32 avail_out_INIT
= cs_avail_out
;
647 Int32 s_save_nblockPP
= s
->save_nblock
+1;
648 unsigned int total_out_lo32_old
;
652 /* try to finish existing run */
653 if (c_state_out_len
> 0) {
655 if (cs_avail_out
== 0) goto return_notr
;
656 if (c_state_out_len
== 1) break;
657 *( (UChar
*)(cs_next_out
) ) = c_state_out_ch
;
658 BZ_UPDATE_CRC ( c_calculatedBlockCRC
, c_state_out_ch
);
663 s_state_out_len_eq_one
:
665 if (cs_avail_out
== 0) {
666 c_state_out_len
= 1; goto return_notr
;
668 *( (UChar
*)(cs_next_out
) ) = c_state_out_ch
;
669 BZ_UPDATE_CRC ( c_calculatedBlockCRC
, c_state_out_ch
);
674 /* can a new run be started? */
675 if (c_nblock_used
== s_save_nblockPP
) {
676 c_state_out_len
= 0; goto return_notr
;
678 c_state_out_ch
= c_k0
;
679 BZ_GET_FAST_C(k1
); c_nblock_used
++;
681 c_k0
= k1
; goto s_state_out_len_eq_one
;
683 if (c_nblock_used
== s_save_nblockPP
)
684 goto s_state_out_len_eq_one
;
687 BZ_GET_FAST_C(k1
); c_nblock_used
++;
688 if (c_nblock_used
== s_save_nblockPP
) continue;
689 if (k1
!= c_k0
) { c_k0
= k1
; continue; };
692 BZ_GET_FAST_C(k1
); c_nblock_used
++;
693 if (c_nblock_used
== s_save_nblockPP
) continue;
694 if (k1
!= c_k0
) { c_k0
= k1
; continue; };
696 BZ_GET_FAST_C(k1
); c_nblock_used
++;
697 c_state_out_len
= ((Int32
)k1
) + 4;
698 BZ_GET_FAST_C(c_k0
); c_nblock_used
++;
702 total_out_lo32_old
= s
->strm
->total_out_lo32
;
703 s
->strm
->total_out_lo32
+= (avail_out_INIT
- cs_avail_out
);
704 if (s
->strm
->total_out_lo32
< total_out_lo32_old
)
705 s
->strm
->total_out_hi32
++;
708 s
->calculatedBlockCRC
= c_calculatedBlockCRC
;
709 s
->state_out_ch
= c_state_out_ch
;
710 s
->state_out_len
= c_state_out_len
;
711 s
->nblock_used
= c_nblock_used
;
715 s
->strm
->next_out
= cs_next_out
;
716 s
->strm
->avail_out
= cs_avail_out
;
723 /*---------------------------------------------------*/
724 __inline__ Int32
BZ2_indexIntoF ( Int32 indx
, Int32
*cftab
)
730 mid
= (nb
+ na
) >> 1;
731 if (indx
>= cftab
[mid
]) nb
= mid
; else na
= mid
;
733 while (na
- nb
!= 1);
738 /*---------------------------------------------------*/
740 void unRLE_obuf_to_output_SMALL ( DState
* s
)
744 if (s
->blockRandomised
) {
747 /* try to finish existing run */
749 if (s
->strm
->avail_out
== 0) return;
750 if (s
->state_out_len
== 0) break;
751 *( (UChar
*)(s
->strm
->next_out
) ) = s
->state_out_ch
;
752 BZ_UPDATE_CRC ( s
->calculatedBlockCRC
, s
->state_out_ch
);
755 s
->strm
->avail_out
--;
756 s
->strm
->total_out_lo32
++;
757 if (s
->strm
->total_out_lo32
== 0) s
->strm
->total_out_hi32
++;
760 /* can a new run be started? */
761 if (s
->nblock_used
== s
->save_nblock
+1) return;
764 s
->state_out_len
= 1;
765 s
->state_out_ch
= s
->k0
;
766 BZ_GET_SMALL(k1
); BZ_RAND_UPD_MASK
;
767 k1
^= BZ_RAND_MASK
; s
->nblock_used
++;
768 if (s
->nblock_used
== s
->save_nblock
+1) continue;
769 if (k1
!= s
->k0
) { s
->k0
= k1
; continue; };
771 s
->state_out_len
= 2;
772 BZ_GET_SMALL(k1
); BZ_RAND_UPD_MASK
;
773 k1
^= BZ_RAND_MASK
; s
->nblock_used
++;
774 if (s
->nblock_used
== s
->save_nblock
+1) continue;
775 if (k1
!= s
->k0
) { s
->k0
= k1
; continue; };
777 s
->state_out_len
= 3;
778 BZ_GET_SMALL(k1
); BZ_RAND_UPD_MASK
;
779 k1
^= BZ_RAND_MASK
; s
->nblock_used
++;
780 if (s
->nblock_used
== s
->save_nblock
+1) continue;
781 if (k1
!= s
->k0
) { s
->k0
= k1
; continue; };
783 BZ_GET_SMALL(k1
); BZ_RAND_UPD_MASK
;
784 k1
^= BZ_RAND_MASK
; s
->nblock_used
++;
785 s
->state_out_len
= ((Int32
)k1
) + 4;
786 BZ_GET_SMALL(s
->k0
); BZ_RAND_UPD_MASK
;
787 s
->k0
^= BZ_RAND_MASK
; s
->nblock_used
++;
793 /* try to finish existing run */
795 if (s
->strm
->avail_out
== 0) return;
796 if (s
->state_out_len
== 0) break;
797 *( (UChar
*)(s
->strm
->next_out
) ) = s
->state_out_ch
;
798 BZ_UPDATE_CRC ( s
->calculatedBlockCRC
, s
->state_out_ch
);
801 s
->strm
->avail_out
--;
802 s
->strm
->total_out_lo32
++;
803 if (s
->strm
->total_out_lo32
== 0) s
->strm
->total_out_hi32
++;
806 /* can a new run be started? */
807 if (s
->nblock_used
== s
->save_nblock
+1) return;
809 s
->state_out_len
= 1;
810 s
->state_out_ch
= s
->k0
;
811 BZ_GET_SMALL(k1
); s
->nblock_used
++;
812 if (s
->nblock_used
== s
->save_nblock
+1) continue;
813 if (k1
!= s
->k0
) { s
->k0
= k1
; continue; };
815 s
->state_out_len
= 2;
816 BZ_GET_SMALL(k1
); s
->nblock_used
++;
817 if (s
->nblock_used
== s
->save_nblock
+1) continue;
818 if (k1
!= s
->k0
) { s
->k0
= k1
; continue; };
820 s
->state_out_len
= 3;
821 BZ_GET_SMALL(k1
); s
->nblock_used
++;
822 if (s
->nblock_used
== s
->save_nblock
+1) continue;
823 if (k1
!= s
->k0
) { s
->k0
= k1
; continue; };
825 BZ_GET_SMALL(k1
); s
->nblock_used
++;
826 s
->state_out_len
= ((Int32
)k1
) + 4;
827 BZ_GET_SMALL(s
->k0
); s
->nblock_used
++;
834 /*---------------------------------------------------*/
835 int BZ_API(BZ2_bzDecompress
) ( bz_stream
*strm
)
838 if (strm
== NULL
) return BZ_PARAM_ERROR
;
840 if (s
== NULL
) return BZ_PARAM_ERROR
;
841 if (s
->strm
!= strm
) return BZ_PARAM_ERROR
;
844 if (s
->state
== BZ_X_IDLE
) return BZ_SEQUENCE_ERROR
;
845 if (s
->state
== BZ_X_OUTPUT
) {
846 if (s
->smallDecompress
)
847 unRLE_obuf_to_output_SMALL ( s
); else
848 unRLE_obuf_to_output_FAST ( s
);
849 if (s
->nblock_used
== s
->save_nblock
+1 && s
->state_out_len
== 0) {
850 BZ_FINALISE_CRC ( s
->calculatedBlockCRC
);
851 if (s
->verbosity
>= 3)
852 VPrintf2 ( " {0x%x, 0x%x}", s
->storedBlockCRC
,
853 s
->calculatedBlockCRC
);
854 if (s
->verbosity
>= 2) VPrintf0 ( "]" );
855 if (s
->calculatedBlockCRC
!= s
->storedBlockCRC
)
856 return BZ_DATA_ERROR
;
857 s
->calculatedCombinedCRC
858 = (s
->calculatedCombinedCRC
<< 1) |
859 (s
->calculatedCombinedCRC
>> 31);
860 s
->calculatedCombinedCRC
^= s
->calculatedBlockCRC
;
861 s
->state
= BZ_X_BLKHDR_1
;
866 if (s
->state
>= BZ_X_MAGIC_1
) {
867 Int32 r
= BZ2_decompress ( s
);
868 if (r
== BZ_STREAM_END
) {
869 if (s
->verbosity
>= 3)
870 VPrintf2 ( "\n combined CRCs: stored = 0x%x, computed = 0x%x",
871 s
->storedCombinedCRC
, s
->calculatedCombinedCRC
);
872 if (s
->calculatedCombinedCRC
!= s
->storedCombinedCRC
)
873 return BZ_DATA_ERROR
;
876 if (s
->state
!= BZ_X_OUTPUT
) return r
;
882 return 0; /*NOTREACHED*/
886 /*---------------------------------------------------*/
887 int BZ_API(BZ2_bzDecompressEnd
) ( bz_stream
*strm
)
890 if (strm
== NULL
) return BZ_PARAM_ERROR
;
892 if (s
== NULL
) return BZ_PARAM_ERROR
;
893 if (s
->strm
!= strm
) return BZ_PARAM_ERROR
;
895 if (s
->tt
!= NULL
) BZFREE(s
->tt
);
896 if (s
->ll16
!= NULL
) BZFREE(s
->ll16
);
897 if (s
->ll4
!= NULL
) BZFREE(s
->ll4
);
907 /*---------------------------------------------------*/
908 /*--- File I/O stuff ---*/
909 /*---------------------------------------------------*/
911 #define BZ_SETERR(eee) \
913 if (bzerror != NULL) *bzerror = eee; \
914 if (bzf != NULL) bzf->lastErr = eee; \
920 Char buf
[BZ_MAX_UNUSED
];
930 /*---------------------------------------------*/
931 static Bool
myfeof ( FILE* f
)
933 Int32 c
= fgetc ( f
);
934 if (c
== EOF
) return True
;
940 /*---------------------------------------------------*/
941 BZFILE
* BZ_API(BZ2_bzWriteOpen
)
954 (blockSize100k
< 1 || blockSize100k
> 9) ||
955 (workFactor
< 0 || workFactor
> 250) ||
956 (verbosity
< 0 || verbosity
> 4))
957 { BZ_SETERR(BZ_PARAM_ERROR
); return NULL
; };
960 { BZ_SETERR(BZ_IO_ERROR
); return NULL
; };
962 bzf
= malloc ( sizeof(bzFile
) );
964 { BZ_SETERR(BZ_MEM_ERROR
); return NULL
; };
967 bzf
->initialisedOk
= False
;
971 bzf
->strm
.bzalloc
= NULL
;
972 bzf
->strm
.bzfree
= NULL
;
973 bzf
->strm
.opaque
= NULL
;
975 if (workFactor
== 0) workFactor
= 30;
976 ret
= BZ2_bzCompressInit ( &(bzf
->strm
), blockSize100k
,
977 verbosity
, workFactor
);
979 { BZ_SETERR(ret
); free(bzf
); return NULL
; };
981 bzf
->strm
.avail_in
= 0;
982 bzf
->initialisedOk
= True
;
988 /*---------------------------------------------------*/
989 void BZ_API(BZ2_bzWrite
)
996 bzFile
* bzf
= (bzFile
*)b
;
999 if (bzf
== NULL
|| buf
== NULL
|| len
< 0)
1000 { BZ_SETERR(BZ_PARAM_ERROR
); return; };
1001 if (!(bzf
->writing
))
1002 { BZ_SETERR(BZ_SEQUENCE_ERROR
); return; };
1003 if (ferror(bzf
->handle
))
1004 { BZ_SETERR(BZ_IO_ERROR
); return; };
1007 { BZ_SETERR(BZ_OK
); return; };
1009 bzf
->strm
.avail_in
= len
;
1010 bzf
->strm
.next_in
= buf
;
1013 bzf
->strm
.avail_out
= BZ_MAX_UNUSED
;
1014 bzf
->strm
.next_out
= bzf
->buf
;
1015 ret
= BZ2_bzCompress ( &(bzf
->strm
), BZ_RUN
);
1016 if (ret
!= BZ_RUN_OK
)
1017 { BZ_SETERR(ret
); return; };
1019 if (bzf
->strm
.avail_out
< BZ_MAX_UNUSED
) {
1020 n
= BZ_MAX_UNUSED
- bzf
->strm
.avail_out
;
1021 n2
= fwrite ( (void*)(bzf
->buf
), sizeof(UChar
),
1023 if (n
!= n2
|| ferror(bzf
->handle
))
1024 { BZ_SETERR(BZ_IO_ERROR
); return; };
1027 if (bzf
->strm
.avail_in
== 0)
1028 { BZ_SETERR(BZ_OK
); return; };
1033 /*---------------------------------------------------*/
1034 void BZ_API(BZ2_bzWriteClose
)
1038 unsigned int* nbytes_in
,
1039 unsigned int* nbytes_out
)
1041 BZ2_bzWriteClose64 ( bzerror
, b
, abandon
,
1042 nbytes_in
, NULL
, nbytes_out
, NULL
);
1046 void BZ_API(BZ2_bzWriteClose64
)
1050 unsigned int* nbytes_in_lo32
,
1051 unsigned int* nbytes_in_hi32
,
1052 unsigned int* nbytes_out_lo32
,
1053 unsigned int* nbytes_out_hi32
)
1056 bzFile
* bzf
= (bzFile
*)b
;
1059 { BZ_SETERR(BZ_OK
); return; };
1060 if (!(bzf
->writing
))
1061 { BZ_SETERR(BZ_SEQUENCE_ERROR
); return; };
1062 if (ferror(bzf
->handle
))
1063 { BZ_SETERR(BZ_IO_ERROR
); return; };
1065 if (nbytes_in_lo32
!= NULL
) *nbytes_in_lo32
= 0;
1066 if (nbytes_in_hi32
!= NULL
) *nbytes_in_hi32
= 0;
1067 if (nbytes_out_lo32
!= NULL
) *nbytes_out_lo32
= 0;
1068 if (nbytes_out_hi32
!= NULL
) *nbytes_out_hi32
= 0;
1070 if ((!abandon
) && bzf
->lastErr
== BZ_OK
) {
1072 bzf
->strm
.avail_out
= BZ_MAX_UNUSED
;
1073 bzf
->strm
.next_out
= bzf
->buf
;
1074 ret
= BZ2_bzCompress ( &(bzf
->strm
), BZ_FINISH
);
1075 if (ret
!= BZ_FINISH_OK
&& ret
!= BZ_STREAM_END
)
1076 { BZ_SETERR(ret
); return; };
1078 if (bzf
->strm
.avail_out
< BZ_MAX_UNUSED
) {
1079 n
= BZ_MAX_UNUSED
- bzf
->strm
.avail_out
;
1080 n2
= fwrite ( (void*)(bzf
->buf
), sizeof(UChar
),
1082 if (n
!= n2
|| ferror(bzf
->handle
))
1083 { BZ_SETERR(BZ_IO_ERROR
); return; };
1086 if (ret
== BZ_STREAM_END
) break;
1090 if ( !abandon
&& !ferror ( bzf
->handle
) ) {
1091 fflush ( bzf
->handle
);
1092 if (ferror(bzf
->handle
))
1093 { BZ_SETERR(BZ_IO_ERROR
); return; };
1096 if (nbytes_in_lo32
!= NULL
)
1097 *nbytes_in_lo32
= bzf
->strm
.total_in_lo32
;
1098 if (nbytes_in_hi32
!= NULL
)
1099 *nbytes_in_hi32
= bzf
->strm
.total_in_hi32
;
1100 if (nbytes_out_lo32
!= NULL
)
1101 *nbytes_out_lo32
= bzf
->strm
.total_out_lo32
;
1102 if (nbytes_out_hi32
!= NULL
)
1103 *nbytes_out_hi32
= bzf
->strm
.total_out_hi32
;
1106 BZ2_bzCompressEnd ( &(bzf
->strm
) );
1111 /*---------------------------------------------------*/
1112 BZFILE
* BZ_API(BZ2_bzReadOpen
)
1126 (small
!= 0 && small
!= 1) ||
1127 (verbosity
< 0 || verbosity
> 4) ||
1128 (unused
== NULL
&& nUnused
!= 0) ||
1129 (unused
!= NULL
&& (nUnused
< 0 || nUnused
> BZ_MAX_UNUSED
)))
1130 { BZ_SETERR(BZ_PARAM_ERROR
); return NULL
; };
1133 { BZ_SETERR(BZ_IO_ERROR
); return NULL
; };
1135 bzf
= malloc ( sizeof(bzFile
) );
1137 { BZ_SETERR(BZ_MEM_ERROR
); return NULL
; };
1141 bzf
->initialisedOk
= False
;
1144 bzf
->writing
= False
;
1145 bzf
->strm
.bzalloc
= NULL
;
1146 bzf
->strm
.bzfree
= NULL
;
1147 bzf
->strm
.opaque
= NULL
;
1149 while (nUnused
> 0) {
1150 bzf
->buf
[bzf
->bufN
] = *((UChar
*)(unused
)); bzf
->bufN
++;
1151 unused
= ((void*)( 1 + ((UChar
*)(unused
)) ));
1155 ret
= BZ2_bzDecompressInit ( &(bzf
->strm
), verbosity
, small
);
1157 { BZ_SETERR(ret
); free(bzf
); return NULL
; };
1159 bzf
->strm
.avail_in
= bzf
->bufN
;
1160 bzf
->strm
.next_in
= bzf
->buf
;
1162 bzf
->initialisedOk
= True
;
1167 /*---------------------------------------------------*/
1168 void BZ_API(BZ2_bzReadClose
) ( int *bzerror
, BZFILE
*b
)
1170 bzFile
* bzf
= (bzFile
*)b
;
1174 { BZ_SETERR(BZ_OK
); return; };
1177 { BZ_SETERR(BZ_SEQUENCE_ERROR
); return; };
1179 if (bzf
->initialisedOk
)
1180 (void)BZ2_bzDecompressEnd ( &(bzf
->strm
) );
1185 /*---------------------------------------------------*/
1186 int BZ_API(BZ2_bzRead
)
1193 bzFile
* bzf
= (bzFile
*)b
;
1197 if (bzf
== NULL
|| buf
== NULL
|| len
< 0)
1198 { BZ_SETERR(BZ_PARAM_ERROR
); return 0; };
1201 { BZ_SETERR(BZ_SEQUENCE_ERROR
); return 0; };
1204 { BZ_SETERR(BZ_OK
); return 0; };
1206 bzf
->strm
.avail_out
= len
;
1207 bzf
->strm
.next_out
= buf
;
1211 if (ferror(bzf
->handle
))
1212 { BZ_SETERR(BZ_IO_ERROR
); return 0; };
1214 if (bzf
->strm
.avail_in
== 0 && !myfeof(bzf
->handle
)) {
1215 n
= fread ( bzf
->buf
, sizeof(UChar
),
1216 BZ_MAX_UNUSED
, bzf
->handle
);
1217 if (ferror(bzf
->handle
))
1218 { BZ_SETERR(BZ_IO_ERROR
); return 0; };
1220 bzf
->strm
.avail_in
= bzf
->bufN
;
1221 bzf
->strm
.next_in
= bzf
->buf
;
1224 ret
= BZ2_bzDecompress ( &(bzf
->strm
) );
1226 if (ret
!= BZ_OK
&& ret
!= BZ_STREAM_END
)
1227 { BZ_SETERR(ret
); return 0; };
1229 if (ret
== BZ_OK
&& myfeof(bzf
->handle
) &&
1230 bzf
->strm
.avail_in
== 0 && bzf
->strm
.avail_out
> 0)
1231 { BZ_SETERR(BZ_UNEXPECTED_EOF
); return 0; };
1233 if (ret
== BZ_STREAM_END
)
1234 { BZ_SETERR(BZ_STREAM_END
);
1235 return len
- bzf
->strm
.avail_out
; };
1236 if (bzf
->strm
.avail_out
== 0)
1237 { BZ_SETERR(BZ_OK
); return len
; };
1241 return 0; /*not reached*/
1245 /*---------------------------------------------------*/
1246 void BZ_API(BZ2_bzReadGetUnused
)
1252 bzFile
* bzf
= (bzFile
*)b
;
1254 { BZ_SETERR(BZ_PARAM_ERROR
); return; };
1255 if (bzf
->lastErr
!= BZ_STREAM_END
)
1256 { BZ_SETERR(BZ_SEQUENCE_ERROR
); return; };
1257 if (unused
== NULL
|| nUnused
== NULL
)
1258 { BZ_SETERR(BZ_PARAM_ERROR
); return; };
1261 *nUnused
= bzf
->strm
.avail_in
;
1262 *unused
= bzf
->strm
.next_in
;
1267 /*---------------------------------------------------*/
1268 /*--- Misc convenience stuff ---*/
1269 /*---------------------------------------------------*/
1271 /*---------------------------------------------------*/
1272 int BZ_API(BZ2_bzBuffToBuffCompress
)
1274 unsigned int* destLen
,
1276 unsigned int sourceLen
,
1284 if (dest
== NULL
|| destLen
== NULL
||
1286 blockSize100k
< 1 || blockSize100k
> 9 ||
1287 verbosity
< 0 || verbosity
> 4 ||
1288 workFactor
< 0 || workFactor
> 250)
1289 return BZ_PARAM_ERROR
;
1291 if (workFactor
== 0) workFactor
= 30;
1292 strm
.bzalloc
= NULL
;
1295 ret
= BZ2_bzCompressInit ( &strm
, blockSize100k
,
1296 verbosity
, workFactor
);
1297 if (ret
!= BZ_OK
) return ret
;
1299 strm
.next_in
= source
;
1300 strm
.next_out
= dest
;
1301 strm
.avail_in
= sourceLen
;
1302 strm
.avail_out
= *destLen
;
1304 ret
= BZ2_bzCompress ( &strm
, BZ_FINISH
);
1305 if (ret
== BZ_FINISH_OK
) goto output_overflow
;
1306 if (ret
!= BZ_STREAM_END
) goto errhandler
;
1308 /* normal termination */
1309 *destLen
-= strm
.avail_out
;
1310 BZ2_bzCompressEnd ( &strm
);
1314 BZ2_bzCompressEnd ( &strm
);
1315 return BZ_OUTBUFF_FULL
;
1318 BZ2_bzCompressEnd ( &strm
);
1323 /*---------------------------------------------------*/
1324 int BZ_API(BZ2_bzBuffToBuffDecompress
)
1326 unsigned int* destLen
,
1328 unsigned int sourceLen
,
1335 if (dest
== NULL
|| destLen
== NULL
||
1337 (small
!= 0 && small
!= 1) ||
1338 verbosity
< 0 || verbosity
> 4)
1339 return BZ_PARAM_ERROR
;
1341 strm
.bzalloc
= NULL
;
1344 ret
= BZ2_bzDecompressInit ( &strm
, verbosity
, small
);
1345 if (ret
!= BZ_OK
) return ret
;
1347 strm
.next_in
= source
;
1348 strm
.next_out
= dest
;
1349 strm
.avail_in
= sourceLen
;
1350 strm
.avail_out
= *destLen
;
1352 ret
= BZ2_bzDecompress ( &strm
);
1353 if (ret
== BZ_OK
) goto output_overflow_or_eof
;
1354 if (ret
!= BZ_STREAM_END
) goto errhandler
;
1356 /* normal termination */
1357 *destLen
-= strm
.avail_out
;
1358 BZ2_bzDecompressEnd ( &strm
);
1361 output_overflow_or_eof
:
1362 if (strm
.avail_out
> 0) {
1363 BZ2_bzDecompressEnd ( &strm
);
1364 return BZ_UNEXPECTED_EOF
;
1366 BZ2_bzDecompressEnd ( &strm
);
1367 return BZ_OUTBUFF_FULL
;
1371 BZ2_bzDecompressEnd ( &strm
);
1376 /*---------------------------------------------------*/
1378 Code contributed by Yoshioka Tsuneo
1379 (QWF00133@niftyserve.or.jp/tsuneo-y@is.aist-nara.ac.jp),
1380 to support better zlib compatibility.
1381 This code is not _officially_ part of libbzip2 (yet);
1382 I haven't tested it, documented it, or considered the
1383 threading-safeness of it.
1384 If this code breaks, please contact both Yoshioka and me.
1386 /*---------------------------------------------------*/
1388 /*---------------------------------------------------*/
1390 return version like "0.9.0c".
1392 const char * BZ_API(BZ2_bzlibVersion
)(void)
1399 /*---------------------------------------------------*/
1401 #if defined(_WIN32) || defined(OS2) || defined(MSDOS)
1404 # define SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY)
1406 # define SET_BINARY_MODE(file)
1409 BZFILE
* bzopen_or_bzdopen
1410 ( const char *path
, /* no use when bzdopen */
1411 int fd
, /* no use when bzdopen */
1413 int open_mode
) /* bzopen: 0, bzdopen:1 */
1416 char unused
[BZ_MAX_UNUSED
];
1417 int blockSize100k
= 9;
1419 char mode2
[10] = "";
1421 BZFILE
*bzfp
= NULL
;
1423 int workFactor
= 30;
1427 if (mode
== NULL
) return NULL
;
1435 smallMode
= 1; break;
1437 if (isdigit((int)(*mode
))) {
1438 blockSize100k
= *mode
-BZ_HDR_0
;
1443 strcat(mode2
, writing
? "w" : "r" );
1444 strcat(mode2
,"b"); /* binary mode */
1447 if (path
==NULL
|| strcmp(path
,"")==0) {
1448 fp
= (writing
? stdout
: stdin
);
1449 SET_BINARY_MODE(fp
);
1451 fp
= fopen(path
,mode2
);
1454 #ifdef BZ_STRICT_ANSI
1457 fp
= fdopen(fd
,mode2
);
1460 if (fp
== NULL
) return NULL
;
1463 /* Guard against total chaos and anarchy -- JRS */
1464 if (blockSize100k
< 1) blockSize100k
= 1;
1465 if (blockSize100k
> 9) blockSize100k
= 9;
1466 bzfp
= BZ2_bzWriteOpen(&bzerr
,fp
,blockSize100k
,
1467 verbosity
,workFactor
);
1469 bzfp
= BZ2_bzReadOpen(&bzerr
,fp
,verbosity
,smallMode
,
1473 if (fp
!= stdin
&& fp
!= stdout
) fclose(fp
);
1480 /*---------------------------------------------------*/
1482 open file for read or write.
1483 ex) bzopen("file","w9")
1484 case path="" or NULL => use stdin or stdout.
1486 BZFILE
* BZ_API(BZ2_bzopen
)
1490 return bzopen_or_bzdopen(path
,-1,mode
,/*bzopen*/0);
1494 /*---------------------------------------------------*/
1495 BZFILE
* BZ_API(BZ2_bzdopen
)
1499 return bzopen_or_bzdopen(NULL
,fd
,mode
,/*bzdopen*/1);
1503 /*---------------------------------------------------*/
1504 int BZ_API(BZ2_bzread
) (BZFILE
* b
, void* buf
, int len
)
1507 if (((bzFile
*)b
)->lastErr
== BZ_STREAM_END
) return 0;
1508 nread
= BZ2_bzRead(&bzerr
,b
,buf
,len
);
1509 if (bzerr
== BZ_OK
|| bzerr
== BZ_STREAM_END
) {
1517 /*---------------------------------------------------*/
1518 int BZ_API(BZ2_bzwrite
) (BZFILE
* b
, void* buf
, int len
)
1522 BZ2_bzWrite(&bzerr
,b
,buf
,len
);
1531 /*---------------------------------------------------*/
1532 int BZ_API(BZ2_bzflush
) (BZFILE
*b
)
1534 /* do nothing now... */
1539 /*---------------------------------------------------*/
1540 void BZ_API(BZ2_bzclose
) (BZFILE
* b
)
1543 FILE *fp
= ((bzFile
*)b
)->handle
;
1545 if (b
==NULL
) {return;}
1546 if(((bzFile
*)b
)->writing
){
1547 BZ2_bzWriteClose(&bzerr
,b
,0,NULL
,NULL
);
1549 BZ2_bzWriteClose(NULL
,b
,1,NULL
,NULL
);
1552 BZ2_bzReadClose(&bzerr
,b
);
1554 if(fp
!=stdin
&& fp
!=stdout
){
1560 /*---------------------------------------------------*/
1562 return last error code
1564 static const char *bzerrorstrings
[] = {
1575 ,"???" /* for future */
1576 ,"???" /* for future */
1577 ,"???" /* for future */
1578 ,"???" /* for future */
1579 ,"???" /* for future */
1580 ,"???" /* for future */
1584 const char * BZ_API(BZ2_bzerror
) (BZFILE
*b
, int *errnum
)
1586 int err
= ((bzFile
*)b
)->lastErr
;
1590 return bzerrorstrings
[err
*-1];
1595 /*-------------------------------------------------------------*/
1596 /*--- end bzlib.c ---*/
1597 /*-------------------------------------------------------------*/