summaryrefslogtreecommitdiffstats
path: root/range_dec.cc
diff options
context:
space:
mode:
Diffstat (limited to 'range_dec.cc')
-rw-r--r--range_dec.cc29
1 files changed, 15 insertions, 14 deletions
diff --git a/range_dec.cc b/range_dec.cc
index 062427a..d4a2b2c 100644
--- a/range_dec.cc
+++ b/range_dec.cc
@@ -72,16 +72,13 @@ int decompress_member( const int infd, const int outfd,
if( pp.verbosity() >= 0 && result <= 2 )
{
pp();
- if( result == 2 )
- std::fprintf( stderr, "File ends unexpectedly at pos %llu.\n",
- mpos + rdec.member_position() );
- else
- std::fprintf( stderr, "Decoder error at pos %llu.\n",
- mpos + rdec.member_position() );
+ std::fprintf( stderr, "%s at pos %llu\n", ( result == 2 ) ?
+ "File ends unexpectedly" : "Decoder error",
+ mpos + rdec.member_position() );
}
return 2;
}
- if( pp.verbosity() >= 2 ) std::fprintf( stderr, "done\n" );
+ if( pp.verbosity() >= 2 ) std::fputs( "done\n", stderr );
}
catch( std::bad_alloc ) { pp( "Not enough memory." ); return 1; }
catch( Error e ) { pp(); show_error( e.msg, errno ); return 1; }
@@ -115,7 +112,7 @@ int list_file( const char * const input_filename, const Pretty_print & pp )
if( pp.verbosity() >= 1 && file_index.members() > 1 )
{
- std::printf( " Total members in file = %ld.\n", file_index.members() );
+ std::printf( " Total members in file = %ld\n", file_index.members() );
if( pp.verbosity() >= 2 )
for( long i = 0; i < file_index.members(); ++i )
{
@@ -141,18 +138,21 @@ const char * format_num( unsigned long long num,
{ "k", "M", "G", "T", "P", "E", "Z", "Y" };
const char * const binary_prefix[8] =
{ "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" };
+ enum { buffers = 8, bufsize = 32 };
+ static char buffer[buffers][bufsize]; // circle of static buffers for printf
+ static int current = 0;
static bool si = true;
- static char buf[32];
if( set_prefix ) si = ( set_prefix > 0 );
const unsigned factor = ( si ? 1000 : 1024 );
+ char * const buf = buffer[current++]; current %= buffers;
const char * const * prefix = ( si ? si_prefix : binary_prefix );
const char * p = "";
bool exact = ( num % factor == 0 );
for( int i = 0; i < 8 && ( num > limit || ( exact && num >= factor ) ); ++i )
{ num /= factor; if( num % factor != 0 ) exact = false; p = prefix[i]; }
- snprintf( buf, sizeof buf, "%llu %s", num, p );
+ snprintf( buf, bufsize, "%llu %s", num, p );
return buf;
}
@@ -203,9 +203,10 @@ int range_decompress( const std::string & input_filename,
if( verbosity >= 2 )
std::fprintf( stderr, "Decompressed file size = %sB\n",
format_num( file_index.data_end() ) );
- std::fprintf( stderr, "Decompressing range %sB", format_num( range.pos() ) );
- std::fprintf( stderr, " to %sB ", format_num( range.pos() + range.size() ) );
- std::fprintf( stderr, "(%sBytes)\n", format_num( range.size() ) );
+ std::fprintf( stderr, "Decompressing range %sB to %sB (%sBytes)\n",
+ format_num( range.pos() ),
+ format_num( range.pos() + range.size() ),
+ format_num( range.size() ) );
}
int outfd = -1;
@@ -241,6 +242,6 @@ int range_decompress( const std::string & input_filename,
cleanup_and_fail( output_filename, -1, 1 );
}
if( verbosity >= 2 && retval == 0 )
- std::fprintf( stderr, "Byte range decompressed successfully.\n" );
+ std::fputs( "Byte range decompressed successfully.\n", stderr );
return retval;
}