diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-07 13:38:24 +0000 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-07 13:38:24 +0000 |
commit | ea3af4362a8e6a6f6fb44d001336e0c31d46134c (patch) | |
tree | 64b34493522b36c1d86b0fe63e0d855e1d424071 /lzcheck.cc | |
parent | Adding upstream version 0.8. (diff) | |
download | lzlib-ea3af4362a8e6a6f6fb44d001336e0c31d46134c.tar.xz lzlib-ea3af4362a8e6a6f6fb44d001336e0c31d46134c.zip |
Adding upstream version 0.9.upstream/0.9
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'lzcheck.cc')
-rw-r--r-- | lzcheck.cc | 59 |
1 files changed, 58 insertions, 1 deletions
@@ -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 |