From 1ed437c55879912627b4f4fcd02cf07866cb48bb Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 7 Nov 2015 12:45:06 +0100 Subject: Adding upstream version 1.16~pre1. Signed-off-by: Daniel Baumann --- split.cc | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'split.cc') diff --git a/split.cc b/split.cc index b61f4eb..8eafd82 100644 --- a/split.cc +++ b/split.cc @@ -1,5 +1,5 @@ /* Lziprecover - Data recovery tool for lzip files - Copyright (C) 2009, 2010, 2011, 2012, 2013 Antonio Diaz Diaz. + Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 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 @@ -62,6 +62,25 @@ bool next_filename( std::string & output_filename, const int max_digits ) } +bool verify_header( const File_header & header, const Pretty_print & pp ) + { + if( !header.verify_magic() ) + { + pp( "Bad magic number (file not in lzip format)." ); + return false; + } + if( !header.verify_version() ) + { + if( pp.verbosity() >= 0 ) + { pp(); + std::fprintf( stderr, "Version %d member format not supported.\n", + header.version() ); } + return false; + } + return true; + } + + // Search forward from 'pos' for "LZIP" (Boyer-Moore algorithm) // Return pos of found string or 'pos+size' if not found. // @@ -97,21 +116,22 @@ int do_split_file( const std::string & input_filename, uint8_t * & base_buffer, uint8_t * const buffer = base_buffer + tsize; struct stat in_stats; - const int infd = open_instream( input_filename, &in_stats, true, true ); + const int infd = open_instream( input_filename.c_str(), &in_stats, true, true ); if( infd < 0 ) return 1; - const File_index file_index( infd ); - if( file_index.retval() != 0 ) show_error( file_index.error().c_str() ); - const int max_members = ( file_index.retval() ? 999999 : file_index.members() ); - int max_digits = 1; - for( int i = max_members; i >= 10; i /= 10 ) ++max_digits; - + Pretty_print pp( input_filename, verbosity ); int size = seek_read( infd, buffer, buffer_size + hsize, 0 ) - hsize; bool at_stream_end = ( size < buffer_size ); if( size != buffer_size && errno ) { show_error( "Read error", errno ); return 1; } if( size < min_member_size ) - { show_error( "Input file is too short." ); return 2; } - if( !verify_header( *(File_header *)buffer, verbosity ) ) return 2; + { pp( "Input file is too short." ); return 2; } + if( !verify_header( *(File_header *)buffer, pp ) ) return 2; + + const File_index file_index( infd ); + if( file_index.retval() != 0 ) pp( file_index.error().c_str() ); + const int max_members = file_index.retval() ? 999999 : file_index.members(); + int max_digits = 1; + for( int i = max_members; i >= 10; i /= 10 ) ++max_digits; std::string output_filename; first_filename( input_filename, default_output_filename, output_filename, -- cgit v1.2.3