2025-02-20 21:31:06 +01:00
|
|
|
/* Buffer to buffer example - Test program for the library lzlib
|
2025-02-20 21:35:19 +01:00
|
|
|
Copyright (C) 2010-2025 Antonio Diaz Diaz.
|
2025-02-20 16:49:45 +01:00
|
|
|
|
2025-02-20 21:31:06 +01:00
|
|
|
This program is free software: you have unlimited permission
|
|
|
|
to copy, distribute, and modify it.
|
2025-02-20 16:49:45 +01:00
|
|
|
|
2025-02-20 21:31:06 +01:00
|
|
|
Usage: bbexample filename
|
2025-02-20 16:49:45 +01:00
|
|
|
|
2025-02-20 21:31:06 +01:00
|
|
|
This program is an example of how buffer-to-buffer
|
|
|
|
compression/decompression can be implemented using lzlib.
|
2025-02-20 16:49:45 +01:00
|
|
|
*/
|
|
|
|
|
2025-02-20 21:31:06 +01:00
|
|
|
#define _FILE_OFFSET_BITS 64
|
|
|
|
|
2025-02-20 21:21:14 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
2025-02-20 16:49:45 +01:00
|
|
|
#include <stdbool.h>
|
2025-02-20 19:59:10 +01:00
|
|
|
#include <stdint.h>
|
2025-02-20 16:49:45 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "lzlib.h"
|
|
|
|
|
2025-02-20 21:31:06 +01:00
|
|
|
#ifndef min
|
|
|
|
#define min(x,y) ((x) <= (y) ? (x) : (y))
|
|
|
|
#endif
|
|
|
|
|
2025-02-20 16:49:45 +01:00
|
|
|
|
2025-02-20 21:32:02 +01:00
|
|
|
/* Return the address of a malloc'd buffer containing the file data and
|
2025-02-20 21:28:08 +01:00
|
|
|
the file size in '*file_sizep'.
|
2025-02-20 21:32:02 +01:00
|
|
|
In case of error, return 0 and do not modify '*file_sizep'.
|
2025-02-20 21:21:14 +01:00
|
|
|
*/
|
2025-02-20 21:28:08 +01:00
|
|
|
uint8_t * read_file( const char * const name, long * const file_sizep )
|
2025-02-20 21:21:14 +01:00
|
|
|
{
|
|
|
|
long buffer_size = 1 << 20, file_size;
|
|
|
|
uint8_t * buffer, * tmp;
|
|
|
|
FILE * const f = fopen( name, "rb" );
|
|
|
|
if( !f )
|
2025-02-20 21:33:45 +01:00
|
|
|
{ fprintf( stderr, "bbexample: %s: Can't open input file: %s\n",
|
2025-02-20 21:31:06 +01:00
|
|
|
name, strerror( errno ) ); return 0; }
|
2025-02-20 21:21:14 +01:00
|
|
|
|
|
|
|
buffer = (uint8_t *)malloc( buffer_size );
|
|
|
|
if( !buffer )
|
2025-02-20 21:31:06 +01:00
|
|
|
{ fputs( "bbexample: read_file: Not enough memory.\n", stderr );
|
|
|
|
fclose( f ); return 0; }
|
2025-02-20 21:21:14 +01:00
|
|
|
file_size = fread( buffer, 1, buffer_size, f );
|
|
|
|
while( file_size >= buffer_size )
|
|
|
|
{
|
|
|
|
if( buffer_size >= LONG_MAX )
|
|
|
|
{
|
2025-02-20 21:33:45 +01:00
|
|
|
fprintf( stderr, "bbexample: %s: Input file is too large.\n", name );
|
2025-02-20 21:31:06 +01:00
|
|
|
free( buffer ); fclose( f ); return 0;
|
2025-02-20 21:21:14 +01:00
|
|
|
}
|
2025-02-20 21:34:58 +01:00
|
|
|
buffer_size = (buffer_size <= LONG_MAX / 2) ? 2 * buffer_size : LONG_MAX;
|
2025-02-20 21:21:14 +01:00
|
|
|
tmp = (uint8_t *)realloc( buffer, buffer_size );
|
|
|
|
if( !tmp )
|
2025-02-20 21:31:06 +01:00
|
|
|
{ fputs( "bbexample: read_file: Not enough memory.\n", stderr );
|
|
|
|
free( buffer ); fclose( f ); return 0; }
|
2025-02-20 21:21:14 +01:00
|
|
|
buffer = tmp;
|
|
|
|
file_size += fread( buffer + file_size, 1, buffer_size - file_size, f );
|
|
|
|
}
|
|
|
|
if( ferror( f ) || !feof( f ) )
|
|
|
|
{
|
2025-02-20 21:33:45 +01:00
|
|
|
fprintf( stderr, "bbexample: %s: Error reading file: %s\n",
|
2025-02-20 21:21:14 +01:00
|
|
|
name, strerror( errno ) );
|
2025-02-20 21:31:06 +01:00
|
|
|
free( buffer ); fclose( f ); return 0;
|
2025-02-20 21:21:14 +01:00
|
|
|
}
|
|
|
|
fclose( f );
|
2025-02-20 21:28:08 +01:00
|
|
|
*file_sizep = file_size;
|
2025-02-20 21:21:14 +01:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-02-20 21:32:02 +01:00
|
|
|
/* Compress 'insize' bytes from 'inbuf'.
|
|
|
|
Return the address of a malloc'd buffer containing the compressed data,
|
2025-02-20 21:31:06 +01:00
|
|
|
and the size of the data in '*outlenp'.
|
2025-02-20 21:32:02 +01:00
|
|
|
In case of error, return 0 and do not modify '*outlenp'.
|
2025-02-20 19:59:10 +01:00
|
|
|
*/
|
2025-02-20 21:31:06 +01:00
|
|
|
uint8_t * bbcompressl( const uint8_t * const inbuf, const long insize,
|
|
|
|
const int level, long * const outlenp )
|
2025-02-20 16:49:45 +01:00
|
|
|
{
|
2025-02-20 21:34:58 +01:00
|
|
|
typedef struct Lzma_options
|
2025-02-20 21:21:14 +01:00
|
|
|
{
|
|
|
|
int dictionary_size; /* 4 KiB .. 512 MiB */
|
|
|
|
int match_len_limit; /* 5 .. 273 */
|
2025-02-20 21:34:58 +01:00
|
|
|
} Lzma_options;
|
2025-02-20 21:33:45 +01:00
|
|
|
/* Mapping from gzip/bzip2 style 0..9 compression levels to the
|
|
|
|
corresponding LZMA compression parameters. */
|
2025-02-20 21:34:58 +01:00
|
|
|
const Lzma_options option_mapping[] =
|
2025-02-20 21:21:14 +01:00
|
|
|
{
|
|
|
|
{ 65535, 16 }, /* -0 (65535,16 chooses fast encoder) */
|
|
|
|
{ 1 << 20, 5 }, /* -1 */
|
|
|
|
{ 3 << 19, 6 }, /* -2 */
|
|
|
|
{ 1 << 21, 8 }, /* -3 */
|
|
|
|
{ 3 << 20, 12 }, /* -4 */
|
|
|
|
{ 1 << 22, 20 }, /* -5 */
|
|
|
|
{ 1 << 23, 36 }, /* -6 */
|
|
|
|
{ 1 << 24, 68 }, /* -7 */
|
|
|
|
{ 3 << 23, 132 }, /* -8 */
|
|
|
|
{ 1 << 25, 273 } }; /* -9 */
|
2025-02-20 21:34:58 +01:00
|
|
|
Lzma_options encoder_options;
|
|
|
|
LZ_Encoder * encoder;
|
2025-02-20 21:31:06 +01:00
|
|
|
uint8_t * outbuf;
|
2025-02-20 21:34:58 +01:00
|
|
|
const long delta_size = insize / 4 + 64; /* insize may be zero */
|
2025-02-20 21:31:06 +01:00
|
|
|
long outsize = delta_size; /* initial outsize */
|
|
|
|
long inpos = 0;
|
|
|
|
long outpos = 0;
|
2025-02-20 20:13:15 +01:00
|
|
|
bool error = false;
|
|
|
|
|
2025-02-20 21:21:14 +01:00
|
|
|
if( level < 0 || level > 9 ) return 0;
|
|
|
|
encoder_options = option_mapping[level];
|
|
|
|
|
2025-02-20 21:31:06 +01:00
|
|
|
if( encoder_options.dictionary_size > insize && level != 0 )
|
|
|
|
encoder_options.dictionary_size = insize; /* saves memory */
|
2025-02-20 21:21:14 +01:00
|
|
|
if( encoder_options.dictionary_size < LZ_min_dictionary_size() )
|
|
|
|
encoder_options.dictionary_size = LZ_min_dictionary_size();
|
|
|
|
encoder = LZ_compress_open( encoder_options.dictionary_size,
|
2025-02-20 21:31:06 +01:00
|
|
|
encoder_options.match_len_limit, INT64_MAX );
|
|
|
|
outbuf = (uint8_t *)malloc( outsize );
|
|
|
|
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok || !outbuf )
|
|
|
|
{ free( outbuf ); LZ_compress_close( encoder ); return 0; }
|
2025-02-20 16:49:45 +01:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2025-02-20 21:31:06 +01:00
|
|
|
int ret = LZ_compress_write( encoder, inbuf + inpos,
|
|
|
|
min( INT_MAX, insize - inpos ) );
|
|
|
|
if( ret < 0 ) { error = true; break; }
|
|
|
|
inpos += ret;
|
|
|
|
if( inpos >= insize ) LZ_compress_finish( encoder );
|
|
|
|
ret = LZ_compress_read( encoder, outbuf + outpos,
|
|
|
|
min( INT_MAX, outsize - outpos ) );
|
|
|
|
if( ret < 0 ) { error = true; break; }
|
|
|
|
outpos += ret;
|
2025-02-20 16:49:45 +01:00
|
|
|
if( LZ_compress_finished( encoder ) == 1 ) break;
|
2025-02-20 21:31:06 +01:00
|
|
|
if( outpos >= outsize )
|
2025-02-20 16:49:45 +01:00
|
|
|
{
|
2025-02-20 21:21:14 +01:00
|
|
|
uint8_t * tmp;
|
2025-02-20 21:31:06 +01:00
|
|
|
if( outsize > LONG_MAX - delta_size ) { error = true; break; }
|
|
|
|
outsize += delta_size;
|
|
|
|
tmp = (uint8_t *)realloc( outbuf, outsize );
|
2025-02-20 16:49:45 +01:00
|
|
|
if( !tmp ) { error = true; break; }
|
2025-02-20 21:31:06 +01:00
|
|
|
outbuf = tmp;
|
2025-02-20 16:49:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( LZ_compress_close( encoder ) < 0 ) error = true;
|
2025-02-20 21:31:06 +01:00
|
|
|
if( error ) { free( outbuf ); return 0; }
|
|
|
|
*outlenp = outpos;
|
|
|
|
return outbuf;
|
2025-02-20 16:49:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-02-20 21:32:02 +01:00
|
|
|
/* Decompress 'insize' bytes from 'inbuf'.
|
|
|
|
Return the address of a malloc'd buffer containing the decompressed
|
2025-02-20 21:31:06 +01:00
|
|
|
data, and the size of the data in '*outlenp'.
|
2025-02-20 21:32:02 +01:00
|
|
|
In case of error, return 0 and do not modify '*outlenp'.
|
2025-02-20 19:59:10 +01:00
|
|
|
*/
|
2025-02-20 21:31:06 +01:00
|
|
|
uint8_t * bbdecompressl( const uint8_t * const inbuf, const long insize,
|
|
|
|
long * const outlenp )
|
2025-02-20 16:49:45 +01:00
|
|
|
{
|
2025-02-20 21:34:58 +01:00
|
|
|
LZ_Decoder * const decoder = LZ_decompress_open();
|
2025-02-20 21:31:06 +01:00
|
|
|
const long delta_size = insize; /* insize must be > zero */
|
|
|
|
long outsize = delta_size; /* initial outsize */
|
|
|
|
uint8_t * outbuf = (uint8_t *)malloc( outsize );
|
|
|
|
long inpos = 0;
|
|
|
|
long outpos = 0;
|
2025-02-20 20:13:15 +01:00
|
|
|
bool error = false;
|
2025-02-20 21:31:06 +01:00
|
|
|
if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok || !outbuf )
|
|
|
|
{ free( outbuf ); LZ_decompress_close( decoder ); return 0; }
|
2025-02-20 16:49:45 +01:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2025-02-20 21:31:06 +01:00
|
|
|
int ret = LZ_decompress_write( decoder, inbuf + inpos,
|
|
|
|
min( INT_MAX, insize - inpos ) );
|
|
|
|
if( ret < 0 ) { error = true; break; }
|
|
|
|
inpos += ret;
|
|
|
|
if( inpos >= insize ) LZ_decompress_finish( decoder );
|
|
|
|
ret = LZ_decompress_read( decoder, outbuf + outpos,
|
|
|
|
min( INT_MAX, outsize - outpos ) );
|
|
|
|
if( ret < 0 ) { error = true; break; }
|
|
|
|
outpos += ret;
|
2025-02-20 16:49:45 +01:00
|
|
|
if( LZ_decompress_finished( decoder ) == 1 ) break;
|
2025-02-20 21:31:06 +01:00
|
|
|
if( outpos >= outsize )
|
2025-02-20 16:49:45 +01:00
|
|
|
{
|
2025-02-20 21:21:14 +01:00
|
|
|
uint8_t * tmp;
|
2025-02-20 21:31:06 +01:00
|
|
|
if( outsize > LONG_MAX - delta_size ) { error = true; break; }
|
|
|
|
outsize += delta_size;
|
|
|
|
tmp = (uint8_t *)realloc( outbuf, outsize );
|
2025-02-20 16:49:45 +01:00
|
|
|
if( !tmp ) { error = true; break; }
|
2025-02-20 21:31:06 +01:00
|
|
|
outbuf = tmp;
|
2025-02-20 16:49:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( LZ_decompress_close( decoder ) < 0 ) error = true;
|
2025-02-20 21:31:06 +01:00
|
|
|
if( error ) { free( outbuf ); return 0; }
|
|
|
|
*outlenp = outpos;
|
|
|
|
return outbuf;
|
2025-02-20 16:49:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-02-20 21:31:06 +01:00
|
|
|
/* Test the whole file at all levels. */
|
|
|
|
int full_test( const uint8_t * const inbuf, const long insize )
|
2025-02-20 16:49:45 +01:00
|
|
|
{
|
2025-02-20 21:21:14 +01:00
|
|
|
int level;
|
2025-02-20 21:31:06 +01:00
|
|
|
for( level = 0; level <= 9; ++level )
|
|
|
|
{
|
|
|
|
long midsize = 0, outsize = 0;
|
|
|
|
uint8_t * outbuf;
|
|
|
|
uint8_t * midbuf = bbcompressl( inbuf, insize, level, &midsize );
|
|
|
|
if( !midbuf )
|
|
|
|
{ fputs( "bbexample: full_test: Not enough memory or compress error.\n",
|
|
|
|
stderr ); return 1; }
|
2025-02-20 20:13:15 +01:00
|
|
|
|
2025-02-20 21:31:06 +01:00
|
|
|
outbuf = bbdecompressl( midbuf, midsize, &outsize );
|
|
|
|
free( midbuf );
|
|
|
|
if( !outbuf )
|
|
|
|
{ fputs( "bbexample: full_test: Not enough memory or decompress error.\n",
|
|
|
|
stderr ); return 1; }
|
|
|
|
|
|
|
|
if( insize != outsize ||
|
|
|
|
( insize > 0 && memcmp( inbuf, outbuf, insize ) != 0 ) )
|
|
|
|
{ fputs( "bbexample: full_test: Decompressed data differs from original.\n",
|
|
|
|
stderr ); free( outbuf ); return 1; }
|
|
|
|
|
|
|
|
free( outbuf );
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-02-20 21:32:02 +01:00
|
|
|
/* Compress 'insize' bytes from 'inbuf' to 'outbuf'.
|
|
|
|
Return the size of the compressed data in '*outlenp'.
|
|
|
|
In case of error, or if 'outsize' is too small, return false and do not
|
|
|
|
modify '*outlenp'.
|
2025-02-20 21:31:06 +01:00
|
|
|
*/
|
|
|
|
bool bbcompress( const uint8_t * const inbuf, const int insize,
|
|
|
|
const int dictionary_size, const int match_len_limit,
|
|
|
|
uint8_t * const outbuf, const int outsize,
|
|
|
|
int * const outlenp )
|
|
|
|
{
|
|
|
|
int inpos = 0, outpos = 0;
|
|
|
|
bool error = false;
|
2025-02-20 21:34:58 +01:00
|
|
|
LZ_Encoder * const encoder =
|
2025-02-20 21:31:06 +01:00
|
|
|
LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX );
|
|
|
|
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
|
|
|
{ LZ_compress_close( encoder ); return false; }
|
|
|
|
|
|
|
|
while( true )
|
2025-02-20 16:49:45 +01:00
|
|
|
{
|
2025-02-20 21:31:06 +01:00
|
|
|
int ret = LZ_compress_write( encoder, inbuf + inpos, insize - inpos );
|
|
|
|
if( ret < 0 ) { error = true; break; }
|
|
|
|
inpos += ret;
|
|
|
|
if( inpos >= insize ) LZ_compress_finish( encoder );
|
|
|
|
ret = LZ_compress_read( encoder, outbuf + outpos, outsize - outpos );
|
|
|
|
if( ret < 0 ) { error = true; break; }
|
|
|
|
outpos += ret;
|
|
|
|
if( LZ_compress_finished( encoder ) == 1 ) break;
|
|
|
|
if( outpos >= outsize ) { error = true; break; }
|
2025-02-20 16:49:45 +01:00
|
|
|
}
|
|
|
|
|
2025-02-20 21:31:06 +01:00
|
|
|
if( LZ_compress_close( encoder ) < 0 ) error = true;
|
|
|
|
if( error ) return false;
|
|
|
|
*outlenp = outpos;
|
|
|
|
return true;
|
|
|
|
}
|
2025-02-20 16:49:45 +01:00
|
|
|
|
2025-02-20 21:31:06 +01:00
|
|
|
|
2025-02-20 21:32:02 +01:00
|
|
|
/* Decompress 'insize' bytes from 'inbuf' to 'outbuf'.
|
|
|
|
Return the size of the decompressed data in '*outlenp'.
|
|
|
|
In case of error, or if 'outsize' is too small, return false and do not
|
|
|
|
modify '*outlenp'.
|
2025-02-20 21:31:06 +01:00
|
|
|
*/
|
|
|
|
bool bbdecompress( const uint8_t * const inbuf, const int insize,
|
|
|
|
uint8_t * const outbuf, const int outsize,
|
|
|
|
int * const outlenp )
|
|
|
|
{
|
|
|
|
int inpos = 0, outpos = 0;
|
|
|
|
bool error = false;
|
2025-02-20 21:34:58 +01:00
|
|
|
LZ_Decoder * const decoder = LZ_decompress_open();
|
2025-02-20 21:31:06 +01:00
|
|
|
if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok )
|
|
|
|
{ LZ_decompress_close( decoder ); return false; }
|
|
|
|
|
|
|
|
while( true )
|
2025-02-20 16:49:45 +01:00
|
|
|
{
|
2025-02-20 21:31:06 +01:00
|
|
|
int ret = LZ_decompress_write( decoder, inbuf + inpos, insize - inpos );
|
|
|
|
if( ret < 0 ) { error = true; break; }
|
|
|
|
inpos += ret;
|
|
|
|
if( inpos >= insize ) LZ_decompress_finish( decoder );
|
|
|
|
ret = LZ_decompress_read( decoder, outbuf + outpos, outsize - outpos );
|
|
|
|
if( ret < 0 ) { error = true; break; }
|
|
|
|
outpos += ret;
|
|
|
|
if( LZ_decompress_finished( decoder ) == 1 ) break;
|
|
|
|
if( outpos >= outsize ) { error = true; break; }
|
|
|
|
}
|
2025-02-20 19:59:10 +01:00
|
|
|
|
2025-02-20 21:31:06 +01:00
|
|
|
if( LZ_decompress_close( decoder ) < 0 ) error = true;
|
|
|
|
if( error ) return false;
|
|
|
|
*outlenp = outpos;
|
|
|
|
return true;
|
|
|
|
}
|
2025-02-20 16:49:45 +01:00
|
|
|
|
|
|
|
|
2025-02-20 21:31:06 +01:00
|
|
|
/* Test at most INT_MAX bytes from the file with buffers of fixed size. */
|
|
|
|
int fixed_test( const uint8_t * const inbuf, const int insize )
|
|
|
|
{
|
|
|
|
int dictionary_size = 65535; /* fast encoder */
|
|
|
|
int midsize = min( INT_MAX, ( insize / 8 ) * 9LL + 44 ), outsize = insize;
|
|
|
|
uint8_t * midbuf = (uint8_t *)malloc( midsize );
|
|
|
|
uint8_t * outbuf = (uint8_t *)malloc( outsize );
|
|
|
|
if( !midbuf || !outbuf )
|
|
|
|
{ fputs( "bbexample: fixed_test: Not enough memory.\n", stderr );
|
|
|
|
free( outbuf ); free( midbuf ); return 1; }
|
|
|
|
|
|
|
|
for( ; dictionary_size <= 8 << 20; dictionary_size += 8323073 )
|
|
|
|
{
|
|
|
|
int midlen, outlen;
|
|
|
|
if( !bbcompress( inbuf, insize, dictionary_size, 16, midbuf, midsize, &midlen ) )
|
|
|
|
{ fputs( "bbexample: fixed_test: Not enough memory or compress error.\n",
|
|
|
|
stderr ); free( outbuf ); free( midbuf ); return 1; }
|
|
|
|
|
|
|
|
if( !bbdecompress( midbuf, midlen, outbuf, outsize, &outlen ) )
|
|
|
|
{ fputs( "bbexample: fixed_test: Not enough memory or decompress error.\n",
|
|
|
|
stderr ); free( outbuf ); free( midbuf ); return 1; }
|
|
|
|
|
|
|
|
if( insize != outlen ||
|
|
|
|
( insize > 0 && memcmp( inbuf, outbuf, insize ) != 0 ) )
|
|
|
|
{ fputs( "bbexample: fixed_test: Decompressed data differs from original.\n",
|
|
|
|
stderr ); free( outbuf ); free( midbuf ); return 1; }
|
2025-02-20 16:49:45 +01:00
|
|
|
|
|
|
|
}
|
2025-02-20 21:31:06 +01:00
|
|
|
free( outbuf );
|
|
|
|
free( midbuf );
|
2025-02-20 16:49:45 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2025-02-20 21:31:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
int main( const int argc, const char * const argv[] )
|
|
|
|
{
|
|
|
|
int retval = 0, i;
|
|
|
|
int open_failures = 0;
|
2025-02-20 21:34:58 +01:00
|
|
|
const bool verbose = argc > 2;
|
2025-02-20 21:31:06 +01:00
|
|
|
|
|
|
|
if( argc < 2 )
|
|
|
|
{
|
|
|
|
fputs( "Usage: bbexample filename\n", stderr );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( i = 1; i < argc && retval == 0; ++i )
|
|
|
|
{
|
|
|
|
long insize;
|
|
|
|
uint8_t * const inbuf = read_file( argv[i], &insize );
|
|
|
|
if( !inbuf ) { ++open_failures; continue; }
|
|
|
|
if( verbose ) fprintf( stderr, " Testing file '%s'\n", argv[i] );
|
|
|
|
|
|
|
|
retval = full_test( inbuf, insize );
|
|
|
|
if( retval == 0 ) retval = fixed_test( inbuf, min( INT_MAX, insize ) );
|
|
|
|
free( inbuf );
|
|
|
|
}
|
|
|
|
if( open_failures > 0 && verbose )
|
|
|
|
fprintf( stderr, "bbexample: warning: %d %s failed to open.\n",
|
|
|
|
open_failures, ( open_failures == 1 ) ? "file" : "files" );
|
|
|
|
if( retval == 0 && open_failures ) retval = 1;
|
|
|
|
return retval;
|
|
|
|
}
|