1
0
Fork 0

Merging upstream version 0.7.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-17 22:51:57 +01:00
parent d419679950
commit ca990cc36e
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
15 changed files with 74 additions and 74 deletions

37
main.c
View file

@ -1,5 +1,5 @@
/* Xlunzip - Test tool for the lzip_decompress linux module
Copyright (C) 2016-2020 Antonio Diaz Diaz.
Copyright (C) 2016-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
@ -75,7 +75,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 = "2020";
static const char * const program_year = "2021";
static const char * invocation_name = "xlunzip"; /* default value */
static const struct { const char * from; const char * to; } known_extensions[] = {
@ -393,6 +393,19 @@ static void signal_handler( int sig )
}
static bool check_tty_in( const char * const input_filename, const int infd,
const bool testing, int * const retval )
{
if( isatty( infd ) ) /* for example /dev/tty */
{ show_file_error( input_filename,
"I won't read compressed data from a terminal.", 0 );
close( infd ); set_retval( retval, 1 );
if( !testing ) cleanup_and_fail( *retval );
return false; }
return true;
}
/* Set permissions, owner, and times. */
static void close_and_set_permissions( const struct stat * const in_statsp )
{
@ -538,9 +551,6 @@ void show_results( struct Pretty_print * const pp, const long in_pos,
}
static inline void set_retval( int * retval, const int new_val )
{ if( *retval < new_val ) *retval = new_val; }
static void show_error( const char * const msg, const int errcode,
const bool help )
{
@ -692,10 +702,12 @@ int main( const int argc, const char * const argv[] )
struct stat in_stats;
const struct stat * in_statsp;
Pp_set_name( &pp, filenames[i] );
if( strcmp( filenames[i], "-" ) == 0 )
{
if( stdin_used ) continue; else stdin_used = true;
infd = STDIN_FILENO;
if( !check_tty_in( pp.name, infd, testing, &retval ) ) continue;
if( one_to_one ) { outfd = STDOUT_FILENO; output_filename[0] = 0; }
}
else
@ -703,24 +715,15 @@ int main( const int argc, const char * const argv[] )
input_filename = filenames[i];
infd = open_instream( input_filename, &in_stats, one_to_one );
if( infd < 0 ) { set_retval( &retval, 1 ); continue; }
if( one_to_one )
if( !check_tty_in( pp.name, infd, testing, &retval ) ) continue;
if( one_to_one ) /* open outfd after verifying infd */
{
set_d_outname( input_filename, extension_index( input_filename ) );
if( !open_outstream( force, true ) )
{ set_retval( &retval, 1 ); close( infd ); infd = -1; continue; }
{ close( infd ); infd = -1; set_retval( &retval, 1 ); continue; }
}
}
Pp_set_name( &pp, input_filename );
if( isatty( infd ) ) /* for example /dev/tty */
{
show_file_error( pp.name,
"I won't read compressed data from a terminal.", 0 );
set_retval( &retval, 1 );
if( testing ) { close( infd ); infd = -1; continue; }
cleanup_and_fail( retval );
}
if( to_file && outfd < 0 ) /* open outfd after verifying infd */
{
output_filename = resize_buffer( output_filename,