"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lzlib.c" between
lzlib-1.11.tar.lz and lzlib-1.12-rc1.tar.lz

About: Lzlib is a data compression library providing in-memory LZMA compression and decompression functions using the lzip format. Release candidate.

lzlib.c  (lzlib-1.11.tar.lz):lzlib.c  (lzlib-1.12-rc1.tar.lz)
/* Lzlib - Compression library for the lzip format /* Lzlib - Compression library for the lzip format
Copyright (C) 2009-2019 Antonio Diaz Diaz. Copyright (C) 2009-2020 Antonio Diaz Diaz.
This library is free software. Redistribution and use in source and This library is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided binary forms, with or without modification, are permitted provided
that the following conditions are met: that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions, and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/ */
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "lzlib.h" #include "lzlib.h"
#include "lzip.h" #include "lzip.h"
#include "cbuffer.c" #include "cbuffer.c"
skipping to change at line 103 skipping to change at line 103
} }
static bool verify_decoder( struct LZ_Decoder * const d ) static bool verify_decoder( struct LZ_Decoder * const d )
{ {
if( !d ) return false; if( !d ) return false;
if( !d->rdec ) if( !d->rdec )
{ d->lz_errno = LZ_bad_argument; return false; } { d->lz_errno = LZ_bad_argument; return false; }
return true; return true;
} }
/*------------------------- Misc Functions -------------------------*/ /* ------------------------- Misc Functions ------------------------- */
int LZ_api_version( void ) { return LZ_API_VERSION; }
const char * LZ_version( void ) { return LZ_version_string; } const char * LZ_version( void ) { return LZ_version_string; }
const char * LZ_strerror( const enum LZ_Errno lz_errno ) const char * LZ_strerror( const enum LZ_Errno lz_errno )
{ {
switch( lz_errno ) switch( lz_errno )
{ {
case LZ_ok : return "ok"; case LZ_ok : return "ok";
case LZ_bad_argument : return "Bad argument"; case LZ_bad_argument : return "Bad argument";
case LZ_mem_error : return "Not enough memory"; case LZ_mem_error : return "Not enough memory";
skipping to change at line 130 skipping to change at line 132
return "Invalid error code"; return "Invalid error code";
} }
int LZ_min_dictionary_bits( void ) { return min_dictionary_bits; } int LZ_min_dictionary_bits( void ) { return min_dictionary_bits; }
int LZ_min_dictionary_size( void ) { return min_dictionary_size; } int LZ_min_dictionary_size( void ) { return min_dictionary_size; }
int LZ_max_dictionary_bits( void ) { return max_dictionary_bits; } int LZ_max_dictionary_bits( void ) { return max_dictionary_bits; }
int LZ_max_dictionary_size( void ) { return max_dictionary_size; } int LZ_max_dictionary_size( void ) { return max_dictionary_size; }
int LZ_min_match_len_limit( void ) { return min_match_len_limit; } int LZ_min_match_len_limit( void ) { return min_match_len_limit; }
int LZ_max_match_len_limit( void ) { return max_match_len; } int LZ_max_match_len_limit( void ) { return max_match_len; }
/*---------------------- Compression Functions ----------------------*/ /* --------------------- Compression Functions --------------------- */
struct LZ_Encoder * LZ_compress_open( const int dictionary_size, struct LZ_Encoder * LZ_compress_open( const int dictionary_size,
const int match_len_limit, const int match_len_limit,
const unsigned long long member_size ) const unsigned long long member_size )
{ {
Lzip_header header; Lzip_header header;
struct LZ_Encoder * const e = struct LZ_Encoder * const e =
(struct LZ_Encoder *)malloc( sizeof (struct LZ_Encoder) ); (struct LZ_Encoder *)malloc( sizeof (struct LZ_Encoder) );
if( !e ) return 0; if( !e ) return 0;
LZ_Encoder_init( e ); LZ_Encoder_init( e );
skipping to change at line 217 skipping to change at line 219
if( e->lz_encoder ) LZe_reset( e->lz_encoder, member_size ); if( e->lz_encoder ) LZe_reset( e->lz_encoder, member_size );
else FLZe_reset( e->flz_encoder, member_size ); else FLZe_reset( e->flz_encoder, member_size );
e->lz_errno = LZ_ok; e->lz_errno = LZ_ok;
return 0; return 0;
} }
int LZ_compress_sync_flush( struct LZ_Encoder * const e ) int LZ_compress_sync_flush( struct LZ_Encoder * const e )
{ {
if( !verify_encoder( e ) || e->fatal ) return -1; if( !verify_encoder( e ) || e->fatal ) return -1;
if( !Mb_flushing_or_end( &e->lz_encoder_base->mb ) ) if( !e->lz_encoder_base->mb.at_stream_end )
e->lz_encoder_base->mb.flushing = true; e->lz_encoder_base->mb.sync_flush_pending = true;
return 0; return 0;
} }
int LZ_compress_read( struct LZ_Encoder * const e, int LZ_compress_read( struct LZ_Encoder * const e,
uint8_t * const buffer, const int size ) uint8_t * const buffer, const int size )
{ {
int out_size = 0;
if( !verify_encoder( e ) || e->fatal ) return -1; if( !verify_encoder( e ) || e->fatal ) return -1;
if( size < 0 ) return 0; if( size < 0 ) return 0;
do {
{ struct LZ_encoder_base * const eb = e->lz_encoder_base;
int out_size = Re_read_data( &eb->renc, buffer, size );
/* minimize number of calls to encode_member */
if( out_size < size || size == 0 )
{
if( ( e->flz_encoder && !FLZe_encode_member( e->flz_encoder ) ) || if( ( e->flz_encoder && !FLZe_encode_member( e->flz_encoder ) ) ||
( e->lz_encoder && !LZe_encode_member( e->lz_encoder ) ) ) ( e->lz_encoder && !LZe_encode_member( e->lz_encoder ) ) )
{ e->lz_errno = LZ_library_error; e->fatal = true; return -1; } { e->lz_errno = LZ_library_error; e->fatal = true; return -1; }
if( e->lz_encoder_base->mb.flushing && if( eb->mb.sync_flush_pending && Mb_available_bytes( &eb->mb ) <= 0 )
Mb_available_bytes( &e->lz_encoder_base->mb ) <= 0 && LZeb_try_sync_flush( eb );
LZeb_sync_flush( e->lz_encoder_base ) ) out_size += Re_read_data( &eb->renc, buffer + out_size, size - out_size );
e->lz_encoder_base->mb.flushing = false;
out_size += Re_read_data( &e->lz_encoder_base->renc,
buffer + out_size, size - out_size );
} }
while( e->lz_encoder_base->mb.flushing && out_size < size && return out_size; }
Mb_enough_available_bytes( &e->lz_encoder_base->mb ) &&
Re_enough_free_bytes( &e->lz_encoder_base->renc ) );
return out_size;
} }
int LZ_compress_write( struct LZ_Encoder * const e, int LZ_compress_write( struct LZ_Encoder * const e,
const uint8_t * const buffer, const int size ) const uint8_t * const buffer, const int size )
{ {
if( !verify_encoder( e ) || e->fatal ) return -1; if( !verify_encoder( e ) || e->fatal ) return -1;
return Mb_write_data( &e->lz_encoder_base->mb, buffer, size ); return Mb_write_data( &e->lz_encoder_base->mb, buffer, size );
} }
int LZ_compress_write_size( struct LZ_Encoder * const e ) int LZ_compress_write_size( struct LZ_Encoder * const e )
skipping to change at line 301 skipping to change at line 301
if( !verify_encoder( e ) ) return 0; if( !verify_encoder( e ) ) return 0;
return e->partial_in_size + Mb_data_position( &e->lz_encoder_base->mb ); return e->partial_in_size + Mb_data_position( &e->lz_encoder_base->mb );
} }
unsigned long long LZ_compress_total_out_size( struct LZ_Encoder * const e ) unsigned long long LZ_compress_total_out_size( struct LZ_Encoder * const e )
{ {
if( !verify_encoder( e ) ) return 0; if( !verify_encoder( e ) ) return 0;
return e->partial_out_size + Re_member_position( &e->lz_encoder_base->renc ); return e->partial_out_size + Re_member_position( &e->lz_encoder_base->renc );
} }
/*--------------------- Decompression Functions ---------------------*/ /* -------------------- Decompression Functions -------------------- */
struct LZ_Decoder * LZ_decompress_open( void ) struct LZ_Decoder * LZ_decompress_open( void )
{ {
struct LZ_Decoder * const d = struct LZ_Decoder * const d =
(struct LZ_Decoder *)malloc( sizeof (struct LZ_Decoder) ); (struct LZ_Decoder *)malloc( sizeof (struct LZ_Decoder) );
if( !d ) return 0; if( !d ) return 0;
LZ_Decoder_init( d ); LZ_Decoder_init( d );
d->rdec = (struct Range_decoder *)malloc( sizeof (struct Range_decoder) ); d->rdec = (struct Range_decoder *)malloc( sizeof (struct Range_decoder) );
if( !d->rdec || !Rd_init( d->rdec ) ) if( !d->rdec || !Rd_init( d->rdec ) )
skipping to change at line 376 skipping to change at line 376
d->lz_errno = LZ_ok; d->lz_errno = LZ_ok;
d->fatal = false; d->fatal = false;
return 0; return 0;
} }
int LZ_decompress_read( struct LZ_Decoder * const d, int LZ_decompress_read( struct LZ_Decoder * const d,
uint8_t * const buffer, const int size ) uint8_t * const buffer, const int size )
{ {
int result; int result;
if( !verify_decoder( d ) ) return -1; if( !verify_decoder( d ) ) return -1;
if( size < 0 ) return 0;
if( d->fatal ) /* don't return error until pending bytes are read */ if( d->fatal ) /* don't return error until pending bytes are read */
{ if( d->lz_decoder && !Cb_empty( &d->lz_decoder->cb ) ) goto get_data; { if( d->lz_decoder && !Cb_empty( &d->lz_decoder->cb ) ) goto get_data;
return -1; } return -1; }
if( d->seeking || size < 0 ) return 0; if( d->seeking ) return 0;
if( d->lz_decoder && LZd_member_finished( d->lz_decoder ) ) if( d->lz_decoder && LZd_member_finished( d->lz_decoder ) )
{ {
d->partial_out_size += LZd_data_position( d->lz_decoder ); d->partial_out_size += LZd_data_position( d->lz_decoder );
LZd_free( d->lz_decoder ); free( d->lz_decoder ); d->lz_decoder = 0; LZd_free( d->lz_decoder ); free( d->lz_decoder ); d->lz_decoder = 0;
} }
if( !d->lz_decoder ) if( !d->lz_decoder )
{ {
int rd; int rd;
d->partial_in_size += d->rdec->member_position; d->partial_in_size += d->rdec->member_position;
 End of changes. 12 change blocks. 
34 lines changed or deleted 35 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)