diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-07 05:02:37 +0000 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-07 05:02:37 +0000 |
commit | e25a5b0f3e358a0bfd478cdc077af191fafe7ec6 (patch) | |
tree | ba338751a206d0619b75e60d27d889831bedd2c3 /main.c | |
parent | Adding upstream version 1.3. (diff) | |
download | lunzip-e25a5b0f3e358a0bfd478cdc077af191fafe7ec6.tar.xz lunzip-e25a5b0f3e358a0bfd478cdc077af191fafe7ec6.zip |
Adding upstream version 1.4~rc1.upstream/1.4_rc1
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 23 |
1 files changed, 11 insertions, 12 deletions
@@ -120,7 +120,7 @@ static void show_version( void ) } -void show_header( const File_header header ) +static void show_header( const File_header header ) { const char * const prefix[8] = { "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" }; @@ -133,8 +133,6 @@ void show_header( const File_header header ) for( i = 0; i < 8 && ( num > 9999 || ( exact && num >= factor ) ); ++i ) { num /= factor; if( num % factor != 0 ) exact = false; p = prefix[i]; np = ""; } - if( verbosity >= 4 ) - fprintf( stderr, "version %d, ", Fh_version( header ) ); fprintf( stderr, "dictionary size %s%4u %sB. ", np, num, p ); } @@ -153,8 +151,8 @@ static int extension_index( const char * const name ) } -static int open_instream( const char * const name, - struct stat * const in_statsp, const bool to_stdout ) +static int open_instream( const char * const name, struct stat * const in_statsp, + const bool testing, const bool to_stdout ) { int infd = -1; infd = open( name, O_RDONLY | o_binary ); @@ -171,12 +169,13 @@ static int open_instream( const char * const name, const bool can_read = ( i == 0 && ( S_ISBLK( mode ) || S_ISCHR( mode ) || S_ISFIFO( mode ) || S_ISSOCK( mode ) ) ); - if( i != 0 || ( !S_ISREG( mode ) && ( !to_stdout || !can_read ) ) ) + const bool no_ofile = to_stdout || testing; + if( i != 0 || ( !S_ISREG( mode ) && ( !can_read || !no_ofile ) ) ) { if( verbosity >= 0 ) fprintf( stderr, "%s: Input file '%s' is not a regular file%s.\n", program_name, name, - ( can_read && !to_stdout ) ? + ( can_read && !no_ofile ) ? " and '--stdout' was not specified" : "" ); close( infd ); infd = -1; @@ -308,7 +307,8 @@ static int decompress( const int infd, struct Pretty_print * const pp, if( Rd_finished( &rdec ) ) /* End Of File */ { if( first_member ) - { Pp_show_msg( pp, "Error reading member header" ); retval = 1; } + { Pp_show_msg( pp, "File ends unexpectedly at member header" ); + retval = 2; } break; } if( !Fh_verify_magic( header ) ) @@ -381,14 +381,13 @@ static void set_signals( void ) void Pp_init( struct Pretty_print * const pp, const char * const filenames[], - const int num_filenames, const int v ) + const int num_filenames ) { unsigned stdin_name_len; int i; pp->name = 0; pp->stdin_name = "(stdin)"; pp->longest_name = 0; - pp->verbosity = v; pp->first_post = false; stdin_name_len = strlen( pp->stdin_name ); @@ -513,7 +512,7 @@ int main( const int argc, const char * const argv[] ) ( filenames_given || default_output_filename[0] ) ) set_signals(); - Pp_init( &pp, filenames, num_filenames, verbosity ); + Pp_init( &pp, filenames, num_filenames ); output_filename = resize_buffer( output_filename, 1 ); for( i = 0; i < num_filenames; ++i ) @@ -549,7 +548,7 @@ int main( const int argc, const char * const argv[] ) else { input_filename = filenames[i]; - infd = open_instream( input_filename, &in_stats, to_stdout ); + infd = open_instream( input_filename, &in_stats, testing, to_stdout ); if( infd < 0 ) { if( retval < 1 ) retval = 1; continue; } if( !testing ) { |