From 8077412ee54bfc991fa5c4afedef24189e7192a9 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 23 Mar 2011 01:51:40 +1100 Subject: [PATCH] Allow files with non-standard extensions to be tested or decompressed if they actually exist. Don't allow a suffix if an actual output filename has been specified. Convert ints to chars when they can be. --- lrzip.c | 12 ++++++++++-- lrzip_private.h | 8 ++++---- main.c | 3 +++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lrzip.c b/lrzip.c index eaea3f5..d90ec65 100644 --- a/lrzip.c +++ b/lrzip.c @@ -531,7 +531,11 @@ void decompress_file(rzip_control *control) struct statvfs fbuf; if (!STDIN) { - if ((tmp = strrchr(control->infile, '.')) && strcmp(tmp,control->suffix)) { + struct stat fdin_stat; + + stat(control->infile, &fdin_stat); + if (!S_ISREG(fdin_stat.st_mode) && (tmp = strrchr(control->infile, '.')) && + strcmp(tmp,control->suffix)) { /* make sure infile has an extension. If not, add it * because manipulations may be made to input filename, set local ptr */ @@ -747,7 +751,11 @@ void get_fileinfo(rzip_control *control) struct stat st; if (!STDIN) { - if ((tmp = strrchr(control->infile, '.')) && strcmp(tmp,control->suffix)) { + struct stat fdin_stat; + + stat(control->infile, &fdin_stat); + if (!S_ISREG(fdin_stat.st_mode) && (tmp = strrchr(control->infile, '.')) && + strcmp(tmp,control->suffix)) { infilecopy = malloc(strlen(control->infile) + strlen(control->suffix) + 1); if (unlikely(infilecopy == NULL)) fatal("Failed to allocate memory for infile suffix\n"); diff --git a/lrzip_private.h b/lrzip_private.h index 0c6d941..cf67926 100644 --- a/lrzip_private.h +++ b/lrzip_private.h @@ -207,7 +207,7 @@ struct rzip_control { i64 in_maxlen; FILE *msgout; //stream for output messages const char *suffix; - int compression_level; + uchar compression_level; i64 overhead; // compressor overhead i64 usable_ram; // the most ram we'll try to use on one activity i64 maxram; // the largest chunk of ram to allocate @@ -218,7 +218,7 @@ struct rzip_control { i64 max_chunk; i64 max_mmap; int threads; - int nice_val; // added for consistency + char nice_val; // added for consistency char major_version; char minor_version; i64 st_size; @@ -243,7 +243,7 @@ struct stream { uchar *buf; i64 buflen; i64 bufp; - int eos; + uchar eos; long uthread_no; long unext_thread; long base_thread; @@ -253,7 +253,7 @@ struct stream { struct stream_info { struct stream *s; - int num_streams; + uchar num_streams; int fd; i64 bufsize; i64 cur_pos; diff --git a/main.c b/main.c index c9d3ba6..92d90a9 100644 --- a/main.c +++ b/main.c @@ -603,6 +603,7 @@ int main(int argc, char *argv[]) if (control.outdir) failure("Cannot have -o and -O together\n"); control.outname = optarg; + control.suffix = ""; break; case 'O': if (control.outname) /* can't mix -o and -O */ @@ -623,6 +624,8 @@ int main(int argc, char *argv[]) control.flags &= ~FLAG_SHOW_PROGRESS; break; case 'S': + if (control.outname) + failure("Specified output filename already, can't specify an extension.\n"); control.suffix = optarg; break; case 't':