summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-01-27 16:11:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-01-27 16:11:22 +0000
commit4e8b4f669846da5166cc09ccaeff06710aaeb1b7 (patch)
tree4d43dd4ea1e336065ba7208e974f29afe542b7d2 /main.c
parentAdding upstream version 0.6. (diff)
downloadxlunzip-4e8b4f669846da5166cc09ccaeff06710aaeb1b7.tar.xz
xlunzip-4e8b4f669846da5166cc09ccaeff06710aaeb1b7.zip
Adding upstream version 0.7.upstream/0.7
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--main.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/main.c b/main.c
index 0dc02c7..dc403da 100644
--- a/main.c
+++ b/main.c
@@ -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,