Merging upstream version 1.15~rc1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
5fdbdd44aa
commit
ae3eafc693
27 changed files with 724 additions and 791 deletions
110
lzlib.c
110
lzlib.c
|
@ -39,14 +39,14 @@ struct LZ_Encoder
|
|||
{
|
||||
unsigned long long partial_in_size;
|
||||
unsigned long long partial_out_size;
|
||||
struct LZ_encoder_base * lz_encoder_base; /* these 3 pointers make a */
|
||||
struct LZ_encoder * lz_encoder; /* polymorphic encoder */
|
||||
struct FLZ_encoder * flz_encoder;
|
||||
enum LZ_Errno lz_errno;
|
||||
LZ_encoder_base * lz_encoder_base; /* these 3 pointers make a */
|
||||
LZ_encoder * lz_encoder; /* polymorphic encoder */
|
||||
FLZ_encoder * flz_encoder;
|
||||
LZ_Errno lz_errno;
|
||||
bool fatal;
|
||||
};
|
||||
|
||||
static void LZ_Encoder_init( struct LZ_Encoder * const e )
|
||||
static void LZ_Encoder_init( LZ_Encoder * const e )
|
||||
{
|
||||
e->partial_in_size = 0;
|
||||
e->partial_out_size = 0;
|
||||
|
@ -62,16 +62,16 @@ struct LZ_Decoder
|
|||
{
|
||||
unsigned long long partial_in_size;
|
||||
unsigned long long partial_out_size;
|
||||
struct Range_decoder * rdec;
|
||||
struct LZ_decoder * lz_decoder;
|
||||
enum LZ_Errno lz_errno;
|
||||
Range_decoder * rdec;
|
||||
LZ_decoder * lz_decoder;
|
||||
LZ_Errno lz_errno;
|
||||
Lzip_header member_header; /* header of current member */
|
||||
bool fatal;
|
||||
bool first_header; /* true until first header is read */
|
||||
bool seeking;
|
||||
};
|
||||
|
||||
static void LZ_Decoder_init( struct LZ_Decoder * const d )
|
||||
static void LZ_Decoder_init( LZ_Decoder * const d )
|
||||
{
|
||||
int i;
|
||||
d->partial_in_size = 0;
|
||||
|
@ -86,7 +86,7 @@ static void LZ_Decoder_init( struct LZ_Decoder * const d )
|
|||
}
|
||||
|
||||
|
||||
static bool check_encoder( struct LZ_Encoder * const e )
|
||||
static bool check_encoder( LZ_Encoder * const e )
|
||||
{
|
||||
if( !e ) return false;
|
||||
if( !e->lz_encoder_base || ( !e->lz_encoder && !e->flz_encoder ) ||
|
||||
|
@ -96,7 +96,7 @@ static bool check_encoder( struct LZ_Encoder * const e )
|
|||
}
|
||||
|
||||
|
||||
static bool check_decoder( struct LZ_Decoder * const d )
|
||||
static bool check_decoder( LZ_Decoder * const d )
|
||||
{
|
||||
if( !d ) return false;
|
||||
if( !d->rdec )
|
||||
|
@ -111,7 +111,7 @@ int LZ_api_version( void ) { return LZ_API_VERSION; }
|
|||
|
||||
const char * LZ_version( void ) { return LZ_version_string; }
|
||||
|
||||
const char * LZ_strerror( const enum LZ_Errno lz_errno )
|
||||
const char * LZ_strerror( const LZ_Errno lz_errno )
|
||||
{
|
||||
switch( lz_errno )
|
||||
{
|
||||
|
@ -138,13 +138,12 @@ int LZ_max_match_len_limit( void ) { return max_match_len; }
|
|||
|
||||
/* --------------------- Compression Functions --------------------- */
|
||||
|
||||
struct LZ_Encoder * LZ_compress_open( const int dictionary_size,
|
||||
const int match_len_limit,
|
||||
const unsigned long long member_size )
|
||||
LZ_Encoder * LZ_compress_open( const int dictionary_size,
|
||||
const int match_len_limit,
|
||||
const unsigned long long member_size )
|
||||
{
|
||||
Lzip_header header;
|
||||
struct LZ_Encoder * const e =
|
||||
(struct LZ_Encoder *)malloc( sizeof (struct LZ_Encoder) );
|
||||
LZ_Encoder * const e = (LZ_Encoder *)malloc( sizeof (LZ_Encoder) );
|
||||
if( !e ) return 0;
|
||||
LZ_Encoder_init( e );
|
||||
if( !Lh_set_dictionary_size( header, dictionary_size ) ||
|
||||
|
@ -156,14 +155,14 @@ struct LZ_Encoder * LZ_compress_open( const int dictionary_size,
|
|||
{
|
||||
if( dictionary_size == 65535 && match_len_limit == 16 )
|
||||
{
|
||||
e->flz_encoder = (struct FLZ_encoder *)malloc( sizeof (struct FLZ_encoder) );
|
||||
e->flz_encoder = (FLZ_encoder *)malloc( sizeof (FLZ_encoder) );
|
||||
if( e->flz_encoder && FLZe_init( e->flz_encoder, member_size ) )
|
||||
{ e->lz_encoder_base = &e->flz_encoder->eb; return e; }
|
||||
free( e->flz_encoder ); e->flz_encoder = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
e->lz_encoder = (struct LZ_encoder *)malloc( sizeof (struct LZ_encoder) );
|
||||
e->lz_encoder = (LZ_encoder *)malloc( sizeof (LZ_encoder) );
|
||||
if( e->lz_encoder && LZe_init( e->lz_encoder, Lh_get_dictionary_size( header ),
|
||||
match_len_limit, member_size ) )
|
||||
{ e->lz_encoder_base = &e->lz_encoder->eb; return e; }
|
||||
|
@ -176,7 +175,7 @@ struct LZ_Encoder * LZ_compress_open( const int dictionary_size,
|
|||
}
|
||||
|
||||
|
||||
int LZ_compress_close( struct LZ_Encoder * const e )
|
||||
int LZ_compress_close( LZ_Encoder * const e )
|
||||
{
|
||||
if( !e ) return -1;
|
||||
if( e->lz_encoder_base )
|
||||
|
@ -187,7 +186,7 @@ int LZ_compress_close( struct LZ_Encoder * const e )
|
|||
}
|
||||
|
||||
|
||||
int LZ_compress_finish( struct LZ_Encoder * const e )
|
||||
int LZ_compress_finish( LZ_Encoder * const e )
|
||||
{
|
||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||
Mb_finish( &e->lz_encoder_base->mb );
|
||||
|
@ -205,7 +204,7 @@ int LZ_compress_finish( struct LZ_Encoder * const e )
|
|||
}
|
||||
|
||||
|
||||
int LZ_compress_restart_member( struct LZ_Encoder * const e,
|
||||
int LZ_compress_restart_member( LZ_Encoder * const e,
|
||||
const unsigned long long member_size )
|
||||
{
|
||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||
|
@ -224,7 +223,7 @@ int LZ_compress_restart_member( struct LZ_Encoder * const e,
|
|||
}
|
||||
|
||||
|
||||
int LZ_compress_sync_flush( struct LZ_Encoder * const e )
|
||||
int LZ_compress_sync_flush( LZ_Encoder * const e )
|
||||
{
|
||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||
if( !e->lz_encoder_base->mb.at_stream_end )
|
||||
|
@ -233,13 +232,13 @@ int LZ_compress_sync_flush( struct LZ_Encoder * const e )
|
|||
}
|
||||
|
||||
|
||||
int LZ_compress_read( struct LZ_Encoder * const e,
|
||||
int LZ_compress_read( LZ_Encoder * const e,
|
||||
uint8_t * const buffer, const int size )
|
||||
{
|
||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||
if( size < 0 ) return 0;
|
||||
|
||||
{ struct LZ_encoder_base * const eb = e->lz_encoder_base;
|
||||
{ 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 )
|
||||
|
@ -255,7 +254,7 @@ int LZ_compress_read( struct LZ_Encoder * const e,
|
|||
}
|
||||
|
||||
|
||||
int LZ_compress_write( struct LZ_Encoder * const e,
|
||||
int LZ_compress_write( LZ_Encoder * const e,
|
||||
const uint8_t * const buffer, const int size )
|
||||
{
|
||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||
|
@ -263,21 +262,21 @@ int LZ_compress_write( struct LZ_Encoder * const e,
|
|||
}
|
||||
|
||||
|
||||
int LZ_compress_write_size( struct LZ_Encoder * const e )
|
||||
int LZ_compress_write_size( LZ_Encoder * const e )
|
||||
{
|
||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||
return Mb_free_bytes( &e->lz_encoder_base->mb );
|
||||
}
|
||||
|
||||
|
||||
enum LZ_Errno LZ_compress_errno( struct LZ_Encoder * const e )
|
||||
LZ_Errno LZ_compress_errno( LZ_Encoder * const e )
|
||||
{
|
||||
if( !e ) return LZ_bad_argument;
|
||||
return e->lz_errno;
|
||||
}
|
||||
|
||||
|
||||
int LZ_compress_finished( struct LZ_Encoder * const e )
|
||||
int LZ_compress_finished( LZ_Encoder * const e )
|
||||
{
|
||||
if( !check_encoder( e ) ) return -1;
|
||||
return Mb_data_finished( &e->lz_encoder_base->mb ) &&
|
||||
|
@ -285,35 +284,35 @@ int LZ_compress_finished( struct LZ_Encoder * const e )
|
|||
}
|
||||
|
||||
|
||||
int LZ_compress_member_finished( struct LZ_Encoder * const e )
|
||||
int LZ_compress_member_finished( LZ_Encoder * const e )
|
||||
{
|
||||
if( !check_encoder( e ) ) return -1;
|
||||
return LZeb_member_finished( e->lz_encoder_base );
|
||||
}
|
||||
|
||||
|
||||
unsigned long long LZ_compress_data_position( struct LZ_Encoder * const e )
|
||||
unsigned long long LZ_compress_data_position( LZ_Encoder * const e )
|
||||
{
|
||||
if( !check_encoder( e ) ) return 0;
|
||||
return Mb_data_position( &e->lz_encoder_base->mb );
|
||||
}
|
||||
|
||||
|
||||
unsigned long long LZ_compress_member_position( struct LZ_Encoder * const e )
|
||||
unsigned long long LZ_compress_member_position( LZ_Encoder * const e )
|
||||
{
|
||||
if( !check_encoder( e ) ) return 0;
|
||||
return Re_member_position( &e->lz_encoder_base->renc );
|
||||
}
|
||||
|
||||
|
||||
unsigned long long LZ_compress_total_in_size( struct LZ_Encoder * const e )
|
||||
unsigned long long LZ_compress_total_in_size( LZ_Encoder * const e )
|
||||
{
|
||||
if( !check_encoder( e ) ) return 0;
|
||||
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( LZ_Encoder * const e )
|
||||
{
|
||||
if( !check_encoder( e ) ) return 0;
|
||||
return e->partial_out_size + Re_member_position( &e->lz_encoder_base->renc );
|
||||
|
@ -322,14 +321,13 @@ unsigned long long LZ_compress_total_out_size( struct LZ_Encoder * const e )
|
|||
|
||||
/* -------------------- Decompression Functions -------------------- */
|
||||
|
||||
struct LZ_Decoder * LZ_decompress_open( void )
|
||||
LZ_Decoder * LZ_decompress_open( void )
|
||||
{
|
||||
struct LZ_Decoder * const d =
|
||||
(struct LZ_Decoder *)malloc( sizeof (struct LZ_Decoder) );
|
||||
LZ_Decoder * const d = (LZ_Decoder *)malloc( sizeof (LZ_Decoder) );
|
||||
if( !d ) return 0;
|
||||
LZ_Decoder_init( d );
|
||||
|
||||
d->rdec = (struct Range_decoder *)malloc( sizeof (struct Range_decoder) );
|
||||
d->rdec = (Range_decoder *)malloc( sizeof (Range_decoder) );
|
||||
if( !d->rdec || !Rd_init( d->rdec ) )
|
||||
{
|
||||
if( d->rdec ) { Rd_free( d->rdec ); free( d->rdec ); d->rdec = 0; }
|
||||
|
@ -339,7 +337,7 @@ struct LZ_Decoder * LZ_decompress_open( void )
|
|||
}
|
||||
|
||||
|
||||
int LZ_decompress_close( struct LZ_Decoder * const d )
|
||||
int LZ_decompress_close( LZ_Decoder * const d )
|
||||
{
|
||||
if( !d ) return -1;
|
||||
if( d->lz_decoder )
|
||||
|
@ -350,7 +348,7 @@ int LZ_decompress_close( struct LZ_Decoder * const d )
|
|||
}
|
||||
|
||||
|
||||
int LZ_decompress_finish( struct LZ_Decoder * const d )
|
||||
int LZ_decompress_finish( LZ_Decoder * const d )
|
||||
{
|
||||
if( !check_decoder( d ) || d->fatal ) return -1;
|
||||
if( d->seeking )
|
||||
|
@ -360,7 +358,7 @@ int LZ_decompress_finish( struct LZ_Decoder * const d )
|
|||
}
|
||||
|
||||
|
||||
int LZ_decompress_reset( struct LZ_Decoder * const d )
|
||||
int LZ_decompress_reset( LZ_Decoder * const d )
|
||||
{
|
||||
if( !check_decoder( d ) ) return -1;
|
||||
if( d->lz_decoder )
|
||||
|
@ -376,7 +374,7 @@ int LZ_decompress_reset( struct LZ_Decoder * const d )
|
|||
}
|
||||
|
||||
|
||||
int LZ_decompress_sync_to_member( struct LZ_Decoder * const d )
|
||||
int LZ_decompress_sync_to_member( LZ_Decoder * const d )
|
||||
{
|
||||
unsigned skipped = 0;
|
||||
if( !check_decoder( d ) ) return -1;
|
||||
|
@ -395,7 +393,7 @@ int LZ_decompress_sync_to_member( struct LZ_Decoder * const d )
|
|||
}
|
||||
|
||||
|
||||
int LZ_decompress_read( struct LZ_Decoder * const d,
|
||||
int LZ_decompress_read( LZ_Decoder * const d,
|
||||
uint8_t * const buffer, const int size )
|
||||
{
|
||||
int result;
|
||||
|
@ -467,7 +465,7 @@ int LZ_decompress_read( struct LZ_Decoder * const d,
|
|||
d->fatal = true;
|
||||
return -1;
|
||||
}
|
||||
d->lz_decoder = (struct LZ_decoder *)malloc( sizeof (struct LZ_decoder) );
|
||||
d->lz_decoder = (LZ_decoder *)malloc( sizeof (LZ_decoder) );
|
||||
if( !d->lz_decoder || !LZd_init( d->lz_decoder, d->rdec,
|
||||
Lh_get_dictionary_size( d->member_header ) ) )
|
||||
{ /* not enough free memory */
|
||||
|
@ -496,7 +494,7 @@ get_data:
|
|||
}
|
||||
|
||||
|
||||
int LZ_decompress_write( struct LZ_Decoder * const d,
|
||||
int LZ_decompress_write( LZ_Decoder * const d,
|
||||
const uint8_t * const buffer, const int size )
|
||||
{
|
||||
int result;
|
||||
|
@ -519,21 +517,21 @@ int LZ_decompress_write( struct LZ_Decoder * const d,
|
|||
}
|
||||
|
||||
|
||||
int LZ_decompress_write_size( struct LZ_Decoder * const d )
|
||||
int LZ_decompress_write_size( LZ_Decoder * const d )
|
||||
{
|
||||
if( !check_decoder( d ) || d->fatal ) return -1;
|
||||
return Rd_free_bytes( d->rdec );
|
||||
}
|
||||
|
||||
|
||||
enum LZ_Errno LZ_decompress_errno( struct LZ_Decoder * const d )
|
||||
LZ_Errno LZ_decompress_errno( LZ_Decoder * const d )
|
||||
{
|
||||
if( !d ) return LZ_bad_argument;
|
||||
return d->lz_errno;
|
||||
}
|
||||
|
||||
|
||||
int LZ_decompress_finished( struct LZ_Decoder * const d )
|
||||
int LZ_decompress_finished( LZ_Decoder * const d )
|
||||
{
|
||||
if( !check_decoder( d ) || d->fatal ) return -1;
|
||||
return Rd_finished( d->rdec ) &&
|
||||
|
@ -541,28 +539,28 @@ int LZ_decompress_finished( struct LZ_Decoder * const d )
|
|||
}
|
||||
|
||||
|
||||
int LZ_decompress_member_finished( struct LZ_Decoder * const d )
|
||||
int LZ_decompress_member_finished( LZ_Decoder * const d )
|
||||
{
|
||||
if( !check_decoder( d ) || d->fatal ) return -1;
|
||||
return d->lz_decoder && LZd_member_finished( d->lz_decoder );
|
||||
}
|
||||
|
||||
|
||||
int LZ_decompress_member_version( struct LZ_Decoder * const d )
|
||||
int LZ_decompress_member_version( LZ_Decoder * const d )
|
||||
{
|
||||
if( !check_decoder( d ) ) return -1;
|
||||
return Lh_version( d->member_header );
|
||||
}
|
||||
|
||||
|
||||
int LZ_decompress_dictionary_size( struct LZ_Decoder * const d )
|
||||
int LZ_decompress_dictionary_size( LZ_Decoder * const d )
|
||||
{
|
||||
if( !check_decoder( d ) ) return -1;
|
||||
return Lh_get_dictionary_size( d->member_header );
|
||||
}
|
||||
|
||||
|
||||
unsigned LZ_decompress_data_crc( struct LZ_Decoder * const d )
|
||||
unsigned LZ_decompress_data_crc( LZ_Decoder * const d )
|
||||
{
|
||||
if( check_decoder( d ) && d->lz_decoder )
|
||||
return LZd_crc( d->lz_decoder );
|
||||
|
@ -570,7 +568,7 @@ unsigned LZ_decompress_data_crc( struct LZ_Decoder * const d )
|
|||
}
|
||||
|
||||
|
||||
unsigned long long LZ_decompress_data_position( struct LZ_Decoder * const d )
|
||||
unsigned long long LZ_decompress_data_position( LZ_Decoder * const d )
|
||||
{
|
||||
if( check_decoder( d ) && d->lz_decoder )
|
||||
return LZd_data_position( d->lz_decoder );
|
||||
|
@ -578,21 +576,21 @@ unsigned long long LZ_decompress_data_position( struct LZ_Decoder * const d )
|
|||
}
|
||||
|
||||
|
||||
unsigned long long LZ_decompress_member_position( struct LZ_Decoder * const d )
|
||||
unsigned long long LZ_decompress_member_position( LZ_Decoder * const d )
|
||||
{
|
||||
if( !check_decoder( d ) ) return 0;
|
||||
return d->rdec->member_position;
|
||||
}
|
||||
|
||||
|
||||
unsigned long long LZ_decompress_total_in_size( struct LZ_Decoder * const d )
|
||||
unsigned long long LZ_decompress_total_in_size( LZ_Decoder * const d )
|
||||
{
|
||||
if( !check_decoder( d ) ) return 0;
|
||||
return d->partial_in_size + d->rdec->member_position;
|
||||
}
|
||||
|
||||
|
||||
unsigned long long LZ_decompress_total_out_size( struct LZ_Decoder * const d )
|
||||
unsigned long long LZ_decompress_total_out_size( LZ_Decoder * const d )
|
||||
{
|
||||
if( !check_decoder( d ) ) return 0;
|
||||
if( d->lz_decoder )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue