1
0
Fork 0

Merging upstream version 0.9.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-24 03:50:51 +01:00
parent 7a8d5107f2
commit b4a17774a7
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
14 changed files with 193 additions and 200 deletions

87
main.cc
View file

@ -48,16 +48,6 @@
#error "Environments where CHAR_BIT != 8 are not supported."
#endif
#ifndef LLONG_MAX
#define LLONG_MAX 0x7FFFFFFFFFFFFFFFLL
#endif
#ifndef LLONG_MIN
#define LLONG_MIN (-LLONG_MAX - 1LL)
#endif
#ifndef ULLONG_MAX
#define ULLONG_MAX 0xFFFFFFFFFFFFFFFFULL
#endif
namespace {
@ -87,13 +77,15 @@ enum Mode { m_compress, m_decompress, m_test };
std::string output_filename;
int outfd = -1;
mode_t outfd_mode = S_IRUSR | S_IWUSR;
const mode_t usr_rw = S_IRUSR | S_IWUSR;
const mode_t all_rw = usr_rw | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
mode_t outfd_mode = usr_rw;
bool delete_output_on_interrupt = false;
pthread_t main_thread;
pid_t main_thread_pid;
void show_help() throw()
void show_help()
{
std::printf( "%s - A parallel compressor compatible with lzip.\n", Program_name );
std::printf( "\nUsage: %s [options] [files]\n", invocation_name );
@ -133,7 +125,7 @@ void show_help() throw()
}
void show_version() throw()
void show_version()
{
std::printf( "%s %s\n", Program_name, PROGVERSION );
std::printf( "Copyright (C) 2009 Laszlo Ersek.\n"
@ -147,7 +139,7 @@ void show_version() throw()
long long getnum( const char * const ptr,
const long long llimit = LLONG_MIN + 1,
const long long ulimit = LLONG_MAX ) throw()
const long long ulimit = LLONG_MAX )
{
errno = 0;
char *tail;
@ -200,7 +192,7 @@ long long getnum( const char * const ptr,
}
int get_dict_size( const char * const arg ) throw()
int get_dict_size( const char * const arg )
{
char *tail;
int bits = std::strtol( arg, &tail, 0 );
@ -211,7 +203,7 @@ int get_dict_size( const char * const arg ) throw()
}
int extension_index( const std::string & name ) throw()
int extension_index( const std::string & name )
{
for( int i = 0; known_extensions[i].from; ++i )
{
@ -226,7 +218,7 @@ int extension_index( const std::string & name ) throw()
int open_instream( const std::string & name, struct stat * const in_statsp,
const Mode program_mode, const int eindex,
const bool recompress, const bool to_stdout ) throw()
const bool recompress, const bool to_stdout )
{
int infd = -1;
if( program_mode == m_compress && !recompress && eindex >= 0 )
@ -268,14 +260,14 @@ int open_instream( const std::string & name, struct stat * const in_statsp,
}
void set_c_outname( const std::string & name ) throw()
void set_c_outname( const std::string & name )
{
output_filename = name;
output_filename += known_extensions[0].from;
}
void set_d_outname( const std::string & name, const int i ) throw()
void set_d_outname( const std::string & name, const int i )
{
if( i >= 0 )
{
@ -294,7 +286,7 @@ void set_d_outname( const std::string & name, const int i ) throw()
}
bool open_outstream( const bool force ) throw()
bool open_outstream( const bool force )
{
int flags = O_CREAT | O_WRONLY | o_binary;
if( force ) flags |= O_TRUNC; else flags |= O_EXCL;
@ -313,7 +305,7 @@ bool open_outstream( const bool force ) throw()
}
bool check_tty( const int infd, const Mode program_mode ) throw()
bool check_tty( const int infd, const Mode program_mode )
{
if( program_mode == m_compress && outfd >= 0 && isatty( outfd ) )
{
@ -330,7 +322,7 @@ bool check_tty( const int infd, const Mode program_mode ) throw()
}
void cleanup_and_fail( const int retval ) throw()
void cleanup_and_fail( const int retval )
{
if( delete_output_on_interrupt )
{
@ -372,7 +364,7 @@ void close_and_set_permissions( const struct stat * const in_statsp )
}
extern "C" void signal_handler( int sig ) throw()
extern "C" void signal_handler( int sig )
{
if( !pthread_equal( pthread_self(), main_thread ) )
kill( main_thread_pid, sig );
@ -382,7 +374,7 @@ extern "C" void signal_handler( int sig ) throw()
}
void set_signals() throw()
void set_signals()
{
std::signal( SIGHUP, signal_handler );
std::signal( SIGINT, signal_handler );
@ -402,7 +394,7 @@ int verbosity = 0;
void fatal() { signal_handler( SIGUSR1 ); }
void Pretty_print::operator()( const char * const msg ) const throw()
void Pretty_print::operator()( const char * const msg ) const
{
if( verbosity >= 0 )
{
@ -419,7 +411,7 @@ void Pretty_print::operator()( const char * const msg ) const throw()
}
void show_error( const char * const msg, const int errcode, const bool help ) throw()
void show_error( const char * const msg, const int errcode, const bool help )
{
if( verbosity >= 0 )
{
@ -437,7 +429,7 @@ void show_error( const char * const msg, const int errcode, const bool help ) th
}
void internal_error( const char * const msg ) throw()
void internal_error( const char * const msg )
{
if( verbosity >= 0 )
std::fprintf( stderr, "%s: internal error: %s.\n", program_name, msg );
@ -445,43 +437,6 @@ void internal_error( const char * const msg ) throw()
}
// Returns the number of bytes really read.
// If (returned value < size) and (errno == 0), means EOF was reached.
//
int readblock( const int fd, uint8_t * const buf, const int size ) throw()
{
int rest = size;
errno = 0;
while( rest > 0 )
{
errno = 0;
const int n = read( fd, buf + size - rest, rest );
if( n > 0 ) rest -= n;
else if( n == 0 ) break;
else if( errno != EINTR && errno != EAGAIN ) break;
}
return ( rest > 0 ) ? size - rest : size;
}
// Returns the number of bytes really written.
// If (returned value < size), it is always an error.
//
int writeblock( const int fd, const uint8_t * const buf, const int size ) throw()
{
int rest = size;
errno = 0;
while( rest > 0 )
{
errno = 0;
const int n = write( fd, buf + size - rest, rest );
if( n > 0 ) rest -= n;
else if( n < 0 && errno != EINTR && errno != EAGAIN ) break;
}
return ( rest > 0 ) ? size - rest : size;
}
int main( const int argc, const char * const argv[] )
{
// Mapping from gzip/bzip2 style 1..9 compression modes
@ -649,7 +604,7 @@ int main( const int argc, const char * const argv[] )
if( program_mode == m_compress )
set_c_outname( default_output_filename );
else output_filename = default_output_filename;
outfd_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
outfd_mode = all_rw;
if( !open_outstream( force ) )
{
if( outfd == -1 && retval < 1 ) retval = 1;
@ -674,7 +629,7 @@ int main( const int argc, const char * const argv[] )
if( program_mode == m_compress )
set_c_outname( input_filename );
else set_d_outname( input_filename, eindex );
outfd_mode = S_IRUSR | S_IWUSR;
outfd_mode = usr_rw;
if( !open_outstream( force ) )
{
if( outfd == -1 && retval < 1 ) retval = 1;