summaryrefslogtreecommitdiffstats
path: root/fec_repair.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-11-24 04:36:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-11-24 04:36:43 +0000
commitab77d16ba47322aab30703e251efbffb680ce0bb (patch)
tree5d2146c01e938fa6cac7c349192088cb2e962ac5 /fec_repair.cc
parentAdding upstream version 1.25~pre1. (diff)
downloadlziprecover-upstream.tar.xz
lziprecover-upstream.zip
Adding upstream version 1.25~rc1.upstream/1.25_rc1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'fec_repair.cc')
-rw-r--r--fec_repair.cc21
1 files changed, 12 insertions, 9 deletions
diff --git a/fec_repair.cc b/fec_repair.cc
index c15dfd3..8d9cd5b 100644
--- a/fec_repair.cc
+++ b/fec_repair.cc
@@ -76,7 +76,7 @@ uint8_t * read_file( const std::string & filename, long * const file_sizep )
{
struct stat in_stats; // not used
const char * const filenamep = printable_name( filename );
- const int infd = ( filename == "-" ) ?
+ const int infd = (filename == "-") ?
STDIN_FILENO : open_instream( filenamep, &in_stats, false );
if( infd < 0 ) return 0;
long buffer_size = 65536;
@@ -88,7 +88,7 @@ uint8_t * read_file( const std::string & filename, long * const file_sizep )
if( buffer_size >= LONG_MAX )
{ show_file_error( filenamep, large_file_msg );
std::free( buffer ); return 0; }
- buffer_size = ( buffer_size <= LONG_MAX / 2 ) ? 2 * buffer_size : LONG_MAX;
+ buffer_size = (buffer_size <= LONG_MAX / 2) ? 2 * buffer_size : LONG_MAX;
uint8_t * const tmp = (uint8_t *)std::realloc( buffer, buffer_size );
if( !tmp )
{ show_file_error( filenamep, mem_msg ); std::free( buffer ); return 0; }
@@ -794,9 +794,12 @@ int fec_test( const std::vector< std::string > & filenames,
// check tty only once and don't try to delete a tty
if( !open_outstream( force, false ) || !check_tty_out() ) return 1;
}
- if( writeblock( outfd, prodata, prodata_size ) != prodata_size ||
- !close_outstream( &in_stats ) ) // write repaired prodata
- { set_retval( retval, 1 ); cleanup_and_fail( retval ); }
+ // write repaired prodata
+ if( writeblock( outfd, prodata, prodata_size ) != prodata_size )
+ { show_file_error( printable_name( output_filename, false ),
+ write_error_msg, errno ); set_retval( retval, 1 ); }
+ else if( !close_outstream( &in_stats ) ) set_retval( retval, 1 );
+ if( retval ) cleanup_and_fail( retval );
if( verbosity >= 1 )
std::fprintf( stderr, "Repaired copy of '%s' written to '%s'\n",
input_filenamep, printable_name( output_filename, false ) );
@@ -868,7 +871,7 @@ int fec_dc( const std::string & input_filename,
const unsigned long cblock_size = fec_blocks / cblocks * fbs;
const unsigned long max_saved_size = cblocks * cblock_size;
uint8_t * const sbuf = new uint8_t[max_saved_size]; // saved data bytes
- const long last_pos = ( prodata_size % cblock_size != 0 ) ?
+ const long last_pos = (prodata_size % cblock_size != 0) ?
prodata_size - prodata_size % cblock_size : prodata_size - cblock_size;
if( verbosity >= 0 )
{ std::printf( "Testing sets of %u block%s of size %s\n", cblocks,
@@ -1034,7 +1037,7 @@ int fec_dZ( const std::string & input_filename,
const int rest = std::min( 2UL, sector_size % fbs );
const long max_saved_size = ( sector_size / fbs + rest ) * fbs;
uint8_t * const sbuf = new uint8_t[max_saved_size]; // saved data bytes
- const long last_pos = ( prodata_size % sector_size != 0 ) ?
+ const long last_pos = (prodata_size % sector_size != 0) ?
prodata_size - prodata_size % sector_size : prodata_size - sector_size;
if( verbosity >= 0 )
{ std::printf( "Testing blocks of size %s (delta %s)\n",
@@ -1042,8 +1045,8 @@ int fec_dZ( const std::string & input_filename,
std::fflush( stdout ); }
unsigned long combinations = 0, repair_attempts = 0, successes = 0,
failed_comparisons = 0;
- int pct = ( prodata_size >= 1000 && isatty( STDERR_FILENO ) ) ? 0 : 100;
- long pct_pos = ( pct < 100 ) ? 0 : prodata_size;
+ int pct = (prodata_size >= 1000 && isatty( STDERR_FILENO )) ? 0 : 100;
+ long pct_pos = (pct < 100) ? 0 : prodata_size;
const int saved_verbosity = verbosity;
verbosity = -1; // suppress all messages
for( long pos = 0; pos <= last_pos; pos += delta )