summaryrefslogtreecommitdiffstats
path: root/lzcheck.cc
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 13:38:34 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 13:38:34 +0000
commit63af4e067acaebd2c134bcef91755c1be7eb3535 (patch)
tree7b36db2d56f6d6f129ba6a7d0467523fa21c10f0 /lzcheck.cc
parentAdding debian version 0.8-1. (diff)
downloadlzlib-63af4e067acaebd2c134bcef91755c1be7eb3535.tar.xz
lzlib-63af4e067acaebd2c134bcef91755c1be7eb3535.zip
Merging upstream version 0.9.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'lzcheck.cc')
-rw-r--r--lzcheck.cc59
1 files changed, 58 insertions, 1 deletions
diff --git a/lzcheck.cc b/lzcheck.cc
index 75f64c7..b54f525 100644
--- a/lzcheck.cc
+++ b/lzcheck.cc
@@ -82,7 +82,64 @@ int main( const int argc, const char * argv[] )
}
int retval = 0;
- while( retval <= 2 )
+ while( retval <= 1 )
+ {
+ const int read_size = std::fread( in_buffer, 1, buffer_size, file );
+ if( read_size <= 0 ) break; // end of file
+
+ for( int l = 0, r = 1; r <= read_size; l = r, ++r )
+ {
+ while( r < read_size && in_buffer[r-1] != '\n' ) ++r;
+ const int in_size = LZ_compress_write( encoder, in_buffer + l, r - l );
+ if( in_size < r - l ) r = l + in_size;
+ LZ_compress_sync_flush( encoder );
+ const int mid_size = LZ_compress_read( encoder, mid_buffer, buffer_size );
+ if( mid_size < 0 )
+ {
+ std::fprintf( stderr, "LZ_compress_read error: %s.\n",
+ LZ_strerror( LZ_compress_errno( encoder ) ) );
+ retval = 3; break;
+ }
+ LZ_decompress_write( decoder, mid_buffer, mid_size );
+ const int out_size = LZ_decompress_read( decoder, out_buffer, buffer_size );
+ if( out_size < 0 )
+ {
+ std::fprintf( stderr, "LZ_decompress_read error: %s.\n",
+ LZ_strerror( LZ_decompress_errno( decoder ) ) );
+ retval = 3; break;
+ }
+
+ if( out_size != in_size || std::memcmp( in_buffer + l, out_buffer, out_size ) )
+ {
+ std::fprintf( stderr, "sync error at pos %d. in_size = %d, out_size = %d\n",
+ l, in_size, out_size );
+ for( int i = 0; i < in_size; ++i )
+ std::fputc( in_buffer[l+i], stderr );
+ if( in_buffer[l+in_size-1] != '\n' )
+ std::fputc( '\n', stderr );
+ for( int i = 0; i < out_size; ++i )
+ std::fputc( out_buffer[i], stderr );
+ std::fputc( '\n', stderr );
+ retval = 1;
+ }
+ }
+ }
+
+ if( retval <= 1 )
+ {
+ std::rewind( file );
+ if( LZ_compress_finish( encoder ) < 0 ||
+ LZ_decompress_write( decoder, mid_buffer, LZ_compress_read( encoder, mid_buffer, buffer_size ) ) < 0 ||
+ LZ_decompress_read( decoder, out_buffer, buffer_size ) != 0 ||
+ LZ_compress_restart_member( encoder, member_size ) < 0 )
+ {
+ std::fprintf( stderr, "can't finish member: %s.\n",
+ LZ_strerror( LZ_decompress_errno( decoder ) ) );
+ retval = 3;
+ }
+ }
+
+ while( retval <= 1 )
{
const int read_size = std::fread( in_buffer, 1, buffer_size / 2, file );
if( read_size <= 0 ) break; // end of file