summaryrefslogtreecommitdiffstats
path: root/lzip.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2018-02-13 07:48:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2018-02-13 07:48:44 +0000
commitbb5c150ab495d201ec035b246c6cd7e204dd74c1 (patch)
tree72e60508f9e4adce2b041efd3ac2314185b012f4 /lzip.h
parentReleasing progress-linux version 1.8-4~dschinn1. (diff)
downloadpdlzip-bb5c150ab495d201ec035b246c6cd7e204dd74c1.zip
pdlzip-bb5c150ab495d201ec035b246c6cd7e204dd74c1.tar.xz
Merging upstream version 1.9.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lzip.h')
-rw-r--r--lzip.h39
1 files changed, 32 insertions, 7 deletions
diff --git a/lzip.h b/lzip.h
index 631599d..0f65f30 100644
--- a/lzip.h
+++ b/lzip.h
@@ -1,5 +1,5 @@
/* Pdlzip - LZMA lossless data compressor
- Copyright (C) 2010-2017 Antonio Diaz Diaz.
+ Copyright (C) 2010-2018 Antonio Diaz Diaz.
This program is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
@@ -24,6 +24,8 @@
#define min(x,y) ((x) <= (y) ? (x) : (y))
#endif
+void * resize_buffer( void * buf, const unsigned min_size );
+
typedef int State;
enum {
@@ -50,9 +52,13 @@ enum {
min_match_len_limit = 5 };
+/* defined in main.c */
+extern int verbosity;
+
struct Pretty_print
{
const char * name;
+ char * padded_name;
const char * stdin_name;
unsigned longest_name;
bool first_post;
@@ -60,11 +66,12 @@ struct Pretty_print
static inline void Pp_init( struct Pretty_print * const pp,
const char * const filenames[],
- const int num_filenames, const int verbosity )
+ const int num_filenames )
{
unsigned stdin_name_len;
int i;
pp->name = 0;
+ pp->padded_name = 0;
pp->stdin_name = "(stdin)";
pp->longest_name = 0;
pp->first_post = false;
@@ -83,9 +90,19 @@ static inline void Pp_init( struct Pretty_print * const pp,
static inline void Pp_set_name( struct Pretty_print * const pp,
const char * const filename )
{
+ unsigned name_len, padded_name_len, i = 0;
+
if( filename && filename[0] && strcmp( filename, "-" ) != 0 )
pp->name = filename;
else pp->name = pp->stdin_name;
+ name_len = strlen( pp->name );
+ padded_name_len = max( name_len, pp->longest_name ) + 4;
+ pp->padded_name = resize_buffer( pp->padded_name, padded_name_len + 1 );
+ while( i < 2 ) pp->padded_name[i++] = ' ';
+ while( i < name_len + 2 ) { pp->padded_name[i] = pp->name[i-2]; ++i; }
+ pp->padded_name[i++] = ':';
+ while( i < padded_name_len ) pp->padded_name[i++] = ' ';
+ pp->padded_name[i] = 0;
pp->first_post = true;
}
@@ -149,12 +166,21 @@ static inline void Fh_set_magic( File_header data )
static inline bool Fh_verify_magic( const File_header data )
{ return ( memcmp( data, magic_string, 4 ) == 0 ); }
-/* detect truncated header */
-static inline bool Fh_verify_prefix( const File_header data, const int size )
+/* detect (truncated) header */
+static inline bool Fh_verify_prefix( const File_header data, const int sz )
{
- int i; for( i = 0; i < size && i < 4; ++i )
+ int i; for( i = 0; i < sz && i < 4; ++i )
if( data[i] != magic_string[i] ) return false;
- return ( size > 0 );
+ return ( sz > 0 );
+ }
+
+/* detect corrupt header */
+static inline bool Fh_verify_corrupt( const File_header data )
+ {
+ int matches = 0;
+ int i; for( i = 0; i < 4; ++i )
+ if( data[i] == magic_string[i] ) ++matches;
+ return ( matches > 1 && matches < 4 );
}
static inline uint8_t Fh_version( const File_header data )
@@ -233,7 +259,6 @@ int readblock( const int fd, uint8_t * const buf, const int size );
int writeblock( const int fd, const uint8_t * const buf, const int size );
/* defined in main.c */
-extern int verbosity;
void cleanup_and_fail( const int retval );
void show_error( const char * const msg, const int errcode, const bool help );
void show_file_error( const char * const filename, const char * const msg,