summaryrefslogtreecommitdiffstats
path: root/lzcheck.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-23 14:39:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-23 14:39:04 +0000
commit819e0c36ebc8567836ec40be92c07b9a639cdbe3 (patch)
tree71fd5d2bfecb19cbc84572e9759020804a923df9 /lzcheck.c
parentAdding upstream version 1.13. (diff)
downloadlzlib-upstream/1.14.tar.xz
lzlib-upstream/1.14.zip
Adding upstream version 1.14.upstream/1.14
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lzcheck.c')
-rw-r--r--lzcheck.c55
1 files changed, 44 insertions, 11 deletions
diff --git a/lzcheck.c b/lzcheck.c
index 88dd4c9..4f4bf9f 100644
--- a/lzcheck.c
+++ b/lzcheck.c
@@ -1,5 +1,5 @@
/* Lzcheck - Test program for the library lzlib
- Copyright (C) 2009-2022 Antonio Diaz Diaz.
+ Copyright (C) 2009-2024 Antonio Diaz Diaz.
This program is free software: you have unlimited permission
to copy, distribute, and modify it.
@@ -26,7 +26,7 @@
const unsigned long long member_size = INT64_MAX;
-enum { buffer_size = 32768 };
+enum { buffer_size = 32749 }; /* largest prime < 32768 */
uint8_t in_buffer[buffer_size];
uint8_t mid_buffer[buffer_size];
uint8_t out_buffer[buffer_size];
@@ -62,6 +62,7 @@ static struct LZ_Encoder * xopen_encoder( const int dictionary_size )
return encoder;
}
+
static struct LZ_Decoder * xopen_decoder( void )
{
struct LZ_Decoder * const decoder = LZ_decompress_open();
@@ -171,17 +172,49 @@ static int check_sync_flush( FILE * const file, const int dictionary_size )
if( line_size <= 0 ) break; /* end of file */
in_size = LZ_compress_write( encoder, line_buf, line_size );
+ if( in_size < 0 )
+ {
+ fprintf( stderr, "lzcheck: LZ_compress_write error: %s\n",
+ LZ_strerror( LZ_compress_errno( encoder ) ) );
+ retval = 3; break;
+ }
if( in_size < line_size )
- fprintf( stderr, "lzcheck: sync: LZ_compress_write only accepted %d of %d bytes\n",
- in_size, line_size );
- LZ_compress_sync_flush( encoder );
- if( line_buf[0] & 1 ) /* read all data at once or byte by byte */
- mid_size = LZ_compress_read( encoder, mid_buffer, buffer_size );
- else for( mid_size = 0; mid_size < buffer_size; )
{
- const int rd = LZ_compress_read( encoder, mid_buffer + mid_size, 1 );
+ fprintf( stderr, "lzcheck: sync: LZ_compress_write only accepted %d "
+ "of %d bytes\n", in_size, line_size );
+ mid_size = LZ_compress_read( encoder, mid_buffer, buffer_size );
+ const int wr =
+ LZ_compress_write( encoder, line_buf + in_size, line_size - in_size );
+ if( wr < 0 )
+ {
+ fprintf( stderr, "lzcheck: LZ_compress_write error: %s\n",
+ LZ_strerror( LZ_compress_errno( encoder ) ) );
+ retval = 3; break;
+ }
+ if( wr + in_size != line_size )
+ {
+ fprintf( stderr, "lzcheck: sync: LZ_compress_write only accepted %d "
+ "of %d remaining bytes\n", wr, line_size - in_size );
+ retval = 3; break;
+ }
+ in_size += wr;
+ LZ_compress_sync_flush( encoder );
+ const int rd = LZ_compress_read( encoder, mid_buffer + mid_size,
+ buffer_size - mid_size );
if( rd > 0 ) mid_size += rd;
- else { if( rd < 0 ) { mid_size = -1; } break; }
+ else if( rd < 0 ) mid_size = -1;
+ }
+ else
+ {
+ LZ_compress_sync_flush( encoder );
+ if( line_buf[0] & 1 ) /* read all data at once or byte by byte */
+ mid_size = LZ_compress_read( encoder, mid_buffer, buffer_size );
+ else for( mid_size = 0; mid_size < buffer_size; )
+ {
+ const int rd = LZ_compress_read( encoder, mid_buffer + mid_size, 1 );
+ if( rd > 0 ) mid_size += rd;
+ else { if( rd < 0 ) { mid_size = -1; } break; }
+ }
}
if( mid_size < 0 )
{
@@ -344,7 +377,7 @@ int main( const int argc, const char * const argv[] )
FILE * file = fopen( argv[i], "rb" );
if( !file )
{
- fprintf( stderr, "lzcheck: Can't open file '%s' for reading.\n", argv[i] );
+ fprintf( stderr, "lzcheck: %s: Can't open file for reading.\n", argv[i] );
++open_failures; continue;
}
if( verbose ) fprintf( stderr, " Testing file '%s'\n", argv[i] );