summaryrefslogtreecommitdiffstats
path: root/lzip.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-23 05:36:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-23 05:36:48 +0000
commit00184d655a72ed5a71aa80449250255fb8ac2caa (patch)
treeedfe486934a7174a4a8504eeb8923243407ad2db /lzip.h
parentReleasing debian version 1.13-6. (diff)
downloadlunzip-00184d655a72ed5a71aa80449250255fb8ac2caa.tar.xz
lunzip-00184d655a72ed5a71aa80449250255fb8ac2caa.zip
Merging upstream version 1.14~rc1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lzip.h')
-rw-r--r--lzip.h67
1 files changed, 39 insertions, 28 deletions
diff --git a/lzip.h b/lzip.h
index 4b77be8..22c75e5 100644
--- a/lzip.h
+++ b/lzip.h
@@ -1,5 +1,5 @@
/* Lunzip - Decompressor for the lzip format
- 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,15 +32,12 @@ 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_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 {
@@ -60,7 +56,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,
@@ -145,63 +141,63 @@ 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 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 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;
}
-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 )
{
@@ -225,7 +221,7 @@ static inline unsigned long long Lt_get_member_size( const Lzip_trailer data )
}
/* 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 );
@@ -240,12 +236,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.";
@@ -254,7 +265,7 @@ int readblock( const int fd, 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;