1
0
Fork 0

Merging upstream version 1.9.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-24 04:17:44 +01:00
parent c7dcd442c7
commit 48c5ddf50f
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
29 changed files with 2003 additions and 1566 deletions

78
lzip.h
View file

@ -1,27 +1,25 @@
/* Plzip - Massively parallel implementation of lzip
Copyright (C) 2009-2019 Antonio Diaz Diaz.
/* Plzip - Massively parallel implementation of lzip
Copyright (C) 2009-2021 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
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
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
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LZ_API_VERSION
#define LZ_API_VERSION 1
#endif
#include <pthread.h>
enum {
min_dictionary_bits = 12,
min_dictionary_size = 1 << min_dictionary_bits,
min_dictionary_size = 1 << min_dictionary_bits, // >= modeled_distances
max_dictionary_bits = 29,
max_dictionary_size = 1 << max_dictionary_bits,
min_member_size = 36 };
@ -88,7 +86,7 @@ struct Lzip_header
{
uint8_t data[6]; // 0-3 magic bytes
// 4 version
// 5 coded_dict_size
// 5 coded dictionary size
enum { size = 6 };
void set_magic() { std::memcpy( data, lzip_magic, 4 ); data[4] = 1; }
@ -134,6 +132,10 @@ struct Lzip_header
}
return true;
}
bool verify() const
{ return verify_magic() && verify_version() &&
isvalid_ds( dictionary_size() ); }
};
@ -190,10 +192,14 @@ struct Lzip_trailer
};
inline void set_retval( int & retval, const int new_val )
{ if( retval < new_val ) retval = new_val; }
const char * const bad_magic_msg = "Bad magic number (file not in lzip format).";
const char * const bad_dict_msg = "Invalid dictionary size in member header.";
const char * const corrupt_mm_msg = "Corrupt header in multimember file.";
const char * const trailing_msg = "Trailing data not allowed.";
const char * const mem_msg = "Not enough memory.";
// defined in compress.cc
int readblock( const int fd, uint8_t * const buf, const int size );
@ -231,13 +237,19 @@ int dec_stream( const unsigned long long cfile_size,
// defined in decompress.cc
int preadblock( const int fd, uint8_t * const buf, const int size,
const long long pos );
int decompress_read_error( struct LZ_Decoder * const decoder,
const Pretty_print & pp, const int worker_id );
class Shared_retval;
void decompress_error( struct LZ_Decoder * const decoder,
const Pretty_print & pp,
Shared_retval & shared_retval, const int worker_id );
void show_results( const unsigned long long in_size,
const unsigned long long out_size,
const unsigned dictionary_size, const bool testing );
int decompress( const unsigned long long cfile_size, int num_workers,
const int infd, const int outfd, const Pretty_print & pp,
const int debug_level, const int in_slots,
const int out_slots, const bool ignore_trailing,
const bool loose_trailing, const bool infd_isreg );
const bool loose_trailing, const bool infd_isreg,
const bool one_to_one );
// defined in list.cc
int list_files( const std::vector< std::string > & filenames,
@ -249,7 +261,7 @@ const char * bad_version( const unsigned version );
const char * format_ds( const unsigned dictionary_size );
void show_header( const unsigned dictionary_size );
int open_instream( const char * const name, struct stat * const in_statsp,
const bool no_ofile, const bool reg_only = false );
const bool one_to_one, const bool reg_only = false );
void cleanup_and_fail( const int retval = 1 ); // terminate the program
void show_error( const char * const msg, const int errcode = 0,
const bool help = false );
@ -295,3 +307,27 @@ public:
xunlock( &mutex );
}
};
class Shared_retval // shared return value protected by a mutex
{
int retval;
pthread_mutex_t mutex;
Shared_retval( const Shared_retval & ); // declared as private
void operator=( const Shared_retval & ); // declared as private
public:
Shared_retval() : retval( 0 ) { xinit_mutex( &mutex ); }
bool set_value( const int val ) // only one thread can set retval > 0
{ // (and print an error message)
xlock( &mutex );
const bool done = ( retval == 0 && val > 0 );
if( done ) retval = val;
xunlock( &mutex );
return done;
}
int operator()() const { return retval; }
};