summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-06 11:31:09 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-06 11:31:09 +0000
commit247ee3b9587f65ca6ec4866f4ef15b986c293f18 (patch)
tree5d758f492403e9750f9f59a44e7a1d13d384b374 /main.c
parentAdding debian version 1.1~rc2-2. (diff)
downloadclzip-247ee3b9587f65ca6ec4866f4ef15b986c293f18.tar.xz
clzip-247ee3b9587f65ca6ec4866f4ef15b986c293f18.zip
Merging upstream version 1.1.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'main.c')
-rw-r--r--main.c67
1 files changed, 37 insertions, 30 deletions
diff --git a/main.c b/main.c
index b4737f8..79a32bd 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,5 @@
/* Clzip - Data compressor based on the LZMA algorithm
- Copyright (C) 2010 Antonio Diaz Diaz.
+ Copyright (C) 2010, 2011 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
@@ -74,7 +74,7 @@ long long int llabs( long long int number );
const char * const Program_name = "Clzip";
const char * const program_name = "clzip";
-const char * const program_year = "2010";
+const char * const program_year = "2011";
const char * invocation_name = 0;
#ifdef O_BINARY
@@ -104,10 +104,15 @@ bool delete_output_on_interrupt = false;
/* assure at least a minimum size for buffer `buf' */
-inline void * resize_buffer( void * buf, const int min_size )
+static void * resize_buffer( void * buf, const int min_size )
{
if( buf ) buf = realloc( buf, min_size );
else buf = malloc( min_size );
+ if( !buf )
+ {
+ show_error( "Not enough memory.", 0, false );
+ cleanup_and_fail( 1 );
+ }
return buf;
}
@@ -124,7 +129,7 @@ static void show_help()
printf( " -d, --decompress decompress\n" );
printf( " -f, --force overwrite existing output files\n" );
printf( " -k, --keep keep (don't delete) input files\n" );
- printf( " -m, --match-length=<n> set match length limit in bytes [80]\n" );
+ printf( " -m, --match-length=<n> set match length limit in bytes [36]\n" );
printf( " -o, --output=<file> if reading stdin, place the output into <file>\n" );
printf( " -q, --quiet suppress all messages\n" );
printf( " -s, --dictionary-size=<n> set dictionary size limit in bytes [8MiB]\n" );
@@ -237,20 +242,6 @@ static int get_dict_size( const char * const arg )
}
-static int extension_index( const char * const name )
- {
- int i;
- for( i = 0; known_extensions[i].from; ++i )
- {
- const char * const ext = known_extensions[i].from;
- if( strlen( name ) > strlen( ext ) &&
- strncmp( name + strlen( name ) - strlen( ext ), ext, strlen( ext ) ) == 0 )
- return i;
- }
- return -1;
- }
-
-
static int open_instream( const char * const name, struct stat * const in_statsp,
const enum Mode program_mode, const int eindex,
const bool force, const bool to_stdout )
@@ -304,6 +295,20 @@ static void set_c_outname( const char * const name, const bool multifile )
}
+static int extension_index( const char * const name )
+ {
+ int i;
+ for( i = 0; known_extensions[i].from; ++i )
+ {
+ const char * const ext = known_extensions[i].from;
+ if( strlen( name ) > strlen( ext ) &&
+ strncmp( name + strlen( name ) - strlen( ext ), ext, strlen( ext ) ) == 0 )
+ return i;
+ }
+ return -1;
+ }
+
+
static void set_d_outname( const char * const name, const int i )
{
if( i >= 0 )
@@ -386,9 +391,10 @@ static void close_and_set_permissions( const struct stat * const in_statsp )
bool error = false;
if( in_statsp )
{
- if( fchmod( outfd, in_statsp->st_mode ) != 0 ||
- ( fchown( outfd, in_statsp->st_uid, in_statsp->st_gid ) != 0 &&
- errno != EPERM ) ) error = true;
+ if( ( fchown( outfd, in_statsp->st_uid, in_statsp->st_gid ) != 0 &&
+ errno != EPERM ) ||
+ fchmod( outfd, in_statsp->st_mode ) != 0 )
+ error = true;
/* fchown will in many cases return with EPERM, which can be safely ignored. */
}
if( close( outfd ) == 0 ) outfd = -1;
@@ -634,7 +640,8 @@ void show_error( const char * const msg, const int errcode, const bool help )
fprintf( stderr, "\n" );
}
if( help && invocation_name && invocation_name[0] )
- fprintf( stderr, "Try `%s --help' for more information.\n", invocation_name );
+ fprintf( stderr, "Try `%s --help' for more information.\n",
+ invocation_name );
}
}
@@ -653,11 +660,11 @@ void internal_error( const char * const msg )
int readblock( const int fd, uint8_t * const buf, const int size )
{
int rest = size;
- errno = 0;
- while( rest > 0 )
+ while( true )
{
int n;
errno = 0;
+ if( rest <= 0 ) break;
n = read( fd, buf + size - rest, rest );
if( n > 0 ) rest -= n;
else if( n == 0 ) break;
@@ -673,11 +680,11 @@ 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 )
{
int rest = size;
- errno = 0;
- while( rest > 0 )
+ while( true )
{
int n;
errno = 0;
+ if( rest <= 0 ) break;
n = write( fd, buf + size - rest, rest );
if( n > 0 ) rest -= n;
else if( errno && errno != EINTR && errno != EAGAIN ) break;
@@ -705,6 +712,10 @@ int main( const int argc, const char * const argv[] )
struct Lzma_options encoder_options = option_mapping[6]; /* default = "-6" */
long long member_size = LLONG_MAX;
long long volume_size = LLONG_MAX;
+ const char * input_filename = "";
+ const char * default_output_filename = "";
+ const char ** filenames = 0;
+ int num_filenames = 0;
int infd = -1;
enum Mode program_mode = m_compress;
int argind = 0;
@@ -714,10 +725,6 @@ int main( const int argc, const char * const argv[] )
bool force = false;
bool keep_input_files = false;
bool to_stdout = false;
- const char * input_filename = "";
- const char * default_output_filename = "";
- const char ** filenames = 0;
- int num_filenames = 0;
struct Pretty_print pp;
const struct ap_Option options[] =