summaryrefslogtreecommitdiffstats
path: root/list.c
diff options
context:
space:
mode:
Diffstat (limited to 'list.c')
-rw-r--r--list.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/list.c b/list.c
index c711031..7ed74ff 100644
--- a/list.c
+++ b/list.c
@@ -17,6 +17,7 @@
#define _FILE_OFFSET_BITS 64
+#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
@@ -43,7 +44,7 @@ static void list_line( const unsigned long long uncomp_size,
int list_files( const char * const filenames[], const int num_filenames,
- const struct Cl_options * const cl_opts )
+ const Cl_options * const cl_opts )
{
unsigned long long total_comp = 0, total_uncomp = 0;
int files = 0, retval = 0;
@@ -53,7 +54,7 @@ int list_files( const char * const filenames[], const int num_filenames,
for( i = 0; i < num_filenames; ++i )
{
- const bool from_stdin = ( strcmp( filenames[i], "-" ) == 0 );
+ const bool from_stdin = strcmp( filenames[i], "-" ) == 0;
if( from_stdin ) { if( stdin_used ) continue; else stdin_used = true; }
const char * const input_filename = from_stdin ? "(stdin)" : filenames[i];
struct stat in_stats; /* not used */
@@ -61,7 +62,7 @@ int list_files( const char * const filenames[], const int num_filenames,
open_instream( input_filename, &in_stats, false, true );
if( infd < 0 ) { set_retval( &retval, 1 ); continue; }
- struct Lzip_index lzip_index;
+ Lzip_index lzip_index;
Li_init( &lzip_index, infd, cl_opts );
close( infd );
if( lzip_index.retval != 0 )
@@ -70,6 +71,8 @@ int list_files( const char * const filenames[], const int num_filenames,
set_retval( &retval, lzip_index.retval );
Li_free( &lzip_index ); continue;
}
+ const bool multi_empty = !from_stdin && Li_multi_empty( &lzip_index );
+ if( multi_empty ) set_retval( &retval, 2 );
if( verbosity < 0 ) { Li_free( &lzip_index ); continue; }
const unsigned long long udata_size = Li_udata_size( &lzip_index );
const unsigned long long cdata_size = Li_cdata_size( &lzip_index );
@@ -81,6 +84,8 @@ int list_files( const char * const filenames[], const int num_filenames,
if( verbosity >= 1 ) fputs( " dict memb trail ", stdout );
fputs( " uncompressed compressed saved name\n", stdout );
}
+ if( multi_empty )
+ { fflush( stdout ); show_file_error( input_filename, empty_msg, 0 ); }
if( verbosity >= 1 )
printf( "%s %5ld %6lld ", format_ds( lzip_index.dictionary_size ),
members, Li_file_size( &lzip_index ) - cdata_size );
@@ -92,8 +97,8 @@ int list_files( const char * const filenames[], const int num_filenames,
fputs( " member data_pos data_size member_pos member_size\n", stdout );
for( i = 0; i < members; ++i )
{
- const struct Block * db = Li_dblock( &lzip_index, i );
- const struct Block * mb = Li_mblock( &lzip_index, i );
+ const Block * db = Li_dblock( &lzip_index, i );
+ const Block * mb = Li_mblock( &lzip_index, i );
printf( "%6ld %14llu %14llu %14llu %14llu\n",
i + 1, db->pos, db->size, mb->pos, mb->size );
}
@@ -101,12 +106,16 @@ int list_files( const char * const filenames[], const int num_filenames,
}
fflush( stdout );
Li_free( &lzip_index );
+ if( ferror( stdout ) ) break;
}
- if( verbosity >= 0 && files > 1 )
+ if( verbosity >= 0 && files > 1 && !ferror( stdout ) )
{
if( verbosity >= 1 ) fputs( " ", stdout );
list_line( total_uncomp, total_comp, "(totals)" );
fflush( stdout );
}
+ if( verbosity >= 0 && ( ferror( stdout ) || fclose( stdout ) != 0 ) )
+ { show_file_error( "(stdout)", write_error_msg, errno );
+ set_retval( &retval, 1 ); }
return retval;
}