summaryrefslogtreecommitdiffstats
path: root/split.cc
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 10:21:04 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 10:21:04 +0000
commit8ea0538d70bde5c4759fce0f5bda0684517d6d92 (patch)
treece7908218be1fc93e32bdfa1a274358770b7ebb0 /split.cc
parentAdding debian version 1.13-4. (diff)
downloadlziprecover-8ea0538d70bde5c4759fce0f5bda0684517d6d92.tar.xz
lziprecover-8ea0538d70bde5c4759fce0f5bda0684517d6d92.zip
Merging upstream version 1.14~rc1.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'split.cc')
-rw-r--r--split.cc22
1 files changed, 11 insertions, 11 deletions
diff --git a/split.cc b/split.cc
index 786d6e9..88cdbfa 100644
--- a/split.cc
+++ b/split.cc
@@ -1,5 +1,5 @@
/* Lziprecover - Data recovery tool for lzipped files
- Copyright (C) 2009, 2010, 2011, 2012 Antonio Diaz Diaz.
+ Copyright (C) 2009, 2010, 2011, 2012, 2013 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
@@ -83,7 +83,8 @@ int find_magic( const uint8_t * const buffer, const int pos, const int size )
int do_split_file( const std::string & input_filename, uint8_t * & base_buffer,
- const std::string & default_output_filename, const bool force )
+ const std::string & default_output_filename,
+ const int verbosity, const bool force )
{
const int hsize = File_header::size;
const int tsize = File_trailer::size();
@@ -99,16 +100,16 @@ int do_split_file( const std::string & input_filename, uint8_t * & base_buffer,
bool at_stream_end = ( size < buffer_size );
if( size != buffer_size && errno )
{ show_error( "Read error", errno ); return 1; }
- if( size <= tsize )
+ if( size < min_member_size )
{ show_error( "Input file is too short." ); return 2; }
- if( !verify_header( *(File_header *)buffer ) ) return 2;
+ if( !verify_header( *(File_header *)buffer, verbosity ) ) return 2;
std::string output_filename;
first_filename( input_filename, default_output_filename, output_filename );
int outfd = open_outstream_rw( output_filename, force );
if( outfd < 0 ) { close( infd ); return 1; }
- long long partial_member_size = 0;
+ unsigned long long partial_member_size = 0;
while( true )
{
int pos = 0;
@@ -117,10 +118,8 @@ int do_split_file( const std::string & input_filename, uint8_t * & base_buffer,
newpos = find_magic( buffer, newpos, size + 4 - newpos );
if( newpos <= size )
{
- long long member_size = 0;
- for( int i = 1; i <= 8; ++i )
- { member_size <<= 8; member_size += base_buffer[tsize+newpos-i]; }
- if( partial_member_size + newpos - pos == member_size )
+ const File_trailer & trailer = *(File_trailer *)(base_buffer + newpos);
+ if( partial_member_size + newpos - pos == trailer.member_size() )
{ // header found
const int wr = writeblock( outfd, buffer + pos, newpos - pos );
if( wr != newpos - pos )
@@ -167,11 +166,12 @@ int do_split_file( const std::string & input_filename, uint8_t * & base_buffer,
int split_file( const std::string & input_filename,
- const std::string & default_output_filename, const bool force )
+ const std::string & default_output_filename,
+ const int verbosity, const bool force )
{
uint8_t * base_buffer;
const int retval = do_split_file( input_filename, base_buffer,
- default_output_filename, force );
+ default_output_filename, verbosity, force );
delete[] base_buffer;
return retval;
}