From ebfebbfb4b77fa42f84e07b6fe671c56cdd12a35 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 7 Nov 2015 16:29:08 +0100 Subject: Adding upstream version 0.9. Signed-off-by: Daniel Baumann --- ChangeLog | 6 ++++ Makefile.in | 15 +++++----- NEWS | 19 +++--------- arg_parser.cc | 12 ++++---- arg_parser.h | 22 +++++++------- compress.cc | 45 ++++++++++++++++++++++------ configure | 66 ++++++++++++++++------------------------- decompress.cc | 2 +- doc/plzip.1 | 4 +-- doc/plzip.info | 21 ++++++++----- doc/plzip.texinfo | 11 +++++-- main.cc | 87 +++++++++++++----------------------------------------- plzip.h | 66 +++++++++++++++++++++++------------------ testsuite/check.sh | 19 +++++++----- 14 files changed, 194 insertions(+), 201 deletions(-) diff --git a/ChangeLog b/ChangeLog index 15b3c82..bf95a75 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-03-01 Antonio Diaz Diaz + + * Version 0.9 released. + * Minor fixes and cleanups. + * configure: 'datadir' renamed to 'datarootdir'. + 2012-01-17 Antonio Diaz Diaz * Version 0.8 released. diff --git a/Makefile.in b/Makefile.in index 02f9cd8..588ede8 100644 --- a/Makefile.in +++ b/Makefile.in @@ -17,10 +17,10 @@ objs = arg_parser.o compress.o decompress.o main.o all : $(progname) $(progname) : $(objs) - $(CXX) $(LDFLAGS) -o $@ $^ $(LIBS) + $(CXX) $(LDFLAGS) -o $@ $(objs) $(LIBS) $(progname)_profiled : $(objs) - $(CXX) $(LDFLAGS) -pg -o $@ $^ $(LIBS) + $(CXX) $(LDFLAGS) -pg -o $@ $(objs) $(LIBS) main.o : main.cc $(CXX) $(CPPFLAGS) $(CXXFLAGS) -DPROGVERSION=\"$(pkgversion)\" -c -o $@ $< @@ -28,11 +28,12 @@ main.o : main.cc %.o : %.cc $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< -$(objs) : Makefile -arg_parser.o : arg_parser.h -compress.o : plzip.h -decompress.o : plzip.h -main.o : arg_parser.h plzip.h +$(objs) : Makefile +arg_parser.o : arg_parser.h +compress.o : plzip.h +decompress.o : plzip.h +main.o : arg_parser.h plzip.h + doc : info man diff --git a/NEWS b/NEWS index 9cfeae0..472b614 100644 --- a/NEWS +++ b/NEWS @@ -1,17 +1,6 @@ -Changes in version 0.8: +Changes in version 0.9: -The option "-F, --recompress", which forces recompression of files whose -name already has the ".lz" or ".tlz" suffix, has been added. +Minor fixes and cleanups. -The options "-d, --decompress" and "-t, --test" now also show -compression ratio. - -Inability to change output file attributes has been downgraded from -error to warning. - -A small change has been made in the "--help" output and man page. - -Quote characters in messages have been changed as advised by GNU Coding -Standards. - -Stdin and stdout are now set in binary mode on OS2. +Configure option "--datadir" has been renamed to "--datarootdir" to +follow GNU Standards. diff --git a/arg_parser.cc b/arg_parser.cc index 27137a1..b3fd48d 100644 --- a/arg_parser.cc +++ b/arg_parser.cc @@ -56,30 +56,30 @@ bool Arg_parser::parse_long_option( const char * const opt, const char * const a if( ambig && !exact ) { - error_ = "option `"; error_ += opt; error_ += "' is ambiguous"; + error_ = "option '"; error_ += opt; error_ += "' is ambiguous"; return false; } if( index < 0 ) // nothing found { - error_ = "unrecognized option `"; error_ += opt; error_ += '\''; + error_ = "unrecognized option '"; error_ += opt; error_ += '\''; return false; } ++argind; data.push_back( Record( options[index].code ) ); - if( opt[len+2] ) // `--=' syntax + if( opt[len+2] ) // '--=' syntax { if( options[index].has_arg == no ) { - error_ = "option `--"; error_ += options[index].name; + error_ = "option '--"; error_ += options[index].name; error_ += "' doesn't allow an argument"; return false; } if( options[index].has_arg == yes && !opt[len+3] ) { - error_ = "option `--"; error_ += options[index].name; + error_ = "option '--"; error_ += options[index].name; error_ += "' requires an argument"; return false; } @@ -91,7 +91,7 @@ bool Arg_parser::parse_long_option( const char * const opt, const char * const a { if( !arg || !arg[0] ) { - error_ = "option `--"; error_ += options[index].name; + error_ = "option '--"; error_ += options[index].name; error_ += "' requires an argument"; return false; } diff --git a/arg_parser.h b/arg_parser.h index 5d036ab..4fbd1af 100644 --- a/arg_parser.h +++ b/arg_parser.h @@ -26,12 +26,12 @@ Public License. */ -/* Arg_parser reads the arguments in `argv' and creates a number of +/* Arg_parser reads the arguments in 'argv' and creates a number of option codes, option arguments and non-option arguments. - In case of error, `error' returns a non-empty error message. + In case of error, 'error' returns a non-empty error message. - `options' is an array of `struct Option' terminated by an element + 'options' is an array of 'struct Option' terminated by an element containing a code which is zero. A null name means a short-only option. A code value outside the unsigned char range means a long-only option. @@ -40,13 +40,13 @@ were specified before all the non-option arguments for the purposes of parsing, even if the user of your program intermixed option and non-option arguments. If you want the arguments in the exact order - the user typed them, call `Arg_parser' with `in_order' = true. + the user typed them, call 'Arg_parser' with 'in_order' = true. - The argument `--' terminates all options; any following arguments are + The argument '--' terminates all options; any following arguments are treated as non-option arguments, even if they begin with a hyphen. - The syntax for optional option arguments is `-' - (without whitespace), or `--='. + The syntax for optional option arguments is '-' + (without whitespace), or '--='. */ class Arg_parser @@ -85,20 +85,20 @@ public: Arg_parser( const char * const opt, const char * const arg, const Option options[] ); - const std::string & error() const throw() { return error_; } + const std::string & error() const { return error_; } // The number of arguments parsed (may be different from argc) - int arguments() const throw() { return data.size(); } + int arguments() const { return data.size(); } // If code( i ) is 0, argument( i ) is a non-option. // Else argument( i ) is the option's argument (or empty). - int code( const int i ) const throw() + int code( const int i ) const { if( i >= 0 && i < arguments() ) return data[i].code; else return 0; } - const std::string & argument( const int i ) const throw() + const std::string & argument( const int i ) const { if( i >= 0 && i < arguments() ) return data[i].argument; else return error_; diff --git a/compress.cc b/compress.cc index cf0135a..bb50358 100644 --- a/compress.cc +++ b/compress.cc @@ -35,15 +35,42 @@ #include "plzip.h" -#ifndef LLONG_MAX -#define LLONG_MAX 0x7FFFFFFFFFFFFFFFLL -#endif -#ifndef LLONG_MIN -#define LLONG_MIN (-LLONG_MAX - 1LL) -#endif -#ifndef ULLONG_MAX -#define ULLONG_MAX 0xFFFFFFFFFFFFFFFFULL -#endif + +// Returns the number of bytes really read. +// If (returned value < size) and (errno == 0), means EOF was reached. +// +int readblock( const int fd, uint8_t * const buf, const int size ) + { + int rest = size; + errno = 0; + while( rest > 0 ) + { + errno = 0; + const int n = read( fd, buf + size - rest, rest ); + if( n > 0 ) rest -= n; + else if( n == 0 ) break; + else if( errno != EINTR && errno != EAGAIN ) break; + } + return ( rest > 0 ) ? size - rest : size; + } + + +// Returns the number of bytes really written. +// If (returned value < size), it is always an error. +// +int writeblock( const int fd, const uint8_t * const buf, const int size ) + { + int rest = size; + errno = 0; + while( rest > 0 ) + { + errno = 0; + const int n = write( fd, buf + size - rest, rest ); + if( n > 0 ) rest -= n; + else if( n < 0 && errno != EINTR && errno != EAGAIN ) break; + } + return ( rest > 0 ) ? size - rest : size; + } void xinit( pthread_mutex_t * const mutex ) diff --git a/configure b/configure index 57497d9..416a21e 100755 --- a/configure +++ b/configure @@ -8,7 +8,7 @@ args= no_create= pkgname=plzip -pkgversion=0.8 +pkgversion=0.9 progname=plzip srctrigger=plzip.h @@ -19,10 +19,9 @@ srcdir= prefix=/usr/local exec_prefix='$(prefix)' bindir='$(exec_prefix)/bin' -datadir='$(prefix)/share' -infodir='$(datadir)/info' -mandir='$(datadir)/man' -sysconfdir='$(prefix)/etc' +datarootdir='$(prefix)/share' +infodir='$(datarootdir)/info' +mandir='$(datarootdir)/man' CXX= CPPFLAGS= CXXFLAGS='-Wall -W -O2' @@ -40,12 +39,12 @@ while [ -n "$1" ] ; do # Split out the argument for options that take them case ${option} in - *=*) optarg=`echo ${option} | sed -e 's,^[^=]*=,,'` ;; + *=*) optarg=`echo ${option} | sed -e 's,^[^=]*=,,;s,/$,,'` ;; esac # Process the options case ${option} in - --help | --he* | -h) + --help | -h) echo "Usage: configure [options]" echo echo "Options: [defaults in brackets]" @@ -55,42 +54,31 @@ while [ -n "$1" ] ; do echo " --prefix=DIR install into DIR [${prefix}]" echo " --exec-prefix=DIR base directory for arch-dependent files [${exec_prefix}]" echo " --bindir=DIR user executables directory [${bindir}]" - echo " --datadir=DIR base directory for doc and data [${datadir}]" + echo " --datarootdir=DIR base directory for doc and data [${datarootdir}]" echo " --infodir=DIR info files directory [${infodir}]" echo " --mandir=DIR man pages directory [${mandir}]" - echo " --sysconfdir=DIR read-only single-machine data directory [${sysconfdir}]" echo " CXX=COMPILER C++ compiler to use [g++]" echo " CPPFLAGS=OPTIONS command line options for the preprocessor [${CPPFLAGS}]" echo " CXXFLAGS=OPTIONS command line options for the C++ compiler [${CXXFLAGS}]" echo " LDFLAGS=OPTIONS command line options for the linker [${LDFLAGS}]" echo exit 0 ;; - --version | --ve* | -V) + --version | -V) echo "Configure script for ${pkgname} version ${pkgversion}" exit 0 ;; - --srcdir* | --sr*) - srcdir=`echo ${optarg} | sed -e 's,/$,,'` ;; - --prefix* | --pr*) - prefix=`echo ${optarg} | sed -e 's,/$,,'` ;; - --exec-prefix* | --ex*) - exec_prefix=`echo ${optarg} | sed -e 's,/$,,'` ;; - --bindir* | --bi*) - bindir=`echo ${optarg} | sed -e 's,/$,,'` ;; - --datadir* | --da*) - datadir=`echo ${optarg} | sed -e 's,/$,,'` ;; - --infodir* | --inf*) - infodir=`echo ${optarg} | sed -e 's,/$,,'` ;; - --mandir* | --ma*) - mandir=`echo ${optarg} | sed -e 's,/$,,'` ;; - --sysconfdir* | --sy*) - sysconfdir=`echo ${optarg} | sed -e 's,/$,,'` ;; - --no-create | --no-c*) - no_create=yes ;; - - CXX=*) CXX=${optarg} ;; + --srcdir=*) srcdir=${optarg} ;; + --prefix=*) prefix=${optarg} ;; + --exec-prefix=*) exec_prefix=${optarg} ;; + --bindir=*) bindir=${optarg} ;; + --datarootdir=*) datarootdir=${optarg} ;; + --infodir=*) infodir=${optarg} ;; + --mandir=*) mandir=${optarg} ;; + --no-create) no_create=yes ;; + + CXX=*) CXX=${optarg} ;; CPPFLAGS=*) CPPFLAGS=${optarg} ;; CXXFLAGS=*) CXXFLAGS=${optarg} ;; - LDFLAGS=*) LDFLAGS=${optarg} ;; + LDFLAGS=*) LDFLAGS=${optarg} ;; --* | *=* | *-*-*) ;; *) @@ -103,14 +91,14 @@ done srcdirtext= if [ -z "${srcdir}" ] ; then srcdirtext="or . or .." ; srcdir=. - if [ ! -r ${srcdir}/${srctrigger} ] ; then srcdir=.. ; fi - if [ ! -r ${srcdir}/${srctrigger} ] ; then + if [ ! -r "${srcdir}/${srctrigger}" ] ; then srcdir=.. ; fi + if [ ! -r "${srcdir}/${srctrigger}" ] ; then ## the sed command below emulates the dirname command srcdir=`echo $0 | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` fi fi -if [ ! -r ${srcdir}/${srctrigger} ] ; then +if [ ! -r "${srcdir}/${srctrigger}" ] ; then exec 1>&2 echo echo "configure: Can't find sources in ${srcdir} ${srcdirtext}" @@ -119,7 +107,7 @@ if [ ! -r ${srcdir}/${srctrigger} ] ; then fi # Set srcdir to . if that's what it is. -if [ "`pwd`" = "`cd ${srcdir} ; pwd`" ] ; then srcdir=. ; fi +if [ "`pwd`" = "`cd "${srcdir}" ; pwd`" ] ; then srcdir=. ; fi # checking whether we are using GNU C++. if [ -z "${CXX}" ] ; then # Let the user override the test. @@ -154,10 +142,9 @@ echo "VPATH = ${srcdir}" echo "prefix = ${prefix}" echo "exec_prefix = ${exec_prefix}" echo "bindir = ${bindir}" -echo "datadir = ${datadir}" +echo "datarootdir = ${datarootdir}" echo "infodir = ${infodir}" echo "mandir = ${mandir}" -echo "sysconfdir = ${sysconfdir}" echo "CXX = ${CXX}" echo "CPPFLAGS = ${CPPFLAGS}" echo "CXXFLAGS = ${CXXFLAGS}" @@ -178,16 +165,15 @@ VPATH = ${srcdir} prefix = ${prefix} exec_prefix = ${exec_prefix} bindir = ${bindir} -datadir = ${datadir} +datarootdir = ${datarootdir} infodir = ${infodir} mandir = ${mandir} -sysconfdir = ${sysconfdir} CXX = ${CXX} CPPFLAGS = ${CPPFLAGS} CXXFLAGS = ${CXXFLAGS} LDFLAGS = ${LDFLAGS} EOF -cat ${srcdir}/Makefile.in >> Makefile +cat "${srcdir}/Makefile.in" >> Makefile echo "OK. Now you can run make." echo "If make fails, verify that the lzlib compression library is correctly" diff --git a/decompress.cc b/decompress.cc index ef098ae..b440ecd 100644 --- a/decompress.cc +++ b/decompress.cc @@ -213,7 +213,7 @@ public: // Search forward from 'pos' for "LZIP" (Boyer-Moore algorithm) // Return pos of found string or 'pos+size' if not found. // -int find_magic( const uint8_t * const buffer, const int pos, const int size ) throw() +int find_magic( const uint8_t * const buffer, const int pos, const int size ) { const uint8_t table[256] = { 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, diff --git a/doc/plzip.1 b/doc/plzip.1 index ec3fc36..4bdc86e 100644 --- a/doc/plzip.1 +++ b/doc/plzip.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1. -.TH PLZIP "1" "January 2012" "Plzip 0.8" "User Commands" +.TH PLZIP "1" "March 2012" "Plzip 0.9" "User Commands" .SH NAME Plzip \- reduces the size of files .SH SYNOPSIS @@ -79,7 +79,7 @@ Plzip home page: http://www.nongnu.org/lzip/plzip.html Copyright \(co 2009 Laszlo Ersek. .br Copyright \(co 2012 Antonio Diaz Diaz. -Using Lzlib 1.3\-rc1 +Using Lzlib 1.3 License GPLv3+: GNU GPL version 3 or later .br This is free software: you are free to change and redistribute it. diff --git a/doc/plzip.info b/doc/plzip.info index 3a12bef..94d96af 100644 --- a/doc/plzip.info +++ b/doc/plzip.info @@ -12,7 +12,7 @@ File: plzip.info, Node: Top, Next: Introduction, Up: (dir) Plzip Manual ************ -This manual is for Plzip (version 0.8, 17 January 2012). +This manual is for Plzip (version 0.9, 1 March 2012). * Menu: @@ -81,6 +81,13 @@ processed. Be aware, though, that the check occurs upon decompression, so it can only tell you that something is wrong. It can't help you recover the original uncompressed data. + WARNING! Even if plzip is bug-free, other causes may result in a +corrupt compressed file (bugs in the system libraries, memory errors, +etc). Therefore, if the data you are going to compress is important, +give the `--keep' option to plzip and do not remove the original file +until you verify the compressed file with a command like +`plzip -cd file.lz | cmp file -'. + Return values: 0 for a normal exit, 1 for environmental problems (file not found, invalid flags, I/O errors, etc), 2 to indicate a corrupt or invalid input file, 3 for an internal consistency error (eg, @@ -351,12 +358,12 @@ Concept Index  Tag Table: Node: Top223 -Node: Introduction845 -Node: Invoking Plzip3641 -Node: Program Design8597 -Node: File Format9259 -Node: Problems11254 -Node: Concept Index11783 +Node: Introduction842 +Node: Invoking Plzip4008 +Node: Program Design8964 +Node: File Format9626 +Node: Problems11621 +Node: Concept Index12150  End Tag Table diff --git a/doc/plzip.texinfo b/doc/plzip.texinfo index c83d5a5..f981207 100644 --- a/doc/plzip.texinfo +++ b/doc/plzip.texinfo @@ -6,8 +6,8 @@ @finalout @c %**end of header -@set UPDATED 17 January 2012 -@set VERSION 0.8 +@set UPDATED 1 March 2012 +@set VERSION 0.9 @dircategory Data Compression @direntry @@ -102,6 +102,13 @@ the check occurs upon decompression, so it can only tell you that something is wrong. It can't help you recover the original uncompressed data. +WARNING! Even if plzip is bug-free, other causes may result in a corrupt +compressed file (bugs in the system libraries, memory errors, etc). +Therefore, if the data you are going to compress is important, give the +@samp{--keep} option to plzip and do not remove the original file until +you verify the compressed file with a command like +@w{@samp{plzip -cd file.lz | cmp file -}}. + Return values: 0 for a normal exit, 1 for environmental problems (file not found, invalid flags, I/O errors, etc), 2 to indicate a corrupt or invalid input file, 3 for an internal consistency error (eg, bug) which diff --git a/main.cc b/main.cc index d96fdb7..97de931 100644 --- a/main.cc +++ b/main.cc @@ -48,16 +48,6 @@ #error "Environments where CHAR_BIT != 8 are not supported." #endif -#ifndef LLONG_MAX -#define LLONG_MAX 0x7FFFFFFFFFFFFFFFLL -#endif -#ifndef LLONG_MIN -#define LLONG_MIN (-LLONG_MAX - 1LL) -#endif -#ifndef ULLONG_MAX -#define ULLONG_MAX 0xFFFFFFFFFFFFFFFFULL -#endif - namespace { @@ -87,13 +77,15 @@ enum Mode { m_compress, m_decompress, m_test }; std::string output_filename; int outfd = -1; -mode_t outfd_mode = S_IRUSR | S_IWUSR; +const mode_t usr_rw = S_IRUSR | S_IWUSR; +const mode_t all_rw = usr_rw | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; +mode_t outfd_mode = usr_rw; bool delete_output_on_interrupt = false; pthread_t main_thread; pid_t main_thread_pid; -void show_help() throw() +void show_help() { std::printf( "%s - A parallel compressor compatible with lzip.\n", Program_name ); std::printf( "\nUsage: %s [options] [files]\n", invocation_name ); @@ -133,7 +125,7 @@ void show_help() throw() } -void show_version() throw() +void show_version() { std::printf( "%s %s\n", Program_name, PROGVERSION ); std::printf( "Copyright (C) 2009 Laszlo Ersek.\n" @@ -147,7 +139,7 @@ void show_version() throw() long long getnum( const char * const ptr, const long long llimit = LLONG_MIN + 1, - const long long ulimit = LLONG_MAX ) throw() + const long long ulimit = LLONG_MAX ) { errno = 0; char *tail; @@ -200,7 +192,7 @@ long long getnum( const char * const ptr, } -int get_dict_size( const char * const arg ) throw() +int get_dict_size( const char * const arg ) { char *tail; int bits = std::strtol( arg, &tail, 0 ); @@ -211,7 +203,7 @@ int get_dict_size( const char * const arg ) throw() } -int extension_index( const std::string & name ) throw() +int extension_index( const std::string & name ) { for( int i = 0; known_extensions[i].from; ++i ) { @@ -226,7 +218,7 @@ int extension_index( const std::string & name ) throw() int open_instream( const std::string & name, struct stat * const in_statsp, const Mode program_mode, const int eindex, - const bool recompress, const bool to_stdout ) throw() + const bool recompress, const bool to_stdout ) { int infd = -1; if( program_mode == m_compress && !recompress && eindex >= 0 ) @@ -268,14 +260,14 @@ int open_instream( const std::string & name, struct stat * const in_statsp, } -void set_c_outname( const std::string & name ) throw() +void set_c_outname( const std::string & name ) { output_filename = name; output_filename += known_extensions[0].from; } -void set_d_outname( const std::string & name, const int i ) throw() +void set_d_outname( const std::string & name, const int i ) { if( i >= 0 ) { @@ -294,7 +286,7 @@ void set_d_outname( const std::string & name, const int i ) throw() } -bool open_outstream( const bool force ) throw() +bool open_outstream( const bool force ) { int flags = O_CREAT | O_WRONLY | o_binary; if( force ) flags |= O_TRUNC; else flags |= O_EXCL; @@ -313,7 +305,7 @@ bool open_outstream( const bool force ) throw() } -bool check_tty( const int infd, const Mode program_mode ) throw() +bool check_tty( const int infd, const Mode program_mode ) { if( program_mode == m_compress && outfd >= 0 && isatty( outfd ) ) { @@ -330,7 +322,7 @@ bool check_tty( const int infd, const Mode program_mode ) throw() } -void cleanup_and_fail( const int retval ) throw() +void cleanup_and_fail( const int retval ) { if( delete_output_on_interrupt ) { @@ -372,7 +364,7 @@ void close_and_set_permissions( const struct stat * const in_statsp ) } -extern "C" void signal_handler( int sig ) throw() +extern "C" void signal_handler( int sig ) { if( !pthread_equal( pthread_self(), main_thread ) ) kill( main_thread_pid, sig ); @@ -382,7 +374,7 @@ extern "C" void signal_handler( int sig ) throw() } -void set_signals() throw() +void set_signals() { std::signal( SIGHUP, signal_handler ); std::signal( SIGINT, signal_handler ); @@ -402,7 +394,7 @@ int verbosity = 0; void fatal() { signal_handler( SIGUSR1 ); } -void Pretty_print::operator()( const char * const msg ) const throw() +void Pretty_print::operator()( const char * const msg ) const { if( verbosity >= 0 ) { @@ -419,7 +411,7 @@ void Pretty_print::operator()( const char * const msg ) const throw() } -void show_error( const char * const msg, const int errcode, const bool help ) throw() +void show_error( const char * const msg, const int errcode, const bool help ) { if( verbosity >= 0 ) { @@ -437,7 +429,7 @@ void show_error( const char * const msg, const int errcode, const bool help ) th } -void internal_error( const char * const msg ) throw() +void internal_error( const char * const msg ) { if( verbosity >= 0 ) std::fprintf( stderr, "%s: internal error: %s.\n", program_name, msg ); @@ -445,43 +437,6 @@ void internal_error( const char * const msg ) throw() } -// Returns the number of bytes really read. -// If (returned value < size) and (errno == 0), means EOF was reached. -// -int readblock( const int fd, uint8_t * const buf, const int size ) throw() - { - int rest = size; - errno = 0; - while( rest > 0 ) - { - errno = 0; - const int n = read( fd, buf + size - rest, rest ); - if( n > 0 ) rest -= n; - else if( n == 0 ) break; - else if( errno != EINTR && errno != EAGAIN ) break; - } - return ( rest > 0 ) ? size - rest : size; - } - - -// Returns the number of bytes really written. -// If (returned value < size), it is always an error. -// -int writeblock( const int fd, const uint8_t * const buf, const int size ) throw() - { - int rest = size; - errno = 0; - while( rest > 0 ) - { - errno = 0; - const int n = write( fd, buf + size - rest, rest ); - if( n > 0 ) rest -= n; - else if( n < 0 && errno != EINTR && errno != EAGAIN ) break; - } - return ( rest > 0 ) ? size - rest : size; - } - - int main( const int argc, const char * const argv[] ) { // Mapping from gzip/bzip2 style 1..9 compression modes @@ -649,7 +604,7 @@ int main( const int argc, const char * const argv[] ) if( program_mode == m_compress ) set_c_outname( default_output_filename ); else output_filename = default_output_filename; - outfd_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; + outfd_mode = all_rw; if( !open_outstream( force ) ) { if( outfd == -1 && retval < 1 ) retval = 1; @@ -674,7 +629,7 @@ int main( const int argc, const char * const argv[] ) if( program_mode == m_compress ) set_c_outname( input_filename ); else set_d_outname( input_filename, eindex ); - outfd_mode = S_IRUSR | S_IWUSR; + outfd_mode = usr_rw; if( !open_outstream( force ) ) { if( outfd == -1 && retval < 1 ) retval = 1; diff --git a/plzip.h b/plzip.h index b12bbbd..f9aed10 100644 --- a/plzip.h +++ b/plzip.h @@ -16,6 +16,17 @@ along with this program. If not, see . */ +#ifndef LLONG_MAX +#define LLONG_MAX 0x7FFFFFFFFFFFFFFFLL +#endif +#ifndef LLONG_MIN +#define LLONG_MIN (-LLONG_MAX - 1LL) +#endif +#ifndef ULLONG_MAX +#define ULLONG_MAX 0xFFFFFFFFFFFFFFFFULL +#endif + + class Pretty_print { const char * const stdin_name; @@ -44,14 +55,16 @@ public: first_post = true; } - void reset() const throw() { if( name_.size() ) first_post = true; } - const char * name() const throw() { return name_.c_str(); } - void operator()( const char * const msg = 0 ) const throw(); + void reset() const { if( name_.size() ) first_post = true; } + const char * name() const { return name_.c_str(); } + void operator()( const char * const msg = 0 ) const; }; /*--------------------- Defined in compress.cc ---------------------*/ +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 ); void xinit( pthread_mutex_t * const mutex ); void xinit( pthread_cond_t * const cond ); void xdestroy( pthread_mutex_t * const mutex ); @@ -62,6 +75,28 @@ void xwait( pthread_cond_t * const cond, pthread_mutex_t * const mutex ); void xsignal( pthread_cond_t * const cond ); void xbroadcast( pthread_cond_t * const cond ); +int compress( const int data_size, const int dictionary_size, + const int match_len_limit, const int num_workers, + const int infd, const int outfd, + const Pretty_print & pp, const int debug_level ); + + +/*-------------------- Defined in decompress.cc --------------------*/ + +int decompress( const int num_workers, const int infd, const int outfd, + const Pretty_print & pp, const int debug_level, + const bool testing ); + + +/*----------------------- Defined in main.cc -----------------------*/ + +extern int verbosity; + +void fatal(); // terminate the program + +void show_error( const char * const msg, const int errcode = 0, const bool help = false ); +void internal_error( const char * const msg ); + class Slot_tally { @@ -104,28 +139,3 @@ public: xunlock( &mutex ); } }; - - -int compress( const int data_size, const int dictionary_size, - const int match_len_limit, const int num_workers, - const int infd, const int outfd, - const Pretty_print & pp, const int debug_level ); - - -/*-------------------- Defined in decompress.cc --------------------*/ - -int decompress( const int num_workers, const int infd, const int outfd, - const Pretty_print & pp, const int debug_level, - const bool testing ); - - -/*----------------------- Defined in main.cc -----------------------*/ - -extern int verbosity; - -void fatal(); // terminate the program - -void show_error( const char * const msg, const int errcode = 0, const bool help = false ) throw(); -void internal_error( const char * const msg ) throw(); -int readblock( const int fd, uint8_t * const buf, const int size ) throw(); -int writeblock( const int fd, const uint8_t * const buf, const int size ) throw(); diff --git a/testsuite/check.sh b/testsuite/check.sh index d4f919a..8b6bf2d 100755 --- a/testsuite/check.sh +++ b/testsuite/check.sh @@ -28,17 +28,22 @@ fail=0 printf "testing plzip-%s..." "$2" "${LZIP}" -t "${testdir}"/test_v0.lz || fail=1 -printf . "${LZIP}" -cd "${testdir}"/test_v0.lz > copy || fail=1 cmp in copy || fail=1 printf . "${LZIP}" -t "${testdir}"/test_v1.lz || fail=1 -printf . "${LZIP}" -cd "${testdir}"/test_v1.lz > copy || fail=1 cmp in copy || fail=1 printf . +"${LZIP}" -cfq "${testdir}"/test_v1.lz > out +if [ $? != 1 ] ; then fail=1 ; printf - ; else printf . ; fi +"${LZIP}" -cF "${testdir}"/test_v1.lz > out || fail=1 +"${LZIP}" -cd out | "${LZIP}" -d > copy || fail=1 +cmp in copy || fail=1 +printf . + for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do "${LZIP}" -k -$i in || fail=1 mv -f in.lz copy.lz || fail=1 @@ -70,11 +75,6 @@ for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do printf . done -"${LZIP}" < in > anyothername || fail=1 -"${LZIP}" -d anyothername || fail=1 -cmp in anyothername.out || fail=1 -printf . - for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; do "${LZIP}" -s4Ki -B8Ki -n$i < in4 > out4 || fail=1 "${LZIP}" -d -n$i < out4 > copy4 || fail=1 @@ -82,6 +82,11 @@ for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; do printf . done +"${LZIP}" < in > anyothername || fail=1 +"${LZIP}" -d anyothername || fail=1 +cmp in anyothername.out || fail=1 +printf . + echo if [ ${fail} = 0 ] ; then echo "tests completed successfully." -- cgit v1.2.3