@@ -394,33 +394,38 @@ pub unsafe fn compress_c(
394394 bzfree : None ,
395395 opaque : std:: ptr:: null_mut :: < libc:: c_void > ( ) ,
396396 } ;
397- let mut ret: libc:: c_int ;
398397 if dest. is_null ( ) || dest_len. is_null ( ) || source. is_null ( ) {
399398 return -2 as libc:: c_int ;
400399 }
401400 strm. bzalloc = None ;
402401 strm. bzfree = None ;
403402 strm. opaque = std:: ptr:: null_mut :: < libc:: c_void > ( ) ;
404403 unsafe {
405- ret = BZ2_bzCompressInit ( & mut strm, blockSize100k, 0 , 30 ) ;
404+ let ret = BZ2_bzCompressInit ( & mut strm, blockSize100k, 0 , 30 ) ;
406405 if ret != 0 as libc:: c_int {
407406 return ret;
408407 }
409408 strm. next_in = source as * mut libc:: c_char ;
410409 strm. next_out = dest. cast :: < core:: ffi:: c_char > ( ) ;
411410 strm. avail_in = source_len;
412411 strm. avail_out = * dest_len;
413- ret = BZ2_bzCompress ( & mut strm, 2 as libc:: c_int ) ;
414- if ret == 3 as libc:: c_int {
415- BZ2_bzCompressEnd ( & mut strm) ;
416- -8 as libc:: c_int
417- } else if ret != 4 as libc:: c_int {
418- BZ2_bzCompressEnd ( & mut strm) ;
419- return ret;
420- } else {
421- * dest_len = ( * dest_len) . wrapping_sub ( strm. avail_out ) ;
422- BZ2_bzCompressEnd ( & mut strm) ;
423- return 0 as libc:: c_int ;
412+ match BZ2_bzCompress ( & mut strm, 2 ) {
413+ BZ_FINISH_OK => {
414+ BZ2_bzCompressEnd ( & mut strm) ;
415+
416+ BZ_OUTBUFF_FULL
417+ }
418+ BZ_STREAM_END => {
419+ * dest_len = ( * dest_len) . wrapping_sub ( strm. avail_out ) ;
420+ BZ2_bzCompressEnd ( & mut strm) ;
421+
422+ BZ_OK
423+ }
424+ ret => {
425+ BZ2_bzCompressEnd ( & mut strm) ;
426+
427+ ret
428+ }
424429 }
425430 }
426431}
@@ -448,33 +453,38 @@ pub unsafe fn compress_rs(
448453 bzfree : None ,
449454 opaque : std:: ptr:: null_mut :: < libc:: c_void > ( ) ,
450455 } ;
451- let mut ret: libc:: c_int ;
452456 if dest. is_null ( ) || dest_len. is_null ( ) || source. is_null ( ) {
453457 return -2 as libc:: c_int ;
454458 }
455459 strm. bzalloc = None ;
456460 strm. bzfree = None ;
457461 strm. opaque = std:: ptr:: null_mut :: < libc:: c_void > ( ) ;
458462 unsafe {
459- ret = BZ2_bzCompressInit ( & mut strm, blockSize100k, 0 , 30 ) ;
463+ let ret = BZ2_bzCompressInit ( & mut strm, blockSize100k, 0 , 30 ) ;
460464 if ret != 0 as libc:: c_int {
461465 return ret;
462466 }
463467 strm. next_in = source as * mut libc:: c_char ;
464468 strm. next_out = dest. cast :: < core:: ffi:: c_char > ( ) ;
465469 strm. avail_in = source_len;
466470 strm. avail_out = * dest_len;
467- ret = BZ2_bzCompress ( & mut strm, 2 as libc:: c_int ) ;
468- if ret == 3 as libc:: c_int {
469- BZ2_bzCompressEnd ( & mut strm) ;
470- -8 as libc:: c_int
471- } else if ret != 4 as libc:: c_int {
472- BZ2_bzCompressEnd ( & mut strm) ;
473- return ret;
474- } else {
475- * dest_len = ( * dest_len) . wrapping_sub ( strm. avail_out ) ;
476- BZ2_bzCompressEnd ( & mut strm) ;
477- return 0 as libc:: c_int ;
471+ match BZ2_bzCompress ( & mut strm, 2 ) {
472+ BZ_FINISH_OK => {
473+ BZ2_bzCompressEnd ( & mut strm) ;
474+
475+ BZ_OUTBUFF_FULL
476+ }
477+ BZ_STREAM_END => {
478+ * dest_len = ( * dest_len) . wrapping_sub ( strm. avail_out ) ;
479+ BZ2_bzCompressEnd ( & mut strm) ;
480+
481+ BZ_OK
482+ }
483+ ret => {
484+ BZ2_bzCompressEnd ( & mut strm) ;
485+
486+ ret
487+ }
478488 }
479489 }
480490}
0 commit comments