summaryrefslogtreecommitdiffstats
path: root/in_place.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2020-05-03 15:08:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2020-05-03 15:08:43 +0000
commitbaa87c84edd812698e37703a897a4a40323b70e4 (patch)
tree2f24a127737c770262cafd56fc537c8994172814 /in_place.c
parentReleasing debian version 0.4-9. (diff)
downloadxlunzip-baa87c84edd812698e37703a897a4a40323b70e4.tar.xz
xlunzip-baa87c84edd812698e37703a897a4a40323b70e4.zip
Merging upstream version 0.5.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'in_place.c')
-rw-r--r--in_place.c42
1 files changed, 14 insertions, 28 deletions
diff --git a/in_place.c b/in_place.c
index 68227cf..1ada24e 100644
--- a/in_place.c
+++ b/in_place.c
@@ -1,5 +1,5 @@
/* Xlunzip - Test tool for the lzip_decompress linux module
- Copyright (C) 2016-2018 Antonio Diaz Diaz.
+ Copyright (C) 2016-2020 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -33,7 +33,7 @@
/* Returns the number of bytes really read.
If (returned value < size) and (errno == 0), means EOF was reached.
*/
-long readblock( const int fd, uint8_t * const buf, const long size )
+static long readblock( const int fd, uint8_t * const buf, const long size )
{
long sz = 0;
errno = 0;
@@ -53,30 +53,30 @@ long readblock( const int fd, uint8_t * const buf, const long size )
the buffer and file sizes in '*buffer_sizep' and '*file_sizep'.
In case of error, returns 0 and does not modify '*size'.
*/
-uint8_t * read_file( const int infd, long * const buffer_sizep,
- long * const file_sizep, struct Pretty_print * const pp )
+static uint8_t * read_file( const int infd, long * const buffer_sizep,
+ long * const file_sizep, const char * const filename )
{
long buffer_size = 1 << 20;
uint8_t * buffer = (uint8_t *)malloc( buffer_size );
if( !buffer )
- { show_file_error( pp->name, "Not enough memory.", 0 ); return 0; }
+ { show_file_error( filename, "Not enough memory.", 0 ); return 0; }
long file_size = readblock( infd, buffer, buffer_size );
while( file_size >= buffer_size && !errno )
{
if( buffer_size >= LONG_MAX )
- { show_file_error( pp->name, "File is too large.", 0 ); free( buffer );
+ { show_file_error( filename, "File is too large.", 0 ); free( buffer );
return 0; }
buffer_size = ( buffer_size <= LONG_MAX / 2 ) ? 2 * buffer_size : LONG_MAX;
uint8_t * const tmp = (uint8_t *)realloc( buffer, buffer_size );
if( !tmp )
- { show_file_error( pp->name, "Not enough memory.", 0 ); free( buffer );
+ { show_file_error( filename, "Not enough memory.", 0 ); free( buffer );
return 0; }
buffer = tmp;
file_size += readblock( infd, buffer + file_size, buffer_size - file_size );
}
if( errno )
- { show_file_error( pp->name, "Error reading file", errno ); free( buffer );
+ { show_file_error( filename, "Error reading file", errno ); free( buffer );
return 0; }
*buffer_sizep = buffer_size;
*file_sizep = file_size;
@@ -91,9 +91,10 @@ struct File_sizes
long trailing;
};
-const char * set_file_sizes( struct File_sizes * const file_sizes,
- const uint8_t * const buffer, const long file_size )
+static const char * set_file_sizes( struct File_sizes * const file_sizes,
+ const uint8_t * const buffer, const long file_size )
{
+ if( file_size <= Lh_size ) return "File ends unexpectedly at member header.";
if( file_size < min_member_size ) return "Input file is too short.";
const Lzip_header * header = (const Lzip_header *)buffer;
if( !Lh_verify_magic( *header ) )
@@ -146,7 +147,7 @@ const char * set_file_sizes( struct File_sizes * const file_sizes,
}
-const char * global_name;
+static const char * global_name; /* copy of filename for 'error' */
static void error(char *x) { show_file_error( global_name, x, 0 ); }
@@ -166,7 +167,7 @@ int decompress_in_place( const int infd, struct Pretty_print * const pp,
const bool testing )
{
long buffer_size = 0, file_size = 0;
- uint8_t * buffer = read_file( infd, &buffer_size, &file_size, pp );
+ uint8_t * buffer = read_file( infd, &buffer_size, &file_size, pp->name );
if( !buffer ) return 1;
struct File_sizes file_sizes;
const char * emsg = set_file_sizes( &file_sizes, buffer, file_size );
@@ -201,21 +202,6 @@ int decompress_in_place( const int infd, struct Pretty_print * const pp,
}
free( buffer );
if( retval ) return retval;
- if( verbosity >= 1 ) Pp_show_msg( pp, 0 );
- if( verbosity >= 2 )
- {
- if( out_pos <= 0 || in_pos <= 0 )
- fputs( "no data compressed. ", stderr );
- else
- fprintf( stderr, "%6.3f:1, %5.2f%% ratio, %5.2f%% saved. ",
- (double)out_pos / in_pos,
- ( 100.0 * in_pos ) / out_pos,
- 100.0 - ( ( 100.0 * in_pos ) / out_pos ) );
- if( verbosity >= 3 )
- fprintf( stderr, "decompressed %9lu, compressed %8lu. ",
- out_pos, in_pos );
- }
- if( verbosity >= 1 )
- fputs( testing ? "ok\n" : "done\n", stderr );
+ show_results( pp, in_pos, out_pos, testing );
return 0;
}