summaryrefslogtreecommitdiffstats
path: root/merge.cc
diff options
context:
space:
mode:
Diffstat (limited to 'merge.cc')
-rw-r--r--merge.cc45
1 files changed, 20 insertions, 25 deletions
diff --git a/merge.cc b/merge.cc
index 08a3d0e..95b9318 100644
--- a/merge.cc
+++ b/merge.cc
@@ -75,6 +75,7 @@ void combine( std::vector< Block > & block_vector, std::vector< Block > & bv )
}
+// positions in 'block_vector' are absolute file positions.
bool diff_member( const long long mpos, const long long msize,
const std::vector< int > & infd_vector,
std::vector< Block > & block_vector )
@@ -220,7 +221,7 @@ int open_input_files( const std::vector< std::string > & filenames,
{
const int infd = infd_vector[i];
bool error = false;
- for( int j = 0; j < file_index.members(); ++j )
+ for( long j = 0; j < file_index.members(); ++j )
{
const long long mpos = file_index.mblock( j ).pos();
const long long msize = file_index.mblock( j ).size();
@@ -284,26 +285,21 @@ bool copy_file( const int infd, const int outfd, const long long max_size )
bool try_decompress_member( const int fd, const unsigned long long msize,
long long * failure_posp )
{
- try {
- Range_decoder rdec( fd );
- File_header header;
- rdec.read_data( header.data, File_header::size );
- if( !rdec.finished() && // End Of File
- header.verify_magic() && header.verify_version() &&
- header.dictionary_size() >= min_dictionary_size &&
- header.dictionary_size() <= max_dictionary_size )
- {
- LZ_decoder decoder( header, rdec, -1 );
- Pretty_print dummy( "", -1 );
+ Range_decoder rdec( fd );
+ File_header header;
+ rdec.read_data( header.data, File_header::size );
+ if( !rdec.finished() && // End Of File
+ header.verify_magic() && header.verify_version() &&
+ header.dictionary_size() >= min_dictionary_size &&
+ header.dictionary_size() <= max_dictionary_size )
+ {
+ LZ_decoder decoder( header, rdec, -1 );
+ Pretty_print dummy( "", -1 );
- if( decoder.decode_member( dummy ) == 0 &&
- rdec.member_position() == msize ) return true;
- if( failure_posp ) *failure_posp = rdec.member_position();
- }
+ if( decoder.decode_member( dummy ) == 0 &&
+ rdec.member_position() == msize ) return true;
+ if( failure_posp ) *failure_posp = rdec.member_position();
}
- catch( std::bad_alloc )
- { show_error( "Not enough memory." ); std::exit( 1 ); }
- catch( Error e ) {}
return false;
}
@@ -325,7 +321,7 @@ int merge_files( const std::vector< std::string > & filenames,
if( !copy_file( infd_vector[0], outfd ) ) // copy whole file
cleanup_and_fail( output_filename, outfd, 1 );
- for( int j = 0; j < file_index.members(); ++j )
+ for( long j = 0; j < file_index.members(); ++j )
{
const long long mpos = file_index.mblock( j ).pos();
const long long msize = file_index.mblock( j ).size();
@@ -360,7 +356,7 @@ int merge_files( const std::vector< std::string > & filenames,
if( verbosity >= 1 && file_index.members() > 1 )
{
- std::printf( "Merging member %d\n", j + 1 );
+ std::printf( "Merging member %ld\n", j + 1 );
std::fflush( stdout );
}
const int base_variations = ipow( files, block_vector.size() );
@@ -378,11 +374,10 @@ int merge_files( const std::vector< std::string > & filenames,
{
const int infd = infd_vector[tmp % files];
tmp /= files;
- if( lseek( infd, block_vector[i].pos(), SEEK_SET ) < 0 ||
- lseek( outfd, block_vector[i].pos(), SEEK_SET ) < 0 ||
+ if( !safe_seek( infd, block_vector[i].pos() ) ||
+ !safe_seek( outfd, block_vector[i].pos() ) ||
!copy_file( infd, outfd, block_vector[i].size() ) )
- { show_error( "Error reading output file", errno );
- cleanup_and_fail( output_filename, outfd, 1 ); }
+ cleanup_and_fail( output_filename, outfd, 1 );
}
if( !safe_seek( outfd, mpos ) )
cleanup_and_fail( output_filename, outfd, 1 );