Merging upstream version 1.14~rc1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
652a26eb4d
commit
8c36724847
28 changed files with 965 additions and 789 deletions
70
lzip.h
70
lzip.h
|
@ -1,5 +1,5 @@
|
|||
/* Clzip - LZMA lossless data compressor
|
||||
Copyright (C) 2010-2022 Antonio Diaz Diaz.
|
||||
Copyright (C) 2010-2023 Antonio Diaz Diaz.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -25,7 +25,6 @@
|
|||
typedef int State;
|
||||
|
||||
enum { states = 12 };
|
||||
|
||||
static inline bool St_is_char( const State st ) { return st < 7; }
|
||||
|
||||
static inline State St_set_char( const State st )
|
||||
|
@ -33,17 +32,13 @@ static inline State St_set_char( const State st )
|
|||
static const State next[states] = { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 };
|
||||
return next[st];
|
||||
}
|
||||
|
||||
static inline State St_set_char_rep() { return 8; }
|
||||
|
||||
static inline State St_set_match( const State st )
|
||||
{ return ( ( st < 7 ) ? 7 : 10 ); }
|
||||
|
||||
{ return ( st < 7 ) ? 7 : 10; }
|
||||
static inline State St_set_rep( const State st )
|
||||
{ return ( ( st < 7 ) ? 8 : 11 ); }
|
||||
|
||||
{ return ( st < 7 ) ? 8 : 11; }
|
||||
static inline State St_set_short_rep( const State st )
|
||||
{ return ( ( st < 7 ) ? 9 : 11 ); }
|
||||
{ return ( st < 7 ) ? 9 : 11; }
|
||||
|
||||
|
||||
enum {
|
||||
|
@ -62,7 +57,7 @@ enum {
|
|||
dis_slot_bits = 6,
|
||||
start_dis_model = 4,
|
||||
end_dis_model = 14,
|
||||
modeled_distances = 1 << (end_dis_model / 2), /* 128 */
|
||||
modeled_distances = 1 << ( end_dis_model / 2 ), /* 128 */
|
||||
dis_align_bits = 4,
|
||||
dis_align_size = 1 << dis_align_bits,
|
||||
|
||||
|
@ -150,8 +145,8 @@ static inline void CRC32_update_buf( uint32_t * const crc,
|
|||
|
||||
|
||||
static inline bool isvalid_ds( const unsigned dictionary_size )
|
||||
{ return ( dictionary_size >= min_dictionary_size &&
|
||||
dictionary_size <= max_dictionary_size ); }
|
||||
{ return dictionary_size >= min_dictionary_size &&
|
||||
dictionary_size <= max_dictionary_size; }
|
||||
|
||||
|
||||
static inline int real_bits( unsigned value )
|
||||
|
@ -164,43 +159,43 @@ static inline int real_bits( unsigned value )
|
|||
|
||||
static const uint8_t lzip_magic[4] = { 0x4C, 0x5A, 0x49, 0x50 }; /* "LZIP" */
|
||||
|
||||
typedef uint8_t Lzip_header[6]; /* 0-3 magic bytes */
|
||||
enum { Lh_size = 6 };
|
||||
typedef uint8_t Lzip_header[Lh_size]; /* 0-3 magic bytes */
|
||||
/* 4 version */
|
||||
/* 5 coded dictionary size */
|
||||
enum { Lh_size = 6 };
|
||||
|
||||
static inline void Lh_set_magic( Lzip_header data )
|
||||
{ memcpy( data, lzip_magic, 4 ); data[4] = 1; }
|
||||
|
||||
static inline bool Lh_verify_magic( const Lzip_header data )
|
||||
{ return ( memcmp( data, lzip_magic, 4 ) == 0 ); }
|
||||
static inline bool Lh_check_magic( const Lzip_header data )
|
||||
{ return memcmp( data, lzip_magic, 4 ) == 0; }
|
||||
|
||||
/* detect (truncated) header */
|
||||
static inline bool Lh_verify_prefix( const Lzip_header data, const int sz )
|
||||
static inline bool Lh_check_prefix( const Lzip_header data, const int sz )
|
||||
{
|
||||
int i; for( i = 0; i < sz && i < 4; ++i )
|
||||
if( data[i] != lzip_magic[i] ) return false;
|
||||
return ( sz > 0 );
|
||||
return sz > 0;
|
||||
}
|
||||
|
||||
/* detect corrupt header */
|
||||
static inline bool Lh_verify_corrupt( const Lzip_header data )
|
||||
static inline bool Lh_check_corrupt( const Lzip_header data )
|
||||
{
|
||||
int matches = 0;
|
||||
int i; for( i = 0; i < 4; ++i )
|
||||
if( data[i] == lzip_magic[i] ) ++matches;
|
||||
return ( matches > 1 && matches < 4 );
|
||||
return matches > 1 && matches < 4;
|
||||
}
|
||||
|
||||
static inline uint8_t Lh_version( const Lzip_header data )
|
||||
{ return data[4]; }
|
||||
|
||||
static inline bool Lh_verify_version( const Lzip_header data )
|
||||
{ return ( data[4] == 1 ); }
|
||||
static inline bool Lh_check_version( const Lzip_header data )
|
||||
{ return data[4] == 1; }
|
||||
|
||||
static inline unsigned Lh_get_dictionary_size( const Lzip_header data )
|
||||
{
|
||||
unsigned sz = ( 1 << ( data[5] & 0x1F ) );
|
||||
unsigned sz = 1 << ( data[5] & 0x1F );
|
||||
if( sz > min_dictionary_size )
|
||||
sz -= ( sz / 16 ) * ( ( data[5] >> 5 ) & 7 );
|
||||
return sz;
|
||||
|
@ -217,23 +212,23 @@ static inline bool Lh_set_dictionary_size( Lzip_header data, const unsigned sz )
|
|||
unsigned i;
|
||||
for( i = 7; i >= 1; --i )
|
||||
if( base_size - ( i * fraction ) >= sz )
|
||||
{ data[5] |= ( i << 5 ); break; }
|
||||
{ data[5] |= i << 5; break; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool Lh_verify( const Lzip_header data )
|
||||
static inline bool Lh_check( const Lzip_header data )
|
||||
{
|
||||
return Lh_verify_magic( data ) && Lh_verify_version( data ) &&
|
||||
return Lh_check_magic( data ) && Lh_check_version( data ) &&
|
||||
isvalid_ds( Lh_get_dictionary_size( data ) );
|
||||
}
|
||||
|
||||
|
||||
typedef uint8_t Lzip_trailer[20];
|
||||
enum { Lt_size = 20 };
|
||||
typedef uint8_t Lzip_trailer[Lt_size];
|
||||
/* 0-3 CRC32 of the uncompressed data */
|
||||
/* 4-11 size of the uncompressed data */
|
||||
/* 12-19 member size including header and trailer */
|
||||
enum { Lt_size = 20 };
|
||||
|
||||
static inline unsigned Lt_get_data_crc( const Lzip_trailer data )
|
||||
{
|
||||
|
@ -266,7 +261,7 @@ static inline void Lt_set_member_size( Lzip_trailer data, unsigned long long sz
|
|||
{ int i; for( i = 12; i <= 19; ++i ) { data[i] = (uint8_t)sz; sz >>= 8; } }
|
||||
|
||||
/* check internal consistency */
|
||||
static inline bool Lt_verify_consistency( const Lzip_trailer data )
|
||||
static inline bool Lt_check_consistency( const Lzip_trailer data )
|
||||
{
|
||||
const unsigned crc = Lt_get_data_crc( data );
|
||||
const unsigned long long dsize = Lt_get_data_size( data );
|
||||
|
@ -281,12 +276,27 @@ static inline bool Lt_verify_consistency( const Lzip_trailer data )
|
|||
}
|
||||
|
||||
|
||||
struct Cl_options /* command-line options */
|
||||
{
|
||||
bool ignore_empty;
|
||||
bool ignore_marking;
|
||||
bool ignore_trailing;
|
||||
bool loose_trailing;
|
||||
};
|
||||
|
||||
static inline void Cl_options_init( struct Cl_options * cl_opts )
|
||||
{ cl_opts->ignore_empty = true; cl_opts->ignore_marking = true;
|
||||
cl_opts->ignore_trailing = true; cl_opts->loose_trailing = false; }
|
||||
|
||||
|
||||
static inline void set_retval( int * retval, const int new_val )
|
||||
{ if( *retval < new_val ) *retval = new_val; }
|
||||
|
||||
static const char * const bad_magic_msg = "Bad magic number (file not in lzip format).";
|
||||
static const char * const bad_dict_msg = "Invalid dictionary size in member header.";
|
||||
static const char * const corrupt_mm_msg = "Corrupt header in multimember file.";
|
||||
static const char * const empty_msg = "Empty member not allowed.";
|
||||
static const char * const marking_msg = "Marking data not allowed.";
|
||||
static const char * const trailing_msg = "Trailing data not allowed.";
|
||||
static const char * const mem_msg = "Not enough memory.";
|
||||
|
||||
|
@ -296,7 +306,7 @@ int writeblock( const int fd, const uint8_t * const buf, const int size );
|
|||
|
||||
/* defined in list.c */
|
||||
int list_files( const char * const filenames[], const int num_filenames,
|
||||
const bool ignore_trailing, const bool loose_trailing );
|
||||
const struct Cl_options * const cl_opts );
|
||||
|
||||
/* defined in main.c */
|
||||
struct stat;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue