From e6759ba4e68c66f0927bb89bfb87215eb29016ae Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 20 May 2016 08:54:36 +0200 Subject: Adding upstream version 1.18. Signed-off-by: Daniel Baumann --- split.cc | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'split.cc') diff --git a/split.cc b/split.cc index fc92ea4..dc17580 100644 --- a/split.cc +++ b/split.cc @@ -1,5 +1,5 @@ /* Lziprecover - Data recovery tool for the lzip format - Copyright (C) 2009-2015 Antonio Diaz Diaz. + Copyright (C) 2009-2016 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 @@ -17,6 +17,7 @@ #define _FILE_OFFSET_BITS 64 +#include #include #include #include @@ -36,12 +37,10 @@ namespace { void first_filename( const std::string & input_filename, const std::string & default_output_filename, - std::string & output_filename, const int max_digits ) + const int max_digits ) { - if( default_output_filename.size() ) - output_filename = default_output_filename; - else - output_filename = input_filename; + output_filename = default_output_filename.empty() ? + input_filename : default_output_filename; int b = output_filename.size(); while( b > 0 && output_filename[b-1] != '/' ) --b; output_filename.insert( b, "rec1" ); @@ -49,7 +48,7 @@ void first_filename( const std::string & input_filename, } -bool next_filename( std::string & output_filename, const int max_digits ) +bool next_filename( const int max_digits ) { int b = output_filename.size(); while( b > 0 && output_filename[b-1] != '/' ) --b; @@ -114,11 +113,9 @@ int do_split_file( const std::string & input_filename, uint8_t * & base_buffer, int max_digits = 1; for( long i = max_members; i >= 10; i /= 10 ) ++max_digits; - std::string output_filename; - first_filename( input_filename, default_output_filename, output_filename, - max_digits ); - int outfd = open_outstream_rw( output_filename, force ); - if( outfd < 0 ) { close( infd ); return 1; } + first_filename( input_filename, default_output_filename, max_digits ); + if( !open_outstream( force, false, false, false ) ) + { close( infd ); return 1; } unsigned long long partial_member_size = 0; while( true ) @@ -135,17 +132,16 @@ int do_split_file( const std::string & input_filename, uint8_t * & base_buffer, const int wr = writeblock( outfd, buffer + pos, newpos - pos ); if( wr != newpos - pos ) { show_error( "Write error", errno ); return 1; } - if( close( outfd ) != 0 ) - { show_error( "Error closing output file", errno ); return 1; } + if( close_outstream( &in_stats ) != 0 ) return 1; if( verbosity >= 1 ) { std::printf( "Member '%s' done \r", output_filename.c_str() ); std::fflush( stdout ); } - if( !next_filename( output_filename, max_digits ) ) + if( !next_filename( max_digits ) ) { show_error( "Too many members in file." ); close( infd ); return 1; } - outfd = open_outstream_rw( output_filename, force ); - if( outfd < 0 ) { close( infd ); return 1; } + if( !open_outstream( force, false, false, false ) ) + { close( infd ); return 1; } partial_member_size = 0; pos = newpos; } @@ -173,8 +169,7 @@ int do_split_file( const std::string & input_filename, uint8_t * & base_buffer, { show_error( "Read error", errno ); return 1; } } close( infd ); - if( close( outfd ) != 0 ) - { show_error( "Error closing output file", errno ); return 1; } + if( close_outstream( &in_stats ) != 0 ) return 1; if( verbosity >= 1 ) { std::printf( "Member '%s' done \n", output_filename.c_str() ); -- cgit v1.2.3