Merging upstream version 0.9.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
bdc3a79f2b
commit
26c5e8d334
22 changed files with 270 additions and 201 deletions
58
main.c
58
main.c
|
@ -1,5 +1,5 @@
|
|||
/* Xlunzip - Test tool for the lzip_decompress linux module
|
||||
Copyright (C) 2016-2024 Antonio Diaz Diaz.
|
||||
Copyright (C) 2016-2025 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
|
||||
|
@ -26,7 +26,7 @@
|
|||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h> /* SSIZE_MAX */
|
||||
#include <limits.h> /* CHAR_BIT, SSIZE_MAX */
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h> /* SIZE_MAX */
|
||||
|
@ -80,7 +80,7 @@ static void show_error( const char * const msg, const int errcode,
|
|||
const bool help );
|
||||
|
||||
static const char * const program_name = "xlunzip";
|
||||
static const char * const program_year = "2024";
|
||||
static const char * const program_year = "2025";
|
||||
static const char * invocation_name = "xlunzip"; /* default value */
|
||||
|
||||
static const struct { const char * from; const char * to; } known_extensions[] = {
|
||||
|
@ -164,7 +164,7 @@ static void * resize_buffer( void * buf, const unsigned min_size )
|
|||
}
|
||||
|
||||
|
||||
static void Pp_init( struct Pretty_print * const pp,
|
||||
static void Pp_init( Pretty_print * const pp,
|
||||
const char * const filenames[], const int num_filenames )
|
||||
{
|
||||
pp->name = 0;
|
||||
|
@ -185,8 +185,10 @@ static void Pp_init( struct Pretty_print * const pp,
|
|||
if( pp->longest_name == 0 ) pp->longest_name = stdin_name_len;
|
||||
}
|
||||
|
||||
static void Pp_set_name( struct Pretty_print * const pp,
|
||||
const char * const filename )
|
||||
void Pp_free( Pretty_print * const pp )
|
||||
{ if( pp->padded_name ) { free( pp->padded_name ); pp->padded_name = 0; } }
|
||||
|
||||
static void Pp_set_name( Pretty_print * const pp, const char * const filename )
|
||||
{
|
||||
unsigned name_len, padded_name_len, i = 0;
|
||||
|
||||
|
@ -204,7 +206,7 @@ static void Pp_set_name( struct Pretty_print * const pp,
|
|||
pp->first_post = true;
|
||||
}
|
||||
|
||||
static void Pp_show_msg( struct Pretty_print * const pp, const char * const msg )
|
||||
static void Pp_show_msg( Pretty_print * const pp, const char * const msg )
|
||||
{
|
||||
if( verbosity < 0 ) return;
|
||||
if( pp->first_post )
|
||||
|
@ -229,7 +231,7 @@ static const char * format_num3( unsigned long long num )
|
|||
char * const buf = buffer[current++]; current %= buffers;
|
||||
char * p = buf + bufsize - 1; /* fill the buffer backwards */
|
||||
*p = 0; /* terminator */
|
||||
if( num > 1024 )
|
||||
if( num > 9999 )
|
||||
{
|
||||
char prefix = 0; /* try binary first, then si */
|
||||
for( i = 0; i < n && num != 0 && num % 1024 == 0; ++i )
|
||||
|
@ -275,7 +277,7 @@ static unsigned long getnum( const char * const arg,
|
|||
|
||||
if( !errno && tail[0] )
|
||||
{
|
||||
const unsigned factor = ( tail[1] == 'i' ) ? 1024 : 1000;
|
||||
const unsigned factor = (tail[1] == 'i') ? 1024 : 1000;
|
||||
int exponent = 0; /* 0 = bad multiplier */
|
||||
int i;
|
||||
switch( tail[0] )
|
||||
|
@ -365,9 +367,9 @@ static int open_instream( const char * const name, struct stat * const in_statsp
|
|||
{
|
||||
const int i = fstat( infd, in_statsp );
|
||||
const mode_t mode = in_statsp->st_mode;
|
||||
const bool can_read = ( i == 0 &&
|
||||
( S_ISBLK( mode ) || S_ISCHR( mode ) ||
|
||||
S_ISFIFO( mode ) || S_ISSOCK( mode ) ) );
|
||||
const bool can_read = i == 0 &&
|
||||
( S_ISBLK( mode ) || S_ISCHR( mode ) ||
|
||||
S_ISFIFO( mode ) || S_ISSOCK( mode ) );
|
||||
if( i != 0 || ( !S_ISREG( mode ) && ( !can_read || one_to_one ) ) )
|
||||
{
|
||||
if( verbosity >= 0 )
|
||||
|
@ -482,10 +484,10 @@ int convert_retval( const int retval )
|
|||
{
|
||||
switch( retval )
|
||||
{
|
||||
case 0: return 0;
|
||||
case 0: return 0;
|
||||
case LZIP_OOM_INBUF:
|
||||
case LZIP_OOM_OUTBUF:
|
||||
case LZIP_WRITE_ERROR: return 1;
|
||||
case LZIP_WRITE_ERROR: return 1;
|
||||
case LZIP_HEADER1_EOF:
|
||||
case LZIP_HEADER2_EOF:
|
||||
case LZIP_BAD_MAGIC1:
|
||||
|
@ -494,8 +496,9 @@ int convert_retval( const int retval )
|
|||
case LZIP_BAD_DICT_SIZE:
|
||||
case LZIP_BAD_DATA:
|
||||
case LZIP_DATA_EOF:
|
||||
case LZIP_BAD_CRC: return 2;
|
||||
default: return 3;
|
||||
case LZIP_BAD_CRC:
|
||||
case LZIP_EMPTY_MEMBER: return 2;
|
||||
default: return 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -519,7 +522,7 @@ static long fill( void * buf, unsigned long size )
|
|||
|
||||
long flush( void * buf, unsigned long size )
|
||||
{
|
||||
unsigned long sz = ( outfd >= 0 ) ? 0 : size;
|
||||
unsigned long sz = (outfd >= 0) ? 0 : size;
|
||||
errno = 0;
|
||||
while( sz < size )
|
||||
{
|
||||
|
@ -535,7 +538,7 @@ static const char * global_name; /* copy of filename for 'error' */
|
|||
static void error(char *x) { show_file_error( global_name, x, 0 ); }
|
||||
|
||||
|
||||
static int decompress( const int infd, struct Pretty_print * const pp,
|
||||
static int decompress( const int infd, Pretty_print * const pp,
|
||||
const long cl_insize, const long cl_outsize,
|
||||
const bool nofill, const bool noflush, const bool testing )
|
||||
{
|
||||
|
@ -574,7 +577,7 @@ static int decompress( const int infd, struct Pretty_print * const pp,
|
|||
}
|
||||
|
||||
|
||||
void show_results( struct Pretty_print * const pp, const long in_pos,
|
||||
void show_results( Pretty_print * const pp, const long in_pos,
|
||||
const long out_pos, const bool testing )
|
||||
{
|
||||
if( verbosity >= 1 ) Pp_show_msg( pp, 0 );
|
||||
|
@ -631,7 +634,6 @@ int main( const int argc, const char * const argv[] )
|
|||
const char * default_output_filename = "";
|
||||
long cl_insize = 0;
|
||||
long cl_outsize = 0;
|
||||
int i;
|
||||
bool force = false;
|
||||
bool in_place = false;
|
||||
bool keep_input_files = false;
|
||||
|
@ -642,7 +644,7 @@ int main( const int argc, const char * const argv[] )
|
|||
if( argc > 0 ) invocation_name = argv[0];
|
||||
|
||||
enum { opt_insize = 256, opt_outsize, opt_nofill, opt_noflush };
|
||||
const struct ap_Option options[] =
|
||||
const ap_Option options[] =
|
||||
{
|
||||
{ 'c', "stdout", ap_no },
|
||||
{ 'd', "decompress", ap_no },
|
||||
|
@ -656,14 +658,14 @@ int main( const int argc, const char * const argv[] )
|
|||
{ 't', "test", ap_no },
|
||||
{ 'v', "verbose", ap_no },
|
||||
{ 'V', "version", ap_no },
|
||||
{ opt_insize, "insize", ap_maybe },
|
||||
{ opt_outsize, "outsize", ap_maybe },
|
||||
{ opt_insize, "insize", ap_maybe },
|
||||
{ opt_outsize, "outsize", ap_maybe },
|
||||
{ opt_nofill, "nofill", ap_no },
|
||||
{ opt_noflush, "noflush", ap_no },
|
||||
{ 0, 0, ap_no } };
|
||||
{ 0, 0, ap_no } };
|
||||
|
||||
/* static because valgrind complains and memory management in C sucks */
|
||||
static struct Arg_parser parser;
|
||||
static Arg_parser parser;
|
||||
if( !ap_init( &parser, argc, argv, options, 0 ) )
|
||||
{ show_error( mem_msg, 0, false ); return 1; }
|
||||
if( ap_error( &parser ) ) /* bad option */
|
||||
|
@ -684,7 +686,7 @@ int main( const int argc, const char * const argv[] )
|
|||
case 'h': show_help(); return 0;
|
||||
case 'I': in_place = true; break;
|
||||
case 'k': keep_input_files = true; break;
|
||||
case 'n': break;
|
||||
case 'n': break; /* ignored */
|
||||
case 'o': if( strcmp( arg, "-" ) == 0 ) to_stdout = true;
|
||||
else { default_output_filename = arg; } break;
|
||||
case 'q': verbosity = -1; break;
|
||||
|
@ -712,6 +714,7 @@ int main( const int argc, const char * const argv[] )
|
|||
filenames = resize_buffer( filenames, num_filenames * sizeof filenames[0] );
|
||||
filenames[0] = "-";
|
||||
|
||||
int i;
|
||||
bool filenames_given = false;
|
||||
for( i = 0; argind + i < ap_arguments( &parser ); ++i )
|
||||
{
|
||||
|
@ -731,7 +734,7 @@ int main( const int argc, const char * const argv[] )
|
|||
if( !to_stdout && !testing && ( filenames_given || to_file ) )
|
||||
set_signals( signal_handler );
|
||||
|
||||
static struct Pretty_print pp;
|
||||
static Pretty_print pp;
|
||||
Pp_init( &pp, filenames, num_filenames );
|
||||
|
||||
int failed_tests = 0;
|
||||
|
@ -807,6 +810,7 @@ int main( const int argc, const char * const argv[] )
|
|||
program_name, failed_tests,
|
||||
( failed_tests == 1 ) ? "file" : "files" );
|
||||
free( output_filename );
|
||||
Pp_free( &pp );
|
||||
free( filenames );
|
||||
ap_free( &parser );
|
||||
return retval;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue