From 396faafcdb436166bc443cf03c1d8dfb1e1fa034 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 20 Feb 2025 21:23:39 +0100 Subject: [PATCH 01/10] Adding upstream version 1.9. Signed-off-by: Daniel Baumann --- COPYING | 345 ++--------------------------------------- COPYING => COPYING.GPL | 0 ChangeLog | 13 +- INSTALL | 2 +- Makefile.in | 10 +- NEWS | 20 +-- README | 14 +- bbexample.c | 2 +- carg_parser.c | 9 +- carg_parser.h | 2 +- cbuffer.c | 32 ++-- configure | 21 +-- decoder.c | 120 ++++++-------- decoder.h | 234 ++++++++++++++-------------- doc/lzlib.info | 48 +++--- doc/lzlib.texi | 24 +-- doc/minilzip.1 | 6 +- encoder.c | 133 +++++++--------- encoder.h | 120 ++++++-------- encoder_base.c | 51 +++--- encoder_base.h | 247 ++++++++++++++++------------- fast_encoder.c | 84 ++++------ fast_encoder.h | 38 ++--- lzcheck.c | 2 +- lzip.h | 38 ++--- lzlib.c | 46 +++--- lzlib.h | 34 ++-- main.c | 87 ++++++----- testsuite/check.sh | 267 ++++++++++++++++++------------- testsuite/test.txt.lz | Bin 7376 -> 7376 bytes 30 files changed, 861 insertions(+), 1188 deletions(-) copy COPYING => COPYING.GPL (100%) diff --git a/COPYING b/COPYING index 4ad17ae..fcf86c4 100644 --- a/COPYING +++ b/COPYING @@ -1,338 +1,17 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 + Lzlib - Compression library for the lzip format + Copyright (C) Antonio Diaz Diaz. - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: - Preamble + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - 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 - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/COPYING b/COPYING.GPL similarity index 100% copy from COPYING copy to COPYING.GPL diff --git a/ChangeLog b/ChangeLog index 3c65439..70eb638 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2017-04-11 Antonio Diaz Diaz + + * Version 1.9 released. + * Compression time of option '-0' has been reduced by 3%. + * Compression time of options -1 to -9 has been reduced by 1%. + * Decompression time has been reduced by 3%. + * main.c: Continue testing if any input file is a terminal. + * License of the library changed to "2-clause BSD". + 2016-05-17 Antonio Diaz Diaz * Version 1.8 released. @@ -20,7 +29,7 @@ 2014-08-27 Antonio Diaz Diaz * Version 1.6 released. - * Compression ratio of option -9 has been slightly increased. + * Compression ratio of option '-9' has been slightly increased. * configure: Added new option '--disable-static'. * configure: Added new option '--disable-ldconfig'. * Makefile.in: Ignore errors from ldconfig. @@ -165,7 +174,7 @@ * Version 0.1 released. -Copyright (C) 2009-2016 Antonio Diaz Diaz. +Copyright (C) 2009-2017 Antonio Diaz Diaz. This file is a collection of facts, and thus it is not copyrightable, but just in case, you have unlimited permission to copy, distribute and diff --git a/INSTALL b/INSTALL index 31237fc..3dbf6e8 100644 --- a/INSTALL +++ b/INSTALL @@ -62,7 +62,7 @@ After running 'configure', you can run 'make' and 'make install' as explained above. -Copyright (C) 2009-2016 Antonio Diaz Diaz. +Copyright (C) 2009-2017 Antonio Diaz Diaz. This file is free documentation: you have unlimited permission to copy, distribute and modify it. diff --git a/Makefile.in b/Makefile.in index 02a1870..c493f5e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -15,7 +15,8 @@ objs = carg_parser.o main.o .PHONY : all install install-bin install-info install-man \ install-strip install-compress install-strip-compress \ install-bin-strip install-info-compress install-man-compress \ - install-as-lzip uninstall uninstall-bin uninstall-info uninstall-man \ + install-as-lzip \ + uninstall uninstall-bin uninstall-info uninstall-man \ doc info man check dist clean distclean all : $(progname_static) $(progname_shared) @@ -155,6 +156,7 @@ dist : doc tar -Hustar --owner=root --group=root -cvf $(DISTNAME).tar \ $(DISTNAME)/AUTHORS \ $(DISTNAME)/COPYING \ + $(DISTNAME)/COPYING.GPL \ $(DISTNAME)/ChangeLog \ $(DISTNAME)/INSTALL \ $(DISTNAME)/Makefile.in \ @@ -164,13 +166,13 @@ dist : doc $(DISTNAME)/doc/$(progname).1 \ $(DISTNAME)/doc/$(pkgname).info \ $(DISTNAME)/doc/$(pkgname).texi \ + $(DISTNAME)/*.h \ + $(DISTNAME)/*.c \ $(DISTNAME)/testsuite/check.sh \ $(DISTNAME)/testsuite/test.txt \ $(DISTNAME)/testsuite/test2.txt \ $(DISTNAME)/testsuite/test.txt.lz \ - $(DISTNAME)/testsuite/test_sync.lz \ - $(DISTNAME)/*.h \ - $(DISTNAME)/*.c + $(DISTNAME)/testsuite/test_sync.lz rm -f $(DISTNAME) lzip -v -9 $(DISTNAME).tar diff --git a/NEWS b/NEWS index e60b1bd..111a899 100644 --- a/NEWS +++ b/NEWS @@ -1,16 +1,12 @@ -Changes in version 1.8: +Changes in version 1.9: -The test of the value remaining in the range decoder has been removed. -(After extensive testing it has been found useless to detect corruption -in the decompressed data. Eliminating it reduces the number of false -positives for corruption and makes error detection more accurate). +Compression time of option '-0' has been reduced by 3%. -The option "-a, --trailing-error", which makes minilzip exit with error -status 2 if any remaining input is detected after decompressing the last -member, has been added. +Compression time of options '-1' to '-9' has been reduced by 1%. -When decompressing with minilzip, the file specified with the '--output' -option is now deleted if the input is a terminal. +Decompression time has been reduced by 3%. -A harmless check failure on Windows, caused by the failed comparison of -a message in text mode, has been fixed. +In test mode, minilzip now continues checking the rest of the files if +any input file is a terminal. + +The license of the library has been changed to "2-clause BSD". diff --git a/README b/README index 97f11e9..178f30f 100644 --- a/README +++ b/README @@ -16,11 +16,11 @@ availability: merging of damaged copies of a file. * The lzip format is as simple as possible (but not simpler). The - lzip manual provides the code of a simple decompressor along with a - detailed explanation of how it works, so that with the only help of - the lzip manual it would be possible for a digital archaeologist to - extract the data from a lzip file long after quantum computers - eventually render LZMA obsolete. + lzip manual provides the source code of a simple decompressor along + with a detailed explanation of how it works, so that with the only + help of the lzip manual it would be possible for a digital + archaeologist to extract the data from a lzip file long after + quantum computers eventually render LZMA obsolete. * Additionally the lzip reference implementation is copylefted, which guarantees that it will remain free forever. @@ -42,7 +42,7 @@ traditional zlib interface. Compression/decompression is done when the read function is called. This means the value returned by the position functions will not be updated -until a read call, even if a lot of data is written. If you want the +until a read call, even if a lot of data are written. If you want the data to be compressed in advance, just call the read function with a size equal to 0. @@ -87,7 +87,7 @@ range encoding), Igor Pavlov (for putting all the above together in LZMA), and Julian Seward (for bzip2's CLI). -Copyright (C) 2009-2016 Antonio Diaz Diaz. +Copyright (C) 2009-2017 Antonio Diaz Diaz. This file is free documentation: you have unlimited permission to copy, distribute and modify it. diff --git a/bbexample.c b/bbexample.c index 6b1352b..ab9a6e0 100644 --- a/bbexample.c +++ b/bbexample.c @@ -1,5 +1,5 @@ /* Buffer to buffer example - Test program for the lzlib library - Copyright (C) 2010-2016 Antonio Diaz Diaz. + Copyright (C) 2010-2017 Antonio Diaz Diaz. This program is free software: you have unlimited permission to copy, distribute and modify it. diff --git a/carg_parser.c b/carg_parser.c index 3d4e89f..6850643 100644 --- a/carg_parser.c +++ b/carg_parser.c @@ -1,5 +1,5 @@ /* Arg_parser - POSIX/GNU command line argument parser. (C version) - Copyright (C) 2006-2016 Antonio Diaz Diaz. + Copyright (C) 2006-2017 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -94,7 +94,7 @@ static char parse_long_option( struct Arg_parser * const ap, else if( index < 0 ) index = i; /* First nonexact match found */ else if( options[index].code != options[i].code || options[index].has_arg != options[i].has_arg ) - ambig = 1; /* Second or later nonexact match found */ + ambig = 1; /* Second or later nonexact match found */ } if( ambig && !exact ) @@ -230,7 +230,9 @@ char ap_init( struct Arg_parser * const ap, } else { - if( !in_order ) + if( in_order ) + { if( !push_back_record( ap, 0, argv[argind++] ) ) return 0; } + else { void * tmp = ap_resize_buffer( non_options, ( non_options_size + 1 ) * sizeof *non_options ); @@ -238,7 +240,6 @@ char ap_init( struct Arg_parser * const ap, non_options = (const char **)tmp; non_options[non_options_size++] = argv[argind++]; } - else if( !push_back_record( ap, 0, argv[argind++] ) ) return 0; } } if( ap->error ) free_data( ap ); diff --git a/carg_parser.h b/carg_parser.h index e918942..c4ce31d 100644 --- a/carg_parser.h +++ b/carg_parser.h @@ -1,5 +1,5 @@ /* Arg_parser - POSIX/GNU command line argument parser. (C version) - Copyright (C) 2006-2016 Antonio Diaz Diaz. + Copyright (C) 2006-2017 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/cbuffer.c b/cbuffer.c index 89693ab..5b8751e 100644 --- a/cbuffer.c +++ b/cbuffer.c @@ -1,28 +1,20 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 Antonio Diaz Diaz. - This library is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this library. If not, see . - - As a special exception, you may use this file as part of a free - software library without restriction. Specifically, if other files - instantiate templates or use macros or inline functions from this - file, or you compile this file and link it with other files to - produce an executable, this file does not by itself cause the - resulting executable to be covered by the GNU General Public - License. This exception does not however invalidate any other - reasons why the executable file might be covered by the GNU General - Public License. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ struct Circular_buffer diff --git a/configure b/configure index 2182cfa..244dca6 100755 --- a/configure +++ b/configure @@ -1,12 +1,12 @@ #! /bin/sh # configure script for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2016 Antonio Diaz Diaz. +# Copyright (C) 2009-2017 Antonio Diaz Diaz. # # This configure script is free software: you have unlimited permission # to copy, distribute and modify it. pkgname=lzlib -pkgversion=1.8 +pkgversion=1.9 soversion=1 progname=minilzip progname_static=${progname} @@ -34,11 +34,11 @@ CFLAGS='-Wall -W -O2' LDFLAGS= # checking whether we are using GNU C. -if /bin/sh -c "${CC} --version" > /dev/null 2>&1 ; then true -else +/bin/sh -c "${CC} --version" > /dev/null 2>&1 || + { CC=cc - CFLAGS='-W -O2' -fi + CFLAGS=-O2 + } # Loop over all args args= @@ -60,9 +60,12 @@ while [ $# != 0 ] ; do # Process the options case ${option} in --help | -h) - echo "Usage: configure [options]" + echo "Usage: $0 [OPTION]... [VAR=VALUE]..." echo - echo "Options: [defaults in brackets]" + echo "To assign makefile variables (e.g., CC, CFLAGS...), specify them as" + echo "arguments to configure in the form VAR=VALUE." + echo + echo "Options and variables: [defaults in brackets]" echo " -h, --help display this help and exit" echo " -V, --version output version information and exit" echo " --srcdir=DIR find the sources in DIR [. or ..]" @@ -191,7 +194,7 @@ echo "LDFLAGS = ${LDFLAGS}" rm -f Makefile cat > Makefile << EOF # Makefile for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2016 Antonio Diaz Diaz. +# Copyright (C) 2009-2017 Antonio Diaz Diaz. # This file was generated automatically by configure. Don't edit. # # This Makefile is free software: you have unlimited permission diff --git a/decoder.c b/decoder.c index 8ef3942..971fc24 100644 --- a/decoder.c +++ b/decoder.c @@ -1,41 +1,35 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 Antonio Diaz Diaz. - This library is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this library. If not, see . - - As a special exception, you may use this file as part of a free - software library without restriction. Specifically, if other files - instantiate templates or use macros or inline functions from this - file, or you compile this file and link it with other files to - produce an executable, this file does not by itself cause the - resulting executable to be covered by the GNU General Public - License. This exception does not however invalidate any other - reasons why the executable file might be covered by the GNU General - Public License. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ -static bool LZd_verify_trailer( struct LZ_decoder * const d ) +static int LZd_try_verify_trailer( struct LZ_decoder * const d ) { File_trailer trailer; - int size = Rd_read_data( d->rdec, trailer, Ft_size ); + if( Rd_available_bytes( d->rdec ) < Ft_size && !d->rdec->at_stream_end ) + return 0; + d->verify_trailer_pending = false; + d->member_finished = true; - if( size < Ft_size ) - return false; - - return ( Ft_get_data_crc( trailer ) == LZd_crc( d ) && - Ft_get_data_size( trailer ) == LZd_data_position( d ) && - Ft_get_member_size( trailer ) == d->rdec->member_position ); + if( Rd_read_data( d->rdec, trailer, Ft_size ) == Ft_size && + Ft_get_data_crc( trailer ) == LZd_crc( d ) && + Ft_get_data_size( trailer ) == LZd_data_position( d ) && + Ft_get_member_size( trailer ) == d->rdec->member_position ) return 0; + return 3; } @@ -46,24 +40,17 @@ static int LZd_decode_member( struct LZ_decoder * const d ) { struct Range_decoder * const rdec = d->rdec; State * const state = &d->state; -/* unsigned long long old_mpos = d->rdec->member_position; */ + /* unsigned old_mpos = d->rdec->member_position; */ if( d->member_finished ) return 0; if( !Rd_try_reload( rdec, false ) ) { if( !rdec->at_stream_end ) return 0; else return 2; } - if( d->verify_trailer_pending ) - { - if( Rd_available_bytes( rdec ) < Ft_size && !rdec->at_stream_end ) - return 0; - d->verify_trailer_pending = false; - d->member_finished = true; - if( LZd_verify_trailer( d ) ) return 0; else return 3; - } + if( d->verify_trailer_pending ) return LZd_try_verify_trailer( d ); while( !Rd_finished( rdec ) ) { const int pos_state = LZd_data_position( d ) & pos_state_mask; -/* const unsigned long long mpos = d->rdec->member_position; + /* const unsigned mpos = d->rdec->member_position; if( mpos - old_mpos > rd_min_available_bytes ) return 5; old_mpos = mpos; */ if( !Rd_enough_available_bytes( rdec ) ) /* check unexpected eof */ @@ -71,19 +58,16 @@ static int LZd_decode_member( struct LZ_decoder * const d ) if( !LZd_enough_free_bytes( d ) ) return 0; if( Rd_decode_bit( rdec, &d->bm_match[*state][pos_state] ) == 0 ) /* 1st bit */ { - const uint8_t prev_byte = LZd_peek_prev( d ); + Bit_model * const bm = d->bm_literal[get_lit_state(LZd_peek_prev( d ))]; if( St_is_char( *state ) ) { *state -= ( *state < 4 ) ? *state : 3; - LZd_put_byte( d, Rd_decode_tree( rdec, - d->bm_literal[get_lit_state(prev_byte)], 8 ) ); + LZd_put_byte( d, Rd_decode_tree8( rdec, bm ) ); } else { *state -= ( *state < 10 ) ? 3 : 6; - LZd_put_byte( d, Rd_decode_matched( rdec, - d->bm_literal[get_lit_state(prev_byte)], - LZd_peek( d, d->rep0 ) ) ); + LZd_put_byte( d, Rd_decode_matched( rdec, bm, LZd_peek( d, d->rep0 ) ) ); } } else /* match or repeated match */ @@ -91,7 +75,13 @@ static int LZd_decode_member( struct LZ_decoder * const d ) int len; if( Rd_decode_bit( rdec, &d->bm_rep[*state] ) != 0 ) /* 2nd bit */ { - if( Rd_decode_bit( rdec, &d->bm_rep0[*state] ) != 0 ) /* 3rd bit */ + if( Rd_decode_bit( rdec, &d->bm_rep0[*state] ) == 0 ) /* 3rd bit */ + { + if( Rd_decode_bit( rdec, &d->bm_len[*state][pos_state] ) == 0 ) /* 4th bit */ + { *state = St_set_short_rep( *state ); + LZd_put_byte( d, LZd_peek( d, d->rep0 ) ); continue; } + } + else { unsigned distance; if( Rd_decode_bit( rdec, &d->bm_rep1[*state] ) == 0 ) /* 4th bit */ @@ -107,43 +97,34 @@ static int LZd_decode_member( struct LZ_decoder * const d ) d->rep1 = d->rep0; d->rep0 = distance; } - else - { - if( Rd_decode_bit( rdec, &d->bm_len[*state][pos_state] ) == 0 ) /* 4th bit */ - { *state = St_set_short_rep( *state ); - LZd_put_byte( d, LZd_peek( d, d->rep0 ) ); continue; } - } *state = St_set_rep( *state ); len = min_match_len + Rd_decode_len( rdec, &d->rep_len_model, pos_state ); } else /* match */ { - const unsigned rep0_saved = d->rep0; - int dis_slot; + unsigned distance; len = min_match_len + Rd_decode_len( rdec, &d->match_len_model, pos_state ); - dis_slot = Rd_decode_tree6( rdec, d->bm_dis_slot[get_len_state(len)] ); - if( dis_slot < start_dis_model ) d->rep0 = dis_slot; - else + distance = Rd_decode_tree6( rdec, d->bm_dis_slot[get_len_state(len)] ); + if( distance >= start_dis_model ) { + const unsigned dis_slot = distance; const int direct_bits = ( dis_slot >> 1 ) - 1; - d->rep0 = ( 2 | ( dis_slot & 1 ) ) << direct_bits; + distance = ( 2 | ( dis_slot & 1 ) ) << direct_bits; if( dis_slot < end_dis_model ) - d->rep0 += Rd_decode_tree_reversed( rdec, - d->bm_dis + d->rep0 - dis_slot - 1, direct_bits ); + distance += Rd_decode_tree_reversed( rdec, + d->bm_dis + ( distance - dis_slot ), direct_bits ); else { - d->rep0 += Rd_decode( rdec, direct_bits - dis_align_bits ) << dis_align_bits; - d->rep0 += Rd_decode_tree_reversed4( rdec, d->bm_align ); - if( d->rep0 == 0xFFFFFFFFU ) /* marker found */ + distance += + Rd_decode( rdec, direct_bits - dis_align_bits ) << dis_align_bits; + distance += Rd_decode_tree_reversed4( rdec, d->bm_align ); + if( distance == 0xFFFFFFFFU ) /* marker found */ { - d->rep0 = rep0_saved; Rd_normalize( rdec ); if( len == min_match_len ) /* End Of Stream marker */ { - if( Rd_available_bytes( rdec ) < Ft_size && !rdec->at_stream_end ) - { d->verify_trailer_pending = true; return 0; } - d->member_finished = true; - if( LZd_verify_trailer( d ) ) return 0; else return 3; + d->verify_trailer_pending = true; + return LZd_try_verify_trailer( d ); } if( len == min_match_len + 1 ) /* Sync Flush marker */ { @@ -154,11 +135,10 @@ static int LZd_decode_member( struct LZ_decoder * const d ) } } } - d->rep3 = d->rep2; d->rep2 = d->rep1; d->rep1 = rep0_saved; + d->rep3 = d->rep2; d->rep2 = d->rep1; d->rep1 = d->rep0; d->rep0 = distance; *state = St_set_match( *state ); if( d->rep0 >= d->dictionary_size || - ( d->rep0 >= d->cb.put && !d->pos_wrapped ) ) - return 1; + ( d->rep0 >= d->cb.put && !d->pos_wrapped ) ) return 1; } LZd_copy_block( d, d->rep0, len ); } diff --git a/decoder.h b/decoder.h index a14156e..8e422a8 100644 --- a/decoder.h +++ b/decoder.h @@ -1,28 +1,20 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 Antonio Diaz Diaz. - This library is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this library. If not, see . - - As a special exception, you may use this file as part of a free - software library without restriction. Specifically, if other files - instantiate templates or use macros or inline functions from this - file, or you compile this file and link it with other files to - produce an executable, this file does not by itself cause the - resulting executable to be covered by the GNU General Public - License. This exception does not however invalidate any other - reasons why the executable file might be covered by the GNU General - Public License. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ enum { rd_min_available_bytes = 8 }; @@ -84,7 +76,7 @@ static inline void Rd_reset( struct Range_decoder * const rdec ) number of bytes skipped. Returns true if it finds a valid header. */ static bool Rd_find_header( struct Range_decoder * const rdec, - int * const skippedp ) + unsigned * const skippedp ) { *skippedp = 0; while( rdec->cb.get != rdec->cb.put ) @@ -158,34 +150,30 @@ static bool Rd_try_reload( struct Range_decoder * const rdec, const bool force ) static inline void Rd_normalize( struct Range_decoder * const rdec ) { if( rdec->range <= 0x00FFFFFFU ) - { - rdec->range <<= 8; - rdec->code = (rdec->code << 8) | Rd_get_byte( rdec ); - } + { rdec->range <<= 8; rdec->code = (rdec->code << 8) | Rd_get_byte( rdec ); } } -static inline int Rd_decode( struct Range_decoder * const rdec, - const int num_bits ) +static inline unsigned Rd_decode( struct Range_decoder * const rdec, + const int num_bits ) { - int symbol = 0; + unsigned symbol = 0; int i; for( i = num_bits; i > 0; --i ) { - uint32_t mask; + bool bit; Rd_normalize( rdec ); rdec->range >>= 1; /* symbol <<= 1; */ /* if( rdec->code >= rdec->range ) { rdec->code -= rdec->range; symbol |= 1; } */ - mask = 0U - (rdec->code < rdec->range); - rdec->code -= rdec->range; - rdec->code += rdec->range & mask; - symbol = (symbol << 1) + (mask + 1); + bit = ( rdec->code >= rdec->range ); + symbol = ( symbol << 1 ) + bit; + rdec->code -= rdec->range & ( 0U - bit ); } return symbol; } -static inline int Rd_decode_bit( struct Range_decoder * const rdec, - Bit_model * const probability ) +static inline unsigned Rd_decode_bit( struct Range_decoder * const rdec, + Bit_model * const probability ) { uint32_t bound; Rd_normalize( rdec ); @@ -205,20 +193,20 @@ static inline int Rd_decode_bit( struct Range_decoder * const rdec, } } -static inline int Rd_decode_tree( struct Range_decoder * const rdec, - Bit_model bm[], const int num_bits ) +static inline unsigned Rd_decode_tree3( struct Range_decoder * const rdec, + Bit_model bm[] ) { - int symbol = 1; - int i; - for( i = num_bits; i > 0; --i ) - symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); - return symbol - (1 << num_bits); + unsigned symbol = 1; + symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); + symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); + symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); + return symbol & 7; } -static inline int Rd_decode_tree6( struct Range_decoder * const rdec, - Bit_model bm[] ) +static inline unsigned Rd_decode_tree6( struct Range_decoder * const rdec, + Bit_model bm[] ) { - int symbol = 1; + unsigned symbol = 1; symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); @@ -228,69 +216,69 @@ static inline int Rd_decode_tree6( struct Range_decoder * const rdec, return symbol & 0x3F; } -static inline int Rd_decode_tree_reversed( struct Range_decoder * const rdec, - Bit_model bm[], const int num_bits ) +static inline unsigned Rd_decode_tree8( struct Range_decoder * const rdec, + Bit_model bm[] ) { - int model = 1; - int symbol = 0; + unsigned symbol = 1; int i; - for( i = 0; i < num_bits; ++i ) - { - const bool bit = Rd_decode_bit( rdec, &bm[model] ); - model <<= 1; - if( bit ) { ++model; symbol |= (1 << i); } - } - return symbol; - } - -static inline int Rd_decode_tree_reversed4( struct Range_decoder * const rdec, - Bit_model bm[] ) - { - int model = 1; - int symbol = Rd_decode_bit( rdec, &bm[model] ); - int bit; - model = (model << 1) + symbol; - bit = Rd_decode_bit( rdec, &bm[model] ); - model = (model << 1) + bit; symbol |= (bit << 1); - bit = Rd_decode_bit( rdec, &bm[model] ); - model = (model << 1) + bit; symbol |= (bit << 2); - if( Rd_decode_bit( rdec, &bm[model] ) ) symbol |= 8; - return symbol; - } - -static inline int Rd_decode_matched( struct Range_decoder * const rdec, - Bit_model bm[], int match_byte ) - { - Bit_model * const bm1 = bm + 0x100; - int symbol = 1; - while( symbol < 0x100 ) - { - int match_bit, bit; - match_byte <<= 1; - match_bit = match_byte & 0x100; - bit = Rd_decode_bit( rdec, &bm1[match_bit+symbol] ); - symbol = ( symbol << 1 ) | bit; - if( match_bit != bit << 8 ) - { - while( symbol < 0x100 ) - symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); - break; - } - } + for( i = 0; i < 8; ++i ) + symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); return symbol & 0xFF; } -static inline int Rd_decode_len( struct Range_decoder * const rdec, - struct Len_model * const lm, - const int pos_state ) +static inline unsigned +Rd_decode_tree_reversed( struct Range_decoder * const rdec, + Bit_model bm[], const int num_bits ) + { + unsigned model = 1; + unsigned symbol = 0; + int i; + for( i = 0; i < num_bits; ++i ) + { + const unsigned bit = Rd_decode_bit( rdec, &bm[model] ); + model = ( model << 1 ) + bit; + symbol |= ( bit << i ); + } + return symbol; + } + +static inline unsigned +Rd_decode_tree_reversed4( struct Range_decoder * const rdec, Bit_model bm[] ) + { + unsigned symbol = Rd_decode_bit( rdec, &bm[1] ); + unsigned model = 2 + symbol; + unsigned bit = Rd_decode_bit( rdec, &bm[model] ); + model = ( model << 1 ) + bit; symbol |= ( bit << 1 ); + bit = Rd_decode_bit( rdec, &bm[model] ); + model = ( model << 1 ) + bit; symbol |= ( bit << 2 ); + symbol |= ( Rd_decode_bit( rdec, &bm[model] ) << 3 ); + return symbol; + } + +static inline unsigned Rd_decode_matched( struct Range_decoder * const rdec, + Bit_model bm[], unsigned match_byte ) + { + unsigned symbol = 1; + unsigned mask = 0x100; + while( true ) + { + const unsigned match_bit = ( match_byte <<= 1 ) & mask; + const unsigned bit = Rd_decode_bit( rdec, &bm[symbol+match_bit+mask] ); + symbol = ( symbol << 1 ) + bit; + if( symbol > 0xFF ) return symbol & 0xFF; + mask &= ~(match_bit ^ (bit << 8)); /* if( match_bit != bit ) mask = 0; */ + } + } + +static inline unsigned Rd_decode_len( struct Range_decoder * const rdec, + struct Len_model * const lm, + const int pos_state ) { if( Rd_decode_bit( rdec, &lm->choice1 ) == 0 ) - return Rd_decode_tree( rdec, lm->bm_low[pos_state], len_low_bits ); + return Rd_decode_tree3( rdec, lm->bm_low[pos_state] ); if( Rd_decode_bit( rdec, &lm->choice2 ) == 0 ) - return len_low_symbols + - Rd_decode_tree( rdec, lm->bm_mid[pos_state], len_mid_bits ); - return len_low_symbols + len_mid_symbols + - Rd_decode_tree( rdec, lm->bm_high, len_high_bits ); + return len_low_symbols + Rd_decode_tree3( rdec, lm->bm_mid[pos_state] ); + return len_low_symbols + len_mid_symbols + Rd_decode_tree8( rdec, lm->bm_high ); } @@ -320,7 +308,7 @@ struct LZ_decoder Bit_model bm_rep2[states]; Bit_model bm_len[states][pos_states]; Bit_model bm_dis_slot[len_states][1<cb.put > 0 ) ? d->cb.put : d->cb.buffer_size ) - 1; - return d->cb.buffer[i]; + if( d->cb.put > 0 ) return d->cb.buffer[d->cb.put-1]; + if( d->pos_wrapped ) return d->cb.buffer[d->cb.buffer_size-1]; + return 0; /* prev_byte of first byte */ } static inline uint8_t LZd_peek( const struct LZ_decoder * const d, const unsigned distance ) { - unsigned i = d->cb.put - distance - 1; - if( d->cb.put <= distance ) i += d->cb.buffer_size; + const unsigned i = ( ( d->cb.put > distance ) ? 0 : d->cb.buffer_size ) + + d->cb.put - distance - 1; return d->cb.buffer[i]; } @@ -355,18 +344,28 @@ static inline void LZd_put_byte( struct LZ_decoder * const d, const uint8_t b ) static inline void LZd_copy_block( struct LZ_decoder * const d, const unsigned distance, unsigned len ) { - unsigned i = d->cb.put - distance - 1; - bool fast; - if( d->cb.put <= distance ) - { i += d->cb.buffer_size; - fast = ( len <= d->cb.buffer_size - i && len <= i - d->cb.put ); } - else - fast = ( len < d->cb.buffer_size - d->cb.put && len <= d->cb.put - i ); - if( fast ) /* no wrap, no overlap */ + unsigned lpos = d->cb.put, i = lpos - distance - 1; + bool fast, fast2; + if( lpos > distance ) { - CRC32_update_buf( &d->crc, d->cb.buffer + i, len ); - memcpy( d->cb.buffer + d->cb.put, d->cb.buffer + i, len ); - d->cb.put += len; + fast = ( len < d->cb.buffer_size - lpos ); + fast2 = ( fast && len <= lpos - i ); + } + else + { + i += d->cb.buffer_size; + fast = ( len < d->cb.buffer_size - i ); /* (i == pos) may happen */ + fast2 = ( fast && len <= i - lpos ); + } + if( fast ) /* no wrap */ + { + const unsigned tlen = len; + if( fast2 ) /* no wrap, no overlap */ + memcpy( d->cb.buffer + lpos, d->cb.buffer + i, len ); + else + for( ; len > 0; --len ) d->cb.buffer[lpos++] = d->cb.buffer[i++]; + CRC32_update_buf( &d->crc, d->cb.buffer + d->cb.put, tlen ); + d->cb.put += tlen; } else for( ; len > 0; --len ) { @@ -402,11 +401,10 @@ static inline bool LZd_init( struct LZ_decoder * const d, Bm_array_init( d->bm_rep2, states ); Bm_array_init( d->bm_len[0], states * pos_states ); Bm_array_init( d->bm_dis_slot[0], len_states * (1 << dis_slot_bits) ); - Bm_array_init( d->bm_dis, modeled_distances - end_dis_model ); + Bm_array_init( d->bm_dis, modeled_distances - end_dis_model + 1 ); Bm_array_init( d->bm_align, dis_align_size ); Lm_init( &d->match_len_model ); Lm_init( &d->rep_len_model ); - d->cb.buffer[d->cb.buffer_size-1] = 0; /* prev_byte of first byte */ return true; } diff --git a/doc/lzlib.info b/doc/lzlib.info index a9f47b3..a2a8c68 100644 --- a/doc/lzlib.info +++ b/doc/lzlib.info @@ -11,7 +11,7 @@ File: lzlib.info, Node: Top, Next: Introduction, Up: (dir) Lzlib Manual ************ -This manual is for Lzlib (version 1.8, 17 May 2016). +This manual is for Lzlib (version 1.9, 11 April 2017). * Menu: @@ -29,7 +29,7 @@ This manual is for Lzlib (version 1.8, 17 May 2016). * Concept index:: Index of concepts - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 Antonio Diaz Diaz. This manual is free documentation: you have unlimited permission to copy, distribute and modify it. @@ -57,11 +57,11 @@ availability: (lziprecover)Data safety. * The lzip format is as simple as possible (but not simpler). The - lzip manual provides the code of a simple decompressor along with - a detailed explanation of how it works, so that with the only help - of the lzip manual it would be possible for a digital - archaeologist to extract the data from a lzip file long after - quantum computers eventually render LZMA obsolete. + lzip manual provides the source code of a simple decompressor + along with a detailed explanation of how it works, so that with + the only help of the lzip manual it would be possible for a + digital archaeologist to extract the data from a lzip file long + after quantum computers eventually render LZMA obsolete. * Additionally the lzip reference implementation is copylefted, which guarantees that it will remain free forever. @@ -83,7 +83,7 @@ traditional zlib interface. Compression/decompression is done when the read function is called. This means the value returned by the position functions will not be -updated until a read call, even if a lot of data is written. If you +updated until a read call, even if a lot of data are written. If you want the data to be compressed in advance, just call the read function with a SIZE equal to 0. @@ -128,6 +128,10 @@ Markov (for the definition of Markov chains), G.N.N. Martin (for the definition of range encoding), Igor Pavlov (for putting all the above together in LZMA), and Julian Seward (for bzip2's CLI). + LANGUAGE NOTE: Uncompressed = not compressed = plain data; it may +never have been compressed. Decompressed is used to refer to data which +have undergone the process of decompression. +  File: lzlib.info, Node: Library version, Next: Buffering, Prev: Introduction, Up: Top @@ -258,7 +262,7 @@ calling 'LZ_compress_errno' before using it. Frees all dynamically allocated data structures for this stream. This function discards any unprocessed input and does not flush any pending output. After a call to 'LZ_compress_close', ENCODER - can no more be used as an argument to any LZ_compress function. + can no longer be used as an argument to any LZ_compress function. -- Function: int LZ_compress_finish ( struct LZ_Encoder * const ENCODER ) @@ -375,7 +379,7 @@ verified by calling 'LZ_decompress_errno' before using it. Frees all dynamically allocated data structures for this stream. This function discards any unprocessed input and does not flush any pending output. After a call to 'LZ_decompress_close', DECODER - can no more be used as an argument to any LZ_decompress function. + can no longer be used as an argument to any LZ_decompress function. -- Function: int LZ_decompress_finish ( struct LZ_Decoder * const DECODER ) @@ -786,18 +790,18 @@ Concept index  Tag Table: Node: Top220 -Node: Introduction1301 -Node: Library version5918 -Node: Buffering6563 -Node: Parameter limits7783 -Node: Compression functions8742 -Node: Decompression functions15282 -Node: Error codes21450 -Node: Error messages23425 -Node: Data format24004 -Node: Examples26569 -Node: Problems30650 -Node: Concept index31222 +Node: Introduction1303 +Node: Library version6115 +Node: Buffering6760 +Node: Parameter limits7980 +Node: Compression functions8939 +Node: Decompression functions15481 +Node: Error codes21651 +Node: Error messages23626 +Node: Data format24205 +Node: Examples26770 +Node: Problems30851 +Node: Concept index31423  End Tag Table diff --git a/doc/lzlib.texi b/doc/lzlib.texi index bc3b9fe..8b4aaaf 100644 --- a/doc/lzlib.texi +++ b/doc/lzlib.texi @@ -6,8 +6,8 @@ @finalout @c %**end of header -@set UPDATED 17 May 2016 -@set VERSION 1.8 +@set UPDATED 11 April 2017 +@set VERSION 1.9 @dircategory Data Compression @direntry @@ -50,7 +50,7 @@ This manual is for Lzlib (version @value{VERSION}, @value{UPDATED}). @end menu @sp 1 -Copyright @copyright{} 2009-2016 Antonio Diaz Diaz. +Copyright @copyright{} 2009-2017 Antonio Diaz Diaz. This manual is free documentation: you have unlimited permission to copy, distribute and modify it. @@ -83,10 +83,10 @@ including error-checked merging of damaged copies of a file. @item The lzip format is as simple as possible (but not simpler). The lzip -manual provides the code of a simple decompressor along with a detailed -explanation of how it works, so that with the only help of the lzip -manual it would be possible for a digital archaeologist to extract the -data from a lzip file long after quantum computers eventually render +manual provides the source code of a simple decompressor along with a +detailed explanation of how it works, so that with the only help of the +lzip manual it would be possible for a digital archaeologist to extract +the data from a lzip file long after quantum computers eventually render LZMA obsolete. @item @@ -111,7 +111,7 @@ traditional zlib interface. Compression/decompression is done when the read function is called. This means the value returned by the position functions will not be updated -until a read call, even if a lot of data is written. If you want the +until a read call, even if a lot of data are written. If you want the data to be compressed in advance, just call the read function with a @var{size} equal to 0. @@ -155,6 +155,10 @@ the definition of Markov chains), G.N.N. Martin (for the definition of range encoding), Igor Pavlov (for putting all the above together in LZMA), and Julian Seward (for bzip2's CLI). +LANGUAGE NOTE: Uncompressed = not compressed = plain data; it may never +have been compressed. Decompressed is used to refer to data which have +undergone the process of decompression. + @node Library version @chapter Library version @@ -293,7 +297,7 @@ for example INT64_MAX. Frees all dynamically allocated data structures for this stream. This function discards any unprocessed input and does not flush any pending output. After a call to @samp{LZ_compress_close}, @var{encoder} can no -more be used as an argument to any LZ_compress function. +longer be used as an argument to any LZ_compress function. @end deftypefun @@ -427,7 +431,7 @@ pointer must not be used and should be freed with Frees all dynamically allocated data structures for this stream. This function discards any unprocessed input and does not flush any pending output. After a call to @samp{LZ_decompress_close}, @var{decoder} can no -more be used as an argument to any LZ_decompress function. +longer be used as an argument to any LZ_decompress function. @end deftypefun diff --git a/doc/minilzip.1 b/doc/minilzip.1 index b5ebf78..3fefa02 100644 --- a/doc/minilzip.1 +++ b/doc/minilzip.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.46.1. -.TH MINILZIP "1" "May 2016" "minilzip 1.8" "User Commands" +.TH MINILZIP "1" "April 2017" "minilzip 1.9" "User Commands" .SH NAME minilzip \- reduces the size of files .SH SYNOPSIS @@ -87,8 +87,8 @@ Report bugs to lzip\-bug@nongnu.org .br Lzlib home page: http://www.nongnu.org/lzip/lzlib.html .SH COPYRIGHT -Copyright \(co 2016 Antonio Diaz Diaz. -Using lzlib 1.8 +Copyright \(co 2017 Antonio Diaz Diaz. +Using lzlib 1.9 License GPLv2+: GNU GPL version 2 or later .br This is free software: you are free to change and redistribute it. diff --git a/encoder.c b/encoder.c index f5b5b46..cb4d222 100644 --- a/encoder.c +++ b/encoder.c @@ -1,28 +1,20 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 Antonio Diaz Diaz. - This library is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this library. If not, see . - - As a special exception, you may use this file as part of a free - software library without restriction. Specifically, if other files - instantiate templates or use macros or inline functions from this - file, or you compile this file and link it with other files to - produce an executable, this file does not by itself cause the - resulting executable to be covered by the GNU General Public - License. This exception does not however invalidate any other - reasons why the executable file might be covered by the GNU General - Public License. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs ) @@ -37,7 +29,7 @@ static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs const int min_pos = ( e->eb.mb.pos > e->eb.mb.dictionary_size ) ? e->eb.mb.pos - e->eb.mb.dictionary_size : 0; const uint8_t * const data = Mb_ptr_to_current_pos( &e->eb.mb ); - int count, key2, key3, key4, newpos; + int count, key2, key3, key4, newpos1; unsigned tmp; int len_limit = e->match_len_limit; @@ -85,16 +77,16 @@ static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs e->eb.mb.prev_positions[key2] = pos1; e->eb.mb.prev_positions[key3] = pos1; - newpos = e->eb.mb.prev_positions[key4]; + newpos1 = e->eb.mb.prev_positions[key4]; e->eb.mb.prev_positions[key4] = pos1; for( count = e->cycles; ; ) { int delta; - if( newpos <= min_pos || --count < 0 ) { *ptr0 = *ptr1 = 0; break; } + if( newpos1 <= min_pos || --count < 0 ) { *ptr0 = *ptr1 = 0; break; } if( e->been_flushed ) len = 0; - delta = pos1 - newpos; + delta = pos1 - newpos1; newptr = e->eb.mb.pos_array + ( ( e->eb.mb.cyclic_pos - delta + ( (e->eb.mb.cyclic_pos >= delta) ? 0 : e->eb.mb.dictionary_size + 1 ) ) << 1 ); @@ -116,16 +108,16 @@ static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs } if( data[len-delta] < data[len] ) { - *ptr0 = newpos; + *ptr0 = newpos1; ptr0 = newptr + 1; - newpos = *ptr0; + newpos1 = *ptr0; len0 = len; if( len1 < len ) len = len1; } else { - *ptr1 = newpos; + *ptr1 = newpos1; ptr1 = newptr; - newpos = *ptr1; + newpos1 = *ptr1; len1 = len; if( len0 < len ) len = len0; } } @@ -141,7 +133,7 @@ static void LZe_update_distance_prices( struct LZ_encoder * const e ) const int dis_slot = dis_slots[dis]; const int direct_bits = ( dis_slot >> 1 ) - 1; const int base = ( 2 | ( dis_slot & 1 ) ) << direct_bits; - const int price = price_symbol_reversed( e->eb.bm_dis + base - dis_slot - 1, + const int price = price_symbol_reversed( e->eb.bm_dis + ( base - dis_slot ), dis - base, direct_bits ); for( len_state = 0; len_state < len_states; ++len_state ) e->dis_prices[len_state][dis] = price; @@ -154,9 +146,9 @@ static void LZe_update_distance_prices( struct LZ_encoder * const e ) const Bit_model * const bmds = e->eb.bm_dis_slot[len_state]; int slot = 0; for( ; slot < end_dis_model; ++slot ) - dsp[slot] = price_symbol( bmds, slot, dis_slot_bits ); + dsp[slot] = price_symbol6( bmds, slot ); for( ; slot < e->num_dis_slots; ++slot ) - dsp[slot] = price_symbol( bmds, slot, dis_slot_bits ) + + dsp[slot] = price_symbol6( bmds, slot ) + (((( slot >> 1 ) - 1 ) - dis_align_bits ) << price_shift_bits ); for( dis = 0; dis < start_dis_model; ++dis ) @@ -169,16 +161,16 @@ static void LZe_update_distance_prices( struct LZ_encoder * const e ) /* Returns the number of bytes advanced (ahead). trials[0]..trials[ahead-1] contain the steps to encode. - ( trials[0].dis == -1 ) means literal. + ( trials[0].dis4 == -1 ) means literal. A match/rep longer or equal than match_len_limit finishes the sequence. */ static int LZe_sequence_optimizer( struct LZ_encoder * const e, const int reps[num_rep_distances], const State state ) { - int main_len, num_pairs, i, rep, cur = 0, num_trials, len; + int main_len, num_pairs, i, rep, num_trials, len; + int rep_index = 0, cur = 0; int replens[num_rep_distances]; - int rep_index = 0; if( e->pending_num_pairs > 0 ) /* from previous call */ { @@ -191,13 +183,13 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, for( i = 0; i < num_rep_distances; ++i ) { - replens[i] = Mb_true_match_len( &e->eb.mb, 0, reps[i] + 1, max_match_len ); + replens[i] = Mb_true_match_len( &e->eb.mb, 0, reps[i] + 1 ); if( replens[i] > replens[rep_index] ) rep_index = i; } if( replens[rep_index] >= e->match_len_limit ) { e->trials[0].price = replens[rep_index]; - e->trials[0].dis = rep_index; + e->trials[0].dis4 = rep_index; if( !LZe_move_and_update( e, replens[rep_index] ) ) return 0; return replens[rep_index]; } @@ -205,7 +197,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, if( main_len >= e->match_len_limit ) { e->trials[0].price = main_len; - e->trials[0].dis = e->pairs[num_pairs-1].dis + num_rep_distances; + e->trials[0].dis4 = e->pairs[num_pairs-1].dis + num_rep_distances; if( !LZe_move_and_update( e, main_len ) ) return 0; return main_len; } @@ -223,7 +215,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, e->trials[1].price += LZeb_price_literal( &e->eb, prev_byte, cur_byte ); else e->trials[1].price += LZeb_price_matched( &e->eb, prev_byte, cur_byte, match_byte ); - e->trials[1].dis = -1; /* literal */ + e->trials[1].dis4 = -1; /* literal */ if( match_byte == cur_byte ) Tr_update( &e->trials[1], rep_match_price + @@ -234,7 +226,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, if( num_trials < min_match_len ) { e->trials[0].price = 1; - e->trials[0].dis = e->trials[1].dis; + e->trials[0].dis4 = e->trials[1].dis4; if( !Mb_move_pos( &e->eb.mb ) ) return 0; return 1; } @@ -259,7 +251,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, if( main_len > replens[0] ) { const int normal_match_price = match_price + price0( e->eb.bm_rep[state] ); - i = 0, len = max( replens[0] + 1, min_match_len ); + int i = 0, len = max( replens[0] + 1, min_match_len ); while( len > e->pairs[i].len ) ++i; while( true ) { @@ -300,7 +292,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, /* give final values to current trial */ cur_trial = &e->trials[cur]; { - int dis = cur_trial->dis; + const int dis4 = cur_trial->dis4; int prev_index = cur_trial->prev_index; const int prev_index2 = cur_trial->prev_index2; @@ -309,32 +301,24 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, cur_state = e->trials[prev_index].state; if( prev_index + 1 == cur ) /* len == 1 */ { - if( dis == 0 ) cur_state = St_set_short_rep( cur_state ); + if( dis4 == 0 ) cur_state = St_set_short_rep( cur_state ); else cur_state = St_set_char( cur_state ); /* literal */ } - else if( dis < num_rep_distances ) cur_state = St_set_rep( cur_state ); + else if( dis4 < num_rep_distances ) cur_state = St_set_rep( cur_state ); else cur_state = St_set_match( cur_state ); } - else if( prev_index2 == dual_step_trial ) /* dis == 0 */ + else { - --prev_index; - cur_state = e->trials[prev_index].state; - cur_state = St_set_char( cur_state ); - cur_state = St_set_rep( cur_state ); - } - else /* if( prev_index2 >= 0 ) */ - { - prev_index = prev_index2; - cur_state = e->trials[prev_index].state; - if( dis < num_rep_distances ) cur_state = St_set_rep( cur_state ); - else cur_state = St_set_match( cur_state ); - cur_state = St_set_char( cur_state ); - cur_state = St_set_rep( cur_state ); + if( prev_index2 == dual_step_trial ) /* dis4 == 0 (rep0) */ + --prev_index; + else /* prev_index2 >= 0 */ + prev_index = prev_index2; + cur_state = 8; /* St_set_char_rep(); */ } cur_trial->state = cur_state; for( i = 0; i < num_rep_distances; ++i ) cur_trial->reps[i] = e->trials[prev_index].reps[i]; - mtf_reps( dis, cur_trial->reps ); + mtf_reps( dis4, cur_trial->reps ); /* literal is ignored */ } pos_state = Mb_data_position( &e->eb.mb ) & pos_state_mask; @@ -357,7 +341,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, match_price = cur_trial->price + price1( e->eb.bm_match[cur_state][pos_state] ); rep_match_price = match_price + price1( e->eb.bm_rep[cur_state] ); - if( match_byte == cur_byte && next_trial->dis != 0 && + if( match_byte == cur_byte && next_trial->dis4 != 0 && next_trial->prev_index2 == single_step_trial ) { const int price = rep_match_price + @@ -365,7 +349,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, if( price <= next_trial->price ) { next_trial->price = price; - next_trial->dis = 0; + next_trial->dis4 = 0; /* rep0 */ next_trial->prev_index = cur; } } @@ -382,16 +366,16 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, const uint8_t * const data = Mb_ptr_to_current_pos( &e->eb.mb ); const int dis = cur_trial->reps[0] + 1; const int limit = min( e->match_len_limit + 1, triable_bytes ); - len = 1; + int len = 1; while( len < limit && data[len-dis] == data[len] ) ++len; if( --len >= min_match_len ) { const int pos_state2 = ( pos_state + 1 ) & pos_state_mask; const State state2 = St_set_char( cur_state ); const int price = next_price + - price1( e->eb.bm_match[state2][pos_state2] ) + - price1( e->eb.bm_rep[state2] ) + - LZe_price_rep0_len( e, len, state2, pos_state2 ); + price1( e->eb.bm_match[state2][pos_state2] ) + + price1( e->eb.bm_rep[state2] ) + + LZe_price_rep0_len( e, len, state2, pos_state2 ); while( num_trials < cur + 1 + len ) e->trials[++num_trials].price = infinite_price; Tr_update2( &e->trials[cur+1+len], price, cur + 1 ); @@ -402,8 +386,8 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, for( rep = 0; rep < num_rep_distances; ++rep ) { const uint8_t * const data = Mb_ptr_to_current_pos( &e->eb.mb ); - int price; const int dis = cur_trial->reps[rep] + 1; + int price; if( data[0-dis] != data[0] || data[1-dis] != data[1] ) continue; for( len = min_match_len; len < len_limit; ++len ) @@ -459,7 +443,6 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, for( len = start_len; ; ++len ) { int price = normal_match_price + LZe_price_pair( e, dis, len, pos_state ); - Tr_update( &e->trials[cur+len], price, dis + num_rep_distances, cur ); /* try match + literal + rep0 */ @@ -508,10 +491,7 @@ static bool LZe_encode_member( struct LZ_encoder * const e ) if( e->eb.member_finished ) return true; if( Re_member_position( &e->eb.renc ) >= e->eb.member_size_limit ) - { - if( LZeb_full_flush( &e->eb ) ) e->eb.member_finished = true; - return true; - } + { LZeb_try_full_flush( &e->eb ); return true; } if( Mb_data_position( &e->eb.mb ) == 0 && !Mb_data_finished( &e->eb.mb ) ) /* encode first byte */ @@ -548,7 +528,6 @@ static bool LZe_encode_member( struct LZ_encoder * const e ) } ahead = LZe_sequence_optimizer( e, e->eb.reps, *state ); - if( ahead <= 0 ) return false; /* can't happen */ e->price_counter -= ahead; for( i = 0; ahead > 0; ) @@ -556,7 +535,7 @@ static bool LZe_encode_member( struct LZ_encoder * const e ) const int pos_state = ( Mb_data_position( &e->eb.mb ) - ahead ) & pos_state_mask; const int len = e->trials[i].price; - const int dis = e->trials[i].dis; + int dis = e->trials[i].dis4; bool bit = ( dis < 0 ); Re_encode_bit( &e->eb.renc, &e->eb.bm_match[*state][pos_state], !bit ); @@ -602,9 +581,9 @@ static bool LZe_encode_member( struct LZ_encoder * const e ) } else /* match */ { - LZeb_encode_pair( &e->eb, dis - num_rep_distances, len, pos_state ); - if( get_slot( dis - num_rep_distances ) >= end_dis_model ) - --e->align_price_counter; + dis -= num_rep_distances; + LZeb_encode_pair( &e->eb, dis, len, pos_state ); + if( dis >= modeled_distances ) --e->align_price_counter; --e->dis_price_counter; Lp_decrement_counter( &e->match_len_prices, pos_state ); *state = St_set_match( *state ); @@ -614,11 +593,11 @@ static bool LZe_encode_member( struct LZ_encoder * const e ) if( Re_member_position( &e->eb.renc ) >= e->eb.member_size_limit ) { if( !Mb_dec_pos( &e->eb.mb, ahead ) ) return false; - if( LZeb_full_flush( &e->eb ) ) e->eb.member_finished = true; + LZeb_try_full_flush( &e->eb ); return true; } } } - if( LZeb_full_flush( &e->eb ) ) e->eb.member_finished = true; + LZeb_try_full_flush( &e->eb ); return true; } diff --git a/encoder.h b/encoder.h index b70a8ec..dd02efb 100644 --- a/encoder.h +++ b/encoder.h @@ -1,28 +1,20 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 Antonio Diaz Diaz. - This library is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this library. If not, see . - - As a special exception, you may use this file as part of a free - software library without restriction. Specifically, if other files - instantiate templates or use macros or inline functions from this - file, or you compile this file and link it with other files to - produce an executable, this file does not by itself cause the - resulting executable to be covered by the GNU General Public - License. This exception does not however invalidate any other - reasons why the executable file might be covered by the GNU General - Public License. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ struct Len_prices @@ -31,7 +23,7 @@ struct Len_prices int len_symbols; int count; int prices[pos_states][max_len_symbols]; - int counters[pos_states]; + int counters[pos_states]; /* may decrement below 0 */ }; static inline void Lp_update_low_mid_prices( struct Len_prices * const lp, @@ -40,14 +32,13 @@ static inline void Lp_update_low_mid_prices( struct Len_prices * const lp, int * const pps = lp->prices[pos_state]; int tmp = price0( lp->lm->choice1 ); int len = 0; - lp->counters[pos_state] = lp->count; for( ; len < len_low_symbols && len < lp->len_symbols; ++len ) - pps[len] = tmp + price_symbol( lp->lm->bm_low[pos_state], len, len_low_bits ); + pps[len] = tmp + price_symbol3( lp->lm->bm_low[pos_state], len ); if( len >= lp->len_symbols ) return; tmp = price1( lp->lm->choice1 ) + price0( lp->lm->choice2 ); for( ; len < len_low_symbols + len_mid_symbols && len < lp->len_symbols; ++len ) pps[len] = tmp + - price_symbol( lp->lm->bm_mid[pos_state], len - len_low_symbols, len_mid_bits ); + price_symbol3( lp->lm->bm_mid[pos_state], len - len_low_symbols ); } static inline void Lp_update_high_prices( struct Len_prices * const lp ) @@ -58,7 +49,7 @@ static inline void Lp_update_high_prices( struct Len_prices * const lp ) /* using 4 slots per value makes "Lp_price" faster */ lp->prices[3][len] = lp->prices[2][len] = lp->prices[1][len] = lp->prices[0][len] = tmp + - price_symbol( lp->lm->bm_high, len - len_low_symbols - len_mid_symbols, len_high_bits ); + price_symbol8( lp->lm->bm_high, len - len_low_symbols - len_mid_symbols ); } static inline void Lp_reset( struct Len_prices * const lp ) @@ -84,14 +75,15 @@ static inline void Lp_update_prices( struct Len_prices * const lp ) bool high_pending = false; for( pos_state = 0; pos_state < pos_states; ++pos_state ) if( lp->counters[pos_state] <= 0 ) - { Lp_update_low_mid_prices( lp, pos_state ); high_pending = true; } + { lp->counters[pos_state] = lp->count; + Lp_update_low_mid_prices( lp, pos_state ); high_pending = true; } if( high_pending && lp->len_symbols > len_low_symbols + len_mid_symbols ) Lp_update_high_prices( lp ); } static inline int Lp_price( const struct Len_prices * const lp, - const int symbol, const int pos_state ) - { return lp->prices[pos_state][symbol - min_match_len]; } + const int len, const int pos_state ) + { return lp->prices[pos_state][len - min_match_len]; } struct Pair /* distance-length pair */ @@ -109,7 +101,7 @@ struct Trial { State state; int price; /* dual use var; cumulative price, match length */ - int dis; /* rep index or match distance. (-1 for literal) */ + int dis4; /* -1 for literal, or rep, or match distance + 4 */ int prev_index; /* index of prev trial in trials[] */ int prev_index2; /* -2 trial is single step */ /* -1 literal + rep0 */ @@ -118,34 +110,28 @@ struct Trial }; static inline void Tr_update( struct Trial * const trial, const int pr, - const int distance, const int p_i ) + const int distance4, const int p_i ) { if( pr < trial->price ) - { - trial->price = pr; trial->dis = distance; trial->prev_index = p_i; - trial->prev_index2 = single_step_trial; - } + { trial->price = pr; trial->dis4 = distance4; trial->prev_index = p_i; + trial->prev_index2 = single_step_trial; } } static inline void Tr_update2( struct Trial * const trial, const int pr, const int p_i ) { if( pr < trial->price ) - { - trial->price = pr; trial->dis = 0; trial->prev_index = p_i; - trial->prev_index2 = dual_step_trial; - } + { trial->price = pr; trial->dis4 = 0; trial->prev_index = p_i; + trial->prev_index2 = dual_step_trial; } } static inline void Tr_update3( struct Trial * const trial, const int pr, - const int distance, const int p_i, + const int distance4, const int p_i, const int p_i2 ) { if( pr < trial->price ) - { - trial->price = pr; trial->dis = distance; trial->prev_index = p_i; - trial->prev_index2 = p_i2; - } + { trial->price = pr; trial->dis4 = distance4; trial->prev_index = p_i; + trial->prev_index2 = p_i2; } } @@ -164,7 +150,7 @@ struct LZ_encoder int dis_prices[len_states][modeled_distances]; int align_prices[dis_align_size]; int num_dis_slots; - int price_counter; + int price_counter; /* counters may decrement below 0 */ int dis_price_counter; int align_price_counter; bool been_flushed; @@ -175,26 +161,25 @@ static inline bool Mb_dec_pos( struct Matchfinder_base * const mb, { if( ahead < 0 || mb->pos < ahead ) return false; mb->pos -= ahead; + if( mb->cyclic_pos < ahead ) mb->cyclic_pos += mb->dictionary_size + 1; mb->cyclic_pos -= ahead; - if( mb->cyclic_pos < 0 ) mb->cyclic_pos += mb->dictionary_size + 1; return true; } static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs ); - /* move-to-front dis in/into reps if( dis > 0 ) */ -static inline void mtf_reps( const int dis, int reps[num_rep_distances] ) + /* move-to-front dis in/into reps; do nothing if( dis4 <= 0 ) */ +static inline void mtf_reps( const int dis4, int reps[num_rep_distances] ) { - int i; - if( dis >= num_rep_distances ) + if( dis4 >= num_rep_distances ) /* match */ { - for( i = num_rep_distances - 1; i > 0; --i ) reps[i] = reps[i-1]; - reps[0] = dis - num_rep_distances; + reps[3] = reps[2]; reps[2] = reps[1]; reps[1] = reps[0]; + reps[0] = dis4 - num_rep_distances; } - else if( dis > 0 ) + else if( dis4 > 0 ) /* repeated match */ { - const int distance = reps[dis]; - for( i = dis; i > 0; --i ) reps[i] = reps[i-1]; + const int distance = reps[dis4]; + int i; for( i = dis4; i > 0; --i ) reps[i] = reps[i-1]; reps[0] = distance; } } @@ -206,8 +191,8 @@ static inline int LZeb_price_shortrep( const struct LZ_encoder_base * const eb, } static inline int LZeb_price_rep( const struct LZ_encoder_base * const eb, - const int rep, - const State state, const int pos_state ) + const int rep, const State state, + const int pos_state ) { int price; if( rep == 0 ) return price0( eb->bm_rep0[state] ) + @@ -224,8 +209,8 @@ static inline int LZeb_price_rep( const struct LZ_encoder_base * const eb, } static inline int LZe_price_rep0_len( const struct LZ_encoder * const e, - const int len, - const State state, const int pos_state ) + const int len, const State state, + const int pos_state ) { return LZeb_price_rep( &e->eb, 0, state, pos_state ) + Lp_price( &e->rep_len_prices, len, pos_state ); @@ -249,13 +234,10 @@ static inline int LZe_read_match_distances( struct LZ_encoder * const e ) const int num_pairs = LZe_get_match_pairs( e, e->pairs ); if( num_pairs > 0 ) { - int len = e->pairs[num_pairs-1].len; + const int len = e->pairs[num_pairs-1].len; if( len == e->match_len_limit && len < max_match_len ) - { - len += Mb_true_match_len( &e->eb.mb, len, e->pairs[num_pairs-1].dis + 1, - max_match_len - len ); - e->pairs[num_pairs-1].len = len; - } + e->pairs[num_pairs-1].len = + Mb_true_match_len( &e->eb.mb, len, e->pairs[num_pairs-1].dis + 1 ); } return num_pairs; } @@ -273,7 +255,7 @@ static inline bool LZe_move_and_update( struct LZ_encoder * const e, int n ) static inline void LZe_backward( struct LZ_encoder * const e, int cur ) { - int * const dis = &e->trials[cur].dis; + int dis4 = e->trials[cur].dis4; while( cur > 0 ) { const int prev_index = e->trials[cur].prev_index; @@ -281,19 +263,19 @@ static inline void LZe_backward( struct LZ_encoder * const e, int cur ) if( e->trials[cur].prev_index2 != single_step_trial ) { - prev_trial->dis = -1; + prev_trial->dis4 = -1; /* literal */ prev_trial->prev_index = prev_index - 1; prev_trial->prev_index2 = single_step_trial; if( e->trials[cur].prev_index2 >= 0 ) { struct Trial * const prev_trial2 = &e->trials[prev_index-1]; - prev_trial2->dis = *dis; *dis = 0; + prev_trial2->dis4 = dis4; dis4 = 0; /* rep0 */ prev_trial2->prev_index = e->trials[cur].prev_index2; prev_trial2->prev_index2 = single_step_trial; } } prev_trial->price = cur - prev_index; /* len */ - cur = *dis; *dis = prev_trial->dis; prev_trial->dis = cur; + cur = dis4; dis4 = prev_trial->dis4; prev_trial->dis4 = cur; cur = prev_index; } } @@ -305,7 +287,7 @@ static inline bool LZe_init( struct LZ_encoder * const e, const int dict_size, const int len_limit, const unsigned long long member_size ) { - enum { before = max_num_trials + 1, + enum { before = max_num_trials, /* bytes to keep in buffer after pos */ after_size = max_num_trials + ( 2 * max_match_len ) + 1, dict_factor = 2, diff --git a/encoder_base.c b/encoder_base.c index ee7e0bb..be9af5d 100644 --- a/encoder_base.c +++ b/encoder_base.c @@ -1,28 +1,20 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 Antonio Diaz Diaz. - This library is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this library. If not, see . - - As a special exception, you may use this file as part of a free - software library without restriction. Specifically, if other files - instantiate templates or use macros or inline functions from this - file, or you compile this file and link it with other files to - produce an executable, this file does not by itself cause the - resulting executable to be covered by the GNU General Public - License. This exception does not however invalidate any other - reasons why the executable file might be covered by the GNU General - Public License. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ static bool Mb_normalize_pos( struct Matchfinder_base * const mb ) @@ -32,11 +24,11 @@ static bool Mb_normalize_pos( struct Matchfinder_base * const mb ) if( !mb->at_stream_end ) { int i; - const int offset = mb->pos - mb->dictionary_size - mb->before_size; + const int offset = mb->pos - mb->before_size - mb->dictionary_size; const int size = mb->stream_pos - offset; memmove( mb->buffer, mb->buffer + offset, size ); mb->partial_data_pos += offset; - mb->pos -= offset; + mb->pos -= offset; /* pos = before_size + dictionary_size */ mb->stream_pos -= offset; for( i = 0; i < mb->num_prev_positions; ++i ) mb->prev_positions[i] -= min( mb->prev_positions[i], offset ); @@ -82,8 +74,9 @@ static bool Mb_init( struct Matchfinder_base * const mb, mb->num_prev_positions = size; mb->pos_array_size = pos_array_factor * ( mb->dictionary_size + 1 ); size += mb->pos_array_size; - if( size * sizeof (int32_t) <= size ) mb->prev_positions = 0; - else mb->prev_positions = (int32_t *)malloc( size * sizeof (int32_t) ); + if( size * sizeof mb->prev_positions[0] <= size ) mb->prev_positions = 0; + else mb->prev_positions = + (int32_t *)malloc( size * sizeof mb->prev_positions[0] ); if( !mb->prev_positions ) { free( mb->buffer ); return false; } mb->pos_array = mb->prev_positions + mb->num_prev_positions; for( i = 0; i < mb->num_prev_positions; ++i ) mb->prev_positions[i] = 0; @@ -100,7 +93,7 @@ static void Mb_adjust_dictionary_size( struct Matchfinder_base * const mb ) mb->dictionary_size = mb->pos_limit = max( min_dictionary_size, mb->stream_pos ); size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 ); - if( mb->dictionary_size > 1 << 26 ) + if( mb->dictionary_size > 1 << 26 ) /* 64 MiB */ size >>= 1; mb->key4_mask = size - 1; size += mb->num_prev_positions23; @@ -126,7 +119,7 @@ static void Mb_reset( struct Matchfinder_base * const mb ) /* End Of Stream mark => (dis == 0xFFFFFFFFU, len == min_match_len) */ -static bool LZeb_full_flush( struct LZ_encoder_base * const eb ) +static void LZeb_try_full_flush( struct LZ_encoder_base * const eb ) { int i; const int pos_state = Mb_data_position( &eb->mb ) & pos_state_mask; @@ -134,7 +127,8 @@ static bool LZeb_full_flush( struct LZ_encoder_base * const eb ) File_trailer trailer; if( eb->member_finished || Cb_free_bytes( &eb->renc.cb ) < max_marker_size + eb->renc.ff_count + Ft_size ) - return false; + return; + eb->member_finished = true; Re_encode_bit( &eb->renc, &eb->bm_match[state][pos_state], 1 ); Re_encode_bit( &eb->renc, &eb->bm_rep[state], 0 ); LZeb_encode_pair( eb, 0xFFFFFFFFU, min_match_len, pos_state ); @@ -144,7 +138,6 @@ static bool LZeb_full_flush( struct LZ_encoder_base * const eb ) Ft_set_member_size( trailer, Re_member_position( &eb->renc ) + Ft_size ); for( i = 0; i < Ft_size; ++i ) Cb_put_byte( &eb->renc.cb, trailer[i] ); - return true; } @@ -183,7 +176,7 @@ static void LZeb_reset( struct LZ_encoder_base * const eb, Bm_array_init( eb->bm_rep2, states ); Bm_array_init( eb->bm_len[0], states * pos_states ); Bm_array_init( eb->bm_dis_slot[0], len_states * (1 << dis_slot_bits) ); - Bm_array_init( eb->bm_dis, modeled_distances - end_dis_model ); + Bm_array_init( eb->bm_dis, modeled_distances - end_dis_model + 1 ); Bm_array_init( eb->bm_align, dis_align_size ); Lm_init( &eb->match_len_model ); Lm_init( &eb->rep_len_model ); diff --git a/encoder_base.h b/encoder_base.h index 3209922..c4cfcca 100644 --- a/encoder_base.h +++ b/encoder_base.h @@ -1,28 +1,20 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 Antonio Diaz Diaz. - This library is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this library. If not, see . - - As a special exception, you may use this file as part of a free - software library without restriction. Specifically, if other files - instantiate templates or use macros or inline functions from this - file, or you compile this file and link it with other files to - produce an executable, this file does not by itself cause the - resulting executable to be covered by the GNU General Public - License. This exception does not however invalidate any other - reasons why the executable file might be covered by the GNU General - Public License. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ enum { price_shift_bits = 6, @@ -149,22 +141,48 @@ static inline int price0( const Bit_model probability ) static inline int price1( const Bit_model probability ) { return get_price( bit_model_total - probability ); } -static inline int price_bit( const Bit_model bm, const int bit ) - { if( bit ) return price1( bm ); else return price0( bm ); } +static inline int price_bit( const Bit_model bm, const bool bit ) + { return ( bit ? price1( bm ) : price0( bm ) ); } -static inline int price_symbol( const Bit_model bm[], int symbol, - const int num_bits ) +static inline int price_symbol3( const Bit_model bm[], int symbol ) { - int price = 0; - symbol |= ( 1 << num_bits ); - while( symbol > 1 ) - { - const int bit = symbol & 1; - symbol >>= 1; - price += price_bit( bm[symbol], bit ); - } - return price; + int price; + bool bit = symbol & 1; + symbol |= 8; symbol >>= 1; + price = price_bit( bm[symbol], bit ); + bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); + return price + price_bit( bm[1], symbol & 1 ); + } + + +static inline int price_symbol6( const Bit_model bm[], unsigned symbol ) + { + int price; + bool bit = symbol & 1; + symbol |= 64; symbol >>= 1; + price = price_bit( bm[symbol], bit ); + bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); + bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); + bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); + bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); + return price + price_bit( bm[1], symbol & 1 ); + } + + +static inline int price_symbol8( const Bit_model bm[], int symbol ) + { + int price; + bool bit = symbol & 1; + symbol |= 0x100; symbol >>= 1; + price = price_bit( bm[symbol], bit ); + bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); + bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); + bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); + bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); + bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); + bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); + return price + price_bit( bm[1], symbol & 1 ); } @@ -176,33 +194,29 @@ static inline int price_symbol_reversed( const Bit_model bm[], int symbol, int i; for( i = num_bits; i > 0; --i ) { - const int bit = symbol & 1; + const bool bit = symbol & 1; + symbol >>= 1; price += price_bit( bm[model], bit ); model = ( model << 1 ) | bit; - symbol >>= 1; } return price; } -static inline int price_matched( const Bit_model bm[], int symbol, - int match_byte ) +static inline int price_matched( const Bit_model bm[], unsigned symbol, + unsigned match_byte ) { int price = 0; - int mask = 0x100; + unsigned mask = 0x100; symbol |= mask; - - do { - int match_bit, bit; - match_byte <<= 1; - match_bit = match_byte & mask; - symbol <<= 1; - bit = symbol & 0x100; - price += price_bit( bm[match_bit+(symbol>>9)+mask], bit ); - mask &= ~(match_byte ^ symbol); /* if( match_bit != bit ) mask = 0; */ + while( true ) + { + const unsigned match_bit = ( match_byte <<= 1 ) & mask; + const bool bit = ( symbol <<= 1 ) & 0x100; + price += price_bit( bm[(symbol>>9)+match_bit+mask], bit ); + if( symbol >= 0x10000 ) return price; + mask &= ~(match_bit ^ symbol); /* if( match_bit != bit ) mask = 0; */ } - while( symbol < 0x10000 ); - return price; } @@ -264,10 +278,8 @@ static inline int Mb_free_bytes( const struct Matchfinder_base * const mb ) return mb->buffer_size - mb->stream_pos; } static inline bool Mb_enough_available_bytes( const struct Matchfinder_base * const mb ) - { - return ( mb->pos + mb->after_size <= mb->stream_pos || - ( Mb_flushing_or_end( mb ) && mb->pos < mb->stream_pos ) ); - } + { return ( mb->pos + mb->after_size <= mb->stream_pos || + ( Mb_flushing_or_end( mb ) && mb->pos < mb->stream_pos ) ); } static inline const uint8_t * Mb_ptr_to_current_pos( const struct Matchfinder_base * const mb ) @@ -284,13 +296,11 @@ static int Mb_write_data( struct Matchfinder_base * const mb, } static inline int Mb_true_match_len( const struct Matchfinder_base * const mb, - const int index, const int distance, - int len_limit ) + const int index, const int distance ) { - const uint8_t * const data = mb->buffer + mb->pos + index; - int i = 0; - if( index + len_limit > Mb_available_bytes( mb ) ) - len_limit = Mb_available_bytes( mb ) - index; + const uint8_t * const data = mb->buffer + mb->pos; + int i = index; + const int len_limit = min( Mb_available_bytes( mb ), max_match_len ); while( i < len_limit && data[i-distance] == data[i] ) ++i; return i; } @@ -317,9 +327,9 @@ struct Range_encoder static inline void Re_shift_low( struct Range_encoder * const renc ) { - const bool carry = ( renc->low > 0xFFFFFFFFU ); - if( carry || renc->low < 0xFF000000U ) + if( renc->low >> 24 != 0xFF ) { + const bool carry = ( renc->low > 0xFFFFFFFFU ); Cb_put_byte( &renc->cb, renc->cache + carry ); for( ; renc->ff_count > 0; --renc->ff_count ) Cb_put_byte( &renc->cb, 0xFF + carry ); @@ -384,18 +394,18 @@ static inline void Re_flush( struct Range_encoder * const renc ) static inline void Re_encode( struct Range_encoder * const renc, const int symbol, const int num_bits ) { - int i; - for( i = num_bits - 1; i >= 0; --i ) + unsigned mask; + for( mask = 1 << ( num_bits - 1 ); mask > 0; mask >>= 1 ) { renc->range >>= 1; - if( (symbol >> i) & 1 ) renc->low += renc->range; + if( symbol & mask ) renc->low += renc->range; if( renc->range <= 0x00FFFFFFU ) { renc->range <<= 8; Re_shift_low( renc ); } } } static inline void Re_encode_bit( struct Range_encoder * const renc, - Bit_model * const probability, const int bit ) + Bit_model * const probability, const bool bit ) { const uint32_t bound = ( renc->range >> bit_model_total_bits ) * *probability; if( !bit ) @@ -409,56 +419,78 @@ static inline void Re_encode_bit( struct Range_encoder * const renc, renc->range -= bound; *probability -= *probability >> bit_model_move_bits; } - if( renc->range <= 0x00FFFFFFU ) - { renc->range <<= 8; Re_shift_low( renc ); } + if( renc->range <= 0x00FFFFFFU ) { renc->range <<= 8; Re_shift_low( renc ); } } -static inline void Re_encode_tree( struct Range_encoder * const renc, - Bit_model bm[], const int symbol, const int num_bits ) +static inline void Re_encode_tree3( struct Range_encoder * const renc, + Bit_model bm[], const int symbol ) + { + int model = 1; + bool bit = ( symbol >> 2 ) & 1; + Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; + bit = ( symbol >> 1 ) & 1; + Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; + Re_encode_bit( renc, &bm[model], symbol & 1 ); + } + +static inline void Re_encode_tree6( struct Range_encoder * const renc, + Bit_model bm[], const unsigned symbol ) + { + int model = 1; + bool bit = ( symbol >> 5 ) & 1; + Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; + bit = ( symbol >> 4 ) & 1; + Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; + bit = ( symbol >> 3 ) & 1; + Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; + bit = ( symbol >> 2 ) & 1; + Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; + bit = ( symbol >> 1 ) & 1; + Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; + Re_encode_bit( renc, &bm[model], symbol & 1 ); + } + +static inline void Re_encode_tree8( struct Range_encoder * const renc, + Bit_model bm[], const int symbol ) { - int mask = ( 1 << ( num_bits - 1 ) ); int model = 1; int i; - for( i = num_bits; i > 0; --i, mask >>= 1 ) + for( i = 7; i >= 0; --i ) { - const int bit = ( symbol & mask ); + const bool bit = ( symbol >> i ) & 1; Re_encode_bit( renc, &bm[model], bit ); - model <<= 1; - if( bit ) model |= 1; + model = ( model << 1 ) | bit; } } static inline void Re_encode_tree_reversed( struct Range_encoder * const renc, - Bit_model bm[], int symbol, const int num_bits ) + Bit_model bm[], int symbol, const int num_bits ) { int model = 1; int i; for( i = num_bits; i > 0; --i ) { - const int bit = symbol & 1; + const bool bit = symbol & 1; + symbol >>= 1; Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; - symbol >>= 1; } } static inline void Re_encode_matched( struct Range_encoder * const renc, - Bit_model bm[], int symbol, - int match_byte ) + Bit_model bm[], unsigned symbol, + unsigned match_byte ) { - int mask = 0x100; + unsigned mask = 0x100; symbol |= mask; - - do { - int match_bit, bit; - match_byte <<= 1; - match_bit = match_byte & mask; - symbol <<= 1; - bit = symbol & 0x100; - Re_encode_bit( renc, &bm[match_bit+(symbol>>9)+mask], bit ); - mask &= ~(match_byte ^ symbol); /* if( match_bit != bit ) mask = 0; */ + while( true ) + { + const unsigned match_bit = ( match_byte <<= 1 ) & mask; + const bool bit = ( symbol <<= 1 ) & 0x100; + Re_encode_bit( renc, &bm[(symbol>>9)+match_bit+mask], bit ); + if( symbol >= 0x10000 ) break; + mask &= ~(match_bit ^ symbol); /* if( match_bit != bit ) mask = 0; */ } - while( symbol < 0x10000 ); } static inline void Re_encode_len( struct Range_encoder * const renc, @@ -468,17 +500,15 @@ static inline void Re_encode_len( struct Range_encoder * const renc, bool bit = ( ( symbol -= min_match_len ) >= len_low_symbols ); Re_encode_bit( renc, &lm->choice1, bit ); if( !bit ) - Re_encode_tree( renc, lm->bm_low[pos_state], symbol, len_low_bits ); + Re_encode_tree3( renc, lm->bm_low[pos_state], symbol ); else { - bit = ( symbol >= len_low_symbols + len_mid_symbols ); + bit = ( ( symbol -= len_low_symbols ) >= len_mid_symbols ); Re_encode_bit( renc, &lm->choice2, bit ); if( !bit ) - Re_encode_tree( renc, lm->bm_mid[pos_state], - symbol - len_low_symbols, len_mid_bits ); + Re_encode_tree3( renc, lm->bm_mid[pos_state], symbol ); else - Re_encode_tree( renc, lm->bm_high, - symbol - len_low_symbols - len_mid_symbols, len_high_bits ); + Re_encode_tree8( renc, lm->bm_high, symbol - len_mid_symbols ); } } @@ -500,7 +530,7 @@ struct LZ_encoder_base Bit_model bm_rep2[states]; Bit_model bm_len[states][pos_states]; Bit_model bm_dis_slot[len_states][1<crc ^ 0xFFFFFFFFU; } static inline int LZeb_price_literal( const struct LZ_encoder_base * const eb, - uint8_t prev_byte, uint8_t symbol ) - { return price_symbol( eb->bm_literal[get_lit_state(prev_byte)], symbol, 8 ); } + const uint8_t prev_byte, const uint8_t symbol ) + { return price_symbol8( eb->bm_literal[get_lit_state(prev_byte)], symbol ); } static inline int LZeb_price_matched( const struct LZ_encoder_base * const eb, - uint8_t prev_byte, uint8_t symbol, - uint8_t match_byte ) + const uint8_t prev_byte, const uint8_t symbol, const uint8_t match_byte ) { return price_matched( eb->bm_literal[get_lit_state(prev_byte)], symbol, match_byte ); } static inline void LZeb_encode_literal( struct LZ_encoder_base * const eb, - uint8_t prev_byte, uint8_t symbol ) - { Re_encode_tree( &eb->renc, - eb->bm_literal[get_lit_state(prev_byte)], symbol, 8 ); } + const uint8_t prev_byte, const uint8_t symbol ) + { Re_encode_tree8( &eb->renc, eb->bm_literal[get_lit_state(prev_byte)], + symbol ); } static inline void LZeb_encode_matched( struct LZ_encoder_base * const eb, - uint8_t prev_byte, uint8_t symbol, - uint8_t match_byte ) + const uint8_t prev_byte, const uint8_t symbol, const uint8_t match_byte ) { Re_encode_matched( &eb->renc, eb->bm_literal[get_lit_state(prev_byte)], symbol, match_byte ); } @@ -563,10 +591,9 @@ static inline void LZeb_encode_pair( struct LZ_encoder_base * const eb, const unsigned dis, const int len, const int pos_state ) { - const int dis_slot = get_slot( dis ); + const unsigned dis_slot = get_slot( dis ); Re_encode_len( &eb->renc, &eb->match_len_model, len, pos_state ); - Re_encode_tree( &eb->renc, eb->bm_dis_slot[get_len_state(len)], dis_slot, - dis_slot_bits ); + Re_encode_tree6( &eb->renc, eb->bm_dis_slot[get_len_state(len)], dis_slot ); if( dis_slot >= start_dis_model ) { @@ -575,7 +602,7 @@ static inline void LZeb_encode_pair( struct LZ_encoder_base * const eb, const unsigned direct_dis = dis - base; if( dis_slot < end_dis_model ) - Re_encode_tree_reversed( &eb->renc, eb->bm_dis + base - dis_slot - 1, + Re_encode_tree_reversed( &eb->renc, eb->bm_dis + ( base - dis_slot ), direct_dis, direct_bits ); else { diff --git a/fast_encoder.c b/fast_encoder.c index 03697cc..af81137 100644 --- a/fast_encoder.c +++ b/fast_encoder.c @@ -1,28 +1,20 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 Antonio Diaz Diaz. - This library is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this library. If not, see . - - As a special exception, you may use this file as part of a free - software library without restriction. Specifically, if other files - instantiate templates or use macros or inline functions from this - file, or you compile this file and link it with other files to - produce an executable, this file does not by itself cause the - resulting executable to be covered by the GNU General Public - License. This exception does not however invalidate any other - reasons why the executable file might be covered by the GNU General - Public License. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ int FLZe_longest_match_len( struct FLZ_encoder * const fe, int * const distance ) @@ -30,21 +22,22 @@ int FLZe_longest_match_len( struct FLZ_encoder * const fe, int * const distance enum { len_limit = 16 }; const uint8_t * const data = Mb_ptr_to_current_pos( &fe->eb.mb ); int32_t * ptr0 = fe->eb.mb.pos_array + fe->eb.mb.cyclic_pos; - int32_t * newptr; const int pos1 = fe->eb.mb.pos + 1; - int maxlen = 0; - int count, delta, newpos; - if( len_limit > Mb_available_bytes( &fe->eb.mb ) ) { *ptr0 = 0; return 0; } + int maxlen = 0, newpos1, count; + const int available = min( Mb_available_bytes( &fe->eb.mb ), max_match_len ); + if( available < len_limit ) { *ptr0 = 0; return 0; } fe->key4 = ( ( fe->key4 << 4 ) ^ data[3] ) & fe->eb.mb.key4_mask; - newpos = fe->eb.mb.prev_positions[fe->key4]; + newpos1 = fe->eb.mb.prev_positions[fe->key4]; fe->eb.mb.prev_positions[fe->key4] = pos1; for( count = 4; ; ) { - if( --count < 0 || newpos <= 0 ) { *ptr0 = 0; break; } - delta = pos1 - newpos; - if( delta > fe->eb.mb.dictionary_size ) { *ptr0 = 0; break; } + int32_t * newptr; + int delta; + if( newpos1 <= 0 || --count < 0 || + ( delta = pos1 - newpos1 ) > fe->eb.mb.dictionary_size ) + { *ptr0 = 0; break; } newptr = fe->eb.mb.pos_array + ( fe->eb.mb.cyclic_pos - delta + ( ( fe->eb.mb.cyclic_pos >= delta ) ? 0 : fe->eb.mb.dictionary_size + 1 ) ); @@ -52,23 +45,15 @@ int FLZe_longest_match_len( struct FLZ_encoder * const fe, int * const distance if( data[maxlen-delta] == data[maxlen] ) { int len = 0; - while( len < len_limit && data[len-delta] == data[len] ) ++len; - if( maxlen < len ) { maxlen = len; *distance = delta - 1; } + while( len < available && data[len-delta] == data[len] ) ++len; + if( maxlen < len ) + { maxlen = len; *distance = delta - 1; + if( maxlen >= len_limit ) { *ptr0 = *newptr; break; } } } - if( maxlen < len_limit ) - { - *ptr0 = newpos; - ptr0 = newptr; - newpos = *ptr0; - } - else - { - *ptr0 = *newptr; - maxlen += Mb_true_match_len( &fe->eb.mb, maxlen, *distance + 1, - max_match_len - maxlen ); - break; - } + *ptr0 = newpos1; + ptr0 = newptr; + newpos1 = *ptr0; } return maxlen; } @@ -81,10 +66,7 @@ bool FLZe_encode_member( struct FLZ_encoder * const fe ) if( fe->eb.member_finished ) return true; if( Re_member_position( &fe->eb.renc ) >= fe->eb.member_size_limit ) - { - if( LZeb_full_flush( &fe->eb ) ) fe->eb.member_finished = true; - return true; - } + { LZeb_try_full_flush( &fe->eb ); return true; } if( Mb_data_position( &fe->eb.mb ) == 0 && !Mb_data_finished( &fe->eb.mb ) ) /* encode first byte */ @@ -105,7 +87,8 @@ bool FLZe_encode_member( struct FLZ_encoder * const fe ) Re_member_position( &fe->eb.renc ) < fe->eb.member_size_limit ) { int match_distance; - int main_len, pos_state, len = 0; + int main_len, pos_state; + int len = 0; if( !Mb_enough_available_bytes( &fe->eb.mb ) || !Re_enough_free_bytes( &fe->eb.renc ) ) return true; main_len = FLZe_longest_match_len( fe, &match_distance ); @@ -113,8 +96,7 @@ bool FLZe_encode_member( struct FLZ_encoder * const fe ) for( i = 0; i < num_rep_distances; ++i ) { - const int tlen = Mb_true_match_len( &fe->eb.mb, 0, - fe->eb.reps[i] + 1, max_match_len ); + const int tlen = Mb_true_match_len( &fe->eb.mb, 0, fe->eb.reps[i] + 1 ); if( tlen > len ) { len = tlen; rep = i; } } if( len > min_match_len && len + 3 > main_len ) @@ -195,6 +177,6 @@ bool FLZe_encode_member( struct FLZ_encoder * const fe ) } } - if( LZeb_full_flush( &fe->eb ) ) fe->eb.member_finished = true; + LZeb_try_full_flush( &fe->eb ); return true; } diff --git a/fast_encoder.h b/fast_encoder.h index 9d9e1c7..c02e9cb 100644 --- a/fast_encoder.h +++ b/fast_encoder.h @@ -1,34 +1,26 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 Antonio Diaz Diaz. - This library is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this library. If not, see . - - As a special exception, you may use this file as part of a free - software library without restriction. Specifically, if other files - instantiate templates or use macros or inline functions from this - file, or you compile this file and link it with other files to - produce an executable, this file does not by itself cause the - resulting executable to be covered by the GNU General Public - License. This exception does not however invalidate any other - reasons why the executable file might be covered by the GNU General - Public License. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ struct FLZ_encoder { struct LZ_encoder_base eb; - int key4; /* key made from latest 4 bytes */ + unsigned key4; /* key made from latest 4 bytes */ }; static inline void FLZe_reset_key4( struct FLZ_encoder * const fe ) @@ -47,12 +39,10 @@ static inline bool FLZe_update_and_move( struct FLZ_encoder * const fe, int n ) { if( Mb_available_bytes( &fe->eb.mb ) >= 4 ) { - int newpos; fe->key4 = ( ( fe->key4 << 4 ) ^ fe->eb.mb.buffer[fe->eb.mb.pos+3] ) & fe->eb.mb.key4_mask; - newpos = fe->eb.mb.prev_positions[fe->key4]; + fe->eb.mb.pos_array[fe->eb.mb.cyclic_pos] = fe->eb.mb.prev_positions[fe->key4]; fe->eb.mb.prev_positions[fe->key4] = fe->eb.mb.pos + 1; - fe->eb.mb.pos_array[fe->eb.mb.cyclic_pos] = newpos; } else fe->eb.mb.pos_array[fe->eb.mb.cyclic_pos] = 0; if( !Mb_move_pos( &fe->eb.mb ) ) return false; diff --git a/lzcheck.c b/lzcheck.c index b9ba11b..9db661f 100644 --- a/lzcheck.c +++ b/lzcheck.c @@ -1,5 +1,5 @@ /* Lzcheck - Test program for the lzlib library - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 Antonio Diaz Diaz. This program is free software: you have unlimited permission to copy, distribute and modify it. diff --git a/lzip.h b/lzip.h index 73fc7f1..5fc1379 100644 --- a/lzip.h +++ b/lzip.h @@ -1,28 +1,20 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 Antonio Diaz Diaz. - This library is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this library. If not, see . - - As a special exception, you may use this file as part of a free - software library without restriction. Specifically, if other files - instantiate templates or use macros or inline functions from this - file, or you compile this file and link it with other files to - produce an executable, this file does not by itself cause the - resulting executable to be covered by the GNU General Public - License. This exception does not however invalidate any other - reasons why the executable file might be covered by the GNU General - Public License. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef max @@ -179,8 +171,10 @@ static inline void CRC32_update_buf( uint32_t * const crc, const int size ) { int i; + uint32_t c = *crc; for( i = 0; i < size; ++i ) - *crc = crc32[(*crc^buffer[i])&0xFF] ^ ( *crc >> 8 ); + c = crc32[(c^buffer[i])&0xFF] ^ ( c >> 8 ); + *crc = c; } @@ -240,7 +234,7 @@ static inline bool Fh_set_dictionary_size( File_header data, const unsigned sz ) { const unsigned base_size = 1 << data[5]; const unsigned fraction = base_size / 16; - int i; + unsigned i; for( i = 7; i >= 1; --i ) if( base_size - ( i * fraction ) >= sz ) { data[5] |= ( i << 5 ); break; } diff --git a/lzlib.c b/lzlib.c index 953f8e3..1a3080a 100644 --- a/lzlib.c +++ b/lzlib.c @@ -1,28 +1,20 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 Antonio Diaz Diaz. - This library is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this library. If not, see . - - As a special exception, you may use this file as part of a free - software library without restriction. Specifically, if other files - instantiate templates or use macros or inline functions from this - file, or you compile this file and link it with other files to - produce an executable, this file does not by itself cause the - resulting executable to be covered by the GNU General Public - License. This exception does not however invalidate any other - reasons why the executable file might be covered by the GNU General - Public License. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include @@ -387,7 +379,7 @@ int LZ_decompress_reset( struct LZ_Decoder * const d ) int LZ_decompress_sync_to_member( struct LZ_Decoder * const d ) { - int skipped = 0; + unsigned skipped = 0; if( !verify_decoder( d ) ) return -1; if( d->lz_decoder ) { LZd_free( d->lz_decoder ); free( d->lz_decoder ); d->lz_decoder = 0; } @@ -434,7 +426,7 @@ int LZ_decompress_read( struct LZ_Decoder * const d, d->fatal = true; return -1; } - if( !Fh_verify( d->member_header ) ) + if( !Fh_verify_magic( d->member_header ) ) { /* unreading the header prevents sync_to_member from skipping a member if leading garbage is shorter than a full header; "lgLZIP\x01\x0C" */ @@ -445,6 +437,13 @@ int LZ_decompress_read( struct LZ_Decoder * const d, d->fatal = true; return -1; } + if( !Fh_verify_version( d->member_header ) || + !isvalid_ds( Fh_get_dictionary_size( d->member_header ) ) ) + { + d->lz_errno = LZ_data_error; /* bad version or bad dict size */ + d->fatal = true; + return -1; + } d->first_header = false; if( Rd_available_bytes( d->rdec ) < 5 ) { @@ -493,7 +492,8 @@ int LZ_decompress_write( struct LZ_Decoder * const d, result = Rd_write_data( d->rdec, buffer, size ); while( d->seeking ) { - int size2, skipped = 0; + int size2; + unsigned skipped = 0; if( Rd_find_header( d->rdec, &skipped ) ) d->seeking = false; d->partial_in_size += skipped; if( result >= size ) break; diff --git a/lzlib.h b/lzlib.h index a734fbf..a58c851 100644 --- a/lzlib.h +++ b/lzlib.h @@ -1,28 +1,20 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 Antonio Diaz Diaz. - This library is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this library. If not, see . - - As a special exception, you may use this file as part of a free - software library without restriction. Specifically, if other files - instantiate templates or use macros or inline functions from this - file, or you compile this file and link it with other files to - produce an executable, this file does not by itself cause the - resulting executable to be covered by the GNU General Public - License. This exception does not however invalidate any other - reasons why the executable file might be covered by the GNU General - Public License. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #ifdef __cplusplus @@ -31,7 +23,7 @@ extern "C" { #define LZ_API_VERSION 1 -static const char * const LZ_version_string = "1.8"; +static const char * const LZ_version_string = "1.9"; enum LZ_Errno { LZ_ok = 0, LZ_bad_argument, LZ_mem_error, LZ_sequence_error, LZ_header_error, LZ_unexpected_eof, diff --git a/main.c b/main.c index c2754bf..633456b 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,5 @@ /* Minilzip - Test program for the lzlib library - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 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 @@ -71,16 +71,18 @@ 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, + const int errcode ); void internal_error( const char * const msg ); int verbosity = 0; const char * const Program_name = "Minilzip"; const char * const program_name = "minilzip"; -const char * const program_year = "2016"; +const char * const program_year = "2017"; const char * invocation_name = 0; -struct { const char * from; const char * to; } const known_extensions[] = { +const struct { const char * from; const char * to; } known_extensions[] = { { ".lz", "" }, { ".tlz", ".tar" }, { 0, 0 } }; @@ -116,9 +118,9 @@ static void Pp_init( struct Pretty_print * const pp, pp->stdin_name = "(stdin)"; pp->longest_name = 0; pp->first_post = false; - stdin_name_len = strlen( pp->stdin_name ); if( verbosity <= 0 ) return; + stdin_name_len = strlen( pp->stdin_name ); for( i = 0; i < num_filenames; ++i ) { const char * const s = filenames[i]; @@ -216,9 +218,9 @@ static void show_header( const unsigned dictionary_size ) { if( verbosity >= 3 ) { + enum { factor = 1024 }; const char * const prefix[8] = { "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" }; - enum { factor = 1024 }; const char * p = ""; const char * np = " "; unsigned num = dictionary_size, i; @@ -227,7 +229,7 @@ static void show_header( const unsigned dictionary_size ) for( i = 0; i < 8 && ( num > 9999 || ( exact && num >= factor ) ); ++i ) { num /= factor; if( num % factor != 0 ) exact = false; p = prefix[i]; np = ""; } - fprintf( stderr, "dictionary size %s%4u %sB. ", np, num, p ); + fprintf( stderr, "dictionary %s%4u %sB. ", np, num, p ); } } @@ -248,7 +250,7 @@ static unsigned long long getnum( const char * const ptr, if( !errno && tail[0] ) { - const int factor = ( tail[1] == 'i' ) ? 1024 : 1000; + const unsigned factor = ( tail[1] == 'i' ) ? 1024 : 1000; int exponent = 0; /* 0 = bad multiplier */ int i; switch( tail[0] ) @@ -288,7 +290,7 @@ static int get_dict_size( const char * const arg ) { char * tail; int dictionary_size; - const int bits = strtol( arg, &tail, 0 ); + const long bits = strtol( arg, &tail, 0 ); if( bits >= LZ_min_dictionary_bits() && bits <= LZ_max_dictionary_bits() && *tail == 0 ) return ( 1 << bits ); @@ -301,15 +303,15 @@ 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 ) + int eindex; + for( eindex = 0; known_extensions[eindex].from; ++eindex ) { - const char * const ext = known_extensions[i].from; + const char * const ext = known_extensions[eindex].from; const unsigned name_len = strlen( name ); const unsigned ext_len = strlen( ext ); if( name_len > ext_len && strncmp( name + name_len - ext_len, ext, ext_len ) == 0 ) - return i; + return eindex; } return -1; } @@ -330,11 +332,7 @@ static int open_instream( const char * const name, struct stat * const in_statsp { infd = open( name, O_RDONLY | O_BINARY ); if( infd < 0 ) - { - if( verbosity >= 0 ) - fprintf( stderr, "%s: Can't open input file '%s': %s\n", - program_name, name, strerror( errno ) ); - } + show_file_error( name, "Can't open input file", errno ); else { const int i = fstat( infd, in_statsp ); @@ -360,7 +358,7 @@ static int open_instream( const char * const name, struct stat * const in_statsp /* assure at least a minimum size for buffer 'buf' */ -static void * resize_buffer( void * buf, const int min_size ) +static void * resize_buffer( void * buf, const unsigned min_size ) { if( buf ) buf = realloc( buf, min_size ); else buf = malloc( min_size ); @@ -383,19 +381,19 @@ static void set_c_outname( const char * const name, const bool multifile ) } -static void set_d_outname( const char * const name, const int i ) +static void set_d_outname( const char * const name, const int eindex ) { const unsigned name_len = strlen( name ); - if( i >= 0 ) + if( eindex >= 0 ) { - const char * const from = known_extensions[i].from; + const char * const from = known_extensions[eindex].from; const unsigned from_len = strlen( from ); if( name_len > from_len ) { output_filename = resize_buffer( output_filename, name_len + - strlen( known_extensions[0].to ) + 1 ); + strlen( known_extensions[eindex].to ) + 1 ); strcpy( output_filename, name ); - strcpy( output_filename + name_len - from_len, known_extensions[i].to ); + strcpy( output_filename + name_len - from_len, known_extensions[eindex].to ); return; } } @@ -431,7 +429,8 @@ static bool open_outstream( const bool force, const bool from_stdin ) } -static bool check_tty( const int infd, const enum Mode program_mode ) +static bool check_tty( const char * const input_filename, const int infd, + const enum Mode program_mode ) { if( program_mode == m_compress && isatty( outfd ) ) { @@ -441,7 +440,8 @@ static bool check_tty( const int infd, const enum Mode program_mode ) if( ( program_mode == m_decompress || program_mode == m_test ) && isatty( infd ) ) { - show_error( "I won't read compressed data from a terminal.", 0, true ); + show_file_error( input_filename, + "I won't read compressed data from a terminal.", 0 ); return false; } return true; @@ -731,7 +731,7 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd, ( 8.0 * member_size ) / data_size, 100.0 * ( 1.0 - ( (double)member_size / data_size ) ) ); if( verbosity >= 4 ) - fprintf( stderr, "data CRC %08X, data size %9llu, member size %8llu. ", + fprintf( stderr, "CRC %08X, decompressed %9llu, compressed %8llu. ", LZ_decompress_data_crc( decoder ), data_size, member_size ); fputs( testing ? "ok\n" : "done\n", stderr ); } @@ -749,10 +749,12 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd, if( lz_errno == LZ_header_error ) { if( first_member ) - { Pp_show_msg( pp, "Bad magic number (file not in lzip format)." ); + { show_file_error( pp->name, + "Bad magic number (file not in lzip format).", 0 ); return 2; } else if( !ignore_trailing ) - { show_error( "Trailing data not allowed.", 0, false ); return 2; } + { show_file_error( pp->name, "Trailing data not allowed.", 0 ); + return 2; } break; } if( lz_errno == LZ_mem_error ) @@ -824,6 +826,16 @@ 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, + const int errcode ) + { + if( verbosity < 0 ) return; + fprintf( stderr, "%s: %s: %s", program_name, filename, msg ); + if( errcode > 0 ) fprintf( stderr, ": %s", strerror( errcode ) ); + fputc( '\n', stderr ); + } + + void internal_error( const char * const msg ) { if( verbosity >= 0 ) @@ -853,7 +865,6 @@ int main( const int argc, const char * const argv[] ) const unsigned long long max_volume_size = 0x4000000000000000ULL; unsigned long long member_size = max_member_size; unsigned long long volume_size = 0; - const char * input_filename = ""; const char * default_output_filename = ""; const char ** filenames = 0; int num_filenames = 0; @@ -866,8 +877,8 @@ int main( const int argc, const char * const argv[] ) bool force = false; bool ignore_trailing = true; bool keep_input_files = false; - bool stdin_used = false; bool recompress = false; + bool stdin_used = false; bool to_stdout = false; struct Pretty_print pp; @@ -955,9 +966,6 @@ int main( const int argc, const char * const argv[] ) setmode( STDOUT_FILENO, O_BINARY ); #endif - if( program_mode == m_test ) - outfd = -1; - num_filenames = max( 1, ap_arguments( &parser ) - argind ); filenames = resize_buffer( filenames, num_filenames * sizeof filenames[0] ); filenames[0] = "-"; @@ -968,6 +976,9 @@ int main( const int argc, const char * const argv[] ) if( strcmp( filenames[i], "-" ) != 0 ) filenames_given = true; } + if( program_mode == m_test ) + outfd = -1; + if( !to_stdout && program_mode != m_test && ( filenames_given || default_output_filename[0] ) ) set_signals(); @@ -977,6 +988,7 @@ int main( const int argc, const char * const argv[] ) output_filename = resize_buffer( output_filename, 1 ); for( i = 0; i < num_filenames; ++i ) { + const char * input_filename = ""; int tmp; struct stat in_stats; const struct stat * in_statsp; @@ -985,7 +997,6 @@ int main( const int argc, const char * const argv[] ) if( !filenames[i][0] || strcmp( filenames[i], "-" ) == 0 ) { if( stdin_used ) continue; else stdin_used = true; - input_filename = ""; infd = STDIN_FILENO; if( program_mode != m_test ) { @@ -1012,8 +1023,7 @@ int main( const int argc, const char * const argv[] ) } else { - const int eindex = extension_index( filenames[i] ); - input_filename = filenames[i]; + const int eindex = extension_index( input_filename = filenames[i] ); infd = open_instream( input_filename, &in_stats, program_mode, eindex, recompress, to_stdout ); if( infd < 0 ) { if( retval < 1 ) retval = 1; continue; } @@ -1035,14 +1045,15 @@ int main( const int argc, const char * const argv[] ) } } - if( !check_tty( infd, program_mode ) ) + Pp_set_name( &pp, input_filename ); + if( !check_tty( pp.name, infd, program_mode ) ) { if( retval < 1 ) retval = 1; + if( program_mode == m_test ) { close( infd ); infd = -1; continue; } cleanup_and_fail( retval ); } in_statsp = input_filename[0] ? &in_stats : 0; - Pp_set_name( &pp, input_filename ); if( program_mode == m_compress ) tmp = compress( member_size, volume_size, infd, &encoder_options, &pp, in_statsp ); diff --git a/testsuite/check.sh b/testsuite/check.sh index a78f156..037e2c9 100755 --- a/testsuite/check.sh +++ b/testsuite/check.sh @@ -1,6 +1,6 @@ #! /bin/sh # check script for Lzlib - A compression library for lzip files -# Copyright (C) 2009-2016 Antonio Diaz Diaz. +# Copyright (C) 2009-2017 Antonio Diaz Diaz. # # This script is free software: you have unlimited permission # to copy, distribute and modify it. @@ -19,12 +19,12 @@ if [ ! -f "${LZIP}" ] || [ ! -x "${LZIP}" ] ; then exit 1 fi -if [ -e "${LZIP}" ] 2> /dev/null ; then true -else +[ -e "${LZIP}" ] 2> /dev/null || + { echo "$0: a POSIX shell is required to run the tests" echo "Try bash -c \"$0 $1 $2\"" exit 1 -fi + } if [ -d tmp ] ; then rm -rf tmp ; fi mkdir tmp @@ -34,163 +34,218 @@ cat "${testdir}"/test.txt > in || framework_failure in_lz="${testdir}"/test.txt.lz test2="${testdir}"/test2.txt fail=0 +test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; } printf "testing lzlib-%s..." "$2" "${LZIP}" -fkqm4 in -if [ $? = 1 ] && [ ! -e in.lz ] ; then printf . ; else printf - ; fail=1 ; fi +{ [ $? = 1 ] && [ ! -e in.lz ] ; } || test_failed $LINENO "${LZIP}" -fkqm274 in -if [ $? = 1 ] && [ ! -e in.lz ] ; then printf . ; else printf - ; fail=1 ; fi -"${LZIP}" -fkqs-1 in -if [ $? = 1 ] && [ ! -e in.lz ] ; then printf . ; else printf - ; fail=1 ; fi -"${LZIP}" -fkqs0 in -if [ $? = 1 ] && [ ! -e in.lz ] ; then printf . ; else printf - ; fail=1 ; fi -"${LZIP}" -fkqs4095 in -if [ $? = 1 ] && [ ! -e in.lz ] ; then printf . ; else printf - ; fail=1 ; fi -"${LZIP}" -fkqs513MiB in -if [ $? = 1 ] && [ ! -e in.lz ] ; then printf . ; else printf - ; fail=1 ; fi +{ [ $? = 1 ] && [ ! -e in.lz ] ; } || test_failed $LINENO +for i in bad_size -1 0 4095 513MiB 1G 1T 1P 1E 1Z 1Y 10KB ; do + "${LZIP}" -fkqs $i in + { [ $? = 1 ] && [ ! -e in.lz ] ; } || test_failed $LINENO $i +done "${LZIP}" -tq in -if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi +[ $? = 2 ] || test_failed $LINENO "${LZIP}" -tq < in -if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi +[ $? = 2 ] || test_failed $LINENO "${LZIP}" -cdq in -if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi +[ $? = 2 ] || test_failed $LINENO "${LZIP}" -cdq < in -if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi -dd if="${in_lz}" bs=1 count=6 2> /dev/null | "${LZIP}" -tq -if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi -dd if="${in_lz}" bs=1 count=20 2> /dev/null | "${LZIP}" -tq -if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi +[ $? = 2 ] || test_failed $LINENO +# these are for code coverage +"${LZIP}" -t -- nx_file 2> /dev/null +[ $? = 1 ] || test_failed $LINENO +"${LZIP}" --help > /dev/null || test_failed $LINENO +"${LZIP}" -n1 -V > /dev/null || test_failed $LINENO +"${LZIP}" -m 2> /dev/null +[ $? = 1 ] || test_failed $LINENO +"${LZIP}" -z 2> /dev/null +[ $? = 1 ] || test_failed $LINENO +"${LZIP}" --bad_option 2> /dev/null +[ $? = 1 ] || test_failed $LINENO +"${LZIP}" --t 2> /dev/null +[ $? = 1 ] || test_failed $LINENO +"${LZIP}" --test=2 2> /dev/null +[ $? = 1 ] || test_failed $LINENO +"${LZIP}" --output= 2> /dev/null +[ $? = 1 ] || test_failed $LINENO +"${LZIP}" --output 2> /dev/null +[ $? = 1 ] || test_failed $LINENO +printf "LZIP\001-.............................." | "${LZIP}" -t 2> /dev/null +printf "LZIP\002-.............................." | "${LZIP}" -t 2> /dev/null +printf "LZIP\001+.............................." | "${LZIP}" -t 2> /dev/null printf "\ntesting decompression..." -"${LZIP}" -t "${in_lz}" -if [ $? = 0 ] ; then printf . ; else printf - ; fail=1 ; fi -"${LZIP}" -cd "${in_lz}" > copy || fail=1 -cmp in copy || fail=1 -printf . +"${LZIP}" -t "${in_lz}" || test_failed $LINENO +"${LZIP}" -cd "${in_lz}" > copy || test_failed $LINENO +cmp in copy || test_failed $LINENO -"${LZIP}" -t "${testdir}"/test_sync.lz -if [ $? = 0 ] ; then printf . ; else printf - ; fail=1 ; fi -"${LZIP}" -cd "${testdir}"/test_sync.lz > copy || fail=1 -cmp in copy || fail=1 -printf . +"${LZIP}" -t "${testdir}"/test_sync.lz || test_failed $LINENO +"${LZIP}" -cd "${testdir}"/test_sync.lz > copy || test_failed $LINENO +cmp in copy || test_failed $LINENO rm -f copy cat "${in_lz}" > copy.lz || framework_failure -"${LZIP}" -dk copy.lz || fail=1 -cmp in copy || fail=1 +"${LZIP}" -dk copy.lz || test_failed $LINENO +cmp in copy || test_failed $LINENO printf "to be overwritten" > copy || framework_failure -"${LZIP}" -dq copy.lz -if [ $? = 1 ] ; then printf . ; else printf - ; fail=1 ; fi +"${LZIP}" -d copy.lz 2> /dev/null +[ $? = 1 ] || test_failed $LINENO "${LZIP}" -df copy.lz -if [ $? = 0 ] && [ ! -e copy.lz ] && cmp in copy ; then - printf . ; else printf - ; fail=1 ; fi +{ [ $? = 0 ] && [ ! -e copy.lz ] && cmp in copy ; } || test_failed $LINENO printf "to be overwritten" > copy || framework_failure -"${LZIP}" -df -o copy < "${in_lz}" || fail=1 -cmp in copy || fail=1 -printf . +"${LZIP}" -df -o copy < "${in_lz}" || test_failed $LINENO +cmp in copy || test_failed $LINENO rm -f copy -"${LZIP}" -s16 < in > anyothername || fail=1 -"${LZIP}" -d -o copy - anyothername - < "${in_lz}" -if [ $? = 0 ] && cmp in copy && cmp in anyothername.out ; then - printf . ; else printf - ; fail=1 ; fi +"${LZIP}" -s16 < in > anyothername || test_failed $LINENO +"${LZIP}" -dv --output copy - anyothername - < "${in_lz}" 2> /dev/null +{ [ $? = 0 ] && cmp in copy && cmp in anyothername.out ; } || + test_failed $LINENO rm -f copy anyothername.out "${LZIP}" -tq in "${in_lz}" -if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi -"${LZIP}" -tq foo.lz "${in_lz}" -if [ $? = 1 ] ; then printf . ; else printf - ; fail=1 ; fi +[ $? = 2 ] || test_failed $LINENO +"${LZIP}" -tq nx_file.lz "${in_lz}" +[ $? = 1 ] || test_failed $LINENO "${LZIP}" -cdq in "${in_lz}" > copy -if [ $? = 2 ] && cat copy in | cmp in - ; then printf . ; else printf - ; fail=1 ; fi -"${LZIP}" -cdq foo.lz "${in_lz}" > copy -if [ $? = 1 ] && cmp in copy ; then printf . ; else printf - ; fail=1 ; fi +{ [ $? = 2 ] && cat copy in | cmp in - ; } || test_failed $LINENO +"${LZIP}" -cdq nx_file.lz "${in_lz}" > copy +{ [ $? = 1 ] && cmp in copy ; } || test_failed $LINENO rm -f copy cat "${in_lz}" > copy.lz || framework_failure +for i in 1 2 3 4 5 6 7 ; do + printf "g" >> copy.lz || framework_failure + "${LZIP}" -atvvvv copy.lz "${in_lz}" 2> /dev/null + [ $? = 2 ] || test_failed $LINENO $i +done "${LZIP}" -dq in copy.lz -if [ $? = 2 ] && [ -e copy.lz ] && [ ! -e copy ] && [ ! -e in.out ] ; then - printf . ; else printf - ; fail=1 ; fi -"${LZIP}" -dq foo.lz copy.lz -if [ $? = 1 ] && [ ! -e copy.lz ] && [ ! -e foo ] && cmp in copy ; then - printf . ; else printf - ; fail=1 ; fi +{ [ $? = 2 ] && [ -e copy.lz ] && [ ! -e copy ] && [ ! -e in.out ] ; } || + test_failed $LINENO +"${LZIP}" -dq nx_file.lz copy.lz +{ [ $? = 1 ] && [ ! -e copy.lz ] && [ ! -e nx_file ] && cmp in copy ; } || + test_failed $LINENO cat in in > in2 || framework_failure -"${LZIP}" -s16 -o copy2 < in2 || fail=1 -"${LZIP}" -t copy2.lz || fail=1 -"${LZIP}" -cd copy2.lz > copy2 || fail=1 -cmp in2 copy2 || fail=1 -printf . +cat "${in_lz}" "${in_lz}" > in2.lz || framework_failure +"${LZIP}" -t in2.lz || test_failed $LINENO +"${LZIP}" -cd in2.lz > copy2 || test_failed $LINENO +cmp in2 copy2 || test_failed $LINENO -printf "garbage" >> copy2.lz || framework_failure +"${LZIP}" -s16 --output=copy2 < in2 || test_failed $LINENO +"${LZIP}" -t copy2.lz || test_failed $LINENO +"${LZIP}" -cd copy2.lz > copy2 || test_failed $LINENO +cmp in2 copy2 || test_failed $LINENO + +printf "\ngarbage" >> copy2.lz || framework_failure +"${LZIP}" -tvvvv copy2.lz 2> /dev/null || test_failed $LINENO rm -f copy2 "${LZIP}" -atq copy2.lz -if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi +[ $? = 2 ] || test_failed $LINENO "${LZIP}" -atq < copy2.lz -if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi +[ $? = 2 ] || test_failed $LINENO "${LZIP}" -adkq copy2.lz -if [ $? = 2 ] && [ ! -e copy2 ] ; then printf . ; else printf - ; fail=1 ; fi +{ [ $? = 2 ] && [ ! -e copy2 ] ; } || test_failed $LINENO "${LZIP}" -adkq -o copy2 < copy2.lz -if [ $? = 2 ] && [ ! -e copy2 ] ; then printf . ; else printf - ; fail=1 ; fi +{ [ $? = 2 ] && [ ! -e copy2 ] ; } || test_failed $LINENO printf "to be overwritten" > copy2 || framework_failure -"${LZIP}" -df copy2.lz || fail=1 -cmp in2 copy2 || fail=1 -printf . +"${LZIP}" -df copy2.lz || test_failed $LINENO +cmp in2 copy2 || test_failed $LINENO printf "\ntesting compression..." -"${LZIP}" -cfq "${in_lz}" > out # /dev/null is a tty on OS/2 -if [ $? = 1 ] ; then printf . ; else printf - ; fail=1 ; fi -"${LZIP}" -cF -s16 "${in_lz}" > out || fail=1 -"${LZIP}" -cd out | "${LZIP}" -d > copy || fail=1 -cmp in copy || fail=1 -printf . +"${LZIP}" -cf "${in_lz}" > out 2> /dev/null # /dev/null is a tty on OS/2 +[ $? = 1 ] || test_failed $LINENO +"${LZIP}" -cFvvm36 -s16 "${in_lz}" > out 2> /dev/null || test_failed $LINENO +"${LZIP}" -cd out | "${LZIP}" -d > copy || test_failed $LINENO +cmp in copy || test_failed $LINENO for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do - "${LZIP}" -k -$i -s16 in || fail=1 - mv -f in.lz copy.lz || fail=1 - printf "garbage" >> copy.lz || fail=1 - "${LZIP}" -df copy.lz || fail=1 - cmp in copy || fail=1 + "${LZIP}" -k -$i -s16 in || test_failed $LINENO $i + mv -f in.lz copy.lz || test_failed $LINENO $i + printf "garbage" >> copy.lz || framework_failure + "${LZIP}" -df copy.lz || test_failed $LINENO $i + cmp in copy || test_failed $LINENO $i done -printf . for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do - "${LZIP}" -c -$i -s16 in > out || fail=1 - printf "g" >> out || fail=1 - "${LZIP}" -cd out > copy || fail=1 - cmp in copy || fail=1 + "${LZIP}" -c -$i -s16 in > out || test_failed $LINENO $i + printf "g" >> out || framework_failure + "${LZIP}" -cd out > copy || test_failed $LINENO $i + cmp in copy || test_failed $LINENO $i done -printf . for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do - "${LZIP}" -$i -s16 < in > out || fail=1 - "${LZIP}" -d < out > copy || fail=1 - cmp in copy || fail=1 + "${LZIP}" -$i -s16 < in > out || test_failed $LINENO $i + "${LZIP}" -d < out > copy || test_failed $LINENO $i + cmp in copy || test_failed $LINENO $i done -printf . for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do - "${LZIP}" -f -$i -s16 -o out < in || fail=1 - "${LZIP}" -df -o copy < out.lz || fail=1 - cmp in copy || fail=1 + "${LZIP}" -f -$i -s16 -o out < in || test_failed $LINENO $i + "${LZIP}" -df -o copy < out.lz || test_failed $LINENO $i + cmp in copy || test_failed $LINENO $i done -printf . -"${BBEXAMPLE}" in || fail=1 -printf . -"${BBEXAMPLE}" out || fail=1 -printf . -"${BBEXAMPLE}" ${test2} || fail=1 -printf . +cat in in in in in in in in > in8 || framework_failure +"${LZIP}" -1s12 -S100k -o out < in8 || test_failed $LINENO +"${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO +"${LZIP}" -cd out00001.lz out00002.lz | cmp in8 - || test_failed $LINENO +rm -f out00001.lz +"${LZIP}" -1ks4Ki -b100000 in8 || test_failed $LINENO +"${LZIP}" -t in8.lz || test_failed $LINENO +"${LZIP}" -cd in8.lz | cmp in8 - || test_failed $LINENO +rm -f in8 +"${LZIP}" -0 -S100k -o out < in8.lz || test_failed $LINENO +"${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO +"${LZIP}" -cd out00001.lz out00002.lz | cmp in8.lz - || test_failed $LINENO +rm -f out00001.lz out00002.lz +"${LZIP}" -0kF -b100k in8.lz || test_failed $LINENO +"${LZIP}" -t in8.lz.lz || test_failed $LINENO +"${LZIP}" -cd in8.lz.lz | cmp in8.lz - || test_failed $LINENO +rm -f in8.lz in8.lz.lz -"${LZCHECK}" in || fail=1 -printf . -"${LZCHECK}" out || fail=1 -printf . -"${LZCHECK}" ${test2} || fail=1 -printf . +"${BBEXAMPLE}" in || test_failed $LINENO +"${BBEXAMPLE}" out || test_failed $LINENO +"${BBEXAMPLE}" ${test2} || test_failed $LINENO + +"${LZCHECK}" in || test_failed $LINENO +"${LZCHECK}" out || test_failed $LINENO +"${LZCHECK}" ${test2} || test_failed $LINENO + +printf "\ntesting bad input..." + +cat "${in_lz}" "${in_lz}" "${in_lz}" > in3.lz || framework_failure +if dd if=in3.lz of=trunc.lz bs=14752 count=1 2> /dev/null && + [ -e trunc.lz ] && cmp in2.lz trunc.lz > /dev/null 2>&1 ; then + for i in 6 20 14734 14753 14754 14755 14756 14757 14758 ; do + dd if=in3.lz of=trunc.lz bs=$i count=1 2> /dev/null + "${LZIP}" -t trunc.lz 2> /dev/null + [ $? = 2 ] || test_failed $LINENO $i + "${LZIP}" -tq < trunc.lz + [ $? = 2 ] || test_failed $LINENO $i + "${LZIP}" -cdq trunc.lz > out + [ $? = 2 ] || test_failed $LINENO $i + "${LZIP}" -dq < trunc.lz > out + [ $? = 2 ] || test_failed $LINENO $i + done +else + printf "\nwarning: skipping truncation test: 'dd' does not work on your system." +fi + +cat "${in_lz}" > ingin.lz || framework_failure +printf "g" >> ingin.lz || framework_failure +cat "${in_lz}" >> ingin.lz || framework_failure +"${LZIP}" -t ingin.lz || test_failed $LINENO +"${LZIP}" -cd ingin.lz > copy || test_failed $LINENO +cmp in copy || test_failed $LINENO +"${LZIP}" -t < ingin.lz || test_failed $LINENO +"${LZIP}" -d < ingin.lz > copy || test_failed $LINENO +cmp in copy || test_failed $LINENO echo if [ ${fail} = 0 ] ; then diff --git a/testsuite/test.txt.lz b/testsuite/test.txt.lz index 41d2e39999a92cd871d646a4ae00ba25ef067cc4..22cea6e4d2a58b4dcb006541dcdb8defabba0cbb 100644 GIT binary patch delta 15 Wcmca$dBKv+C(1K`@%=`&Q!)TBtOex& delta 15 Wcmca$dBKv+C(1K`@xw;8Q!)TBu?6M; From 1b337df7d05e854e396edb10795f1145af58aa2f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 20 Feb 2025 21:25:43 +0100 Subject: [PATCH 02/10] Adding upstream version 1.10. Signed-off-by: Daniel Baumann --- ChangeLog | 28 ++- INSTALL | 2 +- NEWS | 34 +++- README | 2 +- bbexample.c | 2 +- carg_parser.c | 2 +- carg_parser.h | 2 +- cbuffer.c | 2 +- configure | 6 +- decoder.c | 2 +- decoder.h | 10 +- doc/lzlib.info | 284 +++++++++++++++++++++++---- doc/lzlib.texi | 275 ++++++++++++++++++++++---- doc/minilzip.1 | 11 +- encoder.c | 2 +- encoder.h | 6 +- encoder_base.c | 49 +++-- encoder_base.h | 21 +- fast_encoder.c | 2 +- fast_encoder.h | 6 +- lzcheck.c | 89 +++++---- lzip.h | 19 +- lzlib.c | 26 ++- lzlib.h | 4 +- main.c | 473 +++++++++++++++++++++++++-------------------- testsuite/check.sh | 62 +++++- 26 files changed, 998 insertions(+), 423 deletions(-) diff --git a/ChangeLog b/ChangeLog index 70eb638..c13bf2e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2018-02-07 Antonio Diaz Diaz + + * Version 1.10 released. + * LZ_compress_finish now adjusts dictionary size for each member. + * lzlib.c (LZ_decompress_read): Detect corrupt header with HD=3. + * main.c: Added new option '--loose-trailing'. + * main.c (main): Option '-S, --volume-size' now keeps input files. + * main.c: Replaced 'bits/byte' with inverse compression ratio. + * main.c: Show final diagnostic when testing multiple files. + * main.c: Do not add a second .lz extension to the arg of -o. + * main.c: Show dictionary size at verbosity level 4 (-vvvv). + * lzlib.texi: Added chapter 'Invoking minilzip'. + 2017-04-11 Antonio Diaz Diaz * Version 1.9 released. @@ -10,14 +23,15 @@ 2016-05-17 Antonio Diaz Diaz * Version 1.8 released. + * lzlib.h: Define LZ_API_VERSION to 1. * decoder.c (LZd_verify_trailer): Removed test of final code. * main.c: Added new option '-a, --trailing-error'. * main.c (main): Delete '--output' file if infd is a terminal. * main.c (main): Don't use stdin more than once. * configure: Avoid warning on some shells when testing for gcc. * Makefile.in: Detect the existence of install-info. - * testsuite/check.sh: A POSIX shell is required to run the tests. - * testsuite/check.sh: Don't check error messages. + * check.sh: A POSIX shell is required to run the tests. + * check.sh: Don't check error messages. 2015-07-08 Antonio Diaz Diaz @@ -78,7 +92,7 @@ reduces compression time for large values of '--match-length' by up to 6%. * main.cc: Added new option '-F, --recompress'. - * Makefile.in: 'make install' no more tries to run + * Makefile.in: 'make install' no longer tries to run '/sbin/ldconfig' on systems lacking it. 2011-01-03 Antonio Diaz Diaz @@ -129,14 +143,14 @@ allowing LZ_compress_restart_member to restart a finished stream. * lzlib.cc: Accept only query or close operations after a fatal error has occurred. - * Shared version of lzlib is no more built by default. - * testsuite/check.sh: Use 'test1' instead of 'COPYING' for testing. + * Shared version of lzlib is no longer built by default. + * check.sh: Use 'test1' instead of 'COPYING' for testing. 2009-10-20 Antonio Diaz Diaz * Version 0.7 released. * Compression time has been reduced by 4%. - * testsuite/check.sh: Removed -9 to run in less than 256MiB of RAM. + * check.sh: Removed -9 to run in less than 256MiB of RAM. * lzcheck.cc: Read files of any size up to 2^63 bytes. 2009-09-02 Antonio Diaz Diaz @@ -174,7 +188,7 @@ * Version 0.1 released. -Copyright (C) 2009-2017 Antonio Diaz Diaz. +Copyright (C) 2009-2018 Antonio Diaz Diaz. This file is a collection of facts, and thus it is not copyrightable, but just in case, you have unlimited permission to copy, distribute and diff --git a/INSTALL b/INSTALL index 3dbf6e8..735d666 100644 --- a/INSTALL +++ b/INSTALL @@ -62,7 +62,7 @@ After running 'configure', you can run 'make' and 'make install' as explained above. -Copyright (C) 2009-2017 Antonio Diaz Diaz. +Copyright (C) 2009-2018 Antonio Diaz Diaz. This file is free documentation: you have unlimited permission to copy, distribute and modify it. diff --git a/NEWS b/NEWS index 111a899..c610506 100644 --- a/NEWS +++ b/NEWS @@ -1,12 +1,32 @@ -Changes in version 1.9: +Changes in version 1.10: -Compression time of option '-0' has been reduced by 3%. +The function 'LZ_compress_finish' now adjusts the dictionary size for +each member. -Compression time of options '-1' to '-9' has been reduced by 1%. +The option '--loose-trailing', has been added to minilzip. -Decompression time has been reduced by 3%. +The test used by lzlib to discriminate trailing data from a corrupt +header in multimember or concatenated files has been improved to a +Hamming distance (HD) of 3, and the 3 bit flips must happen in different +magic bytes for the test to fail. As a consequence, lzlib now returns a +data error when some kinds of files are appended to a lzip file as +trailing data. +The '--loose-trailing' option of minilzip can be used to ignore such +trailing data when decompressing. +Lziprecover can be used to remove conflicting trailing data from a file. -In test mode, minilzip now continues checking the rest of the files if -any input file is a terminal. +Option '-S, --volume-size' of minilzip now keeps input files unchanged. -The license of the library has been changed to "2-clause BSD". +The 'bits/byte' ratio has been replaced with the inverse compression +ratio in the output of minilzip. + +minilzip now shows a final diagnostic at verbosity level 1 (-v) or +higher if any file fails the test when testing multiple files. + +minilzip no longer adds a second '.lz' extension to the argument of '-o' +if it already ends in '.lz' or '.tlz'. + +minilzip now shows the dictionary size at verbosity level 4 (-vvvv) when +decompressing or testing. + +The new chapter 'Invoking minilzip' has been added to the manual. diff --git a/README b/README index 178f30f..6a9c6f2 100644 --- a/README +++ b/README @@ -87,7 +87,7 @@ range encoding), Igor Pavlov (for putting all the above together in LZMA), and Julian Seward (for bzip2's CLI). -Copyright (C) 2009-2017 Antonio Diaz Diaz. +Copyright (C) 2009-2018 Antonio Diaz Diaz. This file is free documentation: you have unlimited permission to copy, distribute and modify it. diff --git a/bbexample.c b/bbexample.c index ab9a6e0..8c2ff04 100644 --- a/bbexample.c +++ b/bbexample.c @@ -1,5 +1,5 @@ /* Buffer to buffer example - Test program for the lzlib library - Copyright (C) 2010-2017 Antonio Diaz Diaz. + Copyright (C) 2010-2018 Antonio Diaz Diaz. This program is free software: you have unlimited permission to copy, distribute and modify it. diff --git a/carg_parser.c b/carg_parser.c index 6850643..10ad4dc 100644 --- a/carg_parser.c +++ b/carg_parser.c @@ -1,5 +1,5 @@ /* Arg_parser - POSIX/GNU command line argument parser. (C version) - Copyright (C) 2006-2017 Antonio Diaz Diaz. + Copyright (C) 2006-2018 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/carg_parser.h b/carg_parser.h index c4ce31d..e1c70dd 100644 --- a/carg_parser.h +++ b/carg_parser.h @@ -1,5 +1,5 @@ /* Arg_parser - POSIX/GNU command line argument parser. (C version) - Copyright (C) 2006-2017 Antonio Diaz Diaz. + Copyright (C) 2006-2018 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/cbuffer.c b/cbuffer.c index 5b8751e..5e7ab93 100644 --- a/cbuffer.c +++ b/cbuffer.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2017 Antonio Diaz Diaz. + Copyright (C) 2009-2018 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/configure b/configure index 244dca6..5b0c54b 100755 --- a/configure +++ b/configure @@ -1,12 +1,12 @@ #! /bin/sh # configure script for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2017 Antonio Diaz Diaz. +# Copyright (C) 2009-2018 Antonio Diaz Diaz. # # This configure script is free software: you have unlimited permission # to copy, distribute and modify it. pkgname=lzlib -pkgversion=1.9 +pkgversion=1.10 soversion=1 progname=minilzip progname_static=${progname} @@ -194,7 +194,7 @@ echo "LDFLAGS = ${LDFLAGS}" rm -f Makefile cat > Makefile << EOF # Makefile for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2017 Antonio Diaz Diaz. +# Copyright (C) 2009-2018 Antonio Diaz Diaz. # This file was generated automatically by configure. Don't edit. # # This Makefile is free software: you have unlimited permission diff --git a/decoder.c b/decoder.c index 971fc24..d659853 100644 --- a/decoder.c +++ b/decoder.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2017 Antonio Diaz Diaz. + Copyright (C) 2009-2018 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/decoder.h b/decoder.h index 8e422a8..090bf3a 100644 --- a/decoder.h +++ b/decoder.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2017 Antonio Diaz Diaz. + Copyright (C) 2009-2018 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -319,11 +319,7 @@ static inline bool LZd_enough_free_bytes( const struct LZ_decoder * const d ) { return Cb_free_bytes( &d->cb ) >= lzd_min_free_bytes; } static inline uint8_t LZd_peek_prev( const struct LZ_decoder * const d ) - { - if( d->cb.put > 0 ) return d->cb.buffer[d->cb.put-1]; - if( d->pos_wrapped ) return d->cb.buffer[d->cb.buffer_size-1]; - return 0; /* prev_byte of first byte */ - } + { return d->cb.buffer[((d->cb.put > 0) ? d->cb.put : d->cb.buffer_size)-1]; } static inline uint8_t LZd_peek( const struct LZ_decoder * const d, const unsigned distance ) @@ -387,6 +383,8 @@ static inline bool LZd_init( struct LZ_decoder * const d, d->member_finished = false; d->verify_trailer_pending = false; d->pos_wrapped = false; + /* prev_byte of first byte; also for LZd_peek( 0 ) on corrupt file */ + d->cb.buffer[d->cb.buffer_size-1] = 0; d->rep0 = 0; d->rep1 = 0; d->rep2 = 0; diff --git a/doc/lzlib.info b/doc/lzlib.info index a2a8c68..23a4d21 100644 --- a/doc/lzlib.info +++ b/doc/lzlib.info @@ -11,25 +11,26 @@ File: lzlib.info, Node: Top, Next: Introduction, Up: (dir) Lzlib Manual ************ -This manual is for Lzlib (version 1.9, 11 April 2017). +This manual is for Lzlib (version 1.10, 7 February 2018). * Menu: -* Introduction:: Purpose and features of lzlib -* Library version:: Checking library version -* Buffering:: Sizes of lzlib's buffers -* Parameter limits:: Min / max values for some parameters -* Compression functions:: Descriptions of the compression functions -* Decompression functions:: Descriptions of the decompression functions -* Error codes:: Meaning of codes returned by functions -* Error messages:: Error messages corresponding to error codes -* Data format:: Detailed format of the compressed data -* Examples:: A small tutorial with examples -* Problems:: Reporting bugs -* Concept index:: Index of concepts +* Introduction:: Purpose and features of lzlib +* Library version:: Checking library version +* Buffering:: Sizes of lzlib's buffers +* Parameter limits:: Min / max values for some parameters +* Compression functions:: Descriptions of the compression functions +* Decompression functions:: Descriptions of the decompression functions +* Error codes:: Meaning of codes returned by functions +* Error messages:: Error messages corresponding to error codes +* Invoking minilzip:: Command line interface of the test program +* Data format:: Detailed format of the compressed data +* Examples:: A small tutorial with examples +* Problems:: Reporting bugs +* Concept index:: Index of concepts - Copyright (C) 2009-2017 Antonio Diaz Diaz. + Copyright (C) 2009-2018 Antonio Diaz Diaz. This manual is free documentation: you have unlimited permission to copy, distribute and modify it. @@ -50,7 +51,7 @@ archiving, taking into account both data integrity and decoder availability: * The lzip format provides very safe integrity checking and some data - recovery means. The lziprecover program can repair bit-flip errors + recovery means. The lziprecover program can repair bit flip errors (one of the most common forms of data corruption) in lzip files, and provides data recovery capabilities, including error-checked merging of damaged copies of a file. *Note Data safety: @@ -170,8 +171,9 @@ minimum sizes: * Input compression buffer. Written to by the 'LZ_compress_write' function. For the normal variant of LZMA, its size is two times - the dictionary size set with the 'LZ_compress_open' function or 64 - KiB, whichever is larger. For the fast variant, its size is 1 MiB. + the dictionary size set with the 'LZ_compress_open' function or + 64 KiB, whichever is larger. For the fast variant, its size is + 1 MiB. * Output compression buffer. Read from by the 'LZ_compress_read' function. Its size is 64 KiB. @@ -326,6 +328,7 @@ calling 'LZ_compress_errno' before using it. ENCODER ) Returns 1 if all the data have been read and 'LZ_compress_close' can be safely called. Otherwise it returns 0. + 'LZ_compress_finished' implies 'LZ_compress_member_finished'. -- Function: int LZ_compress_member_finished ( struct LZ_Encoder * const ENCODER ) @@ -532,14 +535,19 @@ whether a call failed. If the call failed, then you can examine The end of the data stream was reached in the middle of a member. -- Constant: enum LZ_Errno LZ_data_error - The data stream is corrupt. + The data stream is corrupt. If 'LZ_decompress_member_position' is 6 + or less, it indicates either a format version not supported, an + invalid dictionary size, a corrupt header in a multimember data + stream, or trailing data too similar to a valid lzip header. + Lziprecover can be used to remove conflicting trailing data from a + file. -- Constant: enum LZ_Errno LZ_library_error A bug was detected in the library. Please, report it (*note Problems::).  -File: lzlib.info, Node: Error messages, Next: Data format, Prev: Error codes, Up: Top +File: lzlib.info, Node: Error messages, Next: Invoking minilzip, Prev: Error codes, Up: Top 8 Error messages **************** @@ -555,10 +563,198 @@ File: lzlib.info, Node: Error messages, Next: Data format, Prev: Error codes, 'LZ_(de)compress_errno'.  -File: lzlib.info, Node: Data format, Next: Examples, Prev: Error messages, Up: Top +File: lzlib.info, Node: Invoking minilzip, Next: Data format, Prev: Error messages, Up: Top -9 Data format -************* +9 Invoking minilzip +******************* + +The format for running minilzip is: + + minilzip [OPTIONS] [FILES] + +'-' used as a FILE argument means standard input. It can be mixed with +other FILES and is read just once, the first time it appears in the +command line. + + minilzip supports the following options: + +'-h' +'--help' + Print an informative help message describing the options and exit. + +'-V' +'--version' + Print the version number of minilzip on the standard output and + exit. + +'-a' +'--trailing-error' + Exit with error status 2 if any remaining input is detected after + decompressing the last member. Such remaining input is usually + trailing garbage that can be safely ignored. + +'-b BYTES' +'--member-size=BYTES' + When compressing, set the member size limit to BYTES. A small + member size may degrade compression ratio, so use it only when + needed. Valid values range from 100 kB to 2 PiB. Defaults to + 2 PiB. + +'-c' +'--stdout' + Compress or decompress to standard output; keep input files + unchanged. If compressing several files, each file is compressed + independently. This option is needed when reading from a named + pipe (fifo) or from a device. Use it also to recover as much of + the decompressed data as possible when decompressing a corrupt + file. + +'-d' +'--decompress' + Decompress the specified files. If a file does not exist or can't + be opened, minilzip continues decompressing the rest of the files. + If a file fails to decompress, or is a terminal, minilzip exits + immediately without decompressing the rest of the files. + +'-f' +'--force' + Force overwrite of output files. + +'-F' +'--recompress' + When compressing, force re-compression of files whose name already + has the '.lz' or '.tlz' suffix. + +'-k' +'--keep' + Keep (don't delete) input files during compression or + decompression. + +'-m BYTES' +'--match-length=BYTES' + When compressing, set the match length limit in bytes. After a + match this long is found, the search is finished. Valid values + range from 5 to 273. Larger values usually give better compression + ratios but longer compression times. + +'-o FILE' +'--output=FILE' + When reading from standard input and '--stdout' has not been + specified, use 'FILE' as the virtual name of the uncompressed + file. This produces a file named 'FILE' when decompressing, or a + file named 'FILE.lz' when compressing. A second '.lz' extension is + not added if 'FILE' already ends in '.lz' or '.tlz'. When + compressing and splitting the output in volumes, several files + named 'FILE00001.lz', 'FILE00002.lz', etc, are created. + +'-q' +'--quiet' + Quiet operation. Suppress all messages. + +'-s BYTES' +'--dictionary-size=BYTES' + When compressing, set the dictionary size limit in bytes. Minilzip + will use the smallest possible dictionary size for each file + without exceeding this limit. Valid values range from 4 KiB to + 512 MiB. Values 12 to 29 are interpreted as powers of two, meaning + 2^12 to 2^29 bytes. Note that dictionary sizes are quantized. If + the specified size does not match one of the valid sizes, it will + be rounded upwards by adding up to (BYTES / 8) to it. + + For maximum compression you should use a dictionary size limit as + large as possible, but keep in mind that the decompression memory + requirement is affected at compression time by the choice of + dictionary size limit. + +'-S BYTES' +'--volume-size=BYTES' + When compressing, split the compressed output into several volume + files with names 'original_name00001.lz', 'original_name00002.lz', + etc, and set the volume size limit to BYTES. Input files are kept + unchanged. Each volume is a complete, maybe multimember, lzip + file. A small volume size may degrade compression ratio, so use it + only when needed. Valid values range from 100 kB to 4 EiB. + +'-t' +'--test' + Check integrity of the specified files, but don't decompress them. + This really performs a trial decompression and throws away the + result. Use it together with '-v' to see information about the + files. If a file fails the test, does not exist, can't be opened, + or is a terminal, minilzip continues checking the rest of the + files. A final diagnostic is shown at verbosity level 1 or higher + if any file fails the test when testing multiple files. + +'-v' +'--verbose' + Verbose mode. + When compressing, show the compression ratio and size for each file + processed. + When decompressing or testing, further -v's (up to 4) increase the + verbosity level, showing status, compression ratio, dictionary + size, and trailer contents (CRC, data size, member size). + +'-0 .. -9' + Set the compression parameters (dictionary size and match length + limit) as shown in the table below. The default compression level + is '-6'. Note that '-9' can be much slower than '-0'. These + options have no effect when decompressing or testing. + + The bidimensional parameter space of LZMA can't be mapped to a + linear scale optimal for all files. If your files are large, very + repetitive, etc, you may need to use the '--dictionary-size' and + '--match-length' options directly to achieve optimal performance. + + Level Dictionary size Match length limit + -0 64 KiB 16 bytes + -1 1 MiB 5 bytes + -2 1.5 MiB 6 bytes + -3 2 MiB 8 bytes + -4 3 MiB 12 bytes + -5 4 MiB 20 bytes + -6 8 MiB 36 bytes + -7 16 MiB 68 bytes + -8 24 MiB 132 bytes + -9 32 MiB 273 bytes + +'--fast' +'--best' + Aliases for GNU gzip compatibility. + +'--loose-trailing' + When decompressing or testing, allow trailing data whose first + bytes are so similar to the magic bytes of a lzip header that they + can be confused with a corrupt header. Use this option if a file + triggers a "corrupt header" error and the cause is not indeed a + corrupt header. + + + Numbers given as arguments to options may be followed by a multiplier +and an optional 'B' for "byte". + + Table of SI and binary prefixes (unit multipliers): + +Prefix Value | Prefix Value +k kilobyte (10^3 = 1000) | Ki kibibyte (2^10 = 1024) +M megabyte (10^6) | Mi mebibyte (2^20) +G gigabyte (10^9) | Gi gibibyte (2^30) +T terabyte (10^12) | Ti tebibyte (2^40) +P petabyte (10^15) | Pi pebibyte (2^50) +E exabyte (10^18) | Ei exbibyte (2^60) +Z zettabyte (10^21) | Zi zebibyte (2^70) +Y yottabyte (10^24) | Yi yobibyte (2^80) + + + Exit status: 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 +caused minilzip to panic. + + +File: lzlib.info, Node: Data format, Next: Examples, Prev: Invoking minilzip, Up: Top + +10 Data format +************** Perfection is reached, not when there is no longer anything to add, but when there is no longer anything to take away. @@ -578,9 +774,9 @@ when there is no longer anything to take away. represents a variable number of bytes. - A lzip data stream consists of a series of "members" (compressed data -sets). The members simply appear one after another in the data stream, -with no additional information before, between, or after them. + A lzip data stream consists of a series of "members" (compressed +data sets). The members simply appear one after another in the data +stream, with no additional information before, between, or after them. Each member has the following structure: +--+--+--+--+----+----+=============+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -630,7 +826,7 @@ with no additional information before, between, or after them.  File: lzlib.info, Node: Examples, Next: Problems, Prev: Data format, Up: Top -10 A small tutorial with examples +11 A small tutorial with examples ********************************* This chapter shows the order in which the library functions should be @@ -709,15 +905,15 @@ Example 5: Multimember compression (MEMBER_SIZE < total output). Example 6: Multimember compression (user-restarted members). - 1) LZ_compress_open + 1) LZ_compress_open (with MEMBER_SIZE > largest member). 2) LZ_compress_write 3) LZ_compress_read 4) go back to step 2 until member termination is desired 5) LZ_compress_finish 6) LZ_compress_read 7) go back to step 6 until LZ_compress_member_finished returns 1 - 8) verify that LZ_compress_finished returns 1 - 9) go to step 12 if all input data have been written + 9) go to step 12 if all input data have been written and + LZ_compress_finished returns 1 10) LZ_compress_restart_member 11) go back to step 2 12) LZ_compress_close @@ -750,7 +946,7 @@ next member in case of data error.  File: lzlib.info, Node: Problems, Next: Concept index, Prev: Examples, Up: Top -11 Reporting bugs +12 Reporting bugs ***************** There are probably bugs in lzlib. There are certainly errors and @@ -783,25 +979,29 @@ Concept index * examples: Examples. (line 6) * getting help: Problems. (line 6) * introduction: Introduction. (line 6) +* invoking: Invoking minilzip. (line 6) * library version: Library version. (line 6) +* options: Invoking minilzip. (line 6) * parameter limits: Parameter limits. (line 6)  Tag Table: Node: Top220 -Node: Introduction1303 -Node: Library version6115 -Node: Buffering6760 -Node: Parameter limits7980 -Node: Compression functions8939 -Node: Decompression functions15481 -Node: Error codes21651 -Node: Error messages23626 -Node: Data format24205 -Node: Examples26770 -Node: Problems30851 -Node: Concept index31423 +Node: Introduction1342 +Node: Library version6154 +Node: Buffering6799 +Node: Parameter limits8024 +Node: Compression functions8983 +Node: Decompression functions15592 +Node: Error codes21762 +Node: Error messages24064 +Node: Invoking minilzip24649 +Ref: --trailing-error25243 +Node: Data format31883 +Node: Examples34454 +Node: Problems38570 +Node: Concept index39142  End Tag Table diff --git a/doc/lzlib.texi b/doc/lzlib.texi index 8b4aaaf..34154cd 100644 --- a/doc/lzlib.texi +++ b/doc/lzlib.texi @@ -6,8 +6,8 @@ @finalout @c %**end of header -@set UPDATED 11 April 2017 -@set VERSION 1.9 +@set UPDATED 7 February 2018 +@set VERSION 1.10 @dircategory Data Compression @direntry @@ -35,22 +35,23 @@ This manual is for Lzlib (version @value{VERSION}, @value{UPDATED}). @menu -* Introduction:: Purpose and features of lzlib -* Library version:: Checking library version -* Buffering:: Sizes of lzlib's buffers -* Parameter limits:: Min / max values for some parameters -* Compression functions:: Descriptions of the compression functions -* Decompression functions:: Descriptions of the decompression functions -* Error codes:: Meaning of codes returned by functions -* Error messages:: Error messages corresponding to error codes -* Data format:: Detailed format of the compressed data -* Examples:: A small tutorial with examples -* Problems:: Reporting bugs -* Concept index:: Index of concepts +* Introduction:: Purpose and features of lzlib +* Library version:: Checking library version +* Buffering:: Sizes of lzlib's buffers +* Parameter limits:: Min / max values for some parameters +* Compression functions:: Descriptions of the compression functions +* Decompression functions:: Descriptions of the decompression functions +* Error codes:: Meaning of codes returned by functions +* Error messages:: Error messages corresponding to error codes +* Invoking minilzip:: Command line interface of the test program +* Data format:: Detailed format of the compressed data +* Examples:: A small tutorial with examples +* Problems:: Reporting bugs +* Concept index:: Index of concepts @end menu @sp 1 -Copyright @copyright{} 2009-2017 Antonio Diaz Diaz. +Copyright @copyright{} 2009-2018 Antonio Diaz Diaz. This manual is free documentation: you have unlimited permission to copy, distribute and modify it. @@ -74,7 +75,7 @@ availability: The lzip format provides very safe integrity checking and some data recovery means. The @uref{http://www.nongnu.org/lzip/manual/lziprecover_manual.html#Data-safety,,lziprecover} -program can repair bit-flip errors (one of the most common forms of data +program can repair bit flip errors (one of the most common forms of data corruption) in lzip files, and provides data recovery capabilities, including error-checked merging of damaged copies of a file. @ifnothtml @@ -201,18 +202,18 @@ sizes: @item Input compression buffer. Written to by the @samp{LZ_compress_write} function. For the normal variant of LZMA, its size is two times the dictionary size set with the -@samp{LZ_compress_open} function or 64 KiB, whichever is larger. For the -fast variant, its size is 1 MiB. +@samp{LZ_compress_open} function or @w{64 KiB}, whichever is larger. For +the fast variant, its size is @w{1 MiB}. @item Output compression buffer. Read from by the -@samp{LZ_compress_read} function. Its size is 64 KiB. +@samp{LZ_compress_read} function. Its size is @w{64 KiB}. @item Input decompression buffer. Written to by the -@samp{LZ_decompress_write} function. Its size is 64 KiB. +@samp{LZ_decompress_write} function. Its size is @w{64 KiB}. @item Output decompression buffer. Read from by the @samp{LZ_decompress_read} function. Its size is the dictionary size set -in the header of the member currently being decompressed or 64 KiB, +in the header of the member currently being decompressed or @w{64 KiB}, whichever is larger. @end itemize @@ -271,10 +272,10 @@ does not return @samp{LZ_ok}, the returned pointer must not be used and should be freed with @samp{LZ_compress_close} to avoid memory leaks. @var{dictionary_size} sets the dictionary size to be used, in bytes. -Valid values range from 4 KiB to 512 MiB. Note that dictionary sizes are -quantized. If the specified size does not match one of the valid sizes, -it will be rounded upwards by adding up to (@var{dictionary_size} / 8) -to it. +Valid values range from @w{4 KiB} to @w{512 MiB}. Note that dictionary +sizes are quantized. If the specified size does not match one of the +valid sizes, it will be rounded upwards by adding up to +@w{(@var{dictionary_size} / 8)} to it. @var{match_len_limit} sets the match length limit in bytes. Valid values range from 5 to 273. Larger values usually give better compression @@ -283,13 +284,13 @@ ratios but longer compression times. If @var{dictionary_size} is 65535 and @var{match_len_limit} is 16, the fast variant of LZMA is chosen, which produces identical compressed output as @code{lzip -0}. (The dictionary size used will be rounded -upwards to 64 KiB). +upwards to @w{64 KiB}). @var{member_size} sets the member size limit in bytes. Minimum member -size limit is 100 kB. Small member size may degrade compression ratio, so -use it only when needed. To produce a single-member data stream, give -@var{member_size} a value larger than the amount of data to be produced, -for example INT64_MAX. +size limit is @w{100 kB}. Small member size may degrade compression +ratio, so use it only when needed. To produce a single-member data +stream, give @var{member_size} a value larger than the amount of data to +be produced, for example INT64_MAX. @end deftypefun @@ -369,7 +370,8 @@ Returns the current error code for @var{encoder} (@pxref{Error codes}). @deftypefun int LZ_compress_finished ( struct LZ_Encoder * const @var{encoder} ) Returns 1 if all the data have been read and @samp{LZ_compress_close} -can be safely called. Otherwise it returns 0. +can be safely called. Otherwise it returns 0. @samp{LZ_compress_finished} +implies @samp{LZ_compress_member_finished}. @end deftypefun @@ -606,7 +608,11 @@ The end of the data stream was reached in the middle of a member. @end deftypevr @deftypevr Constant {enum LZ_Errno} LZ_data_error -The data stream is corrupt. +The data stream is corrupt. If @samp{LZ_decompress_member_position} is 6 +or less, it indicates either a format version not supported, an invalid +dictionary size, a corrupt header in a multimember data stream, or +trailing data too similar to a valid lzip header. Lziprecover can be +used to remove conflicting trailing data from a file. @end deftypevr @deftypevr Constant {enum LZ_Errno} LZ_library_error @@ -629,6 +635,199 @@ The value of @var{lz_errno} normally comes from a call to @end deftypefun +@node Invoking minilzip +@chapter Invoking minilzip +@cindex invoking +@cindex options + +The format for running minilzip is: + +@example +minilzip [@var{options}] [@var{files}] +@end example + +@noindent +@samp{-} used as a @var{file} argument means standard input. It can be +mixed with other @var{files} and is read just once, the first time it +appears in the command line. + +minilzip supports the following options: + +@table @code +@item -h +@itemx --help +Print an informative help message describing the options and exit. + +@item -V +@itemx --version +Print the version number of minilzip on the standard output and exit. + +@anchor{--trailing-error} +@item -a +@itemx --trailing-error +Exit with error status 2 if any remaining input is detected after +decompressing the last member. Such remaining input is usually trailing +garbage that can be safely ignored. + +@item -b @var{bytes} +@itemx --member-size=@var{bytes} +When compressing, set the member size limit to @var{bytes}. A small +member size may degrade compression ratio, so use it only when needed. +Valid values range from @w{100 kB} to @w{2 PiB}. Defaults to @w{2 PiB}. + +@item -c +@itemx --stdout +Compress or decompress to standard output; keep input files unchanged. +If compressing several files, each file is compressed independently. +This option is needed when reading from a named pipe (fifo) or from a +device. Use it also to recover as much of the decompressed data as +possible when decompressing a corrupt file. + +@item -d +@itemx --decompress +Decompress the specified files. If a file does not exist or can't be +opened, minilzip continues decompressing the rest of the files. If a file +fails to decompress, or is a terminal, minilzip exits immediately without +decompressing the rest of the files. + +@item -f +@itemx --force +Force overwrite of output files. + +@item -F +@itemx --recompress +When compressing, force re-compression of files whose name already has +the @samp{.lz} or @samp{.tlz} suffix. + +@item -k +@itemx --keep +Keep (don't delete) input files during compression or decompression. + +@item -m @var{bytes} +@itemx --match-length=@var{bytes} +When compressing, set the match length limit in bytes. After a match +this long is found, the search is finished. Valid values range from 5 to +273. Larger values usually give better compression ratios but longer +compression times. + +@item -o @var{file} +@itemx --output=@var{file} +When reading from standard input and @samp{--stdout} has not been +specified, use @samp{@var{file}} as the virtual name of the uncompressed +file. This produces a file named @samp{@var{file}} when decompressing, +or a file named @samp{@var{file}.lz} when compressing. A second +@samp{.lz} extension is not added if @samp{@var{file}} already ends in +@samp{.lz} or @samp{.tlz}. When compressing and splitting the output in +volumes, several files named @samp{@var{file}00001.lz}, +@samp{@var{file}00002.lz}, etc, are created. + +@item -q +@itemx --quiet +Quiet operation. Suppress all messages. + +@item -s @var{bytes} +@itemx --dictionary-size=@var{bytes} +When compressing, set the dictionary size limit in bytes. Minilzip will use +the smallest possible dictionary size for each file without exceeding +this limit. Valid values range from @w{4 KiB} to @w{512 MiB}. Values 12 +to 29 are interpreted as powers of two, meaning 2^12 to 2^29 bytes. Note +that dictionary sizes are quantized. If the specified size does not +match one of the valid sizes, it will be rounded upwards by adding up to +@w{(@var{bytes} / 8)} to it. + +For maximum compression you should use a dictionary size limit as large +as possible, but keep in mind that the decompression memory requirement +is affected at compression time by the choice of dictionary size limit. + +@item -S @var{bytes} +@itemx --volume-size=@var{bytes} +When compressing, split the compressed output into several volume files +with names @samp{original_name00001.lz}, @samp{original_name00002.lz}, +etc, and set the volume size limit to @var{bytes}. Input files are kept +unchanged. Each volume is a complete, maybe multimember, lzip file. A +small volume size may degrade compression ratio, so use it only when +needed. Valid values range from @w{100 kB} to @w{4 EiB}. + +@item -t +@itemx --test +Check integrity of the specified files, but don't decompress them. This +really performs a trial decompression and throws away the result. Use it +together with @samp{-v} to see information about the files. If a file +fails the test, does not exist, can't be opened, or is a terminal, minilzip +continues checking the rest of the files. A final diagnostic is shown at +verbosity level 1 or higher if any file fails the test when testing +multiple files. + +@item -v +@itemx --verbose +Verbose mode.@* +When compressing, show the compression ratio and size for each file +processed.@* +When decompressing or testing, further -v's (up to 4) increase the +verbosity level, showing status, compression ratio, dictionary size, +and trailer contents (CRC, data size, member size). + +@item -0 .. -9 +Set the compression parameters (dictionary size and match length limit) +as shown in the table below. The default compression level is @samp{-6}. +Note that @samp{-9} can be much slower than @samp{-0}. These options +have no effect when decompressing or testing. + +The bidimensional parameter space of LZMA can't be mapped to a linear +scale optimal for all files. If your files are large, very repetitive, +etc, you may need to use the @samp{--dictionary-size} and +@samp{--match-length} options directly to achieve optimal performance. + +@multitable {Level} {Dictionary size} {Match length limit} +@item Level @tab Dictionary size @tab Match length limit +@item -0 @tab 64 KiB @tab 16 bytes +@item -1 @tab 1 MiB @tab 5 bytes +@item -2 @tab 1.5 MiB @tab 6 bytes +@item -3 @tab 2 MiB @tab 8 bytes +@item -4 @tab 3 MiB @tab 12 bytes +@item -5 @tab 4 MiB @tab 20 bytes +@item -6 @tab 8 MiB @tab 36 bytes +@item -7 @tab 16 MiB @tab 68 bytes +@item -8 @tab 24 MiB @tab 132 bytes +@item -9 @tab 32 MiB @tab 273 bytes +@end multitable + +@item --fast +@itemx --best +Aliases for GNU gzip compatibility. + +@item --loose-trailing +When decompressing or testing, allow trailing data whose first bytes are +so similar to the magic bytes of a lzip header that they can be confused +with a corrupt header. Use this option if a file triggers a "corrupt +header" error and the cause is not indeed a corrupt header. + +@end table + +Numbers given as arguments to options may be followed by a multiplier +and an optional @samp{B} for "byte". + +Table of SI and binary prefixes (unit multipliers): + +@multitable {Prefix} {kilobyte (10^3 = 1000)} {|} {Prefix} {kibibyte (2^10 = 1024)} +@item Prefix @tab Value @tab | @tab Prefix @tab Value +@item k @tab kilobyte (10^3 = 1000) @tab | @tab Ki @tab kibibyte (2^10 = 1024) +@item M @tab megabyte (10^6) @tab | @tab Mi @tab mebibyte (2^20) +@item G @tab gigabyte (10^9) @tab | @tab Gi @tab gibibyte (2^30) +@item T @tab terabyte (10^12) @tab | @tab Ti @tab tebibyte (2^40) +@item P @tab petabyte (10^15) @tab | @tab Pi @tab pebibyte (2^50) +@item E @tab exabyte (10^18) @tab | @tab Ei @tab exbibyte (2^60) +@item Z @tab zettabyte (10^21) @tab | @tab Zi @tab zebibyte (2^70) +@item Y @tab yottabyte (10^24) @tab | @tab Yi @tab yobibyte (2^80) +@end multitable + +@sp 1 +Exit status: 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 +caused minilzip to panic. + + @node Data format @chapter Data format @cindex data format @@ -655,9 +854,9 @@ represents one byte; a box like this: represents a variable number of bytes. @sp 1 -A lzip data stream consists of a series of "members" (compressed data -sets). The members simply appear one after another in the data stream, -with no additional information before, between, or after them. +A lzip data stream consists of a series of "members" (compressed data sets). +The members simply appear one after another in the data stream, with no +additional information before, between, or after them. Each member has the following structure: @verbatim @@ -810,15 +1009,15 @@ Example 5: Multimember compression (@var{member_size} < total output). Example 6: Multimember compression (user-restarted members). @example - 1) LZ_compress_open + 1) LZ_compress_open (with @var{member_size} > largest member). 2) LZ_compress_write 3) LZ_compress_read 4) go back to step 2 until member termination is desired 5) LZ_compress_finish 6) LZ_compress_read 7) go back to step 6 until LZ_compress_member_finished returns 1 - 8) verify that LZ_compress_finished returns 1 - 9) go to step 12 if all input data have been written + 9) go to step 12 if all input data have been written and + LZ_compress_finished returns 1 10) LZ_compress_restart_member 11) go back to step 2 12) LZ_compress_close diff --git a/doc/minilzip.1 b/doc/minilzip.1 index 3fefa02..a5f30c8 100644 --- a/doc/minilzip.1 +++ b/doc/minilzip.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.46.1. -.TH MINILZIP "1" "April 2017" "minilzip 1.9" "User Commands" +.TH MINILZIP "1" "February 2018" "minilzip 1.10" "User Commands" .SH NAME minilzip \- reduces the size of files .SH SYNOPSIS @@ -49,7 +49,7 @@ suppress all messages set dictionary size limit in bytes [8 MiB] .TP \fB\-S\fR, \fB\-\-volume\-size=\fR -set volume size limit in bytes +set volume size limit in bytes, implies \fB\-k\fR .TP \fB\-t\fR, \fB\-\-test\fR test compressed file integrity @@ -65,6 +65,9 @@ alias for \fB\-0\fR .TP \fB\-\-best\fR alias for \fB\-9\fR +.TP +\fB\-\-loose\-trailing\fR +allow trailing data seeming corrupt header .PP If no file names are given, or if a file is '\-', minilzip compresses or decompresses from standard input to standard output. @@ -87,8 +90,8 @@ Report bugs to lzip\-bug@nongnu.org .br Lzlib home page: http://www.nongnu.org/lzip/lzlib.html .SH COPYRIGHT -Copyright \(co 2017 Antonio Diaz Diaz. -Using lzlib 1.9 +Copyright \(co 2018 Antonio Diaz Diaz. +Using lzlib 1.10 License GPLv2+: GNU GPL version 2 or later .br This is free software: you are free to change and redistribute it. diff --git a/encoder.c b/encoder.c index cb4d222..7d19235 100644 --- a/encoder.c +++ b/encoder.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2017 Antonio Diaz Diaz. + Copyright (C) 2009-2018 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/encoder.h b/encoder.h index dd02efb..8948013 100644 --- a/encoder.h +++ b/encoder.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2017 Antonio Diaz Diaz. + Copyright (C) 2009-2018 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -287,7 +287,7 @@ static inline bool LZe_init( struct LZ_encoder * const e, const int dict_size, const int len_limit, const unsigned long long member_size ) { - enum { before = max_num_trials, + enum { before_size = max_num_trials, /* bytes to keep in buffer after pos */ after_size = max_num_trials + ( 2 * max_match_len ) + 1, dict_factor = 2, @@ -295,7 +295,7 @@ static inline bool LZe_init( struct LZ_encoder * const e, pos_array_factor = 2, min_free_bytes = 2 * max_num_trials }; - if( !LZeb_init( &e->eb, before, dict_size, after_size, dict_factor, + if( !LZeb_init( &e->eb, before_size, dict_size, after_size, dict_factor, num_prev_positions23, pos_array_factor, min_free_bytes, member_size ) ) return false; e->cycles = ( len_limit < max_match_len ) ? 16 + ( len_limit / 2 ) : 256; diff --git a/encoder_base.c b/encoder_base.c index be9af5d..0dbc617 100644 --- a/encoder_base.c +++ b/encoder_base.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2017 Antonio Diaz Diaz. + Copyright (C) 2009-2018 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -39,39 +39,39 @@ static bool Mb_normalize_pos( struct Matchfinder_base * const mb ) } -static bool Mb_init( struct Matchfinder_base * const mb, - const int before, const int dict_size, - const int after_size, const int dict_factor, - const int num_prev_positions23, +static bool Mb_init( struct Matchfinder_base * const mb, const int before_size, + const int dict_size, const int after_size, + const int dict_factor, const int num_prev_positions23, const int pos_array_factor ) { const int buffer_size_limit = - ( dict_factor * dict_size ) + before + after_size; + ( dict_factor * dict_size ) + before_size + after_size; unsigned size; int i; mb->partial_data_pos = 0; - mb->before_size = before; + mb->before_size = before_size; mb->after_size = after_size; mb->pos = 0; mb->cyclic_pos = 0; mb->stream_pos = 0; + mb->num_prev_positions23 = num_prev_positions23; mb->at_stream_end = false; mb->flushing = false; mb->buffer_size = max( 65536, buffer_size_limit ); mb->buffer = (uint8_t *)malloc( mb->buffer_size ); if( !mb->buffer ) return false; + mb->saved_dictionary_size = dict_size; mb->dictionary_size = dict_size; mb->pos_limit = mb->buffer_size - after_size; size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 ); if( mb->dictionary_size > 1 << 26 ) /* 64 MiB */ size >>= 1; mb->key4_mask = size - 1; - mb->num_prev_positions23 = num_prev_positions23; size += num_prev_positions23; - mb->num_prev_positions = size; + mb->pos_array_size = pos_array_factor * ( mb->dictionary_size + 1 ); size += mb->pos_array_size; if( size * sizeof mb->prev_positions[0] <= size ) mb->prev_positions = 0; @@ -84,21 +84,25 @@ static bool Mb_init( struct Matchfinder_base * const mb, } +static void Mb_adjust_array( struct Matchfinder_base * const mb ) + { + int size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 ); + if( mb->dictionary_size > 1 << 26 ) /* 64 MiB */ + size >>= 1; + mb->key4_mask = size - 1; + size += mb->num_prev_positions23; + mb->num_prev_positions = size; + mb->pos_array = mb->prev_positions + mb->num_prev_positions; + } + + static void Mb_adjust_dictionary_size( struct Matchfinder_base * const mb ) { if( mb->stream_pos < mb->dictionary_size ) { - int size; - mb->buffer_size = - mb->dictionary_size = - mb->pos_limit = max( min_dictionary_size, mb->stream_pos ); - size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 ); - if( mb->dictionary_size > 1 << 26 ) /* 64 MiB */ - size >>= 1; - mb->key4_mask = size - 1; - size += mb->num_prev_positions23; - mb->num_prev_positions = size; - mb->pos_array = mb->prev_positions + mb->num_prev_positions; + mb->dictionary_size = max( min_dictionary_size, mb->stream_pos ); + Mb_adjust_array( mb ); + mb->pos_limit = mb->buffer_size; } } @@ -114,6 +118,9 @@ static void Mb_reset( struct Matchfinder_base * const mb ) mb->cyclic_pos = 0; mb->at_stream_end = false; mb->flushing = false; + mb->dictionary_size = mb->saved_dictionary_size; + Mb_adjust_array( mb ); + mb->pos_limit = mb->buffer_size - mb->after_size; for( i = 0; i < mb->num_prev_positions; ++i ) mb->prev_positions[i] = 0; } @@ -180,7 +187,7 @@ static void LZeb_reset( struct LZ_encoder_base * const eb, Bm_array_init( eb->bm_align, dis_align_size ); Lm_init( &eb->match_len_model ); Lm_init( &eb->rep_len_model ); - Re_reset( &eb->renc ); + Re_reset( &eb->renc, eb->mb.dictionary_size ); for( i = 0; i < num_rep_distances; ++i ) eb->reps[i] = 0; eb->state = 0; eb->member_finished = false; diff --git a/encoder_base.h b/encoder_base.h index c4cfcca..ddba7e6 100644 --- a/encoder_base.h +++ b/encoder_base.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2017 Antonio Diaz Diaz. + Copyright (C) 2009-2018 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -238,16 +238,16 @@ struct Matchfinder_base int num_prev_positions23; int num_prev_positions; /* size of prev_positions */ int pos_array_size; + int saved_dictionary_size; /* dictionary_size restored by Mb_reset */ bool at_stream_end; /* stream_pos shows real end of file */ bool flushing; }; static bool Mb_normalize_pos( struct Matchfinder_base * const mb ); -static bool Mb_init( struct Matchfinder_base * const mb, - const int before, const int dict_size, - const int after_size, const int dict_factor, - const int num_prev_positions23, +static bool Mb_init( struct Matchfinder_base * const mb, const int before_size, + const int dict_size, const int after_size, + const int dict_factor, const int num_prev_positions23, const int pos_array_factor ); static inline void Mb_free( struct Matchfinder_base * const mb ) @@ -339,7 +339,8 @@ static inline void Re_shift_low( struct Range_encoder * const renc ) renc->low = ( renc->low & 0x00FFFFFFU ) << 8; } -static inline void Re_reset( struct Range_encoder * const renc ) +static inline void Re_reset( struct Range_encoder * const renc, + const unsigned dictionary_size ) { int i; Cb_reset( &renc->cb ); @@ -348,6 +349,7 @@ static inline void Re_reset( struct Range_encoder * const renc ) renc->range = 0xFFFFFFFFU; renc->ff_count = 0; renc->cache = 0; + Fh_set_dictionary_size( renc->header, dictionary_size ); for( i = 0; i < Fh_size; ++i ) Cb_put_byte( &renc->cb, renc->header[i] ); } @@ -359,8 +361,7 @@ static inline bool Re_init( struct Range_encoder * const renc, if( !Cb_init( &renc->cb, 65536 + min_free_bytes ) ) return false; renc->min_free_bytes = min_free_bytes; Fh_set_magic( renc->header ); - Fh_set_dictionary_size( renc->header, dictionary_size ); - Re_reset( renc ); + Re_reset( renc, dictionary_size ); return true; } @@ -544,14 +545,14 @@ static void LZeb_reset( struct LZ_encoder_base * const eb, const unsigned long long member_size ); static inline bool LZeb_init( struct LZ_encoder_base * const eb, - const int before, const int dict_size, + const int before_size, const int dict_size, const int after_size, const int dict_factor, const int num_prev_positions23, const int pos_array_factor, const unsigned min_free_bytes, const unsigned long long member_size ) { - if( !Mb_init( &eb->mb, before, dict_size, after_size, dict_factor, + if( !Mb_init( &eb->mb, before_size, dict_size, after_size, dict_factor, num_prev_positions23, pos_array_factor ) ) return false; if( !Re_init( &eb->renc, eb->mb.dictionary_size, min_free_bytes ) ) return false; diff --git a/fast_encoder.c b/fast_encoder.c index af81137..1ba80e0 100644 --- a/fast_encoder.c +++ b/fast_encoder.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2017 Antonio Diaz Diaz. + Copyright (C) 2009-2018 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/fast_encoder.h b/fast_encoder.h index c02e9cb..47dfb3e 100644 --- a/fast_encoder.h +++ b/fast_encoder.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2017 Antonio Diaz Diaz. + Copyright (C) 2009-2018 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -53,7 +53,7 @@ static inline bool FLZe_update_and_move( struct FLZ_encoder * const fe, int n ) static inline bool FLZe_init( struct FLZ_encoder * const fe, const unsigned long long member_size ) { - enum { before = 0, + enum { before_size = 0, dict_size = 65536, /* bytes to keep in buffer after pos */ after_size = max_match_len, @@ -62,7 +62,7 @@ static inline bool FLZe_init( struct FLZ_encoder * const fe, pos_array_factor = 1, min_free_bytes = max_marker_size }; - return LZeb_init( &fe->eb, before, dict_size, after_size, dict_factor, + return LZeb_init( &fe->eb, before_size, dict_size, after_size, dict_factor, num_prev_positions23, pos_array_factor, min_free_bytes, member_size ); } diff --git a/lzcheck.c b/lzcheck.c index 9db661f..83e206d 100644 --- a/lzcheck.c +++ b/lzcheck.c @@ -1,19 +1,20 @@ /* Lzcheck - Test program for the lzlib library - Copyright (C) 2009-2017 Antonio Diaz Diaz. + Copyright (C) 2009-2018 Antonio Diaz Diaz. This program is free software: you have unlimited permission to copy, distribute and modify it. Usage is: - lzcheck filename.txt + lzcheck filename.txt... - This program reads the specified text file and then compresses it, + This program reads each specified text file and then compresses it, line by line, to test the flushing mechanism and the member restart/reset/sync functions. */ #define _FILE_OFFSET_BITS 64 +#include #include #include #include @@ -34,6 +35,15 @@ uint8_t mid_buffer[buffer_size]; uint8_t out_buffer[buffer_size]; +void show_line( const uint8_t * const buffer, const int size ) + { + int i; + for( i = 0; i < size; ++i ) + fputc( isprint( buffer[i] ) ? buffer[i] : '.', stderr ); + fputc( '\n', stderr ); + } + + int lzcheck( FILE * const file, const int dictionary_size ) { const int match_len_limit = 16; @@ -66,7 +76,7 @@ int lzcheck( FILE * const file, const int dictionary_size ) while( retval <= 1 ) { - int i, l, r; + int l, r; const int read_size = fread( in_buffer, 1, buffer_size, file ); if( read_size <= 0 ) break; /* end of file */ @@ -95,15 +105,11 @@ int lzcheck( FILE * const file, const int dictionary_size ) if( out_size != in_size || memcmp( in_buffer + l, out_buffer, out_size ) ) { - fprintf( stderr, "lzcheck: Sync error at pos %d in_size = %d, out_size = %d\n", + fprintf( stderr, "lzcheck: Sync error at pos %d in_size = %d, " + "out_size = %d\n", l, in_size, out_size ); - for( i = 0; i < in_size; ++i ) - fputc( in_buffer[l+i], stderr ); - if( in_buffer[l+in_size-1] != '\n' ) - fputc( '\n', stderr ); - for( i = 0; i < out_size; ++i ) - fputc( out_buffer[i], stderr ); - fputc( '\n', stderr ); + show_line( in_buffer + l, in_size ); + show_line( out_buffer, out_size ); retval = 1; } } @@ -113,7 +119,8 @@ int lzcheck( FILE * const file, const int dictionary_size ) { rewind( file ); if( LZ_compress_finish( encoder ) < 0 || - LZ_decompress_write( decoder, mid_buffer, LZ_compress_read( encoder, mid_buffer, buffer_size ) ) < 0 || + LZ_decompress_write( decoder, mid_buffer, + LZ_compress_read( encoder, mid_buffer, buffer_size ) ) < 0 || LZ_decompress_read( decoder, out_buffer, buffer_size ) != 0 || LZ_compress_restart_member( encoder, member_size ) < 0 ) { @@ -125,7 +132,7 @@ int lzcheck( FILE * const file, const int dictionary_size ) while( retval <= 1 ) { - int i, l, r, size; + int l, r, size; const int read_size = fread( in_buffer, 1, buffer_size / 2, file ); if( read_size <= 0 ) break; /* end of file */ @@ -133,7 +140,7 @@ int lzcheck( FILE * const file, const int dictionary_size ) { int leading_garbage, in_size, mid_size, out_size; while( r < read_size && in_buffer[r-1] != '\n' ) ++r; - leading_garbage = (l == 0) ? min( r, read_size / 2 ) : 0; + leading_garbage = (l == 0) ? min( r, read_size ) / 2 : 0; in_size = LZ_compress_write( encoder, in_buffer + l, r - l ); if( in_size < r - l ) r = l + in_size; LZ_compress_sync_flush( encoder ); @@ -167,22 +174,19 @@ int lzcheck( FILE * const file, const int dictionary_size ) if( out_size != in_size || memcmp( in_buffer + l, out_buffer, out_size ) ) { - fprintf( stderr, "lzcheck: Sync error at pos %d in_size = %d, out_size = %d, leading garbage = %d\n", + fprintf( stderr, "lzcheck: Sync error at pos %d in_size = %d, " + "out_size = %d, leading garbage = %d\n", l, in_size, out_size, leading_garbage ); - for( i = 0; i < in_size; ++i ) - fputc( in_buffer[l+i], stderr ); - if( in_buffer[l+in_size-1] != '\n' ) - fputc( '\n', stderr ); - for( i = 0; i < out_size; ++i ) - fputc( out_buffer[i], stderr ); - fputc( '\n', stderr ); + show_line( in_buffer + l, in_size ); + show_line( out_buffer, out_size ); retval = 1; } } if( retval >= 3 ) break; if( LZ_compress_finish( encoder ) < 0 || - LZ_decompress_write( decoder, mid_buffer, LZ_compress_read( encoder, mid_buffer, buffer_size ) ) < 0 || + LZ_decompress_write( decoder, mid_buffer, + LZ_compress_read( encoder, mid_buffer, buffer_size ) ) < 0 || LZ_decompress_read( decoder, out_buffer, buffer_size ) != 0 || LZ_decompress_reset( decoder ) < 0 || LZ_compress_restart_member( encoder, member_size ) < 0 ) @@ -195,7 +199,8 @@ int lzcheck( FILE * const file, const int dictionary_size ) size = min( 100, read_size ); if( LZ_compress_write( encoder, in_buffer, size ) != size || LZ_compress_finish( encoder ) < 0 || - LZ_decompress_write( decoder, mid_buffer, LZ_compress_read( encoder, mid_buffer, buffer_size ) ) < 0 || + LZ_decompress_write( decoder, mid_buffer, + LZ_compress_read( encoder, mid_buffer, buffer_size ) ) < 0 || LZ_decompress_read( decoder, out_buffer, 0 ) != 0 || LZ_decompress_sync_to_member( decoder ) < 0 || LZ_compress_restart_member( encoder, member_size ) < 0 ) @@ -214,26 +219,34 @@ int lzcheck( FILE * const file, const int dictionary_size ) int main( const int argc, const char * const argv[] ) { - FILE * file; - int retval; + int retval = 0, i; + int open_failures = 0; + const bool verbose = ( argc > 2 ); if( argc < 2 ) { - fputs( "Usage: lzcheck filename.txt\n", stderr ); + fputs( "Usage: lzcheck filename.txt...\n", stderr ); return 1; } - file = fopen( argv[1], "rb" ); - if( !file ) + for( i = 1; i < argc && retval == 0; ++ i ) { - fprintf( stderr, "lzcheck: Can't open file '%s' for reading.\n", argv[1] ); - return 1; - } -/* fprintf( stderr, "lzcheck: Testing file '%s'\n", argv[1] ); */ + FILE * file = fopen( argv[i], "rb" ); + if( !file ) + { + fprintf( stderr, "lzcheck: Can't open file '%s' for reading.\n", argv[i] ); + ++open_failures; continue; + } + if( verbose ) fprintf( stderr, " Testing file '%s'\n", argv[i] ); - retval = lzcheck( file, 65535 ); /* 65535,16 chooses fast encoder */ - if( retval == 0 ) - { rewind( file ); retval = lzcheck( file, 1 << 20 ); } - fclose( file ); + retval = lzcheck( file, 65535 ); /* 65535,16 chooses fast encoder */ + if( retval == 0 ) + { rewind( file ); retval = lzcheck( file, 1 << 20 ); } + fclose( file ); + } + if( open_failures > 0 && verbose ) + fprintf( stderr, "lzcheck: warning: %d %s failed to open.\n", + open_failures, ( open_failures == 1 ) ? "file" : "files" ); + if( retval == 0 && open_failures ) retval = 1; return retval; } diff --git a/lzip.h b/lzip.h index 5fc1379..3fdf70f 100644 --- a/lzip.h +++ b/lzip.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2017 Antonio Diaz Diaz. + Copyright (C) 2009-2018 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -204,12 +204,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 ) diff --git a/lzlib.c b/lzlib.c index 1a3080a..757ad25 100644 --- a/lzlib.c +++ b/lzlib.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2017 Antonio Diaz Diaz. + Copyright (C) 2009-2018 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -193,7 +193,7 @@ int LZ_compress_finish( struct LZ_Encoder * const e ) /* if (open --> write --> finish) use same dictionary size as lzip. */ /* this does not save any memory. */ if( Mb_data_position( &e->lz_encoder_base->mb ) == 0 && - LZ_compress_total_out_size( e ) == Fh_size ) + Re_member_position( &e->lz_encoder_base->renc ) == Fh_size ) { Mb_adjust_dictionary_size( &e->lz_encoder_base->mb ); Fh_set_dictionary_size( e->lz_encoder_base->renc.header, @@ -417,7 +417,7 @@ int LZ_decompress_read( struct LZ_Decoder * const d, !d->rdec->at_stream_end ) return 0; if( Rd_finished( d->rdec ) && !d->first_header ) return 0; rd = Rd_read_data( d->rdec, d->member_header, Fh_size ); - if( Rd_finished( d->rdec ) ) + if( Rd_finished( d->rdec ) ) /* End Of File */ { if( rd <= 0 || Fh_verify_prefix( d->member_header, rd ) ) d->lz_errno = LZ_unexpected_eof; @@ -431,7 +431,12 @@ int LZ_decompress_read( struct LZ_Decoder * const d, /* unreading the header prevents sync_to_member from skipping a member if leading garbage is shorter than a full header; "lgLZIP\x01\x0C" */ if( Rd_unread_data( d->rdec, rd ) ) - d->lz_errno = LZ_header_error; + { + if( d->first_header || !Fh_verify_corrupt( d->member_header ) ) + d->lz_errno = LZ_header_error; + else + d->lz_errno = LZ_data_error; /* corrupt header */ + } else d->lz_errno = LZ_library_error; d->fatal = true; @@ -440,7 +445,10 @@ int LZ_decompress_read( struct LZ_Decoder * const d, if( !Fh_verify_version( d->member_header ) || !isvalid_ds( Fh_get_dictionary_size( d->member_header ) ) ) { - d->lz_errno = LZ_data_error; /* bad version or bad dict size */ + if( Rd_unread_data( d->rdec, 1 + !Fh_verify_version( d->member_header ) ) ) + d->lz_errno = LZ_data_error; /* bad version or bad dict size */ + else + d->lz_errno = LZ_library_error; d->fatal = true; return -1; } @@ -469,10 +477,10 @@ int LZ_decompress_read( struct LZ_Decoder * const d, result = LZd_decode_member( d->lz_decoder ); if( result != 0 ) { - if( result == 2 ) - { d->lz_errno = LZ_unexpected_eof; - d->rdec->member_position += Cb_used_bytes( &d->rdec->cb ); - Cb_reset( &d->rdec->cb ); } + if( result == 2 ) /* set position at EOF */ + { d->rdec->member_position += Cb_used_bytes( &d->rdec->cb ); + Cb_reset( &d->rdec->cb ); + d->lz_errno = LZ_unexpected_eof; } else if( result == 5 ) d->lz_errno = LZ_library_error; else d->lz_errno = LZ_data_error; d->fatal = true; diff --git a/lzlib.h b/lzlib.h index a58c851..1eed1e0 100644 --- a/lzlib.h +++ b/lzlib.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2017 Antonio Diaz Diaz. + Copyright (C) 2009-2018 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -23,7 +23,7 @@ extern "C" { #define LZ_API_VERSION 1 -static const char * const LZ_version_string = "1.9"; +static const char * const LZ_version_string = "1.10"; enum LZ_Errno { LZ_ok = 0, LZ_bad_argument, LZ_mem_error, LZ_sequence_error, LZ_header_error, LZ_unexpected_eof, diff --git a/main.c b/main.c index 633456b..3e3e411 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,5 @@ /* Minilzip - Test program for the lzlib library - Copyright (C) 2009-2017 Antonio Diaz Diaz. + Copyright (C) 2009-2018 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 @@ -79,7 +79,7 @@ int verbosity = 0; const char * const Program_name = "Minilzip"; const char * const program_name = "minilzip"; -const char * const program_year = "2017"; +const char * const program_year = "2018"; const char * invocation_name = 0; const struct { const char * from; const char * to; } known_extensions[] = { @@ -100,66 +100,6 @@ int outfd = -1; bool delete_output_on_interrupt = false; -struct Pretty_print - { - const char * name; - const char * stdin_name; - unsigned longest_name; - bool first_post; - }; - -static void Pp_init( struct Pretty_print * const pp, - const char * const filenames[], - const int num_filenames, const int verbosity ) - { - unsigned stdin_name_len; - int i; - pp->name = 0; - pp->stdin_name = "(stdin)"; - pp->longest_name = 0; - pp->first_post = false; - - if( verbosity <= 0 ) return; - stdin_name_len = strlen( pp->stdin_name ); - for( i = 0; i < num_filenames; ++i ) - { - const char * const s = filenames[i]; - const unsigned len = (strcmp( s, "-" ) == 0) ? stdin_name_len : strlen( s ); - if( len > pp->longest_name ) pp->longest_name = len; - } - if( pp->longest_name == 0 ) pp->longest_name = stdin_name_len; - } - -static inline void Pp_set_name( struct Pretty_print * const pp, - const char * const filename ) - { - if( filename && filename[0] && strcmp( filename, "-" ) != 0 ) - pp->name = filename; - else pp->name = pp->stdin_name; - pp->first_post = true; - } - -static inline void Pp_reset( struct Pretty_print * const pp ) - { if( pp->name && pp->name[0] ) pp->first_post = true; } - -static void Pp_show_msg( struct Pretty_print * const pp, const char * const msg ) - { - if( verbosity >= 0 ) - { - if( pp->first_post ) - { - unsigned i; - pp->first_post = false; - fprintf( stderr, " %s: ", pp->name ); - for( i = strlen( pp->name ); i < pp->longest_name; ++i ) - fputc( ' ', stderr ); - if( !msg ) fflush( stderr ); - } - if( msg ) fprintf( stderr, "%s\n", msg ); - } - } - - static void show_help( void ) { printf( "%s - Test program for the lzlib library.\n", Program_name ); @@ -178,12 +118,13 @@ static void show_help( void ) " -o, --output= if reading standard input, write to \n" " -q, --quiet suppress all messages\n" " -s, --dictionary-size= set dictionary size limit in bytes [8 MiB]\n" - " -S, --volume-size= set volume size limit in bytes\n" + " -S, --volume-size= set volume size limit in bytes, implies -k\n" " -t, --test test compressed file integrity\n" " -v, --verbose be verbose (a 2nd -v gives more)\n" " -0 .. -9 set compression level [default 6]\n" " --fast alias for -0\n" " --best alias for -9\n" + " --loose-trailing allow trailing data seeming corrupt header\n" "If no file names are given, or if a file is '-', minilzip compresses or\n" "decompresses from standard input to standard output.\n" "Numbers may be followed by a multiplier: k = kB = 10^3 = 1000,\n" @@ -214,23 +155,103 @@ static void show_version( void ) } +/* assure at least a minimum size for buffer 'buf' */ +static void * resize_buffer( void * buf, const unsigned 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; + } + + +struct Pretty_print + { + const char * name; + char * padded_name; + const char * stdin_name; + unsigned longest_name; + bool first_post; + }; + +static void Pp_init( struct Pretty_print * const pp, + const char * const filenames[], + 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; + + if( verbosity <= 0 ) return; + stdin_name_len = strlen( pp->stdin_name ); + for( i = 0; i < num_filenames; ++i ) + { + const char * const s = filenames[i]; + const unsigned len = (strcmp( s, "-" ) == 0) ? stdin_name_len : strlen( s ); + if( len > pp->longest_name ) pp->longest_name = len; + } + if( pp->longest_name == 0 ) pp->longest_name = stdin_name_len; + } + +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; + } + +static inline void Pp_reset( struct Pretty_print * const pp ) + { if( pp->name && pp->name[0] ) pp->first_post = true; } + +static void Pp_show_msg( struct Pretty_print * const pp, const char * const msg ) + { + if( verbosity >= 0 ) + { + if( pp->first_post ) + { + pp->first_post = false; + fputs( pp->padded_name, stderr ); + if( !msg ) fflush( stderr ); + } + if( msg ) fprintf( stderr, "%s\n", msg ); + } + } + + static void show_header( const unsigned dictionary_size ) { - if( verbosity >= 3 ) - { - enum { factor = 1024 }; - const char * const prefix[8] = - { "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" }; - const char * p = ""; - const char * np = " "; - unsigned num = dictionary_size, i; - bool exact = ( num % factor == 0 ); + enum { factor = 1024 }; + const char * const prefix[8] = + { "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" }; + const char * p = ""; + const char * np = " "; + unsigned num = dictionary_size; + bool exact = ( num % factor == 0 ); - for( i = 0; i < 8 && ( num > 9999 || ( exact && num >= factor ) ); ++i ) - { num /= factor; if( num % factor != 0 ) exact = false; - p = prefix[i]; np = ""; } - fprintf( stderr, "dictionary %s%4u %sB. ", np, num, p ); - } + int i; for( i = 0; i < 8 && ( num > 9999 || ( exact && num >= factor ) ); ++i ) + { num /= factor; if( num % factor != 0 ) exact = false; + p = prefix[i]; np = ""; } + fprintf( stderr, "dictionary %s%4u %sB, ", np, num, p ); } @@ -317,6 +338,43 @@ static int extension_index( const char * const name ) } +static void set_c_outname( const char * const name, const bool force_ext, + const bool multifile ) + { + output_filename = resize_buffer( output_filename, strlen( name ) + 5 + + strlen( known_extensions[0].from ) + 1 ); + strcpy( output_filename, name ); + if( multifile ) strcat( output_filename, "00001" ); + if( force_ext || multifile || extension_index( output_filename ) < 0 ) + strcat( output_filename, known_extensions[0].from ); + } + + +static void set_d_outname( const char * const name, const int eindex ) + { + const unsigned name_len = strlen( name ); + if( eindex >= 0 ) + { + const char * const from = known_extensions[eindex].from; + const unsigned from_len = strlen( from ); + if( name_len > from_len ) + { + output_filename = resize_buffer( output_filename, name_len + + strlen( known_extensions[eindex].to ) + 1 ); + strcpy( output_filename, name ); + strcpy( output_filename + name_len - from_len, known_extensions[eindex].to ); + return; + } + } + output_filename = resize_buffer( output_filename, name_len + 4 + 1 ); + strcpy( output_filename, name ); + strcat( output_filename, ".out" ); + if( verbosity >= 1 ) + fprintf( stderr, "%s: Can't guess original name for '%s' -- using '%s'\n", + program_name, name, output_filename ); + } + + static int open_instream( const char * const name, struct stat * const in_statsp, const enum Mode program_mode, const int eindex, const bool recompress, const bool to_stdout ) @@ -357,55 +415,6 @@ static int open_instream( const char * const name, struct stat * const in_statsp } -/* assure at least a minimum size for buffer 'buf' */ -static void * resize_buffer( void * buf, const unsigned 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; - } - - -static void set_c_outname( const char * const name, const bool multifile ) - { - output_filename = resize_buffer( output_filename, strlen( name ) + 5 + - strlen( known_extensions[0].from ) + 1 ); - strcpy( output_filename, name ); - if( multifile ) strcat( output_filename, "00001" ); - strcat( output_filename, known_extensions[0].from ); - } - - -static void set_d_outname( const char * const name, const int eindex ) - { - const unsigned name_len = strlen( name ); - if( eindex >= 0 ) - { - const char * const from = known_extensions[eindex].from; - const unsigned from_len = strlen( from ); - if( name_len > from_len ) - { - output_filename = resize_buffer( output_filename, name_len + - strlen( known_extensions[eindex].to ) + 1 ); - strcpy( output_filename, name ); - strcpy( output_filename + name_len - from_len, known_extensions[eindex].to ); - return; - } - } - output_filename = resize_buffer( output_filename, name_len + 4 + 1 ); - strcpy( output_filename, name ); - strcat( output_filename, ".out" ); - if( verbosity >= 1 ) - fprintf( stderr, "%s: Can't guess original name for '%s' -- using '%s'\n", - program_name, name, output_filename ); - } - - static bool open_outstream( const bool force, const bool from_stdin ) { const mode_t usr_rw = S_IRUSR | S_IWUSR; @@ -552,8 +561,8 @@ static bool next_filename( void ) static int do_compress( struct LZ_Encoder * const encoder, const unsigned long long member_size, - const unsigned long long volume_size, - const int infd, struct Pretty_print * const pp, + const unsigned long long volume_size, const int infd, + struct Pretty_print * const pp, const struct stat * const in_statsp ) { unsigned long long partial_volume_size = 0; @@ -597,7 +606,8 @@ static int do_compress( struct LZ_Encoder * const encoder, return 1; } } - else if( in_size == 0 ) internal_error( "library error (LZ_compress_read)." ); + else if( in_size == 0 ) + internal_error( "library error (LZ_compress_read)." ); if( LZ_compress_member_finished( encoder ) ) { unsigned long long size; @@ -638,11 +648,11 @@ static int do_compress( struct LZ_Encoder * const encoder, if( in_size == 0 || out_size == 0 ) fputs( " no data compressed.\n", stderr ); else - fprintf( stderr, "%6.3f:1, %6.3f bits/byte, " - "%5.2f%% saved, %llu in, %llu out.\n", + fprintf( stderr, "%6.3f:1, %5.2f%% ratio, %5.2f%% saved, " + "%llu in, %llu out.\n", (double)in_size / out_size, - ( 8.0 * out_size ) / in_size, - 100.0 * ( 1.0 - ( (double)out_size / in_size ) ), + ( 100.0 * out_size ) / in_size, + 100.0 - ( ( 100.0 * out_size ) / in_size ), in_size, out_size ); } return 0; @@ -677,8 +687,8 @@ static int compress( const unsigned long long member_size, static int do_decompress( struct LZ_Decoder * const decoder, const int infd, - struct Pretty_print * const pp, - const bool ignore_trailing, const bool testing ) + struct Pretty_print * const pp, const bool ignore_trailing, + const bool loose_trailing, const bool testing ) { enum { buffer_size = 65536 }; uint8_t buffer[buffer_size]; @@ -723,73 +733,107 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd, { const unsigned long long data_size = LZ_decompress_data_position( decoder ); const unsigned long long member_size = LZ_decompress_member_position( decoder ); - Pp_show_msg( pp, 0 ); - show_header( LZ_decompress_dictionary_size( decoder ) ); - if( verbosity >= 2 && data_size > 0 && member_size > 0 ) - fprintf( stderr, "%6.3f:1, %6.3f bits/byte, %5.2f%% saved. ", + if( verbosity >= 2 || ( verbosity == 1 && first_member ) ) + Pp_show_msg( pp, 0 ); + if( verbosity >= 2 ) + { + if( verbosity >= 4 ) + show_header( LZ_decompress_dictionary_size( decoder ) ); + if( data_size == 0 || member_size == 0 ) + fputs( "no data compressed. ", stderr ); + else + fprintf( stderr, "%6.3f:1, %5.2f%% ratio, %5.2f%% saved. ", (double)data_size / member_size, - ( 8.0 * member_size ) / data_size, - 100.0 * ( 1.0 - ( (double)member_size / data_size ) ) ); - if( verbosity >= 4 ) - fprintf( stderr, "CRC %08X, decompressed %9llu, compressed %8llu. ", - LZ_decompress_data_crc( decoder ), data_size, member_size ); - fputs( testing ? "ok\n" : "done\n", stderr ); + ( 100.0 * member_size ) / data_size, + 100.0 - ( ( 100.0 * member_size ) / data_size ) ); + if( verbosity >= 4 ) + fprintf( stderr, "CRC %08X, ", LZ_decompress_data_crc( decoder ) ); + if( verbosity >= 3 ) + fprintf( stderr, "decompressed %9llu, compressed %8llu. ", + data_size, member_size ); + fputs( testing ? "ok\n" : "done\n", stderr ); Pp_reset( pp ); + } } - first_member = false; Pp_reset( pp ); + first_member = false; } if( rd <= 0 ) break; } if( out_size < 0 || ( first_member && out_size == 0 ) ) { + const unsigned long long member_pos = LZ_decompress_member_position( decoder ); const enum LZ_Errno lz_errno = LZ_decompress_errno( decoder ); - if( lz_errno == LZ_unexpected_eof && - LZ_decompress_member_position( decoder ) <= 6 ) - { Pp_show_msg( pp, "File ends unexpectedly at member header." ); - return 2; } + if( lz_errno == LZ_library_error ) + internal_error( "library error (LZ_decompress_read)." ); + if( member_pos <= 6 ) + { + if( lz_errno == LZ_unexpected_eof ) + { + if( first_member ) + show_file_error( pp->name, "File ends unexpectedly at member header.", 0 ); + else + Pp_show_msg( pp, "Truncated header in multimember file." ); + return 2; + } + else if( lz_errno == LZ_data_error ) + { + if( member_pos == 4 ) + { if( verbosity >= 0 ) + { Pp_show_msg( pp, 0 ); + fprintf( stderr, "Version %d member format not supported.\n", + LZ_decompress_member_version( decoder ) ); } } + else if( member_pos == 5 ) + Pp_show_msg( pp, "Invalid dictionary size in member header." ); + else if( first_member ) /* for lzlib older than 1.10 */ + Pp_show_msg( pp, "Bad version or dictionary size in member header." ); + else if( !loose_trailing ) + Pp_show_msg( pp, "Corrupt header in multimember file." ); + else if( !ignore_trailing ) + Pp_show_msg( pp, "Trailing data not allowed." ); + else break; /* trailing data */ + return 2; + } + } if( lz_errno == LZ_header_error ) { if( first_member ) - { show_file_error( pp->name, - "Bad magic number (file not in lzip format).", 0 ); - return 2; } + show_file_error( pp->name, + "Bad magic number (file not in lzip format).", 0 ); else if( !ignore_trailing ) - { show_file_error( pp->name, "Trailing data not allowed.", 0 ); - return 2; } - break; + Pp_show_msg( pp, "Trailing data not allowed." ); + else break; /* trailing data */ + return 2; } if( lz_errno == LZ_mem_error ) { Pp_show_msg( pp, "Not enough memory." ); return 1; } if( verbosity >= 0 ) { Pp_show_msg( pp, 0 ); - if( lz_errno == LZ_unexpected_eof ) - fprintf( stderr, "File ends unexpectedly at pos %llu\n", - LZ_decompress_total_in_size( decoder ) ); - else - fprintf( stderr, "Decoder error at pos %llu: %s\n", - LZ_decompress_total_in_size( decoder ), - LZ_strerror( LZ_decompress_errno( decoder ) ) ); + fprintf( stderr, "%s at pos %llu\n", ( lz_errno == LZ_unexpected_eof ) ? + "File ends unexpectedly" : "Decoder error", + LZ_decompress_total_in_size( decoder ) ); } return 2; } if( LZ_decompress_finished( decoder ) == 1 ) break; if( in_size == 0 && out_size == 0 ) - internal_error( "library error (LZ_decompress_read)." ); + internal_error( "library error (stalled)." ); } + if( verbosity == 1 ) fputs( testing ? "ok\n" : "done\n", stderr ); return 0; } static int decompress( const int infd, struct Pretty_print * const pp, - const bool ignore_trailing, const bool testing ) + const bool ignore_trailing, + const bool loose_trailing, const bool testing ) { struct LZ_Decoder * const decoder = LZ_decompress_open(); int retval; if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok ) { Pp_show_msg( pp, "Not enough memory." ); retval = 1; } - else retval = do_decompress( decoder, infd, pp, ignore_trailing, testing ); - + else retval = do_decompress( decoder, infd, pp, ignore_trailing, + loose_trailing, testing ); LZ_decompress_close( decoder ); return retval; } @@ -868,50 +912,53 @@ int main( const int argc, const char * const argv[] ) 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; + int failed_tests = 0; int retval = 0; int i; bool filenames_given = false; bool force = false; bool ignore_trailing = true; bool keep_input_files = false; + bool loose_trailing = false; bool recompress = false; bool stdin_used = false; bool to_stdout = false; struct Pretty_print pp; + enum { opt_lt = 256 }; const struct ap_Option options[] = { - { '0', "fast", ap_no }, - { '1', 0, ap_no }, - { '2', 0, ap_no }, - { '3', 0, ap_no }, - { '4', 0, ap_no }, - { '5', 0, ap_no }, - { '6', 0, ap_no }, - { '7', 0, ap_no }, - { '8', 0, ap_no }, - { '9', "best", ap_no }, - { 'a', "trailing-error", ap_no }, - { 'b', "member-size", ap_yes }, - { 'c', "stdout", ap_no }, - { 'd', "decompress", ap_no }, - { 'f', "force", ap_no }, - { 'F', "recompress", ap_no }, - { 'h', "help", ap_no }, - { 'k', "keep", ap_no }, - { 'm', "match-length", ap_yes }, - { 'n', "threads", ap_yes }, - { 'o', "output", ap_yes }, - { 'q', "quiet", ap_no }, - { 's', "dictionary-size", ap_yes }, - { 'S', "volume-size", ap_yes }, - { 't', "test", ap_no }, - { 'v', "verbose", ap_no }, - { 'V', "version", ap_no }, - { 0 , 0, ap_no } }; + { '0', "fast", ap_no }, + { '1', 0, ap_no }, + { '2', 0, ap_no }, + { '3', 0, ap_no }, + { '4', 0, ap_no }, + { '5', 0, ap_no }, + { '6', 0, ap_no }, + { '7', 0, ap_no }, + { '8', 0, ap_no }, + { '9', "best", ap_no }, + { 'a', "trailing-error", ap_no }, + { 'b', "member-size", ap_yes }, + { 'c', "stdout", ap_no }, + { 'd', "decompress", ap_no }, + { 'f', "force", ap_no }, + { 'F', "recompress", ap_no }, + { 'h', "help", ap_no }, + { 'k', "keep", ap_no }, + { 'm', "match-length", ap_yes }, + { 'n', "threads", ap_yes }, + { 'o', "output", ap_yes }, + { 'q', "quiet", ap_no }, + { 's', "dictionary-size", ap_yes }, + { 'S', "volume-size", ap_yes }, + { 't', "test", ap_no }, + { 'v', "verbose", ap_no }, + { 'V', "version", ap_no }, + { opt_lt, "loose-trailing", ap_no }, + { 0 , 0, ap_no } }; struct Arg_parser parser; @@ -957,6 +1004,7 @@ int main( const int argc, const char * const argv[] ) case 't': program_mode = m_test; break; case 'v': if( verbosity < 4 ) ++verbosity; break; case 'V': show_version(); return 0; + case opt_lt: loose_trailing = true; break; default : internal_error( "uncaught option." ); } } /* end process options */ @@ -983,12 +1031,13 @@ int main( const int argc, const char * const argv[] ) ( filenames_given || default_output_filename[0] ) ) set_signals(); - Pp_init( &pp, filenames, num_filenames, verbosity ); + Pp_init( &pp, filenames, num_filenames ); output_filename = resize_buffer( output_filename, 1 ); for( i = 0; i < num_filenames; ++i ) { const char * input_filename = ""; + int infd; int tmp; struct stat in_stats; const struct stat * in_statsp; @@ -1005,17 +1054,17 @@ int main( const int argc, const char * const argv[] ) else { if( program_mode == m_compress ) - set_c_outname( default_output_filename, volume_size > 0 ); + set_c_outname( default_output_filename, false, volume_size > 0 ); else { output_filename = resize_buffer( output_filename, - strlen( default_output_filename ) + 1 ); + strlen( default_output_filename ) + 1 ); strcpy( output_filename, default_output_filename ); } if( !open_outstream( force, true ) ) { if( retval < 1 ) retval = 1; - close( infd ); infd = -1; + close( infd ); continue; } } @@ -1033,12 +1082,12 @@ int main( const int argc, const char * const argv[] ) else { if( program_mode == m_compress ) - set_c_outname( input_filename, volume_size > 0 ); + set_c_outname( input_filename, true, volume_size > 0 ); else set_d_outname( input_filename, eindex ); if( !open_outstream( force, false ) ) { if( retval < 1 ) retval = 1; - close( infd ); infd = -1; + close( infd ); continue; } } @@ -1049,7 +1098,7 @@ int main( const int argc, const char * const argv[] ) if( !check_tty( pp.name, infd, program_mode ) ) { if( retval < 1 ) retval = 1; - if( program_mode == m_test ) { close( infd ); infd = -1; continue; } + if( program_mode == m_test ) { close( infd ); continue; } cleanup_and_fail( retval ); } @@ -1058,24 +1107,32 @@ int main( const int argc, const char * const argv[] ) tmp = compress( member_size, volume_size, infd, &encoder_options, &pp, in_statsp ); else - tmp = decompress( infd, &pp, ignore_trailing, program_mode == m_test ); + tmp = decompress( infd, &pp, ignore_trailing, + loose_trailing, program_mode == m_test ); if( tmp > retval ) retval = tmp; - if( tmp && program_mode != m_test ) cleanup_and_fail( retval ); + if( tmp ) + { if( program_mode != m_test ) cleanup_and_fail( retval ); + else ++failed_tests; } if( delete_output_on_interrupt ) close_and_set_permissions( in_statsp ); if( input_filename[0] ) { - close( infd ); infd = -1; - if( !keep_input_files && !to_stdout && program_mode != m_test ) + close( infd ); + if( !keep_input_files && !to_stdout && program_mode != m_test && + ( program_mode != m_compress || volume_size == 0 ) ) remove( input_filename ); } } if( outfd >= 0 && close( outfd ) != 0 ) { - show_error( "Can't close stdout", errno, false ); + show_error( "Error closing stdout", errno, false ); if( retval < 1 ) retval = 1; } + if( failed_tests > 0 && verbosity >= 1 && num_filenames > 1 ) + fprintf( stderr, "%s: warning: %d %s failed the test.\n", + program_name, failed_tests, + ( failed_tests == 1 ) ? "file" : "files" ); free( output_filename ); free( filenames ); ap_free( &parser ); diff --git a/testsuite/check.sh b/testsuite/check.sh index 037e2c9..929a690 100755 --- a/testsuite/check.sh +++ b/testsuite/check.sh @@ -1,6 +1,6 @@ #! /bin/sh -# check script for Lzlib - A compression library for lzip files -# Copyright (C) 2009-2017 Antonio Diaz Diaz. +# check script for Lzlib - Compression library for the lzip format +# Copyright (C) 2009-2018 Antonio Diaz Diaz. # # This script is free software: you have unlimited permission # to copy, distribute and modify it. @@ -54,6 +54,8 @@ done [ $? = 2 ] || test_failed $LINENO "${LZIP}" -cdq < in [ $? = 2 ] || test_failed $LINENO +"${LZIP}" -dq -o in < "${in_lz}" +[ $? = 1 ] || test_failed $LINENO # these are for code coverage "${LZIP}" -t -- nx_file 2> /dev/null [ $? = 1 ] || test_failed $LINENO @@ -97,6 +99,11 @@ printf "to be overwritten" > copy || framework_failure "${LZIP}" -df copy.lz { [ $? = 0 ] && [ ! -e copy.lz ] && cmp in copy ; } || test_failed $LINENO +rm -f copy +cat "${in_lz}" > copy.lz || framework_failure +"${LZIP}" -d -S100k copy.lz +{ [ $? = 0 ] && [ ! -e copy.lz ] && cmp in copy ; } || test_failed $LINENO + printf "to be overwritten" > copy || framework_failure "${LZIP}" -df -o copy < "${in_lz}" || test_failed $LINENO cmp in copy || test_failed $LINENO @@ -136,7 +143,7 @@ cat "${in_lz}" "${in_lz}" > in2.lz || framework_failure "${LZIP}" -cd in2.lz > copy2 || test_failed $LINENO cmp in2 copy2 || test_failed $LINENO -"${LZIP}" -s16 --output=copy2 < in2 || test_failed $LINENO +"${LZIP}" -s16 --output=copy2.lz < in2 || test_failed $LINENO "${LZIP}" -t copy2.lz || test_failed $LINENO "${LZIP}" -cd copy2.lz > copy2 || test_failed $LINENO cmp in2 copy2 || test_failed $LINENO @@ -192,10 +199,14 @@ for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do done cat in in in in in in in in > in8 || framework_failure -"${LZIP}" -1s12 -S100k -o out < in8 || test_failed $LINENO -"${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO -"${LZIP}" -cd out00001.lz out00002.lz | cmp in8 - || test_failed $LINENO -rm -f out00001.lz +"${LZIP}" -1s12 -S100k in8 || test_failed $LINENO +"${LZIP}" -t in800001.lz in800002.lz || test_failed $LINENO +"${LZIP}" -cd in800001.lz in800002.lz | cmp in8 - || test_failed $LINENO +rm -f in800001.lz in800002.lz +"${LZIP}" -1s12 -S100k -o out.lz < in8 || test_failed $LINENO +"${LZIP}" -t out.lz00001.lz out.lz00002.lz || test_failed $LINENO +"${LZIP}" -cd out.lz00001.lz out.lz00002.lz | cmp in8 - || test_failed $LINENO +rm -f out.lz00001.lz out.lz00002.lz "${LZIP}" -1ks4Ki -b100000 in8 || test_failed $LINENO "${LZIP}" -t in8.lz || test_failed $LINENO "${LZIP}" -cd in8.lz | cmp in8 - || test_failed $LINENO @@ -203,7 +214,15 @@ rm -f in8 "${LZIP}" -0 -S100k -o out < in8.lz || test_failed $LINENO "${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO "${LZIP}" -cd out00001.lz out00002.lz | cmp in8.lz - || test_failed $LINENO +rm -f out00001.lz +"${LZIP}" -1 -S100k -o out < in8.lz || test_failed $LINENO +"${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO +"${LZIP}" -cd out00001.lz out00002.lz | cmp in8.lz - || test_failed $LINENO rm -f out00001.lz out00002.lz +"${LZIP}" -0 -F -S100k in8.lz || test_failed $LINENO +"${LZIP}" -t in8.lz00001.lz in8.lz00002.lz || test_failed $LINENO +"${LZIP}" -cd in8.lz00001.lz in8.lz00002.lz | cmp in8.lz - || test_failed $LINENO +rm -f in8.lz00001.lz in8.lz00002.lz "${LZIP}" -0kF -b100k in8.lz || test_failed $LINENO "${LZIP}" -t in8.lz.lz || test_failed $LINENO "${LZIP}" -cd in8.lz.lz | cmp in8.lz - || test_failed $LINENO @@ -219,12 +238,37 @@ rm -f in8.lz in8.lz.lz printf "\ntesting bad input..." +headers='LZIp LZiP LZip LzIP LzIp LziP lZIP lZIp lZiP lzIP' +body='\001\014\000\203\377\373\377\377\300\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000$\000\000\000\000\000\000\000' +cat "${in_lz}" > in0.lz +printf "LZIP${body}" >> in0.lz +if "${LZIP}" -tq in0.lz ; then + for header in ${headers} ; do + printf "${header}${body}" > in0.lz # first member + "${LZIP}" -tq in0.lz + [ $? = 2 ] || test_failed $LINENO ${header} + "${LZIP}" -tq --loose-trailing in0.lz + [ $? = 2 ] || test_failed $LINENO ${header} + cat "${in_lz}" > in0.lz + printf "${header}${body}" >> in0.lz # trailing data + "${LZIP}" -tq in0.lz + [ $? = 2 ] || test_failed $LINENO ${header} + "${LZIP}" -t --loose-trailing in0.lz + [ $? = 0 ] || test_failed $LINENO ${header} + "${LZIP}" -tq --loose-trailing --trailing-error in0.lz + [ $? = 2 ] || test_failed $LINENO ${header} + done +else + printf "\nwarning: skipping header test: 'printf' does not work on your system." +fi +rm -f in0.lz + cat "${in_lz}" "${in_lz}" "${in_lz}" > in3.lz || framework_failure if dd if=in3.lz of=trunc.lz bs=14752 count=1 2> /dev/null && [ -e trunc.lz ] && cmp in2.lz trunc.lz > /dev/null 2>&1 ; then for i in 6 20 14734 14753 14754 14755 14756 14757 14758 ; do dd if=in3.lz of=trunc.lz bs=$i count=1 2> /dev/null - "${LZIP}" -t trunc.lz 2> /dev/null + "${LZIP}" -tq trunc.lz [ $? = 2 ] || test_failed $LINENO $i "${LZIP}" -tq < trunc.lz [ $? = 2 ] || test_failed $LINENO $i @@ -236,6 +280,7 @@ if dd if=in3.lz of=trunc.lz bs=14752 count=1 2> /dev/null && else printf "\nwarning: skipping truncation test: 'dd' does not work on your system." fi +rm -f in3.lz trunc.lz cat "${in_lz}" > ingin.lz || framework_failure printf "g" >> ingin.lz || framework_failure @@ -246,6 +291,7 @@ cmp in copy || test_failed $LINENO "${LZIP}" -t < ingin.lz || test_failed $LINENO "${LZIP}" -d < ingin.lz > copy || test_failed $LINENO cmp in copy || test_failed $LINENO +rm -f ingin.lz echo if [ ${fail} = 0 ] ; then From 34f7af7bd16dab6b346983b334abe35f95880fdf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 20 Feb 2025 21:27:58 +0100 Subject: [PATCH 03/10] Adding upstream version 1.11. Signed-off-by: Daniel Baumann --- ChangeLog | 18 ++++- INSTALL | 22 ++++-- Makefile.in | 37 ++++++----- NEWS | 44 ++++++------ README | 30 ++++++--- bbexample.c | 10 +-- carg_parser.c | 2 +- carg_parser.h | 2 +- cbuffer.c | 18 +++-- configure | 20 +++--- decoder.c | 137 +++++++++++++++++++------------------- decoder.h | 18 ++--- doc/lzlib.info | 162 +++++++++++++++++++++++++-------------------- doc/lzlib.texi | 120 ++++++++++++++++++++------------- doc/minilzip.1 | 11 +-- encoder.c | 4 +- encoder.h | 2 +- encoder_base.c | 20 +++--- encoder_base.h | 10 +-- fast_encoder.c | 2 +- fast_encoder.h | 6 +- lzcheck.c | 4 +- lzip.h | 57 ++++++++-------- lzlib.c | 58 ++++++++-------- lzlib.h | 4 +- main.c | 108 ++++++++++++++++++------------ testsuite/check.sh | 130 +++++++++++++++++++++++------------- 27 files changed, 614 insertions(+), 442 deletions(-) diff --git a/ChangeLog b/ChangeLog index c13bf2e..7402b7a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2019-01-02 Antonio Diaz Diaz + + * Version 1.11 released. + * File_* renamed to Lzip_*. + * LZ_decompress_read: Don't return error until all data is read. + * decoder.c (LZd_decode_member): Decode truncated data until EOF. + * main.c: Don't allow mixing different operations (-d and -t). + * main.c: Check return value of close( infd ). + * main.c: Compile on DOS with DJGPP. + * lzlib.texi: Improved descriptions of '-0..-9', '-m' and '-s'. + Document that 'LZ_(de)compress_finish' can be called repeatedly. + * configure: Accept appending to CFLAGS, 'CFLAGS+=OPTIONS'. + * Makefile.in: Targets 'install-bin*' renamed to 'install-lib*'. + * Makefile.in: Targets 'install-bin*' now install minilzip. + * INSTALL: Document use of CFLAGS+='-D __USE_MINGW_ANSI_STDIO'. + 2018-02-07 Antonio Diaz Diaz * Version 1.10 released. @@ -188,7 +204,7 @@ * Version 0.1 released. -Copyright (C) 2009-2018 Antonio Diaz Diaz. +Copyright (C) 2009-2019 Antonio Diaz Diaz. This file is a collection of facts, and thus it is not copyrightable, but just in case, you have unlimited permission to copy, distribute and diff --git a/INSTALL b/INSTALL index 735d666..b5889df 100644 --- a/INSTALL +++ b/INSTALL @@ -1,10 +1,14 @@ Requirements ------------ You will need a C compiler. -I use gcc 5.3.0 and 4.1.2, but the code should compile with any -standards compliant compiler. +I use gcc 5.3.0 and 4.1.2, but the code should compile with any standards +compliant compiler. Gcc is available at http://gcc.gnu.org. +The operating system must allow signal handlers read access to objects with +static storage duration so that the cleanup handler for Control-C can delete +the partial output file. + Procedure --------- @@ -23,6 +27,10 @@ the main archive. cd lzlib[version] ./configure + If you are compiling on MinGW, use: + + ./configure CFLAGS+='-D __USE_MINGW_ANSI_STDIO' + 3. Run make. make @@ -37,11 +45,13 @@ the main archive. become the default in the future). You can install only the library, the info manual or the man page by - typing 'make install-bin', 'make install-info' or 'make install-man' + typing 'make install-lib', 'make install-info' or 'make install-man' respectively. - Instead of 'make install', you can type 'make install-as-lzip' to - install the library and any data files and documentation, and link + 'make install-bin' installs the minilzip program and its man page. + 'install-bin' installs a shared minilzip if the shared library has + been configured. Else it installs a static minilzip. + 'make install-as-lzip' runs 'make install-bin' and then links minilzip to the name 'lzip'. @@ -62,7 +72,7 @@ After running 'configure', you can run 'make' and 'make install' as explained above. -Copyright (C) 2009-2018 Antonio Diaz Diaz. +Copyright (C) 2009-2019 Antonio Diaz Diaz. This file is free documentation: you have unlimited permission to copy, distribute and modify it. diff --git a/Makefile.in b/Makefile.in index c493f5e..1ac03b2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -15,7 +15,7 @@ objs = carg_parser.o main.o .PHONY : all install install-bin install-info install-man \ install-strip install-compress install-strip-compress \ install-bin-strip install-info-compress install-man-compress \ - install-as-lzip \ + install-lib install-lib-strip uninstall-lib install-as-lzip \ uninstall uninstall-bin uninstall-info uninstall-man \ doc info man check dist clean distclean @@ -78,12 +78,19 @@ Makefile : $(VPATH)/configure $(VPATH)/Makefile.in check : $(progname) bbexample lzcheck @$(VPATH)/testsuite/check.sh $(VPATH)/testsuite $(pkgversion) -install : install-bin install-info -install-strip : install-bin-strip install-info -install-compress : install-bin install-info-compress -install-strip-compress : install-bin-strip install-info-compress +install : install-lib install-info +install-strip : install-lib-strip install-info +install-compress : install-lib install-info-compress +install-strip-compress : install-lib-strip install-info-compress -install-bin : all +install-bin : all install-man + if [ ! -d "$(DESTDIR)$(bindir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(bindir)" ; fi + $(INSTALL_PROGRAM) ./$(progname_lzip) "$(DESTDIR)$(bindir)/$(progname)" + +install-bin-strip : all + $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-bin + +install-lib : all if [ ! -d "$(DESTDIR)$(includedir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(includedir)" ; fi if [ ! -d "$(DESTDIR)$(libdir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(libdir)" ; fi $(INSTALL_DATA) $(VPATH)/$(libname)lib.h "$(DESTDIR)$(includedir)/$(libname)lib.h" @@ -104,8 +111,8 @@ install-bin : all [ -x "$(LDCONFIG)" ] ; then "$(LDCONFIG)" -n "$(DESTDIR)$(libdir)" || true ; fi ; \ fi -install-bin-strip : all - $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-bin +install-lib-strip : all + $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-lib install-info : if [ ! -d "$(DESTDIR)$(infodir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(infodir)" ; fi @@ -126,16 +133,16 @@ install-man : install-man-compress : install-man lzip -v -9 "$(DESTDIR)$(mandir)/man1/$(progname).1" -install-as-lzip : install install-man - if [ ! -d "$(DESTDIR)$(bindir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(bindir)" ; fi - $(INSTALL_PROGRAM) ./$(progname_lzip) "$(DESTDIR)$(bindir)/$(progname)" +install-as-lzip : install-bin -rm -f "$(DESTDIR)$(bindir)/lzip" cd "$(DESTDIR)$(bindir)" && ln -s $(progname) lzip -uninstall : uninstall-man uninstall-info uninstall-bin +uninstall : uninstall-info uninstall-lib -uninstall-bin : +uninstall-bin : uninstall-man -rm -f "$(DESTDIR)$(bindir)/$(progname)" + +uninstall-lib : -rm -f "$(DESTDIR)$(includedir)/$(libname)lib.h" -rm -f "$(DESTDIR)$(libdir)/lib$(libname).a" -rm -f "$(DESTDIR)$(libdir)/lib$(libname).so" @@ -171,8 +178,8 @@ dist : doc $(DISTNAME)/testsuite/check.sh \ $(DISTNAME)/testsuite/test.txt \ $(DISTNAME)/testsuite/test2.txt \ - $(DISTNAME)/testsuite/test.txt.lz \ - $(DISTNAME)/testsuite/test_sync.lz + $(DISTNAME)/testsuite/test_sync.lz \ + $(DISTNAME)/testsuite/test.txt.lz rm -f $(DISTNAME) lzip -v -9 $(DISTNAME).tar diff --git a/NEWS b/NEWS index c610506..bdf7f32 100644 --- a/NEWS +++ b/NEWS @@ -1,32 +1,30 @@ -Changes in version 1.10: +Changes in version 1.11: -The function 'LZ_compress_finish' now adjusts the dictionary size for -each member. +In case of decompression error caused by corrupt or truncated data, +LZ_decompress_read now does not signal the error immediately to the +application, but waits until all decoded bytes have been read. This +allows tools like tarlz to recover as much data as possible from damaged +members. -The option '--loose-trailing', has been added to minilzip. +It is now an error to specify two different operations to minilzip in +the command line (--decompress and --test). -The test used by lzlib to discriminate trailing data from a corrupt -header in multimember or concatenated files has been improved to a -Hamming distance (HD) of 3, and the 3 bit flips must happen in different -magic bytes for the test to fail. As a consequence, lzlib now returns a -data error when some kinds of files are appended to a lzip file as -trailing data. -The '--loose-trailing' option of minilzip can be used to ignore such -trailing data when decompressing. -Lziprecover can be used to remove conflicting trailing data from a file. +Minilzip now also checks for errors when closing the input file. -Option '-S, --volume-size' of minilzip now keeps input files unchanged. +Minilzip now compiles on DOS with DJGPP. (Patch from Robert Riebisch). -The 'bits/byte' ratio has been replaced with the inverse compression -ratio in the output of minilzip. +The descriptions of '-0..-9', '-m' and '-s' in the manual have been +improved. -minilzip now shows a final diagnostic at verbosity level 1 (-v) or -higher if any file fails the test when testing multiple files. +It has been documented that it is safe to call 'LZ_(de)compress_finish' +as many times as needed. Examples in the manual have been simplified. -minilzip no longer adds a second '.lz' extension to the argument of '-o' -if it already ends in '.lz' or '.tlz'. +The configure script now accepts appending options to CFLAGS using the +syntax 'CFLAGS+=OPTIONS'. -minilzip now shows the dictionary size at verbosity level 4 (-vvvv) when -decompressing or testing. +Makefile targets 'install-bin*' have been renamed to 'install-lib*'. New +'install-bin*' targets have been created that install a shared minilzip, +or a static minilzip if the shared library has not been configured. -The new chapter 'Invoking minilzip' has been added to the manual. +It has been documented in INSTALL the use of +CFLAGS+='-D __USE_MINGW_ANSI_STDIO' when compiling on MinGW. diff --git a/README b/README index 6a9c6f2..fa1da74 100644 --- a/README +++ b/README @@ -5,22 +5,21 @@ and decompression functions, including integrity checking of the decompressed data. The compressed data format used by the library is the lzip format. Lzlib is written in C. -The lzip file format is designed for data sharing and long-term -archiving, taking into account both data integrity and decoder -availability: +The lzip file format is designed for data sharing and long-term archiving, +taking into account both data integrity and decoder availability: * The lzip format provides very safe integrity checking and some data - recovery means. The lziprecover program can repair bit-flip errors + recovery means. The lziprecover program can repair bit flip errors (one of the most common forms of data corruption) in lzip files, and provides data recovery capabilities, including error-checked merging of damaged copies of a file. * The lzip format is as simple as possible (but not simpler). The - lzip manual provides the source code of a simple decompressor along - with a detailed explanation of how it works, so that with the only - help of the lzip manual it would be possible for a digital - archaeologist to extract the data from a lzip file long after - quantum computers eventually render LZMA obsolete. + lzip manual provides the source code of a simple decompressor + along with a detailed explanation of how it works, so that with + the only help of the lzip manual it would be possible for a + digital archaeologist to extract the data from a lzip file long + after quantum computers eventually render LZMA obsolete. * Additionally the lzip reference implementation is copylefted, which guarantees that it will remain free forever. @@ -48,7 +47,8 @@ size equal to 0. If all the data to be compressed are written in advance, lzlib will automatically adjust the header of the compressed data to use the -smallest possible dictionary size. This feature reduces the amount of +largest dictionary size that does not exceed neither the data size nor +the limit given to LZ_compress_open. This feature reduces the amount of memory needed for decompression and allows minilzip to produce identical compressed output as lzip. @@ -57,6 +57,10 @@ of two or more compressed data streams. The result is the concatenation of the corresponding decompressed data streams. Integrity testing of concatenated compressed data streams is also supported. +Lzlib is able to compress and decompress streams of unlimited size by +automatically creating multimember output. The members so created are +large, about 2 PiB each. + All the library functions are thread safe. The library does not install any signal handler. The decoder checks the consistency of the compressed data, so the library should never crash even in case of corrupted input. @@ -86,8 +90,12 @@ the definition of Markov chains), G.N.N. Martin (for the definition of range encoding), Igor Pavlov (for putting all the above together in LZMA), and Julian Seward (for bzip2's CLI). +LANGUAGE NOTE: Uncompressed = not compressed = plain data; it may never +have been compressed. Decompressed is used to refer to data which have +undergone the process of decompression. -Copyright (C) 2009-2018 Antonio Diaz Diaz. + +Copyright (C) 2009-2019 Antonio Diaz Diaz. This file is free documentation: you have unlimited permission to copy, distribute and modify it. diff --git a/bbexample.c b/bbexample.c index 8c2ff04..e953c35 100644 --- a/bbexample.c +++ b/bbexample.c @@ -1,5 +1,5 @@ /* Buffer to buffer example - Test program for the lzlib library - Copyright (C) 2010-2018 Antonio Diaz Diaz. + Copyright (C) 2010-2019 Antonio Diaz Diaz. This program is free software: you have unlimited permission to copy, distribute and modify it. @@ -26,10 +26,10 @@ /* Returns the address of a malloc'd buffer containing the file data and - its size in '*size'. - In case of error, returns 0 and does not modify '*size'. + the file size in '*file_sizep'. + In case of error, returns 0 and does not modify '*file_sizep'. */ -uint8_t * read_file( const char * const name, long * const size ) +uint8_t * read_file( const char * const name, long * const file_sizep ) { long buffer_size = 1 << 20, file_size; uint8_t * buffer, * tmp; @@ -67,7 +67,7 @@ uint8_t * read_file( const char * const name, long * const size ) free( buffer ); return 0; } fclose( f ); - *size = file_size; + *file_sizep = file_size; return buffer; } diff --git a/carg_parser.c b/carg_parser.c index 10ad4dc..ce01d7b 100644 --- a/carg_parser.c +++ b/carg_parser.c @@ -1,5 +1,5 @@ /* Arg_parser - POSIX/GNU command line argument parser. (C version) - Copyright (C) 2006-2018 Antonio Diaz Diaz. + Copyright (C) 2006-2019 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/carg_parser.h b/carg_parser.h index e1c70dd..dcae2de 100644 --- a/carg_parser.h +++ b/carg_parser.h @@ -1,5 +1,5 @@ /* Arg_parser - POSIX/GNU command line argument parser. (C version) - Copyright (C) 2006-2018 Antonio Diaz Diaz. + Copyright (C) 2006-2019 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/cbuffer.c b/cbuffer.c index 5e7ab93..6b70be4 100644 --- a/cbuffer.c +++ b/cbuffer.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2018 Antonio Diaz Diaz. + Copyright (C) 2009-2019 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -25,9 +25,6 @@ struct Circular_buffer unsigned put; }; -static inline void Cb_reset( struct Circular_buffer * const cb ) - { cb->get = 0; cb->put = 0; } - static inline bool Cb_init( struct Circular_buffer * const cb, const unsigned buf_size ) { @@ -42,6 +39,12 @@ static inline bool Cb_init( struct Circular_buffer * const cb, static inline void Cb_free( struct Circular_buffer * const cb ) { free( cb->buffer ); cb->buffer = 0; } +static inline void Cb_reset( struct Circular_buffer * const cb ) + { cb->get = 0; cb->put = 0; } + +static inline unsigned Cb_empty( const struct Circular_buffer * const cb ) + { return cb->get == cb->put; } + static inline unsigned Cb_used_bytes( const struct Circular_buffer * const cb ) { return ( (cb->get <= cb->put) ? 0 : cb->buffer_size ) + cb->put - cb->get; } @@ -74,7 +77,8 @@ static bool Cb_unread_data( struct Circular_buffer * const cb, /* Copies up to 'out_size' bytes to 'out_buffer' and updates 'get'. - Returns the number of bytes copied. + If 'out_buffer' is null, the bytes are discarded. + Returns the number of bytes copied or discarded. */ static unsigned Cb_read_data( struct Circular_buffer * const cb, uint8_t * const out_buffer, @@ -87,7 +91,7 @@ static unsigned Cb_read_data( struct Circular_buffer * const cb, size = min( cb->buffer_size - cb->get, out_size ); if( size > 0 ) { - memcpy( out_buffer, cb->buffer + cb->get, size ); + if( out_buffer ) memcpy( out_buffer, cb->buffer + cb->get, size ); cb->get += size; if( cb->get >= cb->buffer_size ) cb->get = 0; } @@ -97,7 +101,7 @@ static unsigned Cb_read_data( struct Circular_buffer * const cb, const unsigned size2 = min( cb->put - cb->get, out_size - size ); if( size2 > 0 ) { - memcpy( out_buffer + size, cb->buffer + cb->get, size2 ); + if( out_buffer ) memcpy( out_buffer + size, cb->buffer + cb->get, size2 ); cb->get += size2; size += size2; } diff --git a/configure b/configure index 5b0c54b..60ea883 100755 --- a/configure +++ b/configure @@ -1,12 +1,12 @@ #! /bin/sh # configure script for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2018 Antonio Diaz Diaz. +# Copyright (C) 2009-2019 Antonio Diaz Diaz. # # This configure script is free software: you have unlimited permission # to copy, distribute and modify it. pkgname=lzlib -pkgversion=1.10 +pkgversion=1.11 soversion=1 progname=minilzip progname_static=${progname} @@ -84,6 +84,7 @@ while [ $# != 0 ] ; do echo " CC=COMPILER C compiler to use [${CC}]" echo " CPPFLAGS=OPTIONS command line options for the preprocessor [${CPPFLAGS}]" echo " CFLAGS=OPTIONS command line options for the C compiler [${CFLAGS}]" + echo " CFLAGS+=OPTIONS append options to the current value of CFLAGS" echo " LDFLAGS=OPTIONS command line options for the linker [${LDFLAGS}]" echo exit 0 ;; @@ -114,13 +115,16 @@ while [ $# != 0 ] ; do progname_static= progname_shared=${progname}_shared progname_lzip=${progname}_shared ;; - --enable-shared) progname_shared=${progname}_shared ;; + --enable-shared) + progname_shared=${progname}_shared + progname_lzip=${progname}_shared ;; --disable-ldconfig) disable_ldconfig=yes ;; - CC=*) CC=${optarg} ;; - CPPFLAGS=*) CPPFLAGS=${optarg} ;; - CFLAGS=*) CFLAGS=${optarg} ;; - LDFLAGS=*) LDFLAGS=${optarg} ;; + CC=*) CC=${optarg} ;; + CPPFLAGS=*) CPPFLAGS=${optarg} ;; + CFLAGS=*) CFLAGS=${optarg} ;; + CFLAGS+=*) CFLAGS="${CFLAGS} ${optarg}" ;; + LDFLAGS=*) LDFLAGS=${optarg} ;; --*) echo "configure: WARNING: unrecognized option: '${option}'" 1>&2 ;; @@ -194,7 +198,7 @@ echo "LDFLAGS = ${LDFLAGS}" rm -f Makefile cat > Makefile << EOF # Makefile for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2018 Antonio Diaz Diaz. +# Copyright (C) 2009-2019 Antonio Diaz Diaz. # This file was generated automatically by configure. Don't edit. # # This Makefile is free software: you have unlimited permission diff --git a/decoder.c b/decoder.c index d659853..3dc62cc 100644 --- a/decoder.c +++ b/decoder.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2018 Antonio Diaz Diaz. + Copyright (C) 2009-2019 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -19,16 +19,16 @@ static int LZd_try_verify_trailer( struct LZ_decoder * const d ) { - File_trailer trailer; - if( Rd_available_bytes( d->rdec ) < Ft_size && !d->rdec->at_stream_end ) + Lzip_trailer trailer; + if( Rd_available_bytes( d->rdec ) < Lt_size && !d->rdec->at_stream_end ) return 0; d->verify_trailer_pending = false; d->member_finished = true; - if( Rd_read_data( d->rdec, trailer, Ft_size ) == Ft_size && - Ft_get_data_crc( trailer ) == LZd_crc( d ) && - Ft_get_data_size( trailer ) == LZd_data_position( d ) && - Ft_get_member_size( trailer ) == d->rdec->member_position ) return 0; + if( Rd_read_data( d->rdec, trailer, Lt_size ) == Lt_size && + Lt_get_data_crc( trailer ) == LZd_crc( d ) && + Lt_get_data_size( trailer ) == LZd_data_position( d ) && + Lt_get_member_size( trailer ) == d->rdec->member_position ) return 0; return 3; } @@ -49,15 +49,18 @@ static int LZd_decode_member( struct LZ_decoder * const d ) while( !Rd_finished( rdec ) ) { + int len; const int pos_state = LZd_data_position( d ) & pos_state_mask; /* const unsigned mpos = d->rdec->member_position; if( mpos - old_mpos > rd_min_available_bytes ) return 5; old_mpos = mpos; */ - if( !Rd_enough_available_bytes( rdec ) ) /* check unexpected eof */ - { if( !rdec->at_stream_end ) return 0; else break; } + if( !Rd_enough_available_bytes( rdec ) ) /* check unexpected EOF */ + { if( !rdec->at_stream_end ) return 0; + if( Cb_empty( &rdec->cb ) ) break; } /* decode until EOF */ if( !LZd_enough_free_bytes( d ) ) return 0; - if( Rd_decode_bit( rdec, &d->bm_match[*state][pos_state] ) == 0 ) /* 1st bit */ + if( Rd_decode_bit( rdec, &d->bm_match[*state][pos_state] ) == 0 ) /* 1st bit */ { + /* literal byte */ Bit_model * const bm = d->bm_literal[get_lit_state(LZd_peek_prev( d ))]; if( St_is_char( *state ) ) { @@ -69,79 +72,77 @@ static int LZd_decode_member( struct LZ_decoder * const d ) *state -= ( *state < 10 ) ? 3 : 6; LZd_put_byte( d, Rd_decode_matched( rdec, bm, LZd_peek( d, d->rep0 ) ) ); } + continue; } - else /* match or repeated match */ + /* match or repeated match */ + if( Rd_decode_bit( rdec, &d->bm_rep[*state] ) != 0 ) /* 2nd bit */ { - int len; - if( Rd_decode_bit( rdec, &d->bm_rep[*state] ) != 0 ) /* 2nd bit */ + if( Rd_decode_bit( rdec, &d->bm_rep0[*state] ) == 0 ) /* 3rd bit */ { - if( Rd_decode_bit( rdec, &d->bm_rep0[*state] ) == 0 ) /* 3rd bit */ - { - if( Rd_decode_bit( rdec, &d->bm_len[*state][pos_state] ) == 0 ) /* 4th bit */ - { *state = St_set_short_rep( *state ); - LZd_put_byte( d, LZd_peek( d, d->rep0 ) ); continue; } - } - else - { - unsigned distance; - if( Rd_decode_bit( rdec, &d->bm_rep1[*state] ) == 0 ) /* 4th bit */ - distance = d->rep1; - else - { - if( Rd_decode_bit( rdec, &d->bm_rep2[*state] ) == 0 ) /* 5th bit */ - distance = d->rep2; - else - { distance = d->rep3; d->rep3 = d->rep2; } - d->rep2 = d->rep1; - } - d->rep1 = d->rep0; - d->rep0 = distance; - } - *state = St_set_rep( *state ); - len = min_match_len + Rd_decode_len( rdec, &d->rep_len_model, pos_state ); + if( Rd_decode_bit( rdec, &d->bm_len[*state][pos_state] ) == 0 ) /* 4th bit */ + { *state = St_set_short_rep( *state ); + LZd_put_byte( d, LZd_peek( d, d->rep0 ) ); continue; } } - else /* match */ + else { unsigned distance; - len = min_match_len + Rd_decode_len( rdec, &d->match_len_model, pos_state ); - distance = Rd_decode_tree6( rdec, d->bm_dis_slot[get_len_state(len)] ); - if( distance >= start_dis_model ) + if( Rd_decode_bit( rdec, &d->bm_rep1[*state] ) == 0 ) /* 4th bit */ + distance = d->rep1; + else { - const unsigned dis_slot = distance; - const int direct_bits = ( dis_slot >> 1 ) - 1; - distance = ( 2 | ( dis_slot & 1 ) ) << direct_bits; - if( dis_slot < end_dis_model ) - distance += Rd_decode_tree_reversed( rdec, - d->bm_dis + ( distance - dis_slot ), direct_bits ); + if( Rd_decode_bit( rdec, &d->bm_rep2[*state] ) == 0 ) /* 5th bit */ + distance = d->rep2; else + { distance = d->rep3; d->rep3 = d->rep2; } + d->rep2 = d->rep1; + } + d->rep1 = d->rep0; + d->rep0 = distance; + } + *state = St_set_rep( *state ); + len = min_match_len + Rd_decode_len( rdec, &d->rep_len_model, pos_state ); + } + else /* match */ + { + unsigned distance; + len = min_match_len + Rd_decode_len( rdec, &d->match_len_model, pos_state ); + distance = Rd_decode_tree6( rdec, d->bm_dis_slot[get_len_state(len)] ); + if( distance >= start_dis_model ) + { + const unsigned dis_slot = distance; + const int direct_bits = ( dis_slot >> 1 ) - 1; + distance = ( 2 | ( dis_slot & 1 ) ) << direct_bits; + if( dis_slot < end_dis_model ) + distance += Rd_decode_tree_reversed( rdec, + d->bm_dis + ( distance - dis_slot ), direct_bits ); + else + { + distance += + Rd_decode( rdec, direct_bits - dis_align_bits ) << dis_align_bits; + distance += Rd_decode_tree_reversed4( rdec, d->bm_align ); + if( distance == 0xFFFFFFFFU ) /* marker found */ { - distance += - Rd_decode( rdec, direct_bits - dis_align_bits ) << dis_align_bits; - distance += Rd_decode_tree_reversed4( rdec, d->bm_align ); - if( distance == 0xFFFFFFFFU ) /* marker found */ + Rd_normalize( rdec ); + if( len == min_match_len ) /* End Of Stream marker */ { - Rd_normalize( rdec ); - if( len == min_match_len ) /* End Of Stream marker */ - { - d->verify_trailer_pending = true; - return LZd_try_verify_trailer( d ); - } - if( len == min_match_len + 1 ) /* Sync Flush marker */ - { - if( Rd_try_reload( rdec, true ) ) { /*old_mpos += 5;*/ continue; } - else { if( !rdec->at_stream_end ) return 0; else break; } - } - return 4; + d->verify_trailer_pending = true; + return LZd_try_verify_trailer( d ); } + if( len == min_match_len + 1 ) /* Sync Flush marker */ + { + if( Rd_try_reload( rdec, true ) ) { /*old_mpos += 5;*/ continue; } + else { if( !rdec->at_stream_end ) return 0; else break; } + } + return 4; } } - d->rep3 = d->rep2; d->rep2 = d->rep1; d->rep1 = d->rep0; d->rep0 = distance; - *state = St_set_match( *state ); - if( d->rep0 >= d->dictionary_size || - ( d->rep0 >= d->cb.put && !d->pos_wrapped ) ) return 1; } - LZd_copy_block( d, d->rep0, len ); + d->rep3 = d->rep2; d->rep2 = d->rep1; d->rep1 = d->rep0; d->rep0 = distance; + *state = St_set_match( *state ); + if( d->rep0 >= d->dictionary_size || + ( d->rep0 >= d->cb.put && !d->pos_wrapped ) ) return 1; } + LZd_copy_block( d, d->rep0, len ); } return 2; } diff --git a/decoder.h b/decoder.h index 090bf3a..1873d5e 100644 --- a/decoder.h +++ b/decoder.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2018 Antonio Diaz Diaz. + Copyright (C) 2009-2019 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -44,7 +44,7 @@ static inline void Rd_free( struct Range_decoder * const rdec ) { Cb_free( &rdec->cb ); } static inline bool Rd_finished( const struct Range_decoder * const rdec ) - { return rdec->at_stream_end && !Cb_used_bytes( &rdec->cb ); } + { return rdec->at_stream_end && Cb_empty( &rdec->cb ); } static inline void Rd_finish( struct Range_decoder * const rdec ) { rdec->at_stream_end = true; } @@ -56,7 +56,7 @@ static inline unsigned Rd_available_bytes( const struct Range_decoder * const rd { return Cb_used_bytes( &rdec->cb ); } static inline unsigned Rd_free_bytes( const struct Range_decoder * const rdec ) - { if( rdec->at_stream_end ) return 0; return Cb_free_bytes( &rdec->cb ); } + { return rdec->at_stream_end ? 0 : Cb_free_bytes( &rdec->cb ); } static inline unsigned long long Rd_purge( struct Range_decoder * const rdec ) { @@ -81,18 +81,18 @@ static bool Rd_find_header( struct Range_decoder * const rdec, *skippedp = 0; while( rdec->cb.get != rdec->cb.put ) { - if( rdec->cb.buffer[rdec->cb.get] == magic_string[0] ) + if( rdec->cb.buffer[rdec->cb.get] == lzip_magic[0] ) { unsigned get = rdec->cb.get; int i; - File_header header; - for( i = 0; i < Fh_size; ++i ) + Lzip_header header; + for( i = 0; i < Lh_size; ++i ) { if( get == rdec->cb.put ) return false; /* not enough data */ header[i] = rdec->cb.buffer[get]; if( ++get >= rdec->cb.buffer_size ) get = 0; } - if( Fh_verify( header ) ) return true; + if( Lh_verify( header ) ) return true; } if( ++rdec->cb.get >= rdec->cb.buffer_size ) rdec->cb.get = 0; ++*skippedp; @@ -110,6 +110,8 @@ static inline int Rd_write_data( struct Range_decoder * const rdec, static inline uint8_t Rd_get_byte( struct Range_decoder * const rdec ) { + /* 0xFF avoids decoder error if member is truncated at EOS marker */ + if( Rd_finished( rdec ) ) return 0xFF; ++rdec->member_position; return Cb_get_byte( &rdec->cb ); } @@ -410,7 +412,7 @@ static inline void LZd_free( struct LZ_decoder * const d ) { Cb_free( &d->cb ); } static inline bool LZd_member_finished( const struct LZ_decoder * const d ) - { return ( d->member_finished && !Cb_used_bytes( &d->cb ) ); } + { return ( d->member_finished && Cb_empty( &d->cb ) ); } static inline unsigned LZd_crc( const struct LZ_decoder * const d ) { return d->crc ^ 0xFFFFFFFFU; } diff --git a/doc/lzlib.info b/doc/lzlib.info index 23a4d21..5a1a573 100644 --- a/doc/lzlib.info +++ b/doc/lzlib.info @@ -11,7 +11,7 @@ File: lzlib.info, Node: Top, Next: Introduction, Up: (dir) Lzlib Manual ************ -This manual is for Lzlib (version 1.10, 7 February 2018). +This manual is for Lzlib (version 1.11, 2 January 2019). * Menu: @@ -30,7 +30,7 @@ This manual is for Lzlib (version 1.10, 7 February 2018). * Concept index:: Index of concepts - Copyright (C) 2009-2018 Antonio Diaz Diaz. + Copyright (C) 2009-2019 Antonio Diaz Diaz. This manual is free documentation: you have unlimited permission to copy, distribute and modify it. @@ -41,10 +41,10 @@ File: lzlib.info, Node: Introduction, Next: Library version, Prev: Top, Up: 1 Introduction ************** -Lzlib is a data compression library providing in-memory LZMA compression -and decompression functions, including integrity checking of the -decompressed data. The compressed data format used by the library is the -lzip format. Lzlib is written in C. +Lzlib is a data compression library providing in-memory LZMA +compression and decompression functions, including integrity checking +of the decompressed data. The compressed data format used by the +library is the lzip format. Lzlib is written in C. The lzip file format is designed for data sharing and long-term archiving, taking into account both data integrity and decoder @@ -90,15 +90,20 @@ with a SIZE equal to 0. If all the data to be compressed are written in advance, lzlib will automatically adjust the header of the compressed data to use the -smallest possible dictionary size. This feature reduces the amount of -memory needed for decompression and allows minilzip to produce identical -compressed output as lzip. +largest dictionary size that does not exceed neither the data size nor +the limit given to 'LZ_compress_open'. This feature reduces the amount +of memory needed for decompression and allows minilzip to produce +identical compressed output as lzip. Lzlib will correctly decompress a data stream which is the concatenation of two or more compressed data streams. The result is the concatenation of the corresponding decompressed data streams. Integrity testing of concatenated compressed data streams is also supported. + Lzlib is able to compress and decompress streams of unlimited size by +automatically creating multimember output. The members so created are +large, about 2 PiB each. + All the library functions are thread safe. The library does not install any signal handler. The decoder checks the consistency of the compressed data, so the library should never crash even in case of @@ -253,11 +258,13 @@ calling 'LZ_compress_errno' before using it. output as 'lzip -0'. (The dictionary size used will be rounded upwards to 64 KiB). - MEMBER_SIZE sets the member size limit in bytes. Minimum member - size limit is 100 kB. Small member size may degrade compression - ratio, so use it only when needed. To produce a single-member data - stream, give MEMBER_SIZE a value larger than the amount of data to - be produced, for example INT64_MAX. + MEMBER_SIZE sets the member size limit in bytes. Valid values + range from 100 kB to 2 PiB. Small member size may degrade + compression ratio, so use it only when needed. To produce a + single-member data stream, give MEMBER_SIZE a value larger than + the amount of data to be produced. Values larger than 2 PiB will be + reduced to 2 PiB to prevent the uncompressed size of the member + from overflowing. -- Function: int LZ_compress_close ( struct LZ_Encoder * const ENCODER ) @@ -270,6 +277,7 @@ calling 'LZ_compress_errno' before using it. ENCODER ) Use this function to tell 'lzlib' that all the data for this member have already been written (with the 'LZ_compress_write' function). + It is safe to call 'LZ_compress_finish' as many times as needed. After all the produced compressed data have been read with 'LZ_compress_read' and 'LZ_compress_member_finished' returns 1, a new member can be started with 'LZ_compress_restart_member'. @@ -322,7 +330,7 @@ calling 'LZ_compress_errno' before using it. -- Function: enum LZ_Errno LZ_compress_errno ( struct LZ_Encoder * const ENCODER ) - Returns the current error code for ENCODER (*note Error codes::). + Returns the current error code for ENCODER. *Note Error codes::. -- Function: int LZ_compress_finished ( struct LZ_Encoder * const ENCODER ) @@ -388,7 +396,8 @@ verified by calling 'LZ_decompress_errno' before using it. DECODER ) Use this function to tell 'lzlib' that all the data for this stream have already been written (with the 'LZ_decompress_write' - function). + function). It is safe to call 'LZ_decompress_finish' as many + times as needed. -- Function: int LZ_decompress_reset ( struct LZ_Decoder * const DECODER ) @@ -420,6 +429,12 @@ verified by calling 'LZ_decompress_errno' before using it. 'LZ_decompress_write' function. Note that reading less than SIZE bytes is not an error. + In case of decompression error caused by corrupt or truncated data, + 'LZ_decompress_read' does not signal the error immediately to the + application, but waits until all decoded bytes have been read. This + allows tools like tarlz to recover as much data as possible from + each damaged member. *Note tarlz manual: (tarlz)Top. + -- Function: int LZ_decompress_write ( struct LZ_Decoder * const DECODER, uint8_t * const BUFFER, const int SIZE ) The 'LZ_decompress_write' function writes up to SIZE bytes from @@ -440,7 +455,7 @@ verified by calling 'LZ_decompress_errno' before using it. -- Function: enum LZ_Errno LZ_decompress_errno ( struct LZ_Decoder * const DECODER ) - Returns the current error code for DECODER (*note Error codes::). + Returns the current error code for DECODER. *Note Error codes::. -- Function: int LZ_decompress_finished ( struct LZ_Decoder * const DECODER ) @@ -543,8 +558,8 @@ whether a call failed. If the call failed, then you can examine file. -- Constant: enum LZ_Errno LZ_library_error - A bug was detected in the library. Please, report it (*note - Problems::). + A bug was detected in the library. Please, report it. *Note + Problems::.  File: lzlib.info, Node: Error messages, Next: Invoking minilzip, Prev: Error codes, Up: Top @@ -568,6 +583,9 @@ File: lzlib.info, Node: Invoking minilzip, Next: Data format, Prev: Error mes 9 Invoking minilzip ******************* +Minilzip is a test program for the lzlib compression library, fully +compatible with lzip 1.4 or newer. + The format for running minilzip is: minilzip [OPTIONS] [FILES] @@ -585,7 +603,7 @@ command line. '-V' '--version' Print the version number of minilzip on the standard output and - exit. + exit. This version number should be included in all bug reports. '-a' '--trailing-error' @@ -654,12 +672,14 @@ command line. '-s BYTES' '--dictionary-size=BYTES' When compressing, set the dictionary size limit in bytes. Minilzip - will use the smallest possible dictionary size for each file - without exceeding this limit. Valid values range from 4 KiB to - 512 MiB. Values 12 to 29 are interpreted as powers of two, meaning - 2^12 to 2^29 bytes. Note that dictionary sizes are quantized. If - the specified size does not match one of the valid sizes, it will - be rounded upwards by adding up to (BYTES / 8) to it. + will use for each file the largest dictionary size that does not + exceed neither the file size nor this limit. Valid values range + from 4 KiB to 512 MiB. Values 12 to 29 are interpreted as powers + of two, meaning 2^12 to 2^29 bytes. Dictionary sizes are quantized + so that they can be coded in just one byte (*note + coded-dict-size::). If the specified size does not match one of + the valid sizes, it will be rounded upwards by adding up to + (BYTES / 8) to it. For maximum compression you should use a dictionary size limit as large as possible, but keep in mind that the decompression memory @@ -695,27 +715,32 @@ command line. size, and trailer contents (CRC, data size, member size). '-0 .. -9' - Set the compression parameters (dictionary size and match length - limit) as shown in the table below. The default compression level - is '-6'. Note that '-9' can be much slower than '-0'. These - options have no effect when decompressing or testing. + Compression level. Set the compression parameters (dictionary size + and match length limit) as shown in the table below. The default + compression level is '-6', equivalent to '-s8MiB -m36'. Note that + '-9' can be much slower than '-0'. These options have no effect + when decompressing or testing. The bidimensional parameter space of LZMA can't be mapped to a linear scale optimal for all files. If your files are large, very repetitive, etc, you may need to use the '--dictionary-size' and '--match-length' options directly to achieve optimal performance. - Level Dictionary size Match length limit - -0 64 KiB 16 bytes - -1 1 MiB 5 bytes - -2 1.5 MiB 6 bytes - -3 2 MiB 8 bytes - -4 3 MiB 12 bytes - -5 4 MiB 20 bytes - -6 8 MiB 36 bytes - -7 16 MiB 68 bytes - -8 24 MiB 132 bytes - -9 32 MiB 273 bytes + If several compression levels or '-s' or '-m' options are given, + the last setting is used. For example '-9 -s64MiB' is equivalent + to '-s64MiB -m273' + + Level Dictionary size (-s) Match length limit (-m) + -0 64 KiB 16 bytes + -1 1 MiB 5 bytes + -2 1.5 MiB 6 bytes + -3 2 MiB 8 bytes + -4 3 MiB 12 bytes + -5 4 MiB 20 bytes + -6 8 MiB 36 bytes + -7 16 MiB 68 bytes + -8 24 MiB 132 bytes + -9 32 MiB 273 bytes '--fast' '--best' @@ -795,11 +820,11 @@ stream, with no additional information before, between, or after them. 'DS (coded dictionary size, 1 byte)' The dictionary size is calculated by taking a power of 2 (the base - size) and substracting from it a fraction between 0/16 and 7/16 of + size) and subtracting from it a fraction between 0/16 and 7/16 of the base size. Bits 4-0 contain the base 2 logarithm of the base size (12 to 29). - Bits 7-5 contain the numerator of the fraction (0 to 7) to - substract from the base size to obtain the dictionary size. + Bits 7-5 contain the numerator of the fraction (0 to 7) to subtract + from the base size to obtain the dictionary size. Example: 0xD3 = 2^19 - 6 * 2^15 = 512 KiB - 6 * 32 KiB = 320 KiB Valid values for dictionary size range from 4 KiB to 512 MiB. @@ -845,12 +870,10 @@ Example 1: Normal compression (MEMBER_SIZE > total output). 1) LZ_compress_open 2) LZ_compress_write - 3) LZ_compress_read - 4) go back to step 2 until all input data have been written - 5) LZ_compress_finish - 6) LZ_compress_read - 7) go back to step 6 until LZ_compress_finished returns 1 - 8) LZ_compress_close + 3) if no more data to write, call LZ_compress_finish + 4) LZ_compress_read + 5) go back to step 2 until LZ_compress_finished returns 1 + 6) LZ_compress_close Example 2: Normal compression using LZ_compress_write_size. @@ -868,12 +891,10 @@ Example 3: Decompression. 1) LZ_decompress_open 2) LZ_decompress_write - 3) LZ_decompress_read - 4) go back to step 2 until all input data have been written - 5) LZ_decompress_finish - 6) LZ_decompress_read - 7) go back to step 6 until LZ_decompress_finished returns 1 - 8) LZ_decompress_close + 3) if no more data to write, call LZ_decompress_finish + 4) LZ_decompress_read + 5) go back to step 2 until LZ_decompress_finished returns 1 + 6) LZ_decompress_close Example 4: Decompression using LZ_decompress_write_size. @@ -988,20 +1009,21 @@ Concept index  Tag Table: Node: Top220 -Node: Introduction1342 -Node: Library version6154 -Node: Buffering6799 -Node: Parameter limits8024 -Node: Compression functions8983 -Node: Decompression functions15592 -Node: Error codes21762 -Node: Error messages24064 -Node: Invoking minilzip24649 -Ref: --trailing-error25243 -Node: Data format31883 -Node: Examples34454 -Node: Problems38570 -Node: Concept index39142 +Node: Introduction1341 +Node: Library version6397 +Node: Buffering7042 +Node: Parameter limits8267 +Node: Compression functions9226 +Node: Decompression functions16010 +Node: Error codes22599 +Node: Error messages24900 +Node: Invoking minilzip25485 +Ref: --trailing-error26243 +Node: Data format33248 +Ref: coded-dict-size34557 +Node: Examples35817 +Node: Problems39813 +Node: Concept index40385  End Tag Table diff --git a/doc/lzlib.texi b/doc/lzlib.texi index 34154cd..55e80c2 100644 --- a/doc/lzlib.texi +++ b/doc/lzlib.texi @@ -6,8 +6,8 @@ @finalout @c %**end of header -@set UPDATED 7 February 2018 -@set VERSION 1.10 +@set UPDATED 2 January 2019 +@set VERSION 1.11 @dircategory Data Compression @direntry @@ -51,7 +51,7 @@ This manual is for Lzlib (version @value{VERSION}, @value{UPDATED}). @end menu @sp 1 -Copyright @copyright{} 2009-2018 Antonio Diaz Diaz. +Copyright @copyright{} 2009-2019 Antonio Diaz Diaz. This manual is free documentation: you have unlimited permission to copy, distribute and modify it. @@ -61,14 +61,13 @@ to copy, distribute and modify it. @chapter Introduction @cindex introduction -Lzlib is a data compression library providing in-memory LZMA compression -and decompression functions, including integrity checking of the -decompressed data. The compressed data format used by the library is the -lzip format. Lzlib is written in C. +@uref{http://www.nongnu.org/lzip/lzlib.html,,Lzlib} is a data compression +library providing in-memory LZMA compression and decompression functions, +including integrity checking of the decompressed data. The compressed data +format used by the library is the lzip format. Lzlib is written in C. -The lzip file format is designed for data sharing and long-term -archiving, taking into account both data integrity and decoder -availability: +The lzip file format is designed for data sharing and long-term archiving, +taking into account both data integrity and decoder availability: @itemize @bullet @item @@ -118,15 +117,20 @@ data to be compressed in advance, just call the read function with a If all the data to be compressed are written in advance, lzlib will automatically adjust the header of the compressed data to use the -smallest possible dictionary size. This feature reduces the amount of -memory needed for decompression and allows minilzip to produce identical -compressed output as lzip. +largest dictionary size that does not exceed neither the data size nor +the limit given to @samp{LZ_compress_open}. This feature reduces the +amount of memory needed for decompression and allows minilzip to produce +identical compressed output as lzip. Lzlib will correctly decompress a data stream which is the concatenation of two or more compressed data streams. The result is the concatenation of the corresponding decompressed data streams. Integrity testing of concatenated compressed data streams is also supported. +Lzlib is able to compress and decompress streams of unlimited size by +automatically creating multimember output. The members so created are +large, about @w{2 PiB} each. + All the library functions are thread safe. The library does not install any signal handler. The decoder checks the consistency of the compressed data, so the library should never crash even in case of corrupted input. @@ -286,11 +290,13 @@ fast variant of LZMA is chosen, which produces identical compressed output as @code{lzip -0}. (The dictionary size used will be rounded upwards to @w{64 KiB}). -@var{member_size} sets the member size limit in bytes. Minimum member -size limit is @w{100 kB}. Small member size may degrade compression -ratio, so use it only when needed. To produce a single-member data -stream, give @var{member_size} a value larger than the amount of data to -be produced, for example INT64_MAX. +@var{member_size} sets the member size limit in bytes. Valid values +range from @w{100 kB} to @w{2 PiB}. Small member size may degrade +compression ratio, so use it only when needed. To produce a +single-member data stream, give @var{member_size} a value larger than +the amount of data to be produced. Values larger than @w{2 PiB} will be +reduced to @w{2 PiB} to prevent the uncompressed size of the member from +overflowing. @end deftypefun @@ -305,6 +311,7 @@ longer be used as an argument to any LZ_compress function. @deftypefun int LZ_compress_finish ( struct LZ_Encoder * const @var{encoder} ) Use this function to tell @samp{lzlib} that all the data for this member have already been written (with the @samp{LZ_compress_write} function). +It is safe to call @samp{LZ_compress_finish} as many times as needed. After all the produced compressed data have been read with @samp{LZ_compress_read} and @samp{LZ_compress_member_finished} returns 1, a new member can be started with @samp{LZ_compress_restart_member}. @@ -364,7 +371,7 @@ accept a @var{size} up to the returned number of bytes. @deftypefun {enum LZ_Errno} LZ_compress_errno ( struct LZ_Encoder * const @var{encoder} ) -Returns the current error code for @var{encoder} (@pxref{Error codes}). +Returns the current error code for @var{encoder}. @xref{Error codes}. @end deftypefun @@ -440,6 +447,7 @@ longer be used as an argument to any LZ_decompress function. @deftypefun int LZ_decompress_finish ( struct LZ_Decoder * const @var{decoder} ) Use this function to tell @samp{lzlib} that all the data for this stream have already been written (with the @samp{LZ_decompress_write} function). +It is safe to call @samp{LZ_decompress_finish} as many times as needed. @end deftypefun @@ -474,6 +482,16 @@ less than @var{size}; for example, if there aren't that many bytes left in the stream or if more bytes have to be yet written with the @samp{LZ_decompress_write} function. Note that reading less than @var{size} bytes is not an error. + +In case of decompression error caused by corrupt or truncated data, +@samp{LZ_decompress_read} does not signal the error immediately to the +application, but waits until all decoded bytes have been read. This +allows tools like +@uref{http://www.nongnu.org/lzip/manual/tarlz_manual.html,,tarlz} to +recover as much data as possible from each damaged member. +@ifnothtml +@xref{Top,tarlz manual,,tarlz}. +@end ifnothtml @end deftypefun @@ -498,7 +516,7 @@ will accept a @var{size} up to the returned number of bytes. @deftypefun {enum LZ_Errno} LZ_decompress_errno ( struct LZ_Decoder * const @var{decoder} ) -Returns the current error code for @var{decoder} (@pxref{Error codes}). +Returns the current error code for @var{decoder}. @xref{Error codes}. @end deftypefun @@ -616,7 +634,7 @@ used to remove conflicting trailing data from a file. @end deftypevr @deftypevr Constant {enum LZ_Errno} LZ_library_error -A bug was detected in the library. Please, report it (@pxref{Problems}). +A bug was detected in the library. Please, report it. @xref{Problems}. @end deftypevr @@ -640,6 +658,10 @@ The value of @var{lz_errno} normally comes from a call to @cindex invoking @cindex options +Minilzip is a test program for the lzlib compression library, fully +compatible with lzip 1.4 or newer. + +@noindent The format for running minilzip is: @example @@ -661,6 +683,7 @@ Print an informative help message describing the options and exit. @item -V @itemx --version Print the version number of minilzip on the standard output and exit. +This version number should be included in all bug reports. @anchor{--trailing-error} @item -a @@ -728,12 +751,13 @@ Quiet operation. Suppress all messages. @item -s @var{bytes} @itemx --dictionary-size=@var{bytes} When compressing, set the dictionary size limit in bytes. Minilzip will use -the smallest possible dictionary size for each file without exceeding -this limit. Valid values range from @w{4 KiB} to @w{512 MiB}. Values 12 -to 29 are interpreted as powers of two, meaning 2^12 to 2^29 bytes. Note -that dictionary sizes are quantized. If the specified size does not -match one of the valid sizes, it will be rounded upwards by adding up to -@w{(@var{bytes} / 8)} to it. +for each file the largest dictionary size that does not exceed neither +the file size nor this limit. Valid values range from @w{4 KiB} to +@w{512 MiB}. Values 12 to 29 are interpreted as powers of two, meaning +2^12 to 2^29 bytes. Dictionary sizes are quantized so that they can be +coded in just one byte (@pxref{coded-dict-size}). If the specified size +does not match one of the valid sizes, it will be rounded upwards by +adding up to @w{(@var{bytes} / 8)} to it. For maximum compression you should use a dictionary size limit as large as possible, but keep in mind that the decompression memory requirement @@ -768,18 +792,23 @@ verbosity level, showing status, compression ratio, dictionary size, and trailer contents (CRC, data size, member size). @item -0 .. -9 -Set the compression parameters (dictionary size and match length limit) -as shown in the table below. The default compression level is @samp{-6}. -Note that @samp{-9} can be much slower than @samp{-0}. These options -have no effect when decompressing or testing. +Compression level. Set the compression parameters (dictionary size and +match length limit) as shown in the table below. The default compression +level is @samp{-6}, equivalent to @w{@samp{-s8MiB -m36}}. Note that +@samp{-9} can be much slower than @samp{-0}. These options have no +effect when decompressing or testing. The bidimensional parameter space of LZMA can't be mapped to a linear scale optimal for all files. If your files are large, very repetitive, etc, you may need to use the @samp{--dictionary-size} and @samp{--match-length} options directly to achieve optimal performance. -@multitable {Level} {Dictionary size} {Match length limit} -@item Level @tab Dictionary size @tab Match length limit +If several compression levels or @samp{-s} or @samp{-m} options are +given, the last setting is used. For example @w{@samp{-9 -s64MiB}} is +equivalent to @w{@samp{-s64MiB -m273}} + +@multitable {Level} {Dictionary size (-s)} {Match length limit (-m)} +@item Level @tab Dictionary size (-s) @tab Match length limit (-m) @item -0 @tab 64 KiB @tab 16 bytes @item -1 @tab 1 MiB @tab 5 bytes @item -2 @tab 1.5 MiB @tab 6 bytes @@ -875,12 +904,13 @@ A four byte string, identifying the lzip format, with the value "LZIP" @item VN (version number, 1 byte) Just in case something needs to be modified in the future. 1 for now. +@anchor{coded-dict-size} @item DS (coded dictionary size, 1 byte) The dictionary size is calculated by taking a power of 2 (the base size) -and substracting from it a fraction between 0/16 and 7/16 of the base +and subtracting from it a fraction between 0/16 and 7/16 of the base size.@* Bits 4-0 contain the base 2 logarithm of the base size (12 to 29).@* -Bits 7-5 contain the numerator of the fraction (0 to 7) to substract +Bits 7-5 contain the numerator of the fraction (0 to 7) to subtract from the base size to obtain the dictionary size.@* Example: 0xD3 = 2^19 - 6 * 2^15 = 512 KiB - 6 * 32 KiB = 320 KiB@* Valid values for dictionary size range from 4 KiB to 512 MiB. @@ -934,12 +964,10 @@ Example 1: Normal compression (@var{member_size} > total output). @example 1) LZ_compress_open 2) LZ_compress_write -3) LZ_compress_read -4) go back to step 2 until all input data have been written -5) LZ_compress_finish -6) LZ_compress_read -7) go back to step 6 until LZ_compress_finished returns 1 -8) LZ_compress_close +3) if no more data to write, call LZ_compress_finish +4) LZ_compress_read +5) go back to step 2 until LZ_compress_finished returns 1 +6) LZ_compress_close @end example @sp 1 @@ -963,12 +991,10 @@ Example 3: Decompression. @example 1) LZ_decompress_open 2) LZ_decompress_write -3) LZ_decompress_read -4) go back to step 2 until all input data have been written -5) LZ_decompress_finish -6) LZ_decompress_read -7) go back to step 6 until LZ_decompress_finished returns 1 -8) LZ_decompress_close +3) if no more data to write, call LZ_decompress_finish +4) LZ_decompress_read +5) go back to step 2 until LZ_decompress_finished returns 1 +6) LZ_decompress_close @end example @sp 1 diff --git a/doc/minilzip.1 b/doc/minilzip.1 index a5f30c8..adb6e33 100644 --- a/doc/minilzip.1 +++ b/doc/minilzip.1 @@ -1,12 +1,13 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.46.1. -.TH MINILZIP "1" "February 2018" "minilzip 1.10" "User Commands" +.TH MINILZIP "1" "January 2019" "minilzip 1.11" "User Commands" .SH NAME minilzip \- reduces the size of files .SH SYNOPSIS .B minilzip [\fI\,options\/\fR] [\fI\,files\/\fR] .SH DESCRIPTION -Minilzip \- Test program for the lzlib library. +Minilzip is a test program for the lzlib compression library, fully +compatible with lzip 1.4 or newer. .SH OPTIONS .TP \fB\-h\fR, \fB\-\-help\fR @@ -49,7 +50,7 @@ suppress all messages set dictionary size limit in bytes [8 MiB] .TP \fB\-S\fR, \fB\-\-volume\-size=\fR -set volume size limit in bytes, implies \fB\-k\fR +set volume size limit in bytes .TP \fB\-t\fR, \fB\-\-test\fR test compressed file integrity @@ -90,8 +91,8 @@ Report bugs to lzip\-bug@nongnu.org .br Lzlib home page: http://www.nongnu.org/lzip/lzlib.html .SH COPYRIGHT -Copyright \(co 2018 Antonio Diaz Diaz. -Using lzlib 1.10 +Copyright \(co 2019 Antonio Diaz Diaz. +Using lzlib 1.11 License GPLv2+: GNU GPL version 2 or later .br This is free software: you are free to change and redistribute it. diff --git a/encoder.c b/encoder.c index 7d19235..2ec587b 100644 --- a/encoder.c +++ b/encoder.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2018 Antonio Diaz Diaz. + Copyright (C) 2009-2019 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -313,7 +313,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, --prev_index; else /* prev_index2 >= 0 */ prev_index = prev_index2; - cur_state = 8; /* St_set_char_rep(); */ + cur_state = St_set_char_rep(); } cur_trial->state = cur_state; for( i = 0; i < num_rep_distances; ++i ) diff --git a/encoder.h b/encoder.h index 8948013..8c096df 100644 --- a/encoder.h +++ b/encoder.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2018 Antonio Diaz Diaz. + Copyright (C) 2009-2019 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/encoder_base.c b/encoder_base.c index 0dbc617..d385f2c 100644 --- a/encoder_base.c +++ b/encoder_base.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2018 Antonio Diaz Diaz. + Copyright (C) 2009-2019 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -24,7 +24,8 @@ static bool Mb_normalize_pos( struct Matchfinder_base * const mb ) if( !mb->at_stream_end ) { int i; - const int offset = mb->pos - mb->before_size - mb->dictionary_size; + /* offset is int32_t for the min below */ + const int32_t offset = mb->pos - mb->before_size - mb->dictionary_size; const int size = mb->stream_pos - offset; memmove( mb->buffer, mb->buffer + offset, size ); mb->partial_data_pos += offset; @@ -131,19 +132,19 @@ static void LZeb_try_full_flush( struct LZ_encoder_base * const eb ) int i; const int pos_state = Mb_data_position( &eb->mb ) & pos_state_mask; const State state = eb->state; - File_trailer trailer; + Lzip_trailer trailer; if( eb->member_finished || - Cb_free_bytes( &eb->renc.cb ) < max_marker_size + eb->renc.ff_count + Ft_size ) + Cb_free_bytes( &eb->renc.cb ) < max_marker_size + eb->renc.ff_count + Lt_size ) return; eb->member_finished = true; Re_encode_bit( &eb->renc, &eb->bm_match[state][pos_state], 1 ); Re_encode_bit( &eb->renc, &eb->bm_rep[state], 0 ); LZeb_encode_pair( eb, 0xFFFFFFFFU, min_match_len, pos_state ); Re_flush( &eb->renc ); - Ft_set_data_crc( trailer, LZeb_crc( eb ) ); - Ft_set_data_size( trailer, Mb_data_position( &eb->mb ) ); - Ft_set_member_size( trailer, Re_member_position( &eb->renc ) + Ft_size ); - for( i = 0; i < Ft_size; ++i ) + Lt_set_data_crc( trailer, LZeb_crc( eb ) ); + Lt_set_data_size( trailer, Mb_data_position( &eb->mb ) ); + Lt_set_member_size( trailer, Re_member_position( &eb->renc ) + Lt_size ); + for( i = 0; i < Lt_size; ++i ) Cb_put_byte( &eb->renc.cb, trailer[i] ); } @@ -173,7 +174,8 @@ static void LZeb_reset( struct LZ_encoder_base * const eb, { int i; Mb_reset( &eb->mb ); - eb->member_size_limit = member_size - Ft_size - max_marker_size; + eb->member_size_limit = + min( member_size, 0x0008000000000000ULL ) - Lt_size - max_marker_size; eb->crc = 0xFFFFFFFFU; Bm_array_init( eb->bm_literal[0], (1 << literal_context_bits) * 0x300 ); Bm_array_init( eb->bm_match[0], states * pos_states ); diff --git a/encoder_base.h b/encoder_base.h index ddba7e6..f0240cc 100644 --- a/encoder_base.h +++ b/encoder_base.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2018 Antonio Diaz Diaz. + Copyright (C) 2009-2019 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -322,7 +322,7 @@ struct Range_encoder uint32_t range; unsigned ff_count; uint8_t cache; - File_header header; + Lzip_header header; }; static inline void Re_shift_low( struct Range_encoder * const renc ) @@ -349,8 +349,8 @@ static inline void Re_reset( struct Range_encoder * const renc, renc->range = 0xFFFFFFFFU; renc->ff_count = 0; renc->cache = 0; - Fh_set_dictionary_size( renc->header, dictionary_size ); - for( i = 0; i < Fh_size; ++i ) + Lh_set_dictionary_size( renc->header, dictionary_size ); + for( i = 0; i < Lh_size; ++i ) Cb_put_byte( &renc->cb, renc->header[i] ); } @@ -360,7 +360,7 @@ static inline bool Re_init( struct Range_encoder * const renc, { if( !Cb_init( &renc->cb, 65536 + min_free_bytes ) ) return false; renc->min_free_bytes = min_free_bytes; - Fh_set_magic( renc->header ); + Lh_set_magic( renc->header ); Re_reset( renc, dictionary_size ); return true; } diff --git a/fast_encoder.c b/fast_encoder.c index 1ba80e0..48f8368 100644 --- a/fast_encoder.c +++ b/fast_encoder.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2018 Antonio Diaz Diaz. + Copyright (C) 2009-2019 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/fast_encoder.h b/fast_encoder.h index 47dfb3e..6066b85 100644 --- a/fast_encoder.h +++ b/fast_encoder.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2018 Antonio Diaz Diaz. + Copyright (C) 2009-2019 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -58,9 +58,9 @@ static inline bool FLZe_init( struct FLZ_encoder * const fe, /* bytes to keep in buffer after pos */ after_size = max_match_len, dict_factor = 16, + min_free_bytes = max_marker_size, num_prev_positions23 = 0, - pos_array_factor = 1, - min_free_bytes = max_marker_size }; + pos_array_factor = 1 }; return LZeb_init( &fe->eb, before_size, dict_size, after_size, dict_factor, num_prev_positions23, pos_array_factor, min_free_bytes, diff --git a/lzcheck.c b/lzcheck.c index 83e206d..deb4f2a 100644 --- a/lzcheck.c +++ b/lzcheck.c @@ -1,5 +1,5 @@ /* Lzcheck - Test program for the lzlib library - Copyright (C) 2009-2018 Antonio Diaz Diaz. + Copyright (C) 2009-2019 Antonio Diaz Diaz. This program is free software: you have unlimited permission to copy, distribute and modify it. @@ -119,9 +119,11 @@ int lzcheck( FILE * const file, const int dictionary_size ) { rewind( file ); if( LZ_compress_finish( encoder ) < 0 || + LZ_compress_finish( encoder ) < 0 || LZ_decompress_write( decoder, mid_buffer, LZ_compress_read( encoder, mid_buffer, buffer_size ) ) < 0 || LZ_decompress_read( decoder, out_buffer, buffer_size ) != 0 || + LZ_compress_finish( encoder ) < 0 || LZ_compress_restart_member( encoder, member_size ) < 0 ) { fprintf( stderr, "lzcheck: Can't finish member: %s\n", diff --git a/lzip.h b/lzip.h index 3fdf70f..c0ef9e8 100644 --- a/lzip.h +++ b/lzip.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2018 Antonio Diaz Diaz. + Copyright (C) 2009-2019 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -36,6 +36,8 @@ static inline State St_set_char( const State st ) return next[st]; } +static inline State St_set_char_rep() { return 8; } + static inline State St_set_match( const State st ) { return ( ( st < 7 ) ? 7 : 10 ); } @@ -191,43 +193,43 @@ static inline int real_bits( unsigned value ) } -static const uint8_t magic_string[4] = { 0x4C, 0x5A, 0x49, 0x50 }; /* "LZIP" */ +static const uint8_t lzip_magic[4] = { 0x4C, 0x5A, 0x49, 0x50 }; /* "LZIP" */ -typedef uint8_t File_header[6]; /* 0-3 magic bytes */ +typedef uint8_t Lzip_header[6]; /* 0-3 magic bytes */ /* 4 version */ /* 5 coded_dict_size */ -enum { Fh_size = 6 }; +enum { Lh_size = 6 }; -static inline void Fh_set_magic( File_header data ) - { memcpy( data, magic_string, 4 ); data[4] = 1; } +static inline void Lh_set_magic( Lzip_header data ) + { memcpy( data, lzip_magic, 4 ); data[4] = 1; } -static inline bool Fh_verify_magic( const File_header data ) - { return ( memcmp( data, magic_string, 4 ) == 0 ); } +static inline bool Lh_verify_magic( const Lzip_header data ) + { return ( memcmp( data, lzip_magic, 4 ) == 0 ); } /* detect (truncated) header */ -static inline bool Fh_verify_prefix( const File_header data, const int sz ) +static inline bool Lh_verify_prefix( const Lzip_header data, const int sz ) { int i; for( i = 0; i < sz && i < 4; ++i ) - if( data[i] != magic_string[i] ) return false; + if( data[i] != lzip_magic[i] ) return false; return ( sz > 0 ); } /* detect corrupt header */ -static inline bool Fh_verify_corrupt( const File_header data ) +static inline bool Lh_verify_corrupt( const Lzip_header data ) { int matches = 0; int i; for( i = 0; i < 4; ++i ) - if( data[i] == magic_string[i] ) ++matches; + if( data[i] == lzip_magic[i] ) ++matches; return ( matches > 1 && matches < 4 ); } -static inline uint8_t Fh_version( const File_header data ) +static inline uint8_t Lh_version( const Lzip_header data ) { return data[4]; } -static inline bool Fh_verify_version( const File_header data ) +static inline bool Lh_verify_version( const Lzip_header data ) { return ( data[4] == 1 ); } -static inline unsigned Fh_get_dictionary_size( const File_header data ) +static inline unsigned Lh_get_dictionary_size( const Lzip_header data ) { unsigned sz = ( 1 << ( data[5] & 0x1F ) ); if( sz > min_dictionary_size ) @@ -235,7 +237,7 @@ static inline unsigned Fh_get_dictionary_size( const File_header data ) return sz; } -static inline bool Fh_set_dictionary_size( File_header data, const unsigned sz ) +static inline bool Lh_set_dictionary_size( Lzip_header data, const unsigned sz ) { if( !isvalid_ds( sz ) ) return false; data[5] = real_bits( sz - 1 ); @@ -251,47 +253,46 @@ static inline bool Fh_set_dictionary_size( File_header data, const unsigned sz ) return true; } -static inline bool Fh_verify( const File_header data ) +static inline bool Lh_verify( const Lzip_header data ) { - if( Fh_verify_magic( data ) && Fh_verify_version( data ) ) - return isvalid_ds( Fh_get_dictionary_size( data ) ); + if( Lh_verify_magic( data ) && Lh_verify_version( data ) ) + return isvalid_ds( Lh_get_dictionary_size( data ) ); return false; } -typedef uint8_t File_trailer[20]; +typedef uint8_t Lzip_trailer[20]; /* 0-3 CRC32 of the uncompressed data */ /* 4-11 size of the uncompressed data */ /* 12-19 member size including header and trailer */ +enum { Lt_size = 20 }; -enum { Ft_size = 20 }; - -static inline unsigned Ft_get_data_crc( const File_trailer data ) +static inline unsigned Lt_get_data_crc( const Lzip_trailer data ) { unsigned tmp = 0; int i; for( i = 3; i >= 0; --i ) { tmp <<= 8; tmp += data[i]; } return tmp; } -static inline void Ft_set_data_crc( File_trailer data, unsigned crc ) +static inline void Lt_set_data_crc( Lzip_trailer data, unsigned crc ) { int i; for( i = 0; i <= 3; ++i ) { data[i] = (uint8_t)crc; crc >>= 8; } } -static inline unsigned long long Ft_get_data_size( const File_trailer data ) +static inline unsigned long long Lt_get_data_size( const Lzip_trailer data ) { unsigned long long tmp = 0; int i; for( i = 11; i >= 4; --i ) { tmp <<= 8; tmp += data[i]; } return tmp; } -static inline void Ft_set_data_size( File_trailer data, unsigned long long sz ) +static inline void Lt_set_data_size( Lzip_trailer data, unsigned long long sz ) { int i; for( i = 4; i <= 11; ++i ) { data[i] = (uint8_t)sz; sz >>= 8; } } -static inline unsigned long long Ft_get_member_size( const File_trailer data ) +static inline unsigned long long Lt_get_member_size( const Lzip_trailer data ) { unsigned long long tmp = 0; int i; for( i = 19; i >= 12; --i ) { tmp <<= 8; tmp += data[i]; } return tmp; } -static inline void Ft_set_member_size( File_trailer data, unsigned long long sz ) +static inline void Lt_set_member_size( Lzip_trailer data, unsigned long long sz ) { int i; for( i = 12; i <= 19; ++i ) { data[i] = (uint8_t)sz; sz >>= 8; } } diff --git a/lzlib.c b/lzlib.c index 757ad25..f9f7d2f 100644 --- a/lzlib.c +++ b/lzlib.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2018 Antonio Diaz Diaz. + Copyright (C) 2009-2019 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -65,7 +65,7 @@ struct LZ_Decoder struct Range_decoder * rdec; struct LZ_decoder * lz_decoder; enum LZ_Errno lz_errno; - File_header member_header; /* header of current member */ + Lzip_header member_header; /* header of current member */ bool fatal; bool first_header; /* true until first header is read */ bool seeking; @@ -79,7 +79,7 @@ static void LZ_Decoder_init( struct LZ_Decoder * const d ) d->rdec = 0; d->lz_decoder = 0; d->lz_errno = LZ_ok; - for( i = 0; i < Fh_size; ++i ) d->member_header[i] = 0; + for( i = 0; i < Lh_size; ++i ) d->member_header[i] = 0; d->fatal = false; d->first_header = true; d->seeking = false; @@ -119,7 +119,7 @@ const char * LZ_strerror( const enum LZ_Errno lz_errno ) case LZ_mem_error : return "Not enough memory"; case LZ_sequence_error: return "Sequence error"; case LZ_header_error : return "Header error"; - case LZ_unexpected_eof: return "Unexpected eof"; + case LZ_unexpected_eof: return "Unexpected EOF"; case LZ_data_error : return "Data error"; case LZ_library_error : return "Library error"; } @@ -141,12 +141,12 @@ struct LZ_Encoder * LZ_compress_open( const int dictionary_size, const int match_len_limit, const unsigned long long member_size ) { - File_header header; + Lzip_header header; struct LZ_Encoder * const e = (struct LZ_Encoder *)malloc( sizeof (struct LZ_Encoder) ); if( !e ) return 0; LZ_Encoder_init( e ); - if( !Fh_set_dictionary_size( header, dictionary_size ) || + if( !Lh_set_dictionary_size( header, dictionary_size ) || match_len_limit < min_match_len_limit || match_len_limit > max_match_len || member_size < min_dictionary_size ) @@ -163,7 +163,7 @@ struct LZ_Encoder * LZ_compress_open( const int dictionary_size, else { e->lz_encoder = (struct LZ_encoder *)malloc( sizeof (struct LZ_encoder) ); - if( e->lz_encoder && LZe_init( e->lz_encoder, Fh_get_dictionary_size( header ), + if( e->lz_encoder && LZe_init( e->lz_encoder, Lh_get_dictionary_size( header ), match_len_limit, member_size ) ) { e->lz_encoder_base = &e->lz_encoder->eb; return e; } free( e->lz_encoder ); e->lz_encoder = 0; @@ -193,10 +193,10 @@ int LZ_compress_finish( struct LZ_Encoder * const e ) /* if (open --> write --> finish) use same dictionary size as lzip. */ /* this does not save any memory. */ if( Mb_data_position( &e->lz_encoder_base->mb ) == 0 && - Re_member_position( &e->lz_encoder_base->renc ) == Fh_size ) + Re_member_position( &e->lz_encoder_base->renc ) == Lh_size ) { Mb_adjust_dictionary_size( &e->lz_encoder_base->mb ); - Fh_set_dictionary_size( e->lz_encoder_base->renc.header, + Lh_set_dictionary_size( e->lz_encoder_base->renc.header, e->lz_encoder_base->mb.dictionary_size ); e->lz_encoder_base->renc.cb.buffer[5] = e->lz_encoder_base->renc.header[5]; } @@ -400,7 +400,10 @@ int LZ_decompress_read( struct LZ_Decoder * const d, uint8_t * const buffer, const int size ) { int result; - if( !verify_decoder( d ) || d->fatal ) return -1; + if( !verify_decoder( d ) ) return -1; + if( d->fatal ) /* don't return error until pending bytes are read */ + { if( d->lz_decoder && !Cb_empty( &d->lz_decoder->cb ) ) goto get_data; + return -1; } if( d->seeking || size < 0 ) return 0; if( d->lz_decoder && LZd_member_finished( d->lz_decoder ) ) @@ -413,26 +416,26 @@ int LZ_decompress_read( struct LZ_Decoder * const d, int rd; d->partial_in_size += d->rdec->member_position; d->rdec->member_position = 0; - if( Rd_available_bytes( d->rdec ) < Fh_size + 5 && + if( Rd_available_bytes( d->rdec ) < Lh_size + 5 && !d->rdec->at_stream_end ) return 0; if( Rd_finished( d->rdec ) && !d->first_header ) return 0; - rd = Rd_read_data( d->rdec, d->member_header, Fh_size ); - if( Rd_finished( d->rdec ) ) /* End Of File */ + rd = Rd_read_data( d->rdec, d->member_header, Lh_size ); + if( rd < Lh_size || Rd_finished( d->rdec ) ) /* End Of File */ { - if( rd <= 0 || Fh_verify_prefix( d->member_header, rd ) ) + if( rd <= 0 || Lh_verify_prefix( d->member_header, rd ) ) d->lz_errno = LZ_unexpected_eof; else d->lz_errno = LZ_header_error; d->fatal = true; return -1; } - if( !Fh_verify_magic( d->member_header ) ) + if( !Lh_verify_magic( d->member_header ) ) { /* unreading the header prevents sync_to_member from skipping a member if leading garbage is shorter than a full header; "lgLZIP\x01\x0C" */ if( Rd_unread_data( d->rdec, rd ) ) { - if( d->first_header || !Fh_verify_corrupt( d->member_header ) ) + if( d->first_header || !Lh_verify_corrupt( d->member_header ) ) d->lz_errno = LZ_header_error; else d->lz_errno = LZ_data_error; /* corrupt header */ @@ -442,10 +445,12 @@ int LZ_decompress_read( struct LZ_Decoder * const d, d->fatal = true; return -1; } - if( !Fh_verify_version( d->member_header ) || - !isvalid_ds( Fh_get_dictionary_size( d->member_header ) ) ) + if( !Lh_verify_version( d->member_header ) || + !isvalid_ds( Lh_get_dictionary_size( d->member_header ) ) ) { - if( Rd_unread_data( d->rdec, 1 + !Fh_verify_version( d->member_header ) ) ) + /* Skip a possible "LZIP" leading garbage; "LZIPLZIP\x01\x0C". + Leave member_pos pointing to the first error. */ + if( Rd_unread_data( d->rdec, 1 + !Lh_verify_version( d->member_header ) ) ) d->lz_errno = LZ_data_error; /* bad version or bad dict size */ else d->lz_errno = LZ_library_error; @@ -464,7 +469,7 @@ int LZ_decompress_read( struct LZ_Decoder * const d, } d->lz_decoder = (struct LZ_decoder *)malloc( sizeof (struct LZ_decoder) ); if( !d->lz_decoder || !LZd_init( d->lz_decoder, d->rdec, - Fh_get_dictionary_size( d->member_header ) ) ) + Lh_get_dictionary_size( d->member_header ) ) ) { /* not enough free memory */ if( d->lz_decoder ) { LZd_free( d->lz_decoder ); free( d->lz_decoder ); d->lz_decoder = 0; } @@ -477,15 +482,16 @@ int LZ_decompress_read( struct LZ_Decoder * const d, result = LZd_decode_member( d->lz_decoder ); if( result != 0 ) { - if( result == 2 ) /* set position at EOF */ + if( result == 2 ) /* set input position at EOF */ { d->rdec->member_position += Cb_used_bytes( &d->rdec->cb ); Cb_reset( &d->rdec->cb ); d->lz_errno = LZ_unexpected_eof; } else if( result == 5 ) d->lz_errno = LZ_library_error; else d->lz_errno = LZ_data_error; d->fatal = true; - return -1; + if( Cb_empty( &d->lz_decoder->cb ) ) return -1; } +get_data: return Cb_read_data( &d->lz_decoder->cb, buffer, size ); } @@ -529,7 +535,7 @@ enum LZ_Errno LZ_decompress_errno( struct LZ_Decoder * const d ) int LZ_decompress_finished( struct LZ_Decoder * const d ) { - if( !verify_decoder( d ) ) return -1; + if( !verify_decoder( d ) || d->fatal ) return -1; return ( Rd_finished( d->rdec ) && ( !d->lz_decoder || LZd_member_finished( d->lz_decoder ) ) ); } @@ -537,7 +543,7 @@ int LZ_decompress_finished( struct LZ_Decoder * const d ) int LZ_decompress_member_finished( struct LZ_Decoder * const d ) { - if( !verify_decoder( d ) ) return -1; + if( !verify_decoder( d ) || d->fatal ) return -1; return ( d->lz_decoder && LZd_member_finished( d->lz_decoder ) ); } @@ -545,14 +551,14 @@ int LZ_decompress_member_finished( struct LZ_Decoder * const d ) int LZ_decompress_member_version( struct LZ_Decoder * const d ) { if( !verify_decoder( d ) ) return -1; - return Fh_version( d->member_header ); + return Lh_version( d->member_header ); } int LZ_decompress_dictionary_size( struct LZ_Decoder * const d ) { if( !verify_decoder( d ) ) return -1; - return Fh_get_dictionary_size( d->member_header ); + return Lh_get_dictionary_size( d->member_header ); } diff --git a/lzlib.h b/lzlib.h index 1eed1e0..97672a0 100644 --- a/lzlib.h +++ b/lzlib.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2018 Antonio Diaz Diaz. + Copyright (C) 2009-2019 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -23,7 +23,7 @@ extern "C" { #define LZ_API_VERSION 1 -static const char * const LZ_version_string = "1.10"; +static const char * const LZ_version_string = "1.11"; enum LZ_Errno { LZ_ok = 0, LZ_bad_argument, LZ_mem_error, LZ_sequence_error, LZ_header_error, LZ_unexpected_eof, diff --git a/main.c b/main.c index 3e3e411..b6a13e9 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,5 @@ /* Minilzip - Test program for the lzlib library - Copyright (C) 2009-2018 Antonio Diaz Diaz. + Copyright (C) 2009-2019 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 @@ -35,20 +35,25 @@ #include #include #include -#if defined(__MSVCRT__) +#if defined(__MSVCRT__) || defined(__OS2__) || defined(__DJGPP__) #include +#if defined(__MSVCRT__) #define fchmod(x,y) 0 #define fchown(x,y,z) 0 #define strtoull strtoul #define SIGHUP SIGTERM #define S_ISSOCK(x) 0 +#ifndef S_IRGRP #define S_IRGRP 0 #define S_IWGRP 0 #define S_IROTH 0 #define S_IWOTH 0 #endif -#if defined(__OS2__) -#include +#endif +#if defined(__DJGPP__) +#define S_ISSOCK(x) 0 +#define S_ISVTX 0 +#endif #endif #include "carg_parser.h" @@ -77,9 +82,8 @@ void internal_error( const char * const msg ); int verbosity = 0; -const char * const Program_name = "Minilzip"; const char * const program_name = "minilzip"; -const char * const program_year = "2018"; +const char * const program_year = "2019"; const char * invocation_name = 0; const struct { const char * from; const char * to; } known_extensions[] = { @@ -95,6 +99,8 @@ struct Lzma_options enum Mode { m_compress, m_decompress, m_test }; +/* Variables used in signal handler context. + They are not declared volatile because the handler never returns. */ char * output_filename = 0; int outfd = -1; bool delete_output_on_interrupt = false; @@ -102,8 +108,9 @@ bool delete_output_on_interrupt = false; static void show_help( void ) { - printf( "%s - Test program for the lzlib library.\n", Program_name ); - printf( "\nUsage: %s [options] [files]\n", invocation_name ); + printf( "Minilzip is a test program for the lzlib compression library, fully\n" + "compatible with lzip 1.4 or newer.\n" + "\nUsage: %s [options] [files]\n", invocation_name ); printf( "\nOptions:\n" " -h, --help display this help and exit\n" " -V, --version output version information and exit\n" @@ -118,7 +125,7 @@ static void show_help( void ) " -o, --output= if reading standard input, write to \n" " -q, --quiet suppress all messages\n" " -s, --dictionary-size= set dictionary size limit in bytes [8 MiB]\n" - " -S, --volume-size= set volume size limit in bytes, implies -k\n" + " -S, --volume-size= set volume size limit in bytes\n" " -t, --test test compressed file integrity\n" " -v, --verbose be verbose (a 2nd -v gives more)\n" " -0 .. -9 set compression level [default 6]\n" @@ -196,7 +203,7 @@ static void Pp_init( struct Pretty_print * const pp, { const char * const s = filenames[i]; const unsigned len = (strcmp( s, "-" ) == 0) ? stdin_name_len : strlen( s ); - if( len > pp->longest_name ) pp->longest_name = len; + if( pp->longest_name < len ) pp->longest_name = len; } if( pp->longest_name == 0 ) pp->longest_name = stdin_name_len; } @@ -322,6 +329,17 @@ static int get_dict_size( const char * const arg ) } +void set_mode( enum Mode * const program_modep, const enum Mode new_mode ) + { + if( *program_modep != m_compress && *program_modep != new_mode ) + { + show_error( "Only one operation can be specified.", 0, true ); + exit( 1 ); + } + *program_modep = new_mode; + } + + static int extension_index( const char * const name ) { int eindex; @@ -457,8 +475,17 @@ static bool check_tty( const char * const input_filename, const int infd, } +static void set_signals( void (*action)(int) ) + { + signal( SIGHUP, action ); + signal( SIGINT, action ); + signal( SIGTERM, action ); + } + + void cleanup_and_fail( const int retval ) { + set_signals( SIG_IGN ); /* ignore signals */ if( delete_output_on_interrupt ) { delete_output_on_interrupt = false; @@ -473,6 +500,14 @@ void cleanup_and_fail( const int retval ) } +void signal_handler( int sig ) + { + if( sig ) {} /* keep compiler happy */ + show_error( "Control-C or similar caught, quitting.", 0, false ); + cleanup_and_fail( 1 ); + } + + /* Set permissions, owner and times. */ static void close_and_set_permissions( const struct stat * const in_statsp ) { @@ -696,7 +731,8 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd, for( first_member = true; ; ) { - const int max_in_size = min( LZ_decompress_write_size( decoder ), buffer_size ); + const int max_in_size = + min( LZ_decompress_write_size( decoder ), buffer_size ); int in_size = 0, out_size = 0; if( max_in_size > 0 ) { @@ -712,7 +748,8 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd, } while( true ) { - const int rd = LZ_decompress_read( decoder, buffer, buffer_size ); + const int rd = + LZ_decompress_read( decoder, (outfd >= 0) ? buffer : 0, buffer_size ); if( rd > 0 ) { out_size += rd; @@ -839,31 +876,13 @@ static int decompress( const int infd, struct Pretty_print * const pp, } -void signal_handler( int sig ) - { - if( sig ) {} /* keep compiler happy */ - show_error( "Control-C or similar caught, quitting.", 0, false ); - cleanup_and_fail( 1 ); - } - - -static void set_signals( void ) - { - signal( SIGHUP, signal_handler ); - signal( SIGINT, signal_handler ); - signal( SIGTERM, signal_handler ); - } - - void show_error( const char * const msg, const int errcode, const bool help ) { if( verbosity < 0 ) return; if( msg && msg[0] ) - { - fprintf( stderr, "%s: %s", program_name, msg ); - if( errcode > 0 ) fprintf( stderr, ": %s", strerror( errcode ) ); - fputc( '\n', stderr ); - } + fprintf( stderr, "%s: %s%s%s\n", program_name, msg, + ( errcode > 0 ) ? ": " : "", + ( errcode > 0 ) ? strerror( errcode ) : "" ); if( help ) fprintf( stderr, "Try '%s --help' for more information.\n", invocation_name ); @@ -873,10 +892,10 @@ 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, const int errcode ) { - if( verbosity < 0 ) return; - fprintf( stderr, "%s: %s: %s", program_name, filename, msg ); - if( errcode > 0 ) fprintf( stderr, ": %s", strerror( errcode ) ); - fputc( '\n', stderr ); + if( verbosity >= 0 ) + fprintf( stderr, "%s: %s: %s%s%s\n", program_name, filename, msg, + ( errcode > 0 ) ? ": " : "", + ( errcode > 0 ) ? strerror( errcode ) : "" ); } @@ -987,7 +1006,7 @@ int main( const int argc, const char * const argv[] ) case 'a': ignore_trailing = false; break; case 'b': member_size = getnum( arg, 100000, max_member_size ); break; case 'c': to_stdout = true; break; - case 'd': program_mode = m_decompress; break; + case 'd': set_mode( &program_mode, m_decompress ); break; case 'f': force = true; break; case 'F': recompress = true; break; case 'h': show_help(); return 0; @@ -1001,7 +1020,7 @@ int main( const int argc, const char * const argv[] ) case 's': encoder_options.dictionary_size = get_dict_size( arg ); break; case 'S': volume_size = getnum( arg, 100000, max_volume_size ); break; - case 't': program_mode = m_test; break; + case 't': set_mode( &program_mode, m_test ); break; case 'v': if( verbosity < 4 ) ++verbosity; break; case 'V': show_version(); return 0; case opt_lt: loose_trailing = true; break; @@ -1009,7 +1028,7 @@ int main( const int argc, const char * const argv[] ) } } /* end process options */ -#if defined(__MSVCRT__) || defined(__OS2__) +#if defined(__MSVCRT__) || defined(__OS2__) || defined(__DJGPP__) setmode( STDIN_FILENO, O_BINARY ); setmode( STDOUT_FILENO, O_BINARY ); #endif @@ -1029,7 +1048,7 @@ int main( const int argc, const char * const argv[] ) if( !to_stdout && program_mode != m_test && ( filenames_given || default_output_filename[0] ) ) - set_signals(); + set_signals( signal_handler ); Pp_init( &pp, filenames, num_filenames ); @@ -1109,6 +1128,12 @@ int main( const int argc, const char * const argv[] ) else tmp = decompress( infd, &pp, ignore_trailing, loose_trailing, program_mode == m_test ); + if( close( infd ) != 0 ) + { + show_error( input_filename[0] ? "Error closing input file" : + "Error closing stdin", errno, false ); + if( tmp < 1 ) tmp = 1; + } if( tmp > retval ) retval = tmp; if( tmp ) { if( program_mode != m_test ) cleanup_and_fail( retval ); @@ -1118,7 +1143,6 @@ int main( const int argc, const char * const argv[] ) close_and_set_permissions( in_statsp ); if( input_filename[0] ) { - close( infd ); if( !keep_input_files && !to_stdout && program_mode != m_test && ( program_mode != m_compress || volume_size == 0 ) ) remove( input_filename ); diff --git a/testsuite/check.sh b/testsuite/check.sh index 929a690..026ea2b 100755 --- a/testsuite/check.sh +++ b/testsuite/check.sh @@ -1,6 +1,6 @@ #! /bin/sh # check script for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2018 Antonio Diaz Diaz. +# Copyright (C) 2009-2019 Antonio Diaz Diaz. # # This script is free software: you have unlimited permission # to copy, distribute and modify it. @@ -39,12 +39,15 @@ test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; } printf "testing lzlib-%s..." "$2" "${LZIP}" -fkqm4 in -{ [ $? = 1 ] && [ ! -e in.lz ] ; } || test_failed $LINENO +[ $? = 1 ] || test_failed $LINENO +[ ! -e in.lz ] || test_failed $LINENO "${LZIP}" -fkqm274 in -{ [ $? = 1 ] && [ ! -e in.lz ] ; } || test_failed $LINENO +[ $? = 1 ] || test_failed $LINENO +[ ! -e in.lz ] || test_failed $LINENO for i in bad_size -1 0 4095 513MiB 1G 1T 1P 1E 1Z 1Y 10KB ; do "${LZIP}" -fkqs $i in - { [ $? = 1 ] && [ ! -e in.lz ] ; } || test_failed $LINENO $i + [ $? = 1 ] || test_failed $LINENO $i + [ ! -e in.lz ] || test_failed $LINENO $i done "${LZIP}" -tq in [ $? = 2 ] || test_failed $LINENO @@ -57,6 +60,8 @@ done "${LZIP}" -dq -o in < "${in_lz}" [ $? = 1 ] || test_failed $LINENO # these are for code coverage +"${LZIP}" -cdt "${in_lz}" > out 2> /dev/null +[ $? = 1 ] || test_failed $LINENO "${LZIP}" -t -- nx_file 2> /dev/null [ $? = 1 ] || test_failed $LINENO "${LZIP}" --help > /dev/null || test_failed $LINENO @@ -89,41 +94,46 @@ cmp in copy || test_failed $LINENO "${LZIP}" -cd "${testdir}"/test_sync.lz > copy || test_failed $LINENO cmp in copy || test_failed $LINENO -rm -f copy +rm -f copy || framework_failure cat "${in_lz}" > copy.lz || framework_failure "${LZIP}" -dk copy.lz || test_failed $LINENO cmp in copy || test_failed $LINENO printf "to be overwritten" > copy || framework_failure "${LZIP}" -d copy.lz 2> /dev/null [ $? = 1 ] || test_failed $LINENO -"${LZIP}" -df copy.lz -{ [ $? = 0 ] && [ ! -e copy.lz ] && cmp in copy ; } || test_failed $LINENO +"${LZIP}" -df copy.lz || test_failed $LINENO +[ ! -e copy.lz ] || test_failed $LINENO +cmp in copy || test_failed $LINENO -rm -f copy +rm -f copy || framework_failure cat "${in_lz}" > copy.lz || framework_failure -"${LZIP}" -d -S100k copy.lz -{ [ $? = 0 ] && [ ! -e copy.lz ] && cmp in copy ; } || test_failed $LINENO +"${LZIP}" -d -S100k copy.lz || test_failed $LINENO # ignore -S +[ ! -e copy.lz ] || test_failed $LINENO +cmp in copy || test_failed $LINENO printf "to be overwritten" > copy || framework_failure "${LZIP}" -df -o copy < "${in_lz}" || test_failed $LINENO cmp in copy || test_failed $LINENO -rm -f copy +rm -f copy || framework_failure "${LZIP}" -s16 < in > anyothername || test_failed $LINENO -"${LZIP}" -dv --output copy - anyothername - < "${in_lz}" 2> /dev/null -{ [ $? = 0 ] && cmp in copy && cmp in anyothername.out ; } || +"${LZIP}" -dv --output copy - anyothername - < "${in_lz}" 2> /dev/null || test_failed $LINENO -rm -f copy anyothername.out +cmp in copy || test_failed $LINENO +cmp in anyothername.out || test_failed $LINENO +rm -f copy anyothername.out || framework_failure "${LZIP}" -tq in "${in_lz}" [ $? = 2 ] || test_failed $LINENO "${LZIP}" -tq nx_file.lz "${in_lz}" [ $? = 1 ] || test_failed $LINENO "${LZIP}" -cdq in "${in_lz}" > copy -{ [ $? = 2 ] && cat copy in | cmp in - ; } || test_failed $LINENO +[ $? = 2 ] || test_failed $LINENO +cat copy in | cmp in - || test_failed $LINENO "${LZIP}" -cdq nx_file.lz "${in_lz}" > copy -{ [ $? = 1 ] && cmp in copy ; } || test_failed $LINENO -rm -f copy +[ $? = 1 ] || test_failed $LINENO +cmp in copy || test_failed $LINENO +rm -f copy || framework_failure cat "${in_lz}" > copy.lz || framework_failure for i in 1 2 3 4 5 6 7 ; do printf "g" >> copy.lz || framework_failure @@ -131,11 +141,15 @@ for i in 1 2 3 4 5 6 7 ; do [ $? = 2 ] || test_failed $LINENO $i done "${LZIP}" -dq in copy.lz -{ [ $? = 2 ] && [ -e copy.lz ] && [ ! -e copy ] && [ ! -e in.out ] ; } || - test_failed $LINENO +[ $? = 2 ] || test_failed $LINENO +[ -e copy.lz ] || test_failed $LINENO +[ ! -e copy ] || test_failed $LINENO +[ ! -e in.out ] || test_failed $LINENO "${LZIP}" -dq nx_file.lz copy.lz -{ [ $? = 1 ] && [ ! -e copy.lz ] && [ ! -e nx_file ] && cmp in copy ; } || - test_failed $LINENO +[ $? = 1 ] || test_failed $LINENO +[ ! -e copy.lz ] || test_failed $LINENO +[ ! -e nx_file ] || test_failed $LINENO +cmp in copy || test_failed $LINENO cat in in > in2 || framework_failure cat "${in_lz}" "${in_lz}" > in2.lz || framework_failure @@ -150,18 +164,21 @@ cmp in2 copy2 || test_failed $LINENO printf "\ngarbage" >> copy2.lz || framework_failure "${LZIP}" -tvvvv copy2.lz 2> /dev/null || test_failed $LINENO -rm -f copy2 +rm -f copy2 || framework_failure "${LZIP}" -atq copy2.lz [ $? = 2 ] || test_failed $LINENO "${LZIP}" -atq < copy2.lz [ $? = 2 ] || test_failed $LINENO "${LZIP}" -adkq copy2.lz -{ [ $? = 2 ] && [ ! -e copy2 ] ; } || test_failed $LINENO +[ $? = 2 ] || test_failed $LINENO +[ ! -e copy2 ] || test_failed $LINENO "${LZIP}" -adkq -o copy2 < copy2.lz -{ [ $? = 2 ] && [ ! -e copy2 ] ; } || test_failed $LINENO +[ $? = 2 ] || test_failed $LINENO +[ ! -e copy2 ] || test_failed $LINENO printf "to be overwritten" > copy2 || framework_failure "${LZIP}" -df copy2.lz || test_failed $LINENO cmp in2 copy2 || test_failed $LINENO +rm -f in2 copy2 || framework_failure printf "\ntesting compression..." @@ -197,36 +214,37 @@ for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do "${LZIP}" -df -o copy < out.lz || test_failed $LINENO $i cmp in copy || test_failed $LINENO $i done +rm -f out.lz || framework_failure cat in in in in in in in in > in8 || framework_failure "${LZIP}" -1s12 -S100k in8 || test_failed $LINENO "${LZIP}" -t in800001.lz in800002.lz || test_failed $LINENO "${LZIP}" -cd in800001.lz in800002.lz | cmp in8 - || test_failed $LINENO -rm -f in800001.lz in800002.lz +rm -f in800001.lz in800002.lz || framework_failure "${LZIP}" -1s12 -S100k -o out.lz < in8 || test_failed $LINENO "${LZIP}" -t out.lz00001.lz out.lz00002.lz || test_failed $LINENO "${LZIP}" -cd out.lz00001.lz out.lz00002.lz | cmp in8 - || test_failed $LINENO -rm -f out.lz00001.lz out.lz00002.lz +rm -f out.lz00001.lz out.lz00002.lz || framework_failure "${LZIP}" -1ks4Ki -b100000 in8 || test_failed $LINENO "${LZIP}" -t in8.lz || test_failed $LINENO "${LZIP}" -cd in8.lz | cmp in8 - || test_failed $LINENO -rm -f in8 +rm -f in8 || framework_failure "${LZIP}" -0 -S100k -o out < in8.lz || test_failed $LINENO "${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO "${LZIP}" -cd out00001.lz out00002.lz | cmp in8.lz - || test_failed $LINENO -rm -f out00001.lz +rm -f out00001.lz || framework_failure "${LZIP}" -1 -S100k -o out < in8.lz || test_failed $LINENO "${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO "${LZIP}" -cd out00001.lz out00002.lz | cmp in8.lz - || test_failed $LINENO -rm -f out00001.lz out00002.lz +rm -f out00001.lz out00002.lz || framework_failure "${LZIP}" -0 -F -S100k in8.lz || test_failed $LINENO "${LZIP}" -t in8.lz00001.lz in8.lz00002.lz || test_failed $LINENO "${LZIP}" -cd in8.lz00001.lz in8.lz00002.lz | cmp in8.lz - || test_failed $LINENO -rm -f in8.lz00001.lz in8.lz00002.lz +rm -f in8.lz00001.lz in8.lz00002.lz || framework_failure "${LZIP}" -0kF -b100k in8.lz || test_failed $LINENO "${LZIP}" -t in8.lz.lz || test_failed $LINENO "${LZIP}" -cd in8.lz.lz | cmp in8.lz - || test_failed $LINENO -rm -f in8.lz in8.lz.lz +rm -f in8.lz in8.lz.lz || framework_failure "${BBEXAMPLE}" in || test_failed $LINENO "${BBEXAMPLE}" out || test_failed $LINENO @@ -240,28 +258,48 @@ printf "\ntesting bad input..." headers='LZIp LZiP LZip LzIP LzIp LziP lZIP lZIp lZiP lzIP' body='\001\014\000\203\377\373\377\377\300\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000$\000\000\000\000\000\000\000' -cat "${in_lz}" > in0.lz -printf "LZIP${body}" >> in0.lz -if "${LZIP}" -tq in0.lz ; then +cat "${in_lz}" > int.lz +printf "LZIP${body}" >> int.lz +if "${LZIP}" -tq int.lz ; then for header in ${headers} ; do - printf "${header}${body}" > in0.lz # first member - "${LZIP}" -tq in0.lz + printf "${header}${body}" > int.lz # first member + "${LZIP}" -tq int.lz [ $? = 2 ] || test_failed $LINENO ${header} - "${LZIP}" -tq --loose-trailing in0.lz + "${LZIP}" -tq < int.lz [ $? = 2 ] || test_failed $LINENO ${header} - cat "${in_lz}" > in0.lz - printf "${header}${body}" >> in0.lz # trailing data - "${LZIP}" -tq in0.lz + "${LZIP}" -cdq int.lz > /dev/null [ $? = 2 ] || test_failed $LINENO ${header} - "${LZIP}" -t --loose-trailing in0.lz - [ $? = 0 ] || test_failed $LINENO ${header} - "${LZIP}" -tq --loose-trailing --trailing-error in0.lz + "${LZIP}" -tq --loose-trailing int.lz + [ $? = 2 ] || test_failed $LINENO ${header} + "${LZIP}" -tq --loose-trailing < int.lz + [ $? = 2 ] || test_failed $LINENO ${header} + "${LZIP}" -cdq --loose-trailing int.lz > /dev/null + [ $? = 2 ] || test_failed $LINENO ${header} + cat "${in_lz}" > int.lz + printf "${header}${body}" >> int.lz # trailing data + "${LZIP}" -tq int.lz + [ $? = 2 ] || test_failed $LINENO ${header} + "${LZIP}" -tq < int.lz + [ $? = 2 ] || test_failed $LINENO ${header} + "${LZIP}" -cdq int.lz > /dev/null + [ $? = 2 ] || test_failed $LINENO ${header} + "${LZIP}" -t --loose-trailing int.lz || + test_failed $LINENO ${header} + "${LZIP}" -t --loose-trailing < int.lz || + test_failed $LINENO ${header} + "${LZIP}" -cd --loose-trailing int.lz > /dev/null || + test_failed $LINENO ${header} + "${LZIP}" -tq --loose-trailing --trailing-error int.lz + [ $? = 2 ] || test_failed $LINENO ${header} + "${LZIP}" -tq --loose-trailing --trailing-error < int.lz + [ $? = 2 ] || test_failed $LINENO ${header} + "${LZIP}" -cdq --loose-trailing --trailing-error int.lz > /dev/null [ $? = 2 ] || test_failed $LINENO ${header} done else printf "\nwarning: skipping header test: 'printf' does not work on your system." fi -rm -f in0.lz +rm -f int.lz || framework_failure cat "${in_lz}" "${in_lz}" "${in_lz}" > in3.lz || framework_failure if dd if=in3.lz of=trunc.lz bs=14752 count=1 2> /dev/null && @@ -280,7 +318,7 @@ if dd if=in3.lz of=trunc.lz bs=14752 count=1 2> /dev/null && else printf "\nwarning: skipping truncation test: 'dd' does not work on your system." fi -rm -f in3.lz trunc.lz +rm -f in2.lz in3.lz trunc.lz out || framework_failure cat "${in_lz}" > ingin.lz || framework_failure printf "g" >> ingin.lz || framework_failure @@ -291,7 +329,7 @@ cmp in copy || test_failed $LINENO "${LZIP}" -t < ingin.lz || test_failed $LINENO "${LZIP}" -d < ingin.lz > copy || test_failed $LINENO cmp in copy || test_failed $LINENO -rm -f ingin.lz +rm -f copy ingin.lz || framework_failure echo if [ ${fail} = 0 ] ; then From 02bc104eac1156fc44f6ba72aa7737d72a666268 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 20 Feb 2025 21:30:54 +0100 Subject: [PATCH 04/10] Adding upstream version 1.12. Signed-off-by: Daniel Baumann --- AUTHORS | 8 +- COPYING | 26 +- ChangeLog | 135 +-- INSTALL | 36 +- Makefile.in | 35 +- NEWS | 104 ++- README | 114 ++- bbexample.c | 377 +++++---- carg_parser.c | 26 +- carg_parser.h | 66 +- cbuffer.c | 26 +- configure | 25 +- decoder.c | 42 +- decoder.h | 58 +- doc/lzlib.info | 1357 +++++++++++++++++++------------ doc/lzlib.texi | 908 ++++++++++++++------- doc/minilzip.1 | 38 +- encoder.c | 40 +- encoder.h | 26 +- encoder_base.c | 55 +- encoder_base.h | 65 +- fast_encoder.c | 32 +- fast_encoder.h | 42 +- ffexample.c | 300 +++++++ lzcheck.c | 394 +++++---- lzip.h | 35 +- lzlib.c | 64 +- lzlib.h | 38 +- main.c | 422 +++++----- testsuite/check.sh | 187 ++++- testsuite/fox.lz | Bin 0 -> 80 bytes testsuite/fox_bcrc.lz | Bin 0 -> 80 bytes testsuite/fox_crc0.lz | Bin 0 -> 80 bytes testsuite/fox_das46.lz | Bin 0 -> 80 bytes testsuite/fox_de20.lz | Bin 0 -> 80 bytes testsuite/{test2.txt => fox_lf} | 0 testsuite/fox_mes81.lz | Bin 0 -> 80 bytes testsuite/fox_s11.lz | Bin 0 -> 80 bytes testsuite/fox_v2.lz | Bin 0 -> 80 bytes testsuite/test_em.txt.lz | Bin 0 -> 14024 bytes 40 files changed, 3224 insertions(+), 1857 deletions(-) create mode 100644 ffexample.c create mode 100644 testsuite/fox.lz create mode 100644 testsuite/fox_bcrc.lz create mode 100644 testsuite/fox_crc0.lz create mode 100644 testsuite/fox_das46.lz create mode 100644 testsuite/fox_de20.lz rename testsuite/{test2.txt => fox_lf} (100%) create mode 100644 testsuite/fox_mes81.lz create mode 100644 testsuite/fox_s11.lz create mode 100644 testsuite/fox_v2.lz create mode 100644 testsuite/test_em.txt.lz diff --git a/AUTHORS b/AUTHORS index f34d016..03a0e01 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,7 +1,7 @@ Lzlib was written by Antonio Diaz Diaz. The ideas embodied in lzlib are due to (at least) the following people: -Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for -the definition of Markov chains), G.N.N. Martin (for the definition of -range encoding), Igor Pavlov (for putting all the above together in -LZMA), and Julian Seward (for bzip2's CLI). +Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the +definition of Markov chains), G.N.N. Martin (for the definition of range +encoding), Igor Pavlov (for putting all the above together in LZMA), and +Julian Seward (for bzip2's CLI). diff --git a/COPYING b/COPYING index fcf86c4..a6511c8 100644 --- a/COPYING +++ b/COPYING @@ -1,17 +1,17 @@ - Lzlib - Compression library for the lzip format - Copyright (C) Antonio Diaz Diaz. + Lzlib - Compression library for the lzip format + Copyright (C) Antonio Diaz Diaz. - This library is free software. Redistribution and use in source and - binary forms, with or without modification, are permitted provided - that the following conditions are met: + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/ChangeLog b/ChangeLog index 7402b7a..e38a855 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,16 +1,55 @@ +2021-01-02 Antonio Diaz Diaz + + * Version 1.12 released. + * lzlib.h: Define LZ_API_VERSION as 1000 * major + minor. 1.12 = 1012. + This change does not affect the soversion. + * lzlib.h, lzlib.c: New function LZ_api_version. + * LZd_try_verify_trailer: Return 2 if EOF at trailer or EOS marker. + * Decompression speed has been slightly increased. + * decoder.h: Increase 'rd_min_available_bytes' from 8 to 10. + * encoder_base.c (LZeb_try_sync_flush): + Compensate for the increase in 'rd_min_available_bytes'. + * main.c (do_decompress): Fix false report about library stall. + * main.c: New option '--check-lib'. + * main.c (main): Report an error if a file name is empty. + Make '-o' behave like '-c', but writing to file instead of stdout. + Make '-c' and '-o' check whether the output is a terminal only once. + Do not open output if input is a terminal. + Replace 'decompressed', 'compressed' with 'out', 'in' in output. + Set a valid invocation_name even if argc == 0. + * lzlib.texi: Document the new way of verifying the library version. + Document that 'LZ_(de)compress_close' and 'LZ_(de)compress_errno' + can be called with a null argument. + Document that sync flush marker is not allowed in lzip files. + Document the consequences of not calling 'LZ_decompress_finish'. + Document that 'LZ_decompress_read' returns at least once per member. + Document that 'LZ_(de)compress_read' can be called with a null + buffer pointer argument. + Real code examples for common uses have been added to the tutorial. + * bbexample.c: Don't use 'LZ_(de)compress_write_size'. + * lzcheck.c: New options '-s' (sync) and '-m' (member by member). + Test member by member without 'LZ_decompress_finish'. + * ffexample.c: New file containing example functions for file-to-file + compression/decompression. + * Document extraction from tar.lz in '--help' output and man page. + * Makefile.in: 'install-bin' no longer installs the man page. + New targets 'install-bin-compress' and 'install-bin-strip-compress'. + * testsuite: Add 9 new test files. + 2019-01-02 Antonio Diaz Diaz * Version 1.11 released. - * File_* renamed to Lzip_*. + * Rename File_* to Lzip_*. * LZ_decompress_read: Don't return error until all data is read. * decoder.c (LZd_decode_member): Decode truncated data until EOF. + * cbuffer.c (Cb_read_data): Allow a null buffer pointer. * main.c: Don't allow mixing different operations (-d and -t). * main.c: Check return value of close( infd ). * main.c: Compile on DOS with DJGPP. - * lzlib.texi: Improved descriptions of '-0..-9', '-m' and '-s'. + * lzlib.texi: Improve descriptions of '-0..-9', '-m', and '-s'. Document that 'LZ_(de)compress_finish' can be called repeatedly. * configure: Accept appending to CFLAGS, 'CFLAGS+=OPTIONS'. - * Makefile.in: Targets 'install-bin*' renamed to 'install-lib*'. + * Makefile.in: Rename targets 'install-bin*' to 'install-lib*'. * Makefile.in: Targets 'install-bin*' now install minilzip. * INSTALL: Document use of CFLAGS+='-D __USE_MINGW_ANSI_STDIO'. @@ -19,13 +58,13 @@ * Version 1.10 released. * LZ_compress_finish now adjusts dictionary size for each member. * lzlib.c (LZ_decompress_read): Detect corrupt header with HD=3. - * main.c: Added new option '--loose-trailing'. + * main.c: New option '--loose-trailing'. * main.c (main): Option '-S, --volume-size' now keeps input files. - * main.c: Replaced 'bits/byte' with inverse compression ratio. + * main.c: Replace 'bits/byte' with inverse compression ratio. * main.c: Show final diagnostic when testing multiple files. * main.c: Do not add a second .lz extension to the arg of -o. * main.c: Show dictionary size at verbosity level 4 (-vvvv). - * lzlib.texi: Added chapter 'Invoking minilzip'. + * lzlib.texi: New chapter 'Invoking minilzip'. 2017-04-11 Antonio Diaz Diaz @@ -34,14 +73,15 @@ * Compression time of options -1 to -9 has been reduced by 1%. * Decompression time has been reduced by 3%. * main.c: Continue testing if any input file is a terminal. - * License of the library changed to "2-clause BSD". + * Change the license of the library to "2-clause BSD". 2016-05-17 Antonio Diaz Diaz * Version 1.8 released. * lzlib.h: Define LZ_API_VERSION to 1. - * decoder.c (LZd_verify_trailer): Removed test of final code. - * main.c: Added new option '-a, --trailing-error'. + * lzlib.c (LZ_decompress_sync_to_member): Add skipped size to in_size. + * decoder.c (LZd_verify_trailer): Remove test of final code. + * main.c: New option '-a, --trailing-error'. * main.c (main): Delete '--output' file if infd is a terminal. * main.c (main): Don't use stdin more than once. * configure: Avoid warning on some shells when testing for gcc. @@ -52,26 +92,25 @@ 2015-07-08 Antonio Diaz Diaz * Version 1.7 released. - * Ported fast encoder and option '-0' from lzip. + * Port fast encoder and option '-0' from lzip. * If open-->write-->finish, produce same dictionary size as lzip. - * Makefile.in: Added new targets 'install*-compress'. + * Makefile.in: New targets 'install*-compress'. 2014-08-27 Antonio Diaz Diaz * Version 1.6 released. * Compression ratio of option '-9' has been slightly increased. - * configure: Added new option '--disable-static'. - * configure: Added new option '--disable-ldconfig'. + * configure: New options '--disable-static' and '--disable-ldconfig'. * Makefile.in: Ignore errors from ldconfig. * Makefile.in: Use 'CFLAGS' in every invocation of 'CC'. * main.c (close_and_set_permissions): Behave like 'cp -p'. - * lzlib.texinfo: Renamed to lzlib.texi. - * License changed to "GPL version 2 or later with link exception". + * lzlib.texinfo: Rename to lzlib.texi. + * Change license to "GPL version 2 or later with link exception". 2013-09-15 Antonio Diaz Diaz * Version 1.5 released. - * Removed decompression support for version 0 files. + * Remove decompression support for version 0 files. * The LZ_compress_sync_flush mechanism has been fixed (again). * Minor fixes. @@ -82,12 +121,11 @@ * Compression ratio has been slightly increased. * Compression time has been reduced by 8%. * Decompression time has been reduced by 7%. - * lzlib.h: Changed 'long long' values to 'unsigned long long'. + * lzlib.h: Change 'long long' values to 'unsigned long long'. * encoder.c (Mf_init): Reduce minimum buffer size to 64KiB. * lzlib.c (LZ_decompress_read): Tell LZ_header_error from LZ_unexpected_eof the same way as lzip does. - * Makefile.in: Added new target 'install-as-lzip'. - * Makefile.in: Added new target 'install-bin'. + * Makefile.in: New targets 'install-as-lzip' and 'install-bin'. * main.c: Use 'setmode' instead of '_setmode' on Windows and OS/2. * main.c: Define 'strtoull' to 'strtoul' on Windows. @@ -95,7 +133,7 @@ * Version 1.3 released. * Translated to C from the C++ source of lzlib 1.2. - * configure: 'datadir' renamed to 'datarootdir'. + * configure: Rename 'datadir' to 'datarootdir'. 2011-10-25 Antonio Diaz Diaz @@ -104,10 +142,9 @@ independently of the value of 'pos_state'. This gives better compression for large values of '--match-length' without being slower. - * encoder.h encoder.cc: Optimize pair price calculations. This - reduces compression time for large values of '--match-length' - by up to 6%. - * main.cc: Added new option '-F, --recompress'. + * encoder.h, encoder.cc: Optimize pair price calculations, reducing + compression time for large values of '--match-length' by up to 6%. + * main.cc: New option '-F, --recompress'. * Makefile.in: 'make install' no longer tries to run '/sbin/ldconfig' on systems lacking it. @@ -117,7 +154,7 @@ * Compression time has been reduced by 2%. * All declarations not belonging to the API have been encapsulated in the namespace 'Lzlib'. - * testsuite: 'test1' renamed to 'test.txt'. Added new tests. + * testsuite: Rename 'test1' to 'test.txt'. New tests. * Match length limits set by options -1 to -9 of minilzip have been changed to match those of lzip 1.11. * main.cc: Set stdin/stdout in binary mode on OS2. @@ -127,14 +164,11 @@ 2010-05-08 Antonio Diaz Diaz * Version 1.0 released. - * Added new function LZ_decompress_member_finished. - * Added new function LZ_decompress_member_version. - * Added new function LZ_decompress_dictionary_size. - * Added new function LZ_decompress_data_crc. - * Variables declared 'extern' have been encapsulated in a - namespace. - * main.cc: Fixed warning about fchown's return value being ignored. - * decoder.h: Input_buffer integrated in Range_decoder. + * New functions LZ_decompress_member_version, LZ_decompress_data_crc, + LZ_decompress_member_finished, and LZ_decompress_dictionary_size. + * Variables declared 'extern' have been encapsulated in a namespace. + * main.cc: Fix warning about fchown's return value being ignored. + * decoder.h: Integrate Input_buffer in Range_decoder. 2010-02-10 Antonio Diaz Diaz @@ -145,28 +179,26 @@ 2010-01-17 Antonio Diaz Diaz * Version 0.8 released. - * Added new function LZ_decompress_reset. - * Added new function LZ_decompress_sync_to_member. - * Added new function LZ_decompress_write_size. - * Added new function LZ_strerror. - * lzlib.h: API change. Replaced 'enum' with functions for values - of dictionary size limits to make interface names consistent. - * lzlib.h: API change. 'LZ_errno' replaced with 'LZ_Errno'. - * lzlib.h: API change. Replaced 'void *' with 'struct LZ_Encoder *' + * New functions LZ_decompress_reset, LZ_decompress_sync_to_member, + LZ_decompress_write_size, and LZ_strerror. + * lzlib.h: API change. Replace 'enum' with functions for values of + dictionary size limits to make interface names consistent. + * lzlib.h: API change. Rename 'LZ_errno' to 'LZ_Errno'. + * lzlib.h: API change. Replace 'void *' with 'struct LZ_Encoder *' and 'struct LZ_Decoder *' to make interface type safe. - * decoder.cc: Truncated member trailer is now correctly detected. + * decoder.cc: A truncated member trailer is now correctly detected. * encoder.cc: Matchfinder::reset now also clears at_stream_end_, allowing LZ_compress_restart_member to restart a finished stream. * lzlib.cc: Accept only query or close operations after a fatal error has occurred. - * Shared version of lzlib is no longer built by default. + * The shared version of lzlib is no longer built by default. * check.sh: Use 'test1' instead of 'COPYING' for testing. 2009-10-20 Antonio Diaz Diaz * Version 0.7 released. * Compression time has been reduced by 4%. - * check.sh: Removed -9 to run in less than 256MiB of RAM. + * check.sh: Remove -9 to run in less than 256MiB of RAM. * lzcheck.cc: Read files of any size up to 2^63 bytes. 2009-09-02 Antonio Diaz Diaz @@ -178,15 +210,14 @@ * Version 0.5 released. * Decompression speed has been improved. - * main.cc (signal_handler): Declared as 'extern "C"'. + * main.cc (signal_handler): Declare as 'extern "C"'. 2009-06-03 Antonio Diaz Diaz * Version 0.4 released. - * Added new function LZ_compress_sync_flush. - * Added new function LZ_compress_write_size. + * New functions LZ_compress_sync_flush and LZ_compress_write_size. * Decompression speed has been improved. - * Added chapter 'Buffering' to the manual. + * lzlib.texinfo: New chapter 'Buffering'. 2009-05-03 Antonio Diaz Diaz @@ -196,16 +227,16 @@ 2009-04-26 Antonio Diaz Diaz * Version 0.2 released. - * Fixed a segfault when decompressing trailing garbage. - * Fixed a false positive in LZ_(de)compress_finished. + * Fix a segfault when decompressing trailing garbage. + * Fix a false positive in LZ_(de)compress_finished. 2009-04-21 Antonio Diaz Diaz * Version 0.1 released. -Copyright (C) 2009-2019 Antonio Diaz Diaz. +Copyright (C) 2009-2021 Antonio Diaz Diaz. This file is a collection of facts, and thus it is not copyrightable, -but just in case, you have unlimited permission to copy, distribute and +but just in case, you have unlimited permission to copy, distribute, and modify it. diff --git a/INSTALL b/INSTALL index b5889df..a9a870e 100644 --- a/INSTALL +++ b/INSTALL @@ -1,13 +1,13 @@ Requirements ------------ -You will need a C compiler. -I use gcc 5.3.0 and 4.1.2, but the code should compile with any standards +You will need a C99 compiler. (gcc 3.3.6 or newer is recommended). +I use gcc 6.1.0 and 4.1.2, but the code should compile with any standards compliant compiler. Gcc is available at http://gcc.gnu.org. The operating system must allow signal handlers read access to objects with static storage duration so that the cleanup handler for Control-C can delete -the partial output file. +the partial output file. (This requirement is for minilzip only). Procedure @@ -41,27 +41,29 @@ the main archive. documentation. (You may need to run ldconfig also). Or type 'make install-compress', which additionally compresses the - info manual after installation. (Installing compressed docs may - become the default in the future). + info manual after installation. + (Installing compressed docs may become the default in the future). - You can install only the library, the info manual or the man page by - typing 'make install-lib', 'make install-info' or 'make install-man' - respectively. + You can install only the library or the info manual by typing + 'make install-lib' or 'make install-info' respectively. - 'make install-bin' installs the minilzip program and its man page. - 'install-bin' installs a shared minilzip if the shared library has + 'make install-bin install-man' installs the program minilzip and its man + page. 'install-bin' installs a shared minilzip if the shared library has been configured. Else it installs a static minilzip. - 'make install-as-lzip' runs 'make install-bin' and then links - minilzip to the name 'lzip'. + 'make install-bin-compress' additionally compresses the man page after + installation. + + 'make install-as-lzip' runs 'make install-bin' and then links minilzip to + the name 'lzip'. Another way ----------- You can also compile lzlib into a separate directory. -To do this, you must use a version of 'make' that supports the 'VPATH' -variable, such as GNU 'make'. 'cd' to the directory where you want the +To do this, you must use a version of 'make' that supports the variable +'VPATH', such as GNU 'make'. 'cd' to the directory where you want the object files and executables to go and run the 'configure' script. -'configure' automatically checks for the source code in '.', in '..' and +'configure' automatically checks for the source code in '.', in '..', and in the directory that 'configure' is in. 'configure' recognizes the option '--srcdir=DIR' to control where to @@ -72,7 +74,7 @@ After running 'configure', you can run 'make' and 'make install' as explained above. -Copyright (C) 2009-2019 Antonio Diaz Diaz. +Copyright (C) 2009-2021 Antonio Diaz Diaz. This file is free documentation: you have unlimited permission to copy, -distribute and modify it. +distribute, and modify it. diff --git a/Makefile.in b/Makefile.in index 1ac03b2..94e3770 100644 --- a/Makefile.in +++ b/Makefile.in @@ -15,8 +15,10 @@ objs = carg_parser.o main.o .PHONY : all install install-bin install-info install-man \ install-strip install-compress install-strip-compress \ install-bin-strip install-info-compress install-man-compress \ - install-lib install-lib-strip uninstall-lib install-as-lzip \ - uninstall uninstall-bin uninstall-info uninstall-man \ + install-bin-compress install-bin-strip-compress \ + install-lib install-lib-strip \ + install-as-lzip \ + uninstall uninstall-bin uninstall-lib uninstall-info uninstall-man \ doc info man check dist clean distclean all : $(progname_static) $(progname_shared) @@ -36,6 +38,9 @@ $(progname)_shared : $(objs) lib$(libname).so.$(pkgversion) bbexample : bbexample.o lib$(libname).a $(CC) $(LDFLAGS) $(CFLAGS) -o $@ bbexample.o lib$(libname).a +ffexample : ffexample.o lib$(libname).a + $(CC) $(LDFLAGS) $(CFLAGS) -o $@ ffexample.o lib$(libname).a + lzcheck : lzcheck.o lib$(libname).a $(CC) $(LDFLAGS) $(CFLAGS) -o $@ lzcheck.o lib$(libname).a @@ -57,6 +62,7 @@ lzlib.o : Makefile $(lzdeps) lzlib_sh.o : Makefile $(lzdeps) main.o : carg_parser.h lzlib.h bbexample.o : Makefile lzlib.h +ffexample.o : Makefile lzlib.h lzcheck.o : Makefile lzlib.h @@ -75,15 +81,17 @@ $(VPATH)/doc/$(progname).1 : $(progname) Makefile : $(VPATH)/configure $(VPATH)/Makefile.in ./config.status -check : $(progname) bbexample lzcheck +check : $(progname) bbexample ffexample lzcheck @$(VPATH)/testsuite/check.sh $(VPATH)/testsuite $(pkgversion) install : install-lib install-info install-strip : install-lib-strip install-info install-compress : install-lib install-info-compress install-strip-compress : install-lib-strip install-info-compress +install-bin-compress : install-bin install-man-compress +install-bin-strip-compress : install-bin-strip install-man-compress -install-bin : all install-man +install-bin : all if [ ! -d "$(DESTDIR)$(bindir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(bindir)" ; fi $(INSTALL_PROGRAM) ./$(progname_lzip) "$(DESTDIR)$(bindir)/$(progname)" @@ -119,7 +127,7 @@ install-info : -rm -f "$(DESTDIR)$(infodir)/$(pkgname).info"* $(INSTALL_DATA) $(VPATH)/doc/$(pkgname).info "$(DESTDIR)$(infodir)/$(pkgname).info" -if $(CAN_RUN_INSTALLINFO) ; then \ - install-info --info-dir="$(DESTDIR)$(infodir)" "$(DESTDIR)$(infodir)/$(pkgname).info" ; \ + install-info --info-dir="$(DESTDIR)$(infodir)" "$(DESTDIR)$(infodir)/$(pkgname).info" ; \ fi install-info-compress : install-info @@ -139,7 +147,7 @@ install-as-lzip : install-bin uninstall : uninstall-info uninstall-lib -uninstall-bin : uninstall-man +uninstall-bin : -rm -f "$(DESTDIR)$(bindir)/$(progname)" uninstall-lib : @@ -151,7 +159,7 @@ uninstall-lib : uninstall-info : -if $(CAN_RUN_INSTALLINFO) ; then \ - install-info --info-dir="$(DESTDIR)$(infodir)" --remove "$(DESTDIR)$(infodir)/$(pkgname).info" ; \ + install-info --info-dir="$(DESTDIR)$(infodir)" --remove "$(DESTDIR)$(infodir)/$(pkgname).info" ; \ fi -rm -f "$(DESTDIR)$(infodir)/$(pkgname).info"* @@ -177,16 +185,19 @@ dist : doc $(DISTNAME)/*.c \ $(DISTNAME)/testsuite/check.sh \ $(DISTNAME)/testsuite/test.txt \ - $(DISTNAME)/testsuite/test2.txt \ + $(DISTNAME)/testsuite/fox_lf \ + $(DISTNAME)/testsuite/fox.lz \ + $(DISTNAME)/testsuite/fox_*.lz \ $(DISTNAME)/testsuite/test_sync.lz \ - $(DISTNAME)/testsuite/test.txt.lz + $(DISTNAME)/testsuite/test.txt.lz \ + $(DISTNAME)/testsuite/test_em.txt.lz rm -f $(DISTNAME) lzip -v -9 $(DISTNAME).tar clean : - -rm -f $(progname) $(objs) - -rm -f $(progname)_shared lzlib_sh.o *.so.$(pkgversion) - -rm -f bbexample bbexample.o lzcheck lzcheck.o lzlib.o *.a + -rm -f $(progname) $(objs) lzlib.o lib$(libname).a + -rm -f $(progname)_shared lzlib_sh.o lib$(libname).so* + -rm -f bbexample bbexample.o ffexample ffexample.o lzcheck lzcheck.o distclean : clean -rm -f Makefile config.status *.tar *.tar.lz diff --git a/NEWS b/NEWS index bdf7f32..7b01d52 100644 --- a/NEWS +++ b/NEWS @@ -1,30 +1,92 @@ -Changes in version 1.11: +Changes in version 1.12: -In case of decompression error caused by corrupt or truncated data, -LZ_decompress_read now does not signal the error immediately to the -application, but waits until all decoded bytes have been read. This -allows tools like tarlz to recover as much data as possible from damaged -members. +The value of the version test macro 'LZ_API_VERSION' is now defined as +1000 * major + minor. For version 1.12 it is 1012. +This change does not affect the soversion. -It is now an error to specify two different operations to minilzip in -the command line (--decompress and --test). +The new function 'LZ_api_version', which returns the LZ_API_VERSION of the +library object code being used, has been added to lzlib. -Minilzip now also checks for errors when closing the input file. +If end of file is found at member trailer or EOS marker, +'LZ_decompress_errno' now returns 'LZ_unexpected_eof' instead of +'LZ_data_error'. -Minilzip now compiles on DOS with DJGPP. (Patch from Robert Riebisch). +Decompression speed has been slightly increased. -The descriptions of '-0..-9', '-m' and '-s' in the manual have been -improved. +A bug has been fixed in minilzip that falsely reported a library stall when +decompressing a file with empty members. -It has been documented that it is safe to call 'LZ_(de)compress_finish' -as many times as needed. Examples in the manual have been simplified. +The new option '--check-lib', which compares the version of lzlib used to +compile minilzip with the version actually being used, has been added to +minilzip. -The configure script now accepts appending options to CFLAGS using the -syntax 'CFLAGS+=OPTIONS'. +Minilzip now reports an error if a file name is empty (minilzip -t ""). -Makefile targets 'install-bin*' have been renamed to 'install-lib*'. New -'install-bin*' targets have been created that install a shared minilzip, -or a static minilzip if the shared library has not been configured. +Option '-o, --output' now behaves like '-c, --stdout', but sending the +output unconditionally to a file instead of to standard output. See the new +description of '-o' in the manual. This change is not backwards compatible. +Therefore commands like: + minilzip -o foo.lz - bar < foo +must now be split into: + minilzip -o foo.lz - < foo + minilzip bar +or rewritten as: + minilzip - bar < foo > foo.lz -It has been documented in INSTALL the use of -CFLAGS+='-D __USE_MINGW_ANSI_STDIO' when compiling on MinGW. +When using '-c' or '-o', minilzip now checks whether the output is a +terminal only once. + +Minilzip now does not even open the output file if the input file is a terminal. + +The words 'decompressed' and 'compressed' have been replaced with the +shorter 'out' and 'in' in the verbose output of minilzip when decompressing +or testing. + +It has been documented in the manual that 'LZ_(de)compress_close' and +'LZ_(de)compress_errno' can be called with a null argument. + +It has been documented in the manual that the LZMA marker '3' ("Sync Flush" +marker) is not allowed in lzip files. Marker '3' is a device for interactive +communication between applications using lzlib, but is useless and wasteful +in a file, and is excluded from the media type 'application/lzip'. The LZMA +marker '2' ("End Of Stream" marker) is the only marker allowed in lzip +files. + +It has been documented in the manual that not calling 'LZ_decompress_finish' +prevents lzlib from detecting a truncated member. + +It has been documented in the manual that 'LZ_decompress_read' returns at +least once per member so that 'LZ_decompress_member_finished' can be called +(and trailer data retrieved) for each member, even for empty members. +Therefore, 'LZ_decompress_read' returning 0 does not mean that the end of +the stream has been reached. + +It has been documented in the manual that 'LZ_(de)compress_read' can be +called with a null buffer pointer argument. + +Real code examples for the most common uses of the library have been added +to the tutorial. + +'bbexample.c' has been simplified to not use 'LZ_(de)compress_write_size'. + +'lzcheck' now accepts options '-s' (to check LZ_compress_sync_flush) and +'-m' (to check member by member decompression). + +'lzcheck.c' now also tests member by member decompression without +intermediate calls to 'LZ_decompress_finish'. + +The new file 'ffexample.c', containing example functions for file-to-file +compression/decompression, has been added to the distribution. + +The commands needed to extract files from a tar.lz archive have been +documented in the output of 'minilzip --help' and in the man page. + +'make install-bin' no longer installs the minilzip man page. This is to +prevent 'make install-bin install-man-compress' from installing the man page +twice before compressing it. + +The new targets 'install-bin-compress' and 'install-bin-strip-compress', +which install a (stripped) minilzip and a compressed man page, have been +added to the Makefile. + +9 new test files have been added to the testsuite. diff --git a/README b/README index fa1da74..ee6e6d7 100644 --- a/README +++ b/README @@ -1,65 +1,64 @@ Description -Lzlib is a data compression library providing in-memory LZMA compression -and decompression functions, including integrity checking of the -decompressed data. The compressed data format used by the library is the -lzip format. Lzlib is written in C. +Lzlib is a data compression library providing in-memory LZMA compression and +decompression functions, including integrity checking of the decompressed +data. The compressed data format used by the library is the lzip format. +Lzlib is written in C. The lzip file format is designed for data sharing and long-term archiving, taking into account both data integrity and decoder availability: * The lzip format provides very safe integrity checking and some data - recovery means. The lziprecover program can repair bit flip errors - (one of the most common forms of data corruption) in lzip files, - and provides data recovery capabilities, including error-checked - merging of damaged copies of a file. + recovery means. The program lziprecover can repair bit flip errors + (one of the most common forms of data corruption) in lzip files, and + provides data recovery capabilities, including error-checked merging + of damaged copies of a file. - * The lzip format is as simple as possible (but not simpler). The - lzip manual provides the source code of a simple decompressor - along with a detailed explanation of how it works, so that with - the only help of the lzip manual it would be possible for a - digital archaeologist to extract the data from a lzip file long - after quantum computers eventually render LZMA obsolete. + * The lzip format is as simple as possible (but not simpler). The lzip + manual provides the source code of a simple decompressor along with a + detailed explanation of how it works, so that with the only help of the + lzip manual it would be possible for a digital archaeologist to extract + the data from a lzip file long after quantum computers eventually + render LZMA obsolete. * Additionally the lzip reference implementation is copylefted, which guarantees that it will remain free forever. -A nice feature of the lzip format is that a corrupt byte is easier to -repair the nearer it is from the beginning of the file. Therefore, with -the help of lziprecover, losing an entire archive just because of a -corrupt byte near the beginning is a thing of the past. +A nice feature of the lzip format is that a corrupt byte is easier to repair +the nearer it is from the beginning of the file. Therefore, with the help of +lziprecover, losing an entire archive just because of a corrupt byte near +the beginning is a thing of the past. -The functions and variables forming the interface of the compression -library are declared in the file 'lzlib.h'. Usage examples of the -library are given in the files 'main.c' and 'bbexample.c' from the -source distribution. +The functions and variables forming the interface of the compression library +are declared in the file 'lzlib.h'. Usage examples of the library are given +in the files 'bbexample.c', 'ffexample.c', and 'main.c' from the source +distribution. Compression/decompression is done by repeatedly calling a couple of -read/write functions until all the data have been processed by the -library. This interface is safer and less error prone than the -traditional zlib interface. +read/write functions until all the data have been processed by the library. +This interface is safer and less error prone than the traditional zlib +interface. Compression/decompression is done when the read function is called. This -means the value returned by the position functions will not be updated -until a read call, even if a lot of data are written. If you want the -data to be compressed in advance, just call the read function with a -size equal to 0. +means the value returned by the position functions will not be updated until +a read call, even if a lot of data are written. If you want the data to be +compressed in advance, just call the read function with a size equal to 0. If all the data to be compressed are written in advance, lzlib will -automatically adjust the header of the compressed data to use the -largest dictionary size that does not exceed neither the data size nor -the limit given to LZ_compress_open. This feature reduces the amount of -memory needed for decompression and allows minilzip to produce identical -compressed output as lzip. +automatically adjust the header of the compressed data to use the largest +dictionary size that does not exceed neither the data size nor the limit +given to 'LZ_compress_open'. This feature reduces the amount of memory +needed for decompression and allows minilzip to produce identical compressed +output as lzip. -Lzlib will correctly decompress a data stream which is the concatenation -of two or more compressed data streams. The result is the concatenation -of the corresponding decompressed data streams. Integrity testing of -concatenated compressed data streams is also supported. +Lzlib will correctly decompress a data stream which is the concatenation of +two or more compressed data streams. The result is the concatenation of the +corresponding decompressed data streams. Integrity testing of concatenated +compressed data streams is also supported. Lzlib is able to compress and decompress streams of unlimited size by -automatically creating multimember output. The members so created are -large, about 2 PiB each. +automatically creating multimember output. The members so created are large, +about 2 PiB each. All the library functions are thread safe. The library does not install any signal handler. The decoder checks the consistency of the compressed @@ -67,16 +66,15 @@ data, so the library should never crash even in case of corrupted input. In spite of its name (Lempel-Ziv-Markov chain-Algorithm), LZMA is not a concrete algorithm; it is more like "any algorithm using the LZMA coding -scheme". For example, the option '-0' of lzip uses the scheme in almost -the simplest way possible; issuing the longest match it can find, or a -literal byte if it can't find a match. Inversely, a much more elaborated -way of finding coding sequences of minimum size than the one currently -used by lzip could be developed, and the resulting sequence could also -be coded using the LZMA coding scheme. +scheme". For example, the option '-0' of lzip uses the scheme in almost the +simplest way possible; issuing the longest match it can find, or a literal +byte if it can't find a match. Inversely, a much more elaborated way of +finding coding sequences of minimum size than the one currently used by lzip +could be developed, and the resulting sequence could also be coded using the +LZMA coding scheme. -Lzlib currently implements two variants of the LZMA algorithm; fast -(used by option '-0' of minilzip) and normal (used by all other -compression levels). +Lzlib currently implements two variants of the LZMA algorithm; fast (used by +option '-0' of minilzip) and normal (used by all other compression levels). The high compression of LZMA comes from combining two basic, well-proven compression ideas: sliding dictionaries (LZ77/78) and markov models (the @@ -85,20 +83,20 @@ similar order-0 entropy coder as its last stage) with segregation of contexts according to what the bits are used for. The ideas embodied in lzlib are due to (at least) the following people: -Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for -the definition of Markov chains), G.N.N. Martin (for the definition of -range encoding), Igor Pavlov (for putting all the above together in -LZMA), and Julian Seward (for bzip2's CLI). +Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the +definition of Markov chains), G.N.N. Martin (for the definition of range +encoding), Igor Pavlov (for putting all the above together in LZMA), and +Julian Seward (for bzip2's CLI). -LANGUAGE NOTE: Uncompressed = not compressed = plain data; it may never -have been compressed. Decompressed is used to refer to data which have -undergone the process of decompression. +LANGUAGE NOTE: Uncompressed = not compressed = plain data; it may never have +been compressed. Decompressed is used to refer to data which have undergone +the process of decompression. -Copyright (C) 2009-2019 Antonio Diaz Diaz. +Copyright (C) 2009-2021 Antonio Diaz Diaz. This file is free documentation: you have unlimited permission to copy, -distribute and modify it. +distribute, and modify it. The file Makefile.in is a data file used by configure to produce the Makefile. It has the same copyright owner and permissions that configure diff --git a/bbexample.c b/bbexample.c index e953c35..96257ee 100644 --- a/bbexample.c +++ b/bbexample.c @@ -1,21 +1,20 @@ -/* Buffer to buffer example - Test program for the lzlib library - Copyright (C) 2010-2019 Antonio Diaz Diaz. +/* Buffer to buffer example - Test program for the library lzlib + Copyright (C) 2010-2021 Antonio Diaz Diaz. - This program is free software: you have unlimited permission - to copy, distribute and modify it. + This program is free software: you have unlimited permission + to copy, distribute, and modify it. - Usage is: - bbexample filename + Usage: bbexample filename - This program is an example of how buffer-to-buffer - compression/decompression can be implemented using lzlib. + This program is an example of how buffer-to-buffer + compression/decompression can be implemented using lzlib. */ +#define _FILE_OFFSET_BITS 64 + #include #include -#ifndef __cplusplus #include -#endif #include #include #include @@ -24,6 +23,10 @@ #include "lzlib.h" +#ifndef min + #define min(x,y) ((x) <= (y) ? (x) : (y)) +#endif + /* Returns the address of a malloc'd buffer containing the file data and the file size in '*file_sizep'. @@ -35,28 +38,26 @@ uint8_t * read_file( const char * const name, long * const file_sizep ) uint8_t * buffer, * tmp; FILE * const f = fopen( name, "rb" ); if( !f ) - { - fprintf( stderr, "bbexample: Can't open input file '%s': %s\n", - name, strerror( errno ) ); - return 0; - } + { fprintf( stderr, "bbexample: Can't open input file '%s': %s\n", + name, strerror( errno ) ); return 0; } buffer = (uint8_t *)malloc( buffer_size ); if( !buffer ) - { fputs( "bbexample: Not enough memory.\n", stderr ); return 0; } + { fputs( "bbexample: read_file: Not enough memory.\n", stderr ); + fclose( f ); return 0; } file_size = fread( buffer, 1, buffer_size, f ); while( file_size >= buffer_size ) { if( buffer_size >= LONG_MAX ) { fprintf( stderr, "bbexample: Input file '%s' is too large.\n", name ); - free( buffer ); return 0; + free( buffer ); fclose( f ); return 0; } buffer_size = ( buffer_size <= LONG_MAX / 2 ) ? 2 * buffer_size : LONG_MAX; tmp = (uint8_t *)realloc( buffer, buffer_size ); if( !tmp ) - { fputs( "bbexample: Not enough memory.\n", stderr ); - free( buffer ); return 0; } + { fputs( "bbexample: read_file: Not enough memory.\n", stderr ); + free( buffer ); fclose( f ); return 0; } buffer = tmp; file_size += fread( buffer + file_size, 1, buffer_size - file_size, f ); } @@ -64,7 +65,7 @@ uint8_t * read_file( const char * const name, long * const file_sizep ) { fprintf( stderr, "bbexample: Error reading file '%s': %s\n", name, strerror( errno ) ); - free( buffer ); return 0; + free( buffer ); fclose( f ); return 0; } fclose( f ); *file_sizep = file_size; @@ -72,13 +73,13 @@ uint8_t * read_file( const char * const name, long * const file_sizep ) } -/* Compresses 'size' bytes from 'data'. Returns the address of a - malloc'd buffer containing the compressed data and its size in - '*out_sizep'. - In case of error, returns 0 and does not modify '*out_sizep'. +/* Compresses 'insize' bytes from 'inbuf'. + Returns the address of a malloc'd buffer containing the compressed data, + and the size of the data in '*outlenp'. + In case of error, returns 0 and does not modify '*outlenp'. */ -uint8_t * bbcompress( const uint8_t * const data, const long size, - const int level, long * const out_sizep ) +uint8_t * bbcompressl( const uint8_t * const inbuf, const long insize, + const int level, long * const outlenp ) { struct Lzma_options { @@ -100,132 +101,246 @@ uint8_t * bbcompress( const uint8_t * const data, const long size, { 3 << 23, 132 }, /* -8 */ { 1 << 25, 273 } }; /* -9 */ struct Lzma_options encoder_options; - const unsigned long long member_size = 0x7FFFFFFFFFFFFFFFULL; /* INT64_MAX */ struct LZ_Encoder * encoder; - uint8_t * new_data; - const long delta_size = ( size / 4 ) + 64; /* size may be zero */ - long new_data_size = delta_size; /* initial size */ - long new_pos = 0; - long written = 0; + uint8_t * outbuf; + const long delta_size = ( insize / 4 ) + 64; /* insize may be zero */ + long outsize = delta_size; /* initial outsize */ + long inpos = 0; + long outpos = 0; bool error = false; if( level < 0 || level > 9 ) return 0; encoder_options = option_mapping[level]; - if( encoder_options.dictionary_size > size && level != 0 ) - encoder_options.dictionary_size = size; /* saves memory */ + if( encoder_options.dictionary_size > insize && level != 0 ) + encoder_options.dictionary_size = insize; /* saves memory */ if( encoder_options.dictionary_size < LZ_min_dictionary_size() ) encoder_options.dictionary_size = LZ_min_dictionary_size(); encoder = LZ_compress_open( encoder_options.dictionary_size, - encoder_options.match_len_limit, member_size ); - if( !encoder || LZ_compress_errno( encoder ) != LZ_ok ) - { LZ_compress_close( encoder ); return 0; } - - new_data = (uint8_t *)malloc( new_data_size ); - if( !new_data ) - { LZ_compress_close( encoder ); return 0; } + encoder_options.match_len_limit, INT64_MAX ); + outbuf = (uint8_t *)malloc( outsize ); + if( !encoder || LZ_compress_errno( encoder ) != LZ_ok || !outbuf ) + { free( outbuf ); LZ_compress_close( encoder ); return 0; } while( true ) { - int rd; - if( LZ_compress_write_size( encoder ) > 0 ) - { - if( written < size ) - { - const int wr = LZ_compress_write( encoder, data + written, - size - written ); - if( wr < 0 ) { error = true; break; } - written += wr; - } - if( written >= size ) LZ_compress_finish( encoder ); - } - rd = LZ_compress_read( encoder, new_data + new_pos, - new_data_size - new_pos ); - if( rd < 0 ) { error = true; break; } - new_pos += rd; + int ret = LZ_compress_write( encoder, inbuf + inpos, + min( INT_MAX, insize - inpos ) ); + if( ret < 0 ) { error = true; break; } + inpos += ret; + if( inpos >= insize ) LZ_compress_finish( encoder ); + ret = LZ_compress_read( encoder, outbuf + outpos, + min( INT_MAX, outsize - outpos ) ); + if( ret < 0 ) { error = true; break; } + outpos += ret; if( LZ_compress_finished( encoder ) == 1 ) break; - if( new_pos >= new_data_size ) + if( outpos >= outsize ) { uint8_t * tmp; - if( new_data_size > LONG_MAX - delta_size ) { error = true; break; } - new_data_size += delta_size; - tmp = (uint8_t *)realloc( new_data, new_data_size ); + if( outsize > LONG_MAX - delta_size ) { error = true; break; } + outsize += delta_size; + tmp = (uint8_t *)realloc( outbuf, outsize ); if( !tmp ) { error = true; break; } - new_data = tmp; + outbuf = tmp; } } if( LZ_compress_close( encoder ) < 0 ) error = true; - if( error ) { free( new_data ); return 0; } - *out_sizep = new_pos; - return new_data; + if( error ) { free( outbuf ); return 0; } + *outlenp = outpos; + return outbuf; } -/* Decompresses 'size' bytes from 'data'. Returns the address of a - malloc'd buffer containing the decompressed data and its size in - '*out_sizep'. - In case of error, returns 0 and does not modify '*out_sizep'. +/* Decompresses 'insize' bytes from 'inbuf'. + Returns the address of a malloc'd buffer containing the decompressed + data, and the size of the data in '*outlenp'. + In case of error, returns 0 and does not modify '*outlenp'. */ -uint8_t * bbdecompress( const uint8_t * const data, const long size, - long * const out_sizep ) +uint8_t * bbdecompressl( const uint8_t * const inbuf, const long insize, + long * const outlenp ) { struct LZ_Decoder * const decoder = LZ_decompress_open(); - uint8_t * new_data; - const long delta_size = size; /* size must be > zero */ - long new_data_size = delta_size; /* initial size */ - long new_pos = 0; - long written = 0; + const long delta_size = insize; /* insize must be > zero */ + long outsize = delta_size; /* initial outsize */ + uint8_t * outbuf = (uint8_t *)malloc( outsize ); + long inpos = 0; + long outpos = 0; bool error = false; - if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok ) - { LZ_decompress_close( decoder ); return 0; } - - new_data = (uint8_t *)malloc( new_data_size ); - if( !new_data ) - { LZ_decompress_close( decoder ); return 0; } + if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok || !outbuf ) + { free( outbuf ); LZ_decompress_close( decoder ); return 0; } while( true ) { - int rd; - if( LZ_decompress_write_size( decoder ) > 0 ) - { - if( written < size ) - { - const int wr = LZ_decompress_write( decoder, data + written, - size - written ); - if( wr < 0 ) { error = true; break; } - written += wr; - } - if( written >= size ) LZ_decompress_finish( decoder ); - } - rd = LZ_decompress_read( decoder, new_data + new_pos, - new_data_size - new_pos ); - if( rd < 0 ) { error = true; break; } - new_pos += rd; + int ret = LZ_decompress_write( decoder, inbuf + inpos, + min( INT_MAX, insize - inpos ) ); + if( ret < 0 ) { error = true; break; } + inpos += ret; + if( inpos >= insize ) LZ_decompress_finish( decoder ); + ret = LZ_decompress_read( decoder, outbuf + outpos, + min( INT_MAX, outsize - outpos ) ); + if( ret < 0 ) { error = true; break; } + outpos += ret; if( LZ_decompress_finished( decoder ) == 1 ) break; - if( new_pos >= new_data_size ) + if( outpos >= outsize ) { uint8_t * tmp; - if( new_data_size > LONG_MAX - delta_size ) { error = true; break; } - new_data_size += delta_size; - tmp = (uint8_t *)realloc( new_data, new_data_size ); + if( outsize > LONG_MAX - delta_size ) { error = true; break; } + outsize += delta_size; + tmp = (uint8_t *)realloc( outbuf, outsize ); if( !tmp ) { error = true; break; } - new_data = tmp; + outbuf = tmp; } } if( LZ_decompress_close( decoder ) < 0 ) error = true; - if( error ) { free( new_data ); return 0; } - *out_sizep = new_pos; - return new_data; + if( error ) { free( outbuf ); return 0; } + *outlenp = outpos; + return outbuf; + } + + +/* Test the whole file at all levels. */ +int full_test( const uint8_t * const inbuf, const long insize ) + { + int level; + for( level = 0; level <= 9; ++level ) + { + long midsize = 0, outsize = 0; + uint8_t * outbuf; + uint8_t * midbuf = bbcompressl( inbuf, insize, level, &midsize ); + if( !midbuf ) + { fputs( "bbexample: full_test: Not enough memory or compress error.\n", + stderr ); return 1; } + + outbuf = bbdecompressl( midbuf, midsize, &outsize ); + free( midbuf ); + if( !outbuf ) + { fputs( "bbexample: full_test: Not enough memory or decompress error.\n", + stderr ); return 1; } + + if( insize != outsize || + ( insize > 0 && memcmp( inbuf, outbuf, insize ) != 0 ) ) + { fputs( "bbexample: full_test: Decompressed data differs from original.\n", + stderr ); free( outbuf ); return 1; } + + free( outbuf ); + } + return 0; + } + + +/* Compresses 'insize' bytes from 'inbuf' to 'outbuf'. + Returns the size of the compressed data in '*outlenp'. + In case of error, or if 'outsize' is too small, returns false and does + not modify '*outlenp'. +*/ +bool bbcompress( const uint8_t * const inbuf, const int insize, + const int dictionary_size, const int match_len_limit, + uint8_t * const outbuf, const int outsize, + int * const outlenp ) + { + int inpos = 0, outpos = 0; + bool error = false; + struct LZ_Encoder * const encoder = + LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX ); + if( !encoder || LZ_compress_errno( encoder ) != LZ_ok ) + { LZ_compress_close( encoder ); return false; } + + while( true ) + { + int ret = LZ_compress_write( encoder, inbuf + inpos, insize - inpos ); + if( ret < 0 ) { error = true; break; } + inpos += ret; + if( inpos >= insize ) LZ_compress_finish( encoder ); + ret = LZ_compress_read( encoder, outbuf + outpos, outsize - outpos ); + if( ret < 0 ) { error = true; break; } + outpos += ret; + if( LZ_compress_finished( encoder ) == 1 ) break; + if( outpos >= outsize ) { error = true; break; } + } + + if( LZ_compress_close( encoder ) < 0 ) error = true; + if( error ) return false; + *outlenp = outpos; + return true; + } + + +/* Decompresses 'insize' bytes from 'inbuf' to 'outbuf'. + Returns the size of the decompressed data in '*outlenp'. + In case of error, or if 'outsize' is too small, returns false and does + not modify '*outlenp'. +*/ +bool bbdecompress( const uint8_t * const inbuf, const int insize, + uint8_t * const outbuf, const int outsize, + int * const outlenp ) + { + int inpos = 0, outpos = 0; + bool error = false; + struct LZ_Decoder * const decoder = LZ_decompress_open(); + if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok ) + { LZ_decompress_close( decoder ); return false; } + + while( true ) + { + int ret = LZ_decompress_write( decoder, inbuf + inpos, insize - inpos ); + if( ret < 0 ) { error = true; break; } + inpos += ret; + if( inpos >= insize ) LZ_decompress_finish( decoder ); + ret = LZ_decompress_read( decoder, outbuf + outpos, outsize - outpos ); + if( ret < 0 ) { error = true; break; } + outpos += ret; + if( LZ_decompress_finished( decoder ) == 1 ) break; + if( outpos >= outsize ) { error = true; break; } + } + + if( LZ_decompress_close( decoder ) < 0 ) error = true; + if( error ) return false; + *outlenp = outpos; + return true; + } + + +/* Test at most INT_MAX bytes from the file with buffers of fixed size. */ +int fixed_test( const uint8_t * const inbuf, const int insize ) + { + int dictionary_size = 65535; /* fast encoder */ + int midsize = min( INT_MAX, ( insize / 8 ) * 9LL + 44 ), outsize = insize; + uint8_t * midbuf = (uint8_t *)malloc( midsize ); + uint8_t * outbuf = (uint8_t *)malloc( outsize ); + if( !midbuf || !outbuf ) + { fputs( "bbexample: fixed_test: Not enough memory.\n", stderr ); + free( outbuf ); free( midbuf ); return 1; } + + for( ; dictionary_size <= 8 << 20; dictionary_size += 8323073 ) + { + int midlen, outlen; + if( !bbcompress( inbuf, insize, dictionary_size, 16, midbuf, midsize, &midlen ) ) + { fputs( "bbexample: fixed_test: Not enough memory or compress error.\n", + stderr ); free( outbuf ); free( midbuf ); return 1; } + + if( !bbdecompress( midbuf, midlen, outbuf, outsize, &outlen ) ) + { fputs( "bbexample: fixed_test: Not enough memory or decompress error.\n", + stderr ); free( outbuf ); free( midbuf ); return 1; } + + if( insize != outlen || + ( insize > 0 && memcmp( inbuf, outbuf, insize ) != 0 ) ) + { fputs( "bbexample: fixed_test: Decompressed data differs from original.\n", + stderr ); free( outbuf ); free( midbuf ); return 1; } + + } + free( outbuf ); + free( midbuf ); + return 0; } int main( const int argc, const char * const argv[] ) { - uint8_t * in_buffer; - long in_size = 0; - int level; + int retval = 0, i; + int open_failures = 0; + const bool verbose = ( argc > 2 ); if( argc < 2 ) { @@ -233,38 +348,20 @@ int main( const int argc, const char * const argv[] ) return 1; } - in_buffer = read_file( argv[1], &in_size ); - if( !in_buffer ) return 1; - - for( level = 0; level <= 9; ++level ) + for( i = 1; i < argc && retval == 0; ++i ) { - uint8_t * mid_buffer, * out_buffer; - long mid_size = 0, out_size = 0; + long insize; + uint8_t * const inbuf = read_file( argv[i], &insize ); + if( !inbuf ) { ++open_failures; continue; } + if( verbose ) fprintf( stderr, " Testing file '%s'\n", argv[i] ); - mid_buffer = bbcompress( in_buffer, in_size, level, &mid_size ); - if( !mid_buffer ) - { - fputs( "bbexample: Not enough memory or compress error.\n", stderr ); - return 1; - } - - out_buffer = bbdecompress( mid_buffer, mid_size, &out_size ); - if( !out_buffer ) - { - fputs( "bbexample: Not enough memory or decompress error.\n", stderr ); - return 1; - } - - if( in_size != out_size || - ( in_size > 0 && memcmp( in_buffer, out_buffer, in_size ) != 0 ) ) - { - fputs( "bbexample: Decompressed data differs from original.\n", stderr ); - return 1; - } - - free( out_buffer ); - free( mid_buffer ); + retval = full_test( inbuf, insize ); + if( retval == 0 ) retval = fixed_test( inbuf, min( INT_MAX, insize ) ); + free( inbuf ); } - free( in_buffer ); - return 0; + if( open_failures > 0 && verbose ) + fprintf( stderr, "bbexample: warning: %d %s failed to open.\n", + open_failures, ( open_failures == 1 ) ? "file" : "files" ); + if( retval == 0 && open_failures ) retval = 1; + return retval; } diff --git a/carg_parser.c b/carg_parser.c index ce01d7b..d0c05d5 100644 --- a/carg_parser.c +++ b/carg_parser.c @@ -1,20 +1,20 @@ -/* Arg_parser - POSIX/GNU command line argument parser. (C version) - Copyright (C) 2006-2019 Antonio Diaz Diaz. +/* Arg_parser - POSIX/GNU command line argument parser. (C version) + Copyright (C) 2006-2021 Antonio Diaz Diaz. - This library is free software. Redistribution and use in source and - binary forms, with or without modification, are permitted provided - that the following conditions are met: + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include diff --git a/carg_parser.h b/carg_parser.h index dcae2de..c5f2352 100644 --- a/carg_parser.h +++ b/carg_parser.h @@ -1,44 +1,44 @@ -/* Arg_parser - POSIX/GNU command line argument parser. (C version) - Copyright (C) 2006-2019 Antonio Diaz Diaz. +/* Arg_parser - POSIX/GNU command line argument parser. (C version) + Copyright (C) 2006-2021 Antonio Diaz Diaz. - This library is free software. Redistribution and use in source and - binary forms, with or without modification, are permitted provided - that the following conditions are met: + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ -/* Arg_parser reads the arguments in 'argv' and creates a number of - option codes, option arguments and non-option arguments. +/* Arg_parser reads the arguments in 'argv' and creates a number of + option codes, option arguments, and non-option arguments. - In case of error, 'ap_error' returns a non-null pointer to an error - message. + In case of error, 'ap_error' returns a non-null pointer to an error + message. - 'options' is an array of 'struct ap_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. + 'options' is an array of 'struct ap_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. - Arg_parser normally makes it appear as if all the option arguments - 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 'ap_init' with 'in_order' = true. + Arg_parser normally makes it appear as if all the option arguments + 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 'ap_init' with 'in_order' = true. - The argument '--' terminates all options; any following arguments are - treated as non-option arguments, even if they begin with a hyphen. + 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 '--='. */ #ifdef __cplusplus @@ -79,11 +79,11 @@ void ap_free( struct Arg_parser * const ap ); const char * ap_error( const struct Arg_parser * const ap ); - /* The number of arguments parsed (may be different from argc) */ +/* The number of arguments parsed. May be different from argc. */ int ap_arguments( const struct Arg_parser * const ap ); - /* If ap_code( i ) is 0, ap_argument( i ) is a non-option. - Else ap_argument( i ) is the option's argument (or empty). */ +/* If ap_code( i ) is 0, ap_argument( i ) is a non-option. + Else ap_argument( i ) is the option's argument (or empty). */ int ap_code( const struct Arg_parser * const ap, const int i ); const char * ap_argument( const struct Arg_parser * const ap, const int i ); diff --git a/cbuffer.c b/cbuffer.c index 6b70be4..ee54131 100644 --- a/cbuffer.c +++ b/cbuffer.c @@ -1,20 +1,20 @@ -/* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2019 Antonio Diaz Diaz. +/* Lzlib - Compression library for the lzip format + Copyright (C) 2009-2021 Antonio Diaz Diaz. - This library is free software. Redistribution and use in source and - binary forms, with or without modification, are permitted provided - that the following conditions are met: + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ struct Circular_buffer diff --git a/configure b/configure index 60ea883..d74cf5d 100755 --- a/configure +++ b/configure @@ -1,12 +1,12 @@ #! /bin/sh # configure script for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2019 Antonio Diaz Diaz. +# Copyright (C) 2009-2021 Antonio Diaz Diaz. # # This configure script is free software: you have unlimited permission -# to copy, distribute and modify it. +# to copy, distribute, and modify it. pkgname=lzlib -pkgversion=1.11 +pkgversion=1.12 soversion=1 progname=minilzip progname_static=${progname} @@ -34,11 +34,7 @@ CFLAGS='-Wall -W -O2' LDFLAGS= # checking whether we are using GNU C. -/bin/sh -c "${CC} --version" > /dev/null 2>&1 || - { - CC=cc - CFLAGS=-O2 - } +/bin/sh -c "${CC} --version" > /dev/null 2>&1 || { CC=cc ; CFLAGS=-O2 ; } # Loop over all args args= @@ -50,11 +46,12 @@ while [ $# != 0 ] ; do shift # Add the argument quoted to args - args="${args} \"${option}\"" + if [ -z "${args}" ] ; then args="\"${option}\"" + else args="${args} \"${option}\"" ; fi # Split out the argument for options that take them case ${option} in - *=*) optarg=`echo ${option} | sed -e 's,^[^=]*=,,;s,/$,,'` ;; + *=*) optarg=`echo "${option}" | sed -e 's,^[^=]*=,,;s,/$,,'` ;; esac # Process the options @@ -151,7 +148,7 @@ if [ -z "${srcdir}" ] ; 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,^$,.,'` + srcdir=`echo "$0" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` fi fi @@ -174,7 +171,7 @@ if [ -z "${no_create}" ] ; then # Run this file to recreate the current configuration. # # This script is free software: you have unlimited permission -# to copy, distribute and modify it. +# to copy, distribute, and modify it. exec /bin/sh $0 ${args} --no-create EOF @@ -198,11 +195,11 @@ echo "LDFLAGS = ${LDFLAGS}" rm -f Makefile cat > Makefile << EOF # Makefile for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2019 Antonio Diaz Diaz. +# Copyright (C) 2009-2021 Antonio Diaz Diaz. # This file was generated automatically by configure. Don't edit. # # This Makefile is free software: you have unlimited permission -# to copy, distribute and modify it. +# to copy, distribute, and modify it. pkgname = ${pkgname} pkgversion = ${pkgversion} diff --git a/decoder.c b/decoder.c index 3dc62cc..82472b3 100644 --- a/decoder.c +++ b/decoder.c @@ -1,27 +1,27 @@ -/* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2019 Antonio Diaz Diaz. +/* Lzlib - Compression library for the lzip format + Copyright (C) 2009-2021 Antonio Diaz Diaz. - This library is free software. Redistribution and use in source and - binary forms, with or without modification, are permitted provided - that the following conditions are met: + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ static int LZd_try_verify_trailer( struct LZ_decoder * const d ) { Lzip_trailer trailer; - if( Rd_available_bytes( d->rdec ) < Lt_size && !d->rdec->at_stream_end ) - return 0; + if( Rd_available_bytes( d->rdec ) < Lt_size ) + { if( !d->rdec->at_stream_end ) return 0; else return 2; } d->verify_trailer_pending = false; d->member_finished = true; @@ -40,10 +40,10 @@ static int LZd_decode_member( struct LZ_decoder * const d ) { struct Range_decoder * const rdec = d->rdec; State * const state = &d->state; - /* unsigned old_mpos = d->rdec->member_position; */ + /* unsigned old_mpos = rdec->member_position; */ if( d->member_finished ) return 0; - if( !Rd_try_reload( rdec, false ) ) + if( !Rd_try_reload( rdec ) ) { if( !rdec->at_stream_end ) return 0; else return 2; } if( d->verify_trailer_pending ) return LZd_try_verify_trailer( d ); @@ -51,7 +51,7 @@ static int LZd_decode_member( struct LZ_decoder * const d ) { int len; const int pos_state = LZd_data_position( d ) & pos_state_mask; - /* const unsigned mpos = d->rdec->member_position; + /* const unsigned mpos = rdec->member_position; if( mpos - old_mpos > rd_min_available_bytes ) return 5; old_mpos = mpos; */ if( !Rd_enough_available_bytes( rdec ) ) /* check unexpected EOF */ @@ -123,6 +123,9 @@ static int LZd_decode_member( struct LZ_decoder * const d ) if( distance == 0xFFFFFFFFU ) /* marker found */ { Rd_normalize( rdec ); + /* const unsigned mpos = rdec->member_position; + if( mpos - old_mpos > rd_min_available_bytes ) return 5; + old_mpos = mpos; */ if( len == min_match_len ) /* End Of Stream marker */ { d->verify_trailer_pending = true; @@ -130,7 +133,8 @@ static int LZd_decode_member( struct LZ_decoder * const d ) } if( len == min_match_len + 1 ) /* Sync Flush marker */ { - if( Rd_try_reload( rdec, true ) ) { /*old_mpos += 5;*/ continue; } + rdec->reload_pending = true; + if( Rd_try_reload( rdec ) ) continue; else { if( !rdec->at_stream_end ) return 0; else break; } } return 4; diff --git a/decoder.h b/decoder.h index 1873d5e..15d5dfb 100644 --- a/decoder.h +++ b/decoder.h @@ -1,23 +1,23 @@ -/* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2019 Antonio Diaz Diaz. +/* Lzlib - Compression library for the lzip format + Copyright (C) 2009-2021 Antonio Diaz Diaz. - This library is free software. Redistribution and use in source and - binary forms, with or without modification, are permitted provided - that the following conditions are met: + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ -enum { rd_min_available_bytes = 8 }; +enum { rd_min_available_bytes = 10 }; struct Range_decoder { @@ -133,9 +133,8 @@ static inline bool Rd_unread_data( struct Range_decoder * const rdec, return true; } -static bool Rd_try_reload( struct Range_decoder * const rdec, const bool force ) +static bool Rd_try_reload( struct Range_decoder * const rdec ) { - if( force ) rdec->reload_pending = true; if( rdec->reload_pending && Rd_available_bytes( rdec ) >= 5 ) { int i; @@ -168,7 +167,7 @@ static inline unsigned Rd_decode( struct Range_decoder * const rdec, /* symbol <<= 1; */ /* if( rdec->code >= rdec->range ) { rdec->code -= rdec->range; symbol |= 1; } */ bit = ( rdec->code >= rdec->range ); - symbol = ( symbol << 1 ) + bit; + symbol <<= 1; symbol += bit; rdec->code -= rdec->range & ( 0U - bit ); } return symbol; @@ -182,15 +181,15 @@ static inline unsigned Rd_decode_bit( struct Range_decoder * const rdec, bound = ( rdec->range >> bit_model_total_bits ) * *probability; if( rdec->code < bound ) { - rdec->range = bound; *probability += (bit_model_total - *probability) >> bit_model_move_bits; + rdec->range = bound; return 0; } else { - rdec->range -= bound; - rdec->code -= bound; *probability -= *probability >> bit_model_move_bits; + rdec->code -= bound; + rdec->range -= bound; return 1; } } @@ -198,8 +197,7 @@ static inline unsigned Rd_decode_bit( struct Range_decoder * const rdec, static inline unsigned Rd_decode_tree3( struct Range_decoder * const rdec, Bit_model bm[] ) { - unsigned symbol = 1; - symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); + unsigned symbol = 2 | Rd_decode_bit( rdec, &bm[1] ); symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); return symbol & 7; @@ -208,8 +206,7 @@ static inline unsigned Rd_decode_tree3( struct Range_decoder * const rdec, static inline unsigned Rd_decode_tree6( struct Range_decoder * const rdec, Bit_model bm[] ) { - unsigned symbol = 1; - symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); + unsigned symbol = 2 | Rd_decode_bit( rdec, &bm[1] ); symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); @@ -238,7 +235,7 @@ Rd_decode_tree_reversed( struct Range_decoder * const rdec, for( i = 0; i < num_bits; ++i ) { const unsigned bit = Rd_decode_bit( rdec, &bm[model] ); - model = ( model << 1 ) + bit; + model <<= 1; model += bit; symbol |= ( bit << i ); } return symbol; @@ -248,12 +245,9 @@ static inline unsigned Rd_decode_tree_reversed4( struct Range_decoder * const rdec, Bit_model bm[] ) { unsigned symbol = Rd_decode_bit( rdec, &bm[1] ); - unsigned model = 2 + symbol; - unsigned bit = Rd_decode_bit( rdec, &bm[model] ); - model = ( model << 1 ) + bit; symbol |= ( bit << 1 ); - bit = Rd_decode_bit( rdec, &bm[model] ); - model = ( model << 1 ) + bit; symbol |= ( bit << 2 ); - symbol |= ( Rd_decode_bit( rdec, &bm[model] ) << 3 ); + symbol += Rd_decode_bit( rdec, &bm[2+symbol] ) << 1; + symbol += Rd_decode_bit( rdec, &bm[4+symbol] ) << 2; + symbol += Rd_decode_bit( rdec, &bm[8+symbol] ) << 3; return symbol; } @@ -266,7 +260,7 @@ static inline unsigned Rd_decode_matched( struct Range_decoder * const rdec, { const unsigned match_bit = ( match_byte <<= 1 ) & mask; const unsigned bit = Rd_decode_bit( rdec, &bm[symbol+match_bit+mask] ); - symbol = ( symbol << 1 ) + bit; + symbol <<= 1; symbol += bit; if( symbol > 0xFF ) return symbol & 0xFF; mask &= ~(match_bit ^ (bit << 8)); /* if( match_bit != bit ) mask = 0; */ } diff --git a/doc/lzlib.info b/doc/lzlib.info index 5a1a573..bef1859 100644 --- a/doc/lzlib.info +++ b/doc/lzlib.info @@ -11,7 +11,7 @@ File: lzlib.info, Node: Top, Next: Introduction, Up: (dir) Lzlib Manual ************ -This manual is for Lzlib (version 1.11, 2 January 2019). +This manual is for Lzlib (version 1.12, 2 January 2021). * Menu: @@ -30,10 +30,10 @@ This manual is for Lzlib (version 1.11, 2 January 2019). * Concept index:: Index of concepts - Copyright (C) 2009-2019 Antonio Diaz Diaz. + Copyright (C) 2009-2021 Antonio Diaz Diaz. - This manual is free documentation: you have unlimited permission to -copy, distribute and modify it. + This manual is free documentation: you have unlimited permission to copy, +distribute, and modify it.  File: lzlib.info, Node: Introduction, Next: Library version, Prev: Top, Up: Top @@ -41,102 +41,99 @@ File: lzlib.info, Node: Introduction, Next: Library version, Prev: Top, Up: 1 Introduction ************** -Lzlib is a data compression library providing in-memory LZMA -compression and decompression functions, including integrity checking -of the decompressed data. The compressed data format used by the -library is the lzip format. Lzlib is written in C. +Lzlib is a data compression library providing in-memory LZMA compression and +decompression functions, including integrity checking of the decompressed +data. The compressed data format used by the library is the lzip format. +Lzlib is written in C. The lzip file format is designed for data sharing and long-term -archiving, taking into account both data integrity and decoder -availability: +archiving, taking into account both data integrity and decoder availability: * The lzip format provides very safe integrity checking and some data - recovery means. The lziprecover program can repair bit flip errors - (one of the most common forms of data corruption) in lzip files, - and provides data recovery capabilities, including error-checked - merging of damaged copies of a file. *Note Data safety: - (lziprecover)Data safety. + recovery means. The program lziprecover can repair bit flip errors + (one of the most common forms of data corruption) in lzip files, and + provides data recovery capabilities, including error-checked merging + of damaged copies of a file. *Note Data safety: (lziprecover)Data + safety. - * The lzip format is as simple as possible (but not simpler). The - lzip manual provides the source code of a simple decompressor - along with a detailed explanation of how it works, so that with - the only help of the lzip manual it would be possible for a - digital archaeologist to extract the data from a lzip file long - after quantum computers eventually render LZMA obsolete. + * The lzip format is as simple as possible (but not simpler). The lzip + manual provides the source code of a simple decompressor along with a + detailed explanation of how it works, so that with the only help of the + lzip manual it would be possible for a digital archaeologist to extract + the data from a lzip file long after quantum computers eventually + render LZMA obsolete. * Additionally the lzip reference implementation is copylefted, which guarantees that it will remain free forever. A nice feature of the lzip format is that a corrupt byte is easier to -repair the nearer it is from the beginning of the file. Therefore, with -the help of lziprecover, losing an entire archive just because of a -corrupt byte near the beginning is a thing of the past. +repair the nearer it is from the beginning of the file. Therefore, with the +help of lziprecover, losing an entire archive just because of a corrupt +byte near the beginning is a thing of the past. The functions and variables forming the interface of the compression -library are declared in the file 'lzlib.h'. Usage examples of the -library are given in the files 'main.c' and 'bbexample.c' from the +library are declared in the file 'lzlib.h'. Usage examples of the library +are given in the files 'bbexample.c', 'ffexample.c', and 'main.c' from the source distribution. Compression/decompression is done by repeatedly calling a couple of -read/write functions until all the data have been processed by the -library. This interface is safer and less error prone than the -traditional zlib interface. +read/write functions until all the data have been processed by the library. +This interface is safer and less error prone than the traditional zlib +interface. - Compression/decompression is done when the read function is called. -This means the value returned by the position functions will not be -updated until a read call, even if a lot of data are written. If you -want the data to be compressed in advance, just call the read function -with a SIZE equal to 0. + Compression/decompression is done when the read function is called. This +means the value returned by the position functions will not be updated until +a read call, even if a lot of data are written. If you want the data to be +compressed in advance, just call the read function with a SIZE equal to 0. If all the data to be compressed are written in advance, lzlib will -automatically adjust the header of the compressed data to use the -largest dictionary size that does not exceed neither the data size nor -the limit given to 'LZ_compress_open'. This feature reduces the amount -of memory needed for decompression and allows minilzip to produce -identical compressed output as lzip. +automatically adjust the header of the compressed data to use the largest +dictionary size that does not exceed neither the data size nor the limit +given to 'LZ_compress_open'. This feature reduces the amount of memory +needed for decompression and allows minilzip to produce identical compressed +output as lzip. - Lzlib will correctly decompress a data stream which is the -concatenation of two or more compressed data streams. The result is the -concatenation of the corresponding decompressed data streams. Integrity -testing of concatenated compressed data streams is also supported. + Lzlib will correctly decompress a data stream which is the concatenation +of two or more compressed data streams. The result is the concatenation of +the corresponding decompressed data streams. Integrity testing of +concatenated compressed data streams is also supported. Lzlib is able to compress and decompress streams of unlimited size by -automatically creating multimember output. The members so created are -large, about 2 PiB each. +automatically creating multimember output. The members so created are large, +about 2 PiB each. - All the library functions are thread safe. The library does not -install any signal handler. The decoder checks the consistency of the -compressed data, so the library should never crash even in case of -corrupted input. + All the library functions are thread safe. The library does not install +any signal handler. The decoder checks the consistency of the compressed +data, so the library should never crash even in case of corrupted input. - In spite of its name (Lempel-Ziv-Markov chain-Algorithm), LZMA is -not a concrete algorithm; it is more like "any algorithm using the LZMA -coding scheme". For example, the option '-0' of lzip uses the scheme in -almost the simplest way possible; issuing the longest match it can -find, or a literal byte if it can't find a match. Inversely, a much -more elaborated way of finding coding sequences of minimum size than -the one currently used by lzip could be developed, and the resulting -sequence could also be coded using the LZMA coding scheme. + In spite of its name (Lempel-Ziv-Markov chain-Algorithm), LZMA is not a +concrete algorithm; it is more like "any algorithm using the LZMA coding +scheme". For example, the option '-0' of lzip uses the scheme in almost the +simplest way possible; issuing the longest match it can find, or a literal +byte if it can't find a match. Inversely, a much more elaborated way of +finding coding sequences of minimum size than the one currently used by +lzip could be developed, and the resulting sequence could also be coded +using the LZMA coding scheme. Lzlib currently implements two variants of the LZMA algorithm; fast -(used by option '-0' of minilzip) and normal (used by all other -compression levels). +(used by option '-0' of minilzip) and normal (used by all other compression +levels). - The high compression of LZMA comes from combining two basic, -well-proven compression ideas: sliding dictionaries (LZ77/78) and -markov models (the thing used by every compression algorithm that uses -a range encoder or similar order-0 entropy coder as its last stage) -with segregation of contexts according to what the bits are used for. + The high compression of LZMA comes from combining two basic, well-proven +compression ideas: sliding dictionaries (LZ77/78) and markov models (the +thing used by every compression algorithm that uses a range encoder or +similar order-0 entropy coder as its last stage) with segregation of +contexts according to what the bits are used for. - The ideas embodied in lzlib are due to (at least) the following -people: Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey -Markov (for the definition of Markov chains), G.N.N. Martin (for the -definition of range encoding), Igor Pavlov (for putting all the above -together in LZMA), and Julian Seward (for bzip2's CLI). + The ideas embodied in lzlib are due to (at least) the following people: +Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the +definition of Markov chains), G.N.N. Martin (for the definition of range +encoding), Igor Pavlov (for putting all the above together in LZMA), and +Julian Seward (for bzip2's CLI). - LANGUAGE NOTE: Uncompressed = not compressed = plain data; it may -never have been compressed. Decompressed is used to refer to data which -have undergone the process of decompression. + LANGUAGE NOTE: Uncompressed = not compressed = plain data; it may never +have been compressed. Decompressed is used to refer to data which have +undergone the process of decompression.  File: lzlib.info, Node: Library version, Next: Buffering, Prev: Introduction, Up: Top @@ -144,19 +141,53 @@ File: lzlib.info, Node: Library version, Next: Buffering, Prev: Introduction, 2 Library version ***************** - -- Function: const char * LZ_version ( void ) - Returns the library version as a string. +One goal of lzlib is to keep perfect backward compatibility with older +versions of itself down to 1.0. Any application working with an older lzlib +should work with a newer lzlib. Installing a newer lzlib should not break +anything. This chapter describes the constants and functions that the +application can use to discover the version of the library being used. + + -- Constant: LZ_API_VERSION + This constant is defined in 'lzlib.h' and works as a version test + macro. The application should verify at compile time that + LZ_API_VERSION is greater than or equal to the version required by the + application: + + #if !defined LZ_API_VERSION || LZ_API_VERSION < 1012 + #error "lzlib 1.12 or newer needed." + #endif + + Before version 1.8, lzlib didn't define LZ_API_VERSION. + LZ_API_VERSION was first defined in lzlib 1.8 to 1. + Since lzlib 1.12, LZ_API_VERSION is defined as (major * 1000 + minor). + + NOTE: Version test macros are the library's way of announcing +functionality to the application. They should not be confused with feature +test macros, which allow the application to announce to the library its +desire to have certain symbols and prototypes exposed. + + -- Function: int LZ_api_version ( void ) + If LZ_API_VERSION >= 1012, this function is declared in 'lzlib.h' (else + it doesn't exist). It returns the LZ_API_VERSION of the library object + code being used. The application should verify at run time that the + value returned by 'LZ_api_version' is greater than or equal to the + version required by the application. An application may be dinamically + linked at run time with a different version of lzlib than the one it + was compiled for, and this should not break the program as long as the + library used provides the functionality required by the application. + + #if defined LZ_API_VERSION && LZ_API_VERSION >= 1012 + if( LZ_api_version() < 1012 ) + show_error( "lzlib 1.12 or newer needed." ); + #endif -- Constant: const char * LZ_version_string - This constant is defined in the header file 'lzlib.h'. + This string constant is defined in the header file 'lzlib.h' and + represents the version of the library being used at compile time. - The application should compare LZ_version and LZ_version_string for -consistency. If the first character differs, the library code actually -used may be incompatible with the 'lzlib.h' header file used by the -application. - - if( LZ_version()[0] != LZ_version_string[0] ) - error( "bad library version" ); + -- Function: const char * LZ_version ( void ) + This function returns a string representing the version of the library + being used at run time.  File: lzlib.info, Node: Buffering, Next: Parameter limits, Prev: Library version, Up: Top @@ -164,31 +195,31 @@ File: lzlib.info, Node: Buffering, Next: Parameter limits, Prev: Library vers 3 Buffering *********** -Lzlib internal functions need access to a memory chunk at least as large -as the dictionary size (sliding window). For efficiency reasons, the -input buffer for compression is twice or sixteen times as large as the -dictionary size. +Lzlib internal functions need access to a memory chunk at least as large as +the dictionary size (sliding window). For efficiency reasons, the input +buffer for compression is twice or sixteen times as large as the dictionary +size. Finally, for safety reasons, lzlib uses two more internal buffers. - These are the four buffers used by lzlib, and their guaranteed -minimum sizes: + These are the four buffers used by lzlib, and their guaranteed minimum +sizes: - * Input compression buffer. Written to by the 'LZ_compress_write' - function. For the normal variant of LZMA, its size is two times - the dictionary size set with the 'LZ_compress_open' function or - 64 KiB, whichever is larger. For the fast variant, its size is - 1 MiB. + * Input compression buffer. Written to by the function + 'LZ_compress_write'. For the normal variant of LZMA, its size is two + times the dictionary size set with the function 'LZ_compress_open' or + 64 KiB, whichever is larger. For the fast variant, its size is 1 MiB. - * Output compression buffer. Read from by the 'LZ_compress_read' - function. Its size is 64 KiB. + * Output compression buffer. Read from by the function + 'LZ_compress_read'. Its size is 64 KiB. - * Input decompression buffer. Written to by the - 'LZ_decompress_write' function. Its size is 64 KiB. + * Input decompression buffer. Written to by the function + 'LZ_decompress_write'. Its size is 64 KiB. - * Output decompression buffer. Read from by the 'LZ_decompress_read' - function. Its size is the dictionary size set in the header of the - member currently being decompressed or 64 KiB, whichever is larger. + * Output decompression buffer. Read from by the function + 'LZ_decompress_read'. Its size is the dictionary size set in the header + of the member currently being decompressed or 64 KiB, whichever is + larger.  File: lzlib.info, Node: Parameter limits, Next: Compression functions, Prev: Buffering, Up: Top @@ -207,8 +238,7 @@ Current values are shown in square brackets. Returns the smallest valid dictionary size [4 KiB]. -- Function: int LZ_max_dictionary_bits ( void ) - Returns the base 2 logarithm of the largest valid dictionary size - [29]. + Returns the base 2 logarithm of the largest valid dictionary size [29]. -- Function: int LZ_max_dictionary_size ( void ) Returns the largest valid dictionary size [512 MiB]. @@ -227,26 +257,26 @@ File: lzlib.info, Node: Compression functions, Next: Decompression functions, These are the functions used to compress data. In case of error, all of them return -1 or 0, for signed and unsigned return values respectively, -except 'LZ_compress_open' whose return value must be verified by -calling 'LZ_compress_errno' before using it. +except 'LZ_compress_open' whose return value must be verified by calling +'LZ_compress_errno' before using it. -- Function: struct LZ_Encoder * LZ_compress_open ( const int - DICTIONARY_SIZE, const int MATCH_LEN_LIMIT, const unsigned - long long MEMBER_SIZE ) + DICTIONARY_SIZE, const int MATCH_LEN_LIMIT, const unsigned long + long MEMBER_SIZE ) Initializes the internal stream state for compression and returns a - pointer that can only be used as the ENCODER argument for the - other LZ_compress functions, or a null pointer if the encoder - could not be allocated. + pointer that can only be used as the ENCODER argument for the other + LZ_compress functions, or a null pointer if the encoder could not be + allocated. - The returned pointer must be verified by calling - 'LZ_compress_errno' before using it. If 'LZ_compress_errno' does - not return 'LZ_ok', the returned pointer must not be used and - should be freed with 'LZ_compress_close' to avoid memory leaks. + The returned pointer must be verified by calling 'LZ_compress_errno' + before using it. If 'LZ_compress_errno' does not return 'LZ_ok', the + returned pointer must not be used and should be freed with + 'LZ_compress_close' to avoid memory leaks. - DICTIONARY_SIZE sets the dictionary size to be used, in bytes. - Valid values range from 4 KiB to 512 MiB. Note that dictionary - sizes are quantized. If the specified size does not match one of - the valid sizes, it will be rounded upwards by adding up to + DICTIONARY_SIZE sets the dictionary size to be used, in bytes. Valid + values range from 4 KiB to 512 MiB. Note that dictionary sizes are + quantized. If the size specified does not match one of the valid + sizes, it will be rounded upwards by adding up to (DICTIONARY_SIZE / 8) to it. MATCH_LEN_LIMIT sets the match length limit in bytes. Valid values @@ -254,95 +284,117 @@ calling 'LZ_compress_errno' before using it. ratios but longer compression times. If DICTIONARY_SIZE is 65535 and MATCH_LEN_LIMIT is 16, the fast - variant of LZMA is chosen, which produces identical compressed - output as 'lzip -0'. (The dictionary size used will be rounded - upwards to 64 KiB). + variant of LZMA is chosen, which produces identical compressed output + as 'lzip -0'. (The dictionary size used will be rounded upwards to + 64 KiB). - MEMBER_SIZE sets the member size limit in bytes. Valid values - range from 100 kB to 2 PiB. Small member size may degrade - compression ratio, so use it only when needed. To produce a - single-member data stream, give MEMBER_SIZE a value larger than - the amount of data to be produced. Values larger than 2 PiB will be - reduced to 2 PiB to prevent the uncompressed size of the member - from overflowing. + MEMBER_SIZE sets the member size limit in bytes. Valid values range + from 4 KiB to 2 PiB. A small member size may degrade compression + ratio, so use it only when needed. To produce a single-member data + stream, give MEMBER_SIZE a value larger than the amount of data to be + produced. Values larger than 2 PiB will be reduced to 2 PiB to prevent + the uncompressed size of the member from overflowing. - -- Function: int LZ_compress_close ( struct LZ_Encoder * const ENCODER - ) - Frees all dynamically allocated data structures for this stream. - This function discards any unprocessed input and does not flush - any pending output. After a call to 'LZ_compress_close', ENCODER - can no longer be used as an argument to any LZ_compress function. + -- Function: int LZ_compress_close ( struct LZ_Encoder * const ENCODER ) + Frees all dynamically allocated data structures for this stream. This + function discards any unprocessed input and does not flush any pending + output. After a call to 'LZ_compress_close', ENCODER can no longer be + used as an argument to any LZ_compress function. It is safe to call + 'LZ_compress_close' with a null argument. - -- Function: int LZ_compress_finish ( struct LZ_Encoder * const - ENCODER ) + -- Function: int LZ_compress_finish ( struct LZ_Encoder * const ENCODER ) Use this function to tell 'lzlib' that all the data for this member - have already been written (with the 'LZ_compress_write' function). - It is safe to call 'LZ_compress_finish' as many times as needed. - After all the produced compressed data have been read with - 'LZ_compress_read' and 'LZ_compress_member_finished' returns 1, a - new member can be started with 'LZ_compress_restart_member'. + have already been written (with the function 'LZ_compress_write'). It + is safe to call 'LZ_compress_finish' as many times as needed. After + all the compressed data have been read with 'LZ_compress_read' and + 'LZ_compress_member_finished' returns 1, a new member can be started + with 'LZ_compress_restart_member'. - -- Function: int LZ_compress_restart_member ( struct LZ_Encoder * - const ENCODER, const unsigned long long MEMBER_SIZE ) - Use this function to start a new member in a multimember data - stream. Call this function only after - 'LZ_compress_member_finished' indicates that the current member - has been fully read (with the 'LZ_compress_read' function). + -- Function: int LZ_compress_restart_member ( struct LZ_Encoder * const + ENCODER, const unsigned long long MEMBER_SIZE ) + Use this function to start a new member in a multimember data stream. + Call this function only after 'LZ_compress_member_finished' indicates + that the current member has been fully read (with the function + 'LZ_compress_read'). *Note member_size::, for a description of + MEMBER_SIZE. -- Function: int LZ_compress_sync_flush ( struct LZ_Encoder * const ENCODER ) - Use this function to make available to 'LZ_compress_read' all the - data already written with the 'LZ_compress_write' function. First - call 'LZ_compress_sync_flush'. Then call 'LZ_compress_read' until - it returns 0. + Use this function to make available to 'LZ_compress_read' all the data + already written with the function 'LZ_compress_write'. First call + 'LZ_compress_sync_flush'. Then call 'LZ_compress_read' until it + returns 0. + + This function writes a LZMA marker '3' ("Sync Flush" marker) to the + compressed output. Note that the sync flush marker is not allowed in + lzip files; it is a device for interactive communication between + applications using lzlib, but is useless and wasteful in a file, and + is excluded from the media type 'application/lzip'. The LZMA marker + '2' ("End Of Stream" marker) is the only marker allowed in lzip files. + *Note Data format::. Repeated use of 'LZ_compress_sync_flush' may degrade compression - ratio, so use it only when needed. + ratio, so use it only when needed. If the interval between calls to + 'LZ_compress_sync_flush' is large (comparable to dictionary size), + creating a multimember data stream with 'LZ_compress_restart_member' + may be an alternative. + + Combining multimember stream creation with flushing may be tricky. If + there are more bytes available than those needed to complete + MEMBER_SIZE, 'LZ_compress_restart_member' needs to be called when + 'LZ_compress_member_finished' returns 1, followed by a new call to + 'LZ_compress_sync_flush'. -- Function: int LZ_compress_read ( struct LZ_Encoder * const ENCODER, uint8_t * const BUFFER, const int SIZE ) - The 'LZ_compress_read' function reads up to SIZE bytes from the - stream pointed to by ENCODER, storing the results in BUFFER. + The function 'LZ_compress_read' reads up to SIZE bytes from the stream + pointed to by ENCODER, storing the results in BUFFER. If + LZ_API_VERSION >= 1012, BUFFER may be a null pointer, in which case + the bytes read are discarded. - The return value is the number of bytes actually read. This might - be less than SIZE; for example, if there aren't that many bytes - left in the stream or if more bytes have to be yet written with the - 'LZ_compress_write' function. Note that reading less than SIZE - bytes is not an error. + The return value is the number of bytes actually read. This might be + less than SIZE; for example, if there aren't that many bytes left in + the stream or if more bytes have to be yet written with the function + 'LZ_compress_write'. Note that reading less than SIZE bytes is not an + error. - -- Function: int LZ_compress_write ( struct LZ_Encoder * const - ENCODER, uint8_t * const BUFFER, const int SIZE ) - The 'LZ_compress_write' function writes up to SIZE bytes from - BUFFER to the stream pointed to by ENCODER. + -- Function: int LZ_compress_write ( struct LZ_Encoder * const ENCODER, + uint8_t * const BUFFER, const int SIZE ) + The function 'LZ_compress_write' writes up to SIZE bytes from BUFFER + to the stream pointed to by ENCODER. - The return value is the number of bytes actually written. This - might be less than SIZE. Note that writing less than SIZE bytes is - not an error. + The return value is the number of bytes actually written. This might be + less than SIZE. Note that writing less than SIZE bytes is not an error. -- Function: int LZ_compress_write_size ( struct LZ_Encoder * const ENCODER ) - The 'LZ_compress_write_size' function returns the maximum number of - bytes that can be immediately written through the - 'LZ_compress_write' function. + The function 'LZ_compress_write_size' returns the maximum number of + bytes that can be immediately written through 'LZ_compress_write'. For + efficiency reasons, once the input buffer is full and + 'LZ_compress_write_size' returns 0, almost all the buffer must be + compressed before a size greater than 0 is returned again. (This is + done to minimize the amount of data that must be copied to the + beginning of the buffer before new data can be accepted). It is guaranteed that an immediate call to 'LZ_compress_write' will accept a SIZE up to the returned number of bytes. - -- Function: enum LZ_Errno LZ_compress_errno ( struct LZ_Encoder * - const ENCODER ) - Returns the current error code for ENCODER. *Note Error codes::. - - -- Function: int LZ_compress_finished ( struct LZ_Encoder * const + -- Function: enum LZ_Errno LZ_compress_errno ( struct LZ_Encoder * const ENCODER ) - Returns 1 if all the data have been read and 'LZ_compress_close' - can be safely called. Otherwise it returns 0. - 'LZ_compress_finished' implies 'LZ_compress_member_finished'. + Returns the current error code for ENCODER. *Note Error codes::. It is + safe to call 'LZ_compress_errno' with a null argument, in which case + it returns 'LZ_bad_argument'. - -- Function: int LZ_compress_member_finished ( struct LZ_Encoder * - const ENCODER ) - Returns 1 if the current member, in a multimember data stream, has - been fully read and 'LZ_compress_restart_member' can be safely - called. Otherwise it returns 0. + -- Function: int LZ_compress_finished ( struct LZ_Encoder * const ENCODER ) + Returns 1 if all the data have been read and 'LZ_compress_close' can + be safely called. Otherwise it returns 0. 'LZ_compress_finished' + implies 'LZ_compress_member_finished'. + + -- Function: int LZ_compress_member_finished ( struct LZ_Encoder * const + ENCODER ) + Returns 1 if the current member, in a multimember data stream, has been + fully read and 'LZ_compress_restart_member' can be safely called. + Otherwise it returns 0. -- Function: unsigned long long LZ_compress_data_position ( struct LZ_Encoder * const ENCODER ) @@ -351,8 +403,8 @@ calling 'LZ_compress_errno' before using it. -- Function: unsigned long long LZ_compress_member_position ( struct LZ_Encoder * const ENCODER ) - Returns the number of compressed bytes already produced, but - perhaps not yet read, in the current member. + Returns the number of compressed bytes already produced, but perhaps + not yet read, in the current member. -- Function: unsigned long long LZ_compress_total_in_size ( struct LZ_Encoder * const ENCODER ) @@ -369,130 +421,144 @@ File: lzlib.info, Node: Decompression functions, Next: Error codes, Prev: Com 6 Decompression functions ************************* -These are the functions used to decompress data. In case of error, all -of them return -1 or 0, for signed and unsigned return values -respectively, except 'LZ_decompress_open' whose return value must be -verified by calling 'LZ_decompress_errno' before using it. +These are the functions used to decompress data. In case of error, all of +them return -1 or 0, for signed and unsigned return values respectively, +except 'LZ_decompress_open' whose return value must be verified by calling +'LZ_decompress_errno' before using it. -- Function: struct LZ_Decoder * LZ_decompress_open ( void ) - Initializes the internal stream state for decompression and - returns a pointer that can only be used as the DECODER argument - for the other LZ_decompress functions, or a null pointer if the - decoder could not be allocated. + Initializes the internal stream state for decompression and returns a + pointer that can only be used as the DECODER argument for the other + LZ_decompress functions, or a null pointer if the decoder could not be + allocated. - The returned pointer must be verified by calling - 'LZ_decompress_errno' before using it. If 'LZ_decompress_errno' - does not return 'LZ_ok', the returned pointer must not be used and - should be freed with 'LZ_decompress_close' to avoid memory leaks. + The returned pointer must be verified by calling 'LZ_decompress_errno' + before using it. If 'LZ_decompress_errno' does not return 'LZ_ok', the + returned pointer must not be used and should be freed with + 'LZ_decompress_close' to avoid memory leaks. - -- Function: int LZ_decompress_close ( struct LZ_Decoder * const - DECODER ) - Frees all dynamically allocated data structures for this stream. - This function discards any unprocessed input and does not flush - any pending output. After a call to 'LZ_decompress_close', DECODER - can no longer be used as an argument to any LZ_decompress function. + -- Function: int LZ_decompress_close ( struct LZ_Decoder * const DECODER ) + Frees all dynamically allocated data structures for this stream. This + function discards any unprocessed input and does not flush any pending + output. After a call to 'LZ_decompress_close', DECODER can no longer + be used as an argument to any LZ_decompress function. It is safe to + call 'LZ_decompress_close' with a null argument. - -- Function: int LZ_decompress_finish ( struct LZ_Decoder * const - DECODER ) + -- Function: int LZ_decompress_finish ( struct LZ_Decoder * const DECODER ) Use this function to tell 'lzlib' that all the data for this stream - have already been written (with the 'LZ_decompress_write' - function). It is safe to call 'LZ_decompress_finish' as many - times as needed. + have already been written (with the function 'LZ_decompress_write'). + It is safe to call 'LZ_decompress_finish' as many times as needed. It + is not required to call 'LZ_decompress_finish' if the input stream + only contains whole members, but not calling it prevents lzlib from + detecting a truncated member. - -- Function: int LZ_decompress_reset ( struct LZ_Decoder * const + -- Function: int LZ_decompress_reset ( struct LZ_Decoder * const DECODER ) + Resets the internal state of DECODER as it was just after opening it + with the function 'LZ_decompress_open'. Data stored in the internal + buffers is discarded. Position counters are set to 0. + + -- Function: int LZ_decompress_sync_to_member ( struct LZ_Decoder * const DECODER ) - Resets the internal state of DECODER as it was just after opening - it with the 'LZ_decompress_open' function. Data stored in the - internal buffers is discarded. Position counters are set to 0. + Resets the error state of DECODER and enters a search state that lasts + until a new member header (or the end of the stream) is found. After a + successful call to 'LZ_decompress_sync_to_member', data written with + 'LZ_decompress_write' will be consumed and 'LZ_decompress_read' will + return 0 until a header is found. - -- Function: int LZ_decompress_sync_to_member ( struct LZ_Decoder * - const DECODER ) - Resets the error state of DECODER and enters a search state that - lasts until a new member header (or the end of the stream) is - found. After a successful call to 'LZ_decompress_sync_to_member', - data written with 'LZ_decompress_write' will be consumed and - 'LZ_decompress_read' will return 0 until a header is found. + This function is useful to discard any data preceding the first member, + or to discard the rest of the current member, for example in case of a + data error. If the decoder is already at the beginning of a member, + this function does nothing. - This function is useful to discard any data preceding the first - member, or to discard the rest of the current member, for example - in case of a data error. If the decoder is already at the - beginning of a member, this function does nothing. + -- Function: int LZ_decompress_read ( struct LZ_Decoder * const DECODER, + uint8_t * const BUFFER, const int SIZE ) + The function 'LZ_decompress_read' reads up to SIZE bytes from the + stream pointed to by DECODER, storing the results in BUFFER. If + LZ_API_VERSION >= 1012, BUFFER may be a null pointer, in which case + the bytes read are discarded. - -- Function: int LZ_decompress_read ( struct LZ_Decoder * const - DECODER, uint8_t * const BUFFER, const int SIZE ) - The 'LZ_decompress_read' function reads up to SIZE bytes from the - stream pointed to by DECODER, storing the results in BUFFER. + The return value is the number of bytes actually read. This might be + less than SIZE; for example, if there aren't that many bytes left in + the stream or if more bytes have to be yet written with the function + 'LZ_decompress_write'. Note that reading less than SIZE bytes is not + an error. - The return value is the number of bytes actually read. This might - be less than SIZE; for example, if there aren't that many bytes - left in the stream or if more bytes have to be yet written with the - 'LZ_decompress_write' function. Note that reading less than SIZE - bytes is not an error. + 'LZ_decompress_read' returns at least once per member so that + 'LZ_decompress_member_finished' can be called (and trailer data + retrieved) for each member, even for empty members. Therefore, + 'LZ_decompress_read' returning 0 does not mean that the end of the + stream has been reached. The increase in the value returned by + 'LZ_decompress_total_in_size' can be used to tell the end of the stream + from an empty member. In case of decompression error caused by corrupt or truncated data, 'LZ_decompress_read' does not signal the error immediately to the - application, but waits until all decoded bytes have been read. This - allows tools like tarlz to recover as much data as possible from - each damaged member. *Note tarlz manual: (tarlz)Top. + application, but waits until all the bytes decoded have been read. This + allows tools like tarlz to recover as much data as possible from each + damaged member. *Note tarlz manual: (tarlz)Top. - -- Function: int LZ_decompress_write ( struct LZ_Decoder * const - DECODER, uint8_t * const BUFFER, const int SIZE ) - The 'LZ_decompress_write' function writes up to SIZE bytes from - BUFFER to the stream pointed to by DECODER. + -- Function: int LZ_decompress_write ( struct LZ_Decoder * const DECODER, + uint8_t * const BUFFER, const int SIZE ) + The function 'LZ_decompress_write' writes up to SIZE bytes from BUFFER + to the stream pointed to by DECODER. - The return value is the number of bytes actually written. This - might be less than SIZE. Note that writing less than SIZE bytes is - not an error. + The return value is the number of bytes actually written. This might be + less than SIZE. Note that writing less than SIZE bytes is not an error. -- Function: int LZ_decompress_write_size ( struct LZ_Decoder * const DECODER ) - The 'LZ_decompress_write_size' function returns the maximum number - of bytes that can be immediately written through the - 'LZ_decompress_write' function. + The function 'LZ_decompress_write_size' returns the maximum number of + bytes that can be immediately written through 'LZ_decompress_write'. + This number varies smoothly; each compressed byte consumed may be + overwritten immediately, increasing by 1 the value returned. - It is guaranteed that an immediate call to 'LZ_decompress_write' - will accept a SIZE up to the returned number of bytes. + It is guaranteed that an immediate call to 'LZ_decompress_write' will + accept a SIZE up to the returned number of bytes. - -- Function: enum LZ_Errno LZ_decompress_errno ( struct LZ_Decoder * - const DECODER ) - Returns the current error code for DECODER. *Note Error codes::. + -- Function: enum LZ_Errno LZ_decompress_errno ( struct LZ_Decoder * const + DECODER ) + Returns the current error code for DECODER. *Note Error codes::. It is + safe to call 'LZ_decompress_errno' with a null argument, in which case + it returns 'LZ_bad_argument'. -- Function: int LZ_decompress_finished ( struct LZ_Decoder * const DECODER ) - Returns 1 if all the data have been read and 'LZ_decompress_close' - can be safely called. Otherwise it returns 0. + Returns 1 if all the data have been read and 'LZ_decompress_close' can + be safely called. Otherwise it returns 0. 'LZ_decompress_finished' + does not imply 'LZ_decompress_member_finished'. - -- Function: int LZ_decompress_member_finished ( struct LZ_Decoder * - const DECODER ) - Returns 1 if the previous call to 'LZ_decompress_read' finished - reading the current member, indicating that final values for - member are available through 'LZ_decompress_data_crc', - 'LZ_decompress_data_position', and - 'LZ_decompress_member_position'. Otherwise it returns 0. + -- Function: int LZ_decompress_member_finished ( struct LZ_Decoder * const + DECODER ) + Returns 1 if the previous call to 'LZ_decompress_read' finished reading + the current member, indicating that final values for member are + available through 'LZ_decompress_data_crc', + 'LZ_decompress_data_position', and 'LZ_decompress_member_position'. + Otherwise it returns 0. - -- Function: int LZ_decompress_member_version ( struct LZ_Decoder * - const DECODER ) + -- Function: int LZ_decompress_member_version ( struct LZ_Decoder * const + DECODER ) Returns the version of current member from member header. - -- Function: int LZ_decompress_dictionary_size ( struct LZ_Decoder * - const DECODER ) - Returns the dictionary size of current member from member header. + -- Function: int LZ_decompress_dictionary_size ( struct LZ_Decoder * const + DECODER ) + Returns the dictionary size of the current member, read from the member + header. - -- Function: unsigned LZ_decompress_data_crc ( struct LZ_Decoder * - const DECODER ) - Returns the 32 bit Cyclic Redundancy Check of the data - decompressed from the current member. The returned value is valid - only when 'LZ_decompress_member_finished' returns 1. + -- Function: unsigned LZ_decompress_data_crc ( struct LZ_Decoder * const + DECODER ) + Returns the 32 bit Cyclic Redundancy Check of the data decompressed + from the current member. The returned value is valid only when + 'LZ_decompress_member_finished' returns 1. -- Function: unsigned long long LZ_decompress_data_position ( struct LZ_Decoder * const DECODER ) - Returns the number of decompressed bytes already produced, but - perhaps not yet read, in the current member. + Returns the number of decompressed bytes already produced, but perhaps + not yet read, in the current member. -- Function: unsigned long long LZ_decompress_member_position ( struct LZ_Decoder * const DECODER ) - Returns the number of input bytes already decompressed in the - current member. + Returns the number of input bytes already decompressed in the current + member. -- Function: unsigned long long LZ_decompress_total_in_size ( struct LZ_Decoder * const DECODER ) @@ -500,8 +566,8 @@ verified by calling 'LZ_decompress_errno' before using it. -- Function: unsigned long long LZ_decompress_total_out_size ( struct LZ_Decoder * const DECODER ) - Returns the total number of decompressed bytes already produced, - but perhaps not yet read. + Returns the total number of decompressed bytes already produced, but + perhaps not yet read.  File: lzlib.info, Node: Error codes, Next: Error messages, Prev: Decompression functions, Up: Top @@ -516,16 +582,15 @@ what kind of error it was, you need to verify the error code by calling Library functions don't change the value returned by 'LZ_(de)compress_errno' when they succeed; thus, the value returned by -'LZ_(de)compress_errno' after a successful call is not necessarily -LZ_ok, and you should not use 'LZ_(de)compress_errno' to determine -whether a call failed. If the call failed, then you can examine -'LZ_(de)compress_errno'. +'LZ_(de)compress_errno' after a successful call is not necessarily LZ_ok, +and you should not use 'LZ_(de)compress_errno' to determine whether a call +failed. If the call failed, then you can examine 'LZ_(de)compress_errno'. The error codes are defined in the header file 'lzlib.h'. -- Constant: enum LZ_Errno LZ_ok - The value of this constant is 0 and is used to indicate that there - is no error. + The value of this constant is 0 and is used to indicate that there is + no error. -- Constant: enum LZ_Errno LZ_bad_argument At least one of the arguments passed to the library function was @@ -542,24 +607,22 @@ whether a call failed. If the call failed, then you can examine finished. -- Constant: enum LZ_Errno LZ_header_error - An invalid member header (one with the wrong magic bytes) was - read. If this happens at the end of the data stream it may - indicate trailing data. + An invalid member header (one with the wrong magic bytes) was read. If + this happens at the end of the data stream it may indicate trailing + data. -- Constant: enum LZ_Errno LZ_unexpected_eof The end of the data stream was reached in the middle of a member. -- Constant: enum LZ_Errno LZ_data_error - The data stream is corrupt. If 'LZ_decompress_member_position' is 6 - or less, it indicates either a format version not supported, an - invalid dictionary size, a corrupt header in a multimember data - stream, or trailing data too similar to a valid lzip header. - Lziprecover can be used to remove conflicting trailing data from a - file. + The data stream is corrupt. If 'LZ_decompress_member_position' is 6 or + less, it indicates either a format version not supported, an invalid + dictionary size, a corrupt header in a multimember data stream, or + trailing data too similar to a valid lzip header. Lziprecover can be + used to remove conflicting trailing data from a file. -- Constant: enum LZ_Errno LZ_library_error - A bug was detected in the library. Please, report it. *Note - Problems::. + A bug was detected in the library. Please, report it. *Note Problems::.  File: lzlib.info, Node: Error messages, Next: Invoking minilzip, Prev: Error codes, Up: Top @@ -568,11 +631,10 @@ File: lzlib.info, Node: Error messages, Next: Invoking minilzip, Prev: Error **************** -- Function: const char * LZ_strerror ( const enum LZ_Errno LZ_ERRNO ) - Returns the standard error message for a given error code. The - messages are fairly short; there are no multi-line messages or - embedded newlines. This function makes it easy for your program - to report informative error messages about the failure of a - library call. + Returns the standard error message for a given error code. The messages + are fairly short; there are no multi-line messages or embedded + newlines. This function makes it easy for your program to report + informative error messages about the failure of a library call. The value of LZ_ERRNO normally comes from a call to 'LZ_(de)compress_errno'. @@ -583,18 +645,30 @@ File: lzlib.info, Node: Invoking minilzip, Next: Data format, Prev: Error mes 9 Invoking minilzip ******************* -Minilzip is a test program for the lzlib compression library, fully +Minilzip is a test program for the compression library lzlib, fully compatible with lzip 1.4 or newer. + Lzip is a lossless data compressor with a user interface similar to the +one of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov +chain-Algorithm' (LZMA) stream format, chosen to maximize safety and +interoperability. Lzip can compress about as fast as gzip (lzip -0) or +compress most files more than bzip2 (lzip -9). Decompression speed is +intermediate between gzip and bzip2. Lzip is better than gzip and bzip2 +from a data recovery perspective. Lzip has been designed, written, and +tested with great care to replace gzip and bzip2 as the standard +general-purpose compressed format for unix-like systems. + The format for running minilzip is: minilzip [OPTIONS] [FILES] -'-' used as a FILE argument means standard input. It can be mixed with -other FILES and is read just once, the first time it appears in the -command line. +If no file names are specified, minilzip compresses (or decompresses) from +standard input to standard output. A hyphen '-' used as a FILE argument +means standard input. It can be mixed with other FILES and is read just +once, the first time it appears in the command line. - minilzip supports the following options: + minilzip supports the following options: *Note Argument syntax: +(arg_parser)Argument syntax. '-h' '--help' @@ -602,37 +676,39 @@ command line. '-V' '--version' - Print the version number of minilzip on the standard output and - exit. This version number should be included in all bug reports. + Print the version number of minilzip on the standard output and exit. + This version number should be included in all bug reports. '-a' '--trailing-error' Exit with error status 2 if any remaining input is detected after - decompressing the last member. Such remaining input is usually - trailing garbage that can be safely ignored. + decompressing the last member. Such remaining input is usually trailing + garbage that can be safely ignored. '-b BYTES' '--member-size=BYTES' - When compressing, set the member size limit to BYTES. A small - member size may degrade compression ratio, so use it only when - needed. Valid values range from 100 kB to 2 PiB. Defaults to - 2 PiB. + When compressing, set the member size limit to BYTES. It is advisable + to keep members smaller than RAM size so that they can be repaired with + lziprecover in case of corruption. A small member size may degrade + compression ratio, so use it only when needed. Valid values range from + 100 kB to 2 PiB. Defaults to 2 PiB. '-c' '--stdout' - Compress or decompress to standard output; keep input files - unchanged. If compressing several files, each file is compressed - independently. This option is needed when reading from a named - pipe (fifo) or from a device. Use it also to recover as much of - the decompressed data as possible when decompressing a corrupt - file. + Compress or decompress to standard output; keep input files unchanged. + If compressing several files, each file is compressed independently. + (The output consists of a sequence of independently compressed + members). This option (or '-o') is needed when reading from a named + pipe (fifo) or from a device. Use it also to recover as much of the + decompressed data as possible when decompressing a corrupt file. '-c' + overrides '-o' and '-S'. '-c' has no effect when testing or listing. '-d' '--decompress' - Decompress the specified files. If a file does not exist or can't - be opened, minilzip continues decompressing the rest of the files. - If a file fails to decompress, or is a terminal, minilzip exits - immediately without decompressing the rest of the files. + Decompress the files specified. If a file does not exist or can't be + opened, minilzip continues decompressing the rest of the files. If a + file fails to decompress, or is a terminal, minilzip exits immediately + without decompressing the rest of the files. '-f' '--force' @@ -640,30 +716,32 @@ command line. '-F' '--recompress' - When compressing, force re-compression of files whose name already - has the '.lz' or '.tlz' suffix. + When compressing, force re-compression of files whose name already has + the '.lz' or '.tlz' suffix. '-k' '--keep' - Keep (don't delete) input files during compression or - decompression. + Keep (don't delete) input files during compression or decompression. '-m BYTES' '--match-length=BYTES' - When compressing, set the match length limit in bytes. After a - match this long is found, the search is finished. Valid values - range from 5 to 273. Larger values usually give better compression - ratios but longer compression times. + When compressing, set the match length limit in bytes. After a match + this long is found, the search is finished. Valid values range from 5 + to 273. Larger values usually give better compression ratios but longer + compression times. '-o FILE' '--output=FILE' - When reading from standard input and '--stdout' has not been - specified, use 'FILE' as the virtual name of the uncompressed - file. This produces a file named 'FILE' when decompressing, or a - file named 'FILE.lz' when compressing. A second '.lz' extension is - not added if 'FILE' already ends in '.lz' or '.tlz'. When - compressing and splitting the output in volumes, several files - named 'FILE00001.lz', 'FILE00002.lz', etc, are created. + If '-c' has not been also specified, write the (de)compressed output to + FILE; keep input files unchanged. If compressing several files, each + file is compressed independently. (The output consists of a sequence of + independently compressed members). This option (or '-c') is needed when + reading from a named pipe (fifo) or from a device. '-o -' is + equivalent to '-c'. '-o' has no effect when testing or listing. + + When compressing and splitting the output in volumes, FILE is used as + a prefix, and several files named 'FILE00001.lz', 'FILE00002.lz', etc, + are created. In this case, only one input file is allowed. '-q' '--quiet' @@ -673,37 +751,36 @@ command line. '--dictionary-size=BYTES' When compressing, set the dictionary size limit in bytes. Minilzip will use for each file the largest dictionary size that does not - exceed neither the file size nor this limit. Valid values range - from 4 KiB to 512 MiB. Values 12 to 29 are interpreted as powers - of two, meaning 2^12 to 2^29 bytes. Dictionary sizes are quantized - so that they can be coded in just one byte (*note - coded-dict-size::). If the specified size does not match one of - the valid sizes, it will be rounded upwards by adding up to - (BYTES / 8) to it. + exceed neither the file size nor this limit. Valid values range from + 4 KiB to 512 MiB. Values 12 to 29 are interpreted as powers of two, + meaning 2^12 to 2^29 bytes. Dictionary sizes are quantized so that + they can be coded in just one byte (*note coded-dict-size::). If the + size specified does not match one of the valid sizes, it will be + rounded upwards by adding up to (BYTES / 8) to it. - For maximum compression you should use a dictionary size limit as - large as possible, but keep in mind that the decompression memory - requirement is affected at compression time by the choice of - dictionary size limit. + For maximum compression you should use a dictionary size limit as large + as possible, but keep in mind that the decompression memory requirement + is affected at compression time by the choice of dictionary size limit. '-S BYTES' '--volume-size=BYTES' - When compressing, split the compressed output into several volume - files with names 'original_name00001.lz', 'original_name00002.lz', - etc, and set the volume size limit to BYTES. Input files are kept - unchanged. Each volume is a complete, maybe multimember, lzip - file. A small volume size may degrade compression ratio, so use it - only when needed. Valid values range from 100 kB to 4 EiB. + When compressing, and '-c' has not been also specified, split the + compressed output into several volume files with names + 'original_name00001.lz', 'original_name00002.lz', etc, and set the + volume size limit to BYTES. Input files are kept unchanged. Each + volume is a complete, maybe multimember, lzip file. A small volume + size may degrade compression ratio, so use it only when needed. Valid + values range from 100 kB to 4 EiB. '-t' '--test' - Check integrity of the specified files, but don't decompress them. - This really performs a trial decompression and throws away the - result. Use it together with '-v' to see information about the - files. If a file fails the test, does not exist, can't be opened, - or is a terminal, minilzip continues checking the rest of the - files. A final diagnostic is shown at verbosity level 1 or higher - if any file fails the test when testing multiple files. + Check integrity of the files specified, but don't decompress them. This + really performs a trial decompression and throws away the result. Use + it together with '-v' to see information about the files. If a file + fails the test, does not exist, can't be opened, or is a terminal, + minilzip continues checking the rest of the files. A final diagnostic + is shown at verbosity level 1 or higher if any file fails the test + when testing multiple files. '-v' '--verbose' @@ -711,24 +788,24 @@ command line. When compressing, show the compression ratio and size for each file processed. When decompressing or testing, further -v's (up to 4) increase the - verbosity level, showing status, compression ratio, dictionary - size, and trailer contents (CRC, data size, member size). + verbosity level, showing status, compression ratio, dictionary size, + and trailer contents (CRC, data size, member size). '-0 .. -9' - Compression level. Set the compression parameters (dictionary size - and match length limit) as shown in the table below. The default - compression level is '-6', equivalent to '-s8MiB -m36'. Note that - '-9' can be much slower than '-0'. These options have no effect - when decompressing or testing. + Compression level. Set the compression parameters (dictionary size and + match length limit) as shown in the table below. The default + compression level is '-6', equivalent to '-s8MiB -m36'. Note that '-9' + can be much slower than '-0'. These options have no effect when + decompressing or testing. - The bidimensional parameter space of LZMA can't be mapped to a - linear scale optimal for all files. If your files are large, very - repetitive, etc, you may need to use the '--dictionary-size' and - '--match-length' options directly to achieve optimal performance. + The bidimensional parameter space of LZMA can't be mapped to a linear + scale optimal for all files. If your files are large, very repetitive, + etc, you may need to use the options '--dictionary-size' and + '--match-length' directly to achieve optimal performance. - If several compression levels or '-s' or '-m' options are given, - the last setting is used. For example '-9 -s64MiB' is equivalent - to '-s64MiB -m273' + If several compression levels or '-s' or '-m' options are given, the + last setting is used. For example '-9 -s64MiB' is equivalent to + '-s64MiB -m273' Level Dictionary size (-s) Match length limit (-m) -0 64 KiB 16 bytes @@ -747,11 +824,19 @@ command line. Aliases for GNU gzip compatibility. '--loose-trailing' - When decompressing or testing, allow trailing data whose first - bytes are so similar to the magic bytes of a lzip header that they - can be confused with a corrupt header. Use this option if a file - triggers a "corrupt header" error and the cause is not indeed a - corrupt header. + When decompressing or testing, allow trailing data whose first bytes + are so similar to the magic bytes of a lzip header that they can be + confused with a corrupt header. Use this option if a file triggers a + "corrupt header" error and the cause is not indeed a corrupt header. + +'--check-lib' + Compare the version of lzlib used to compile minilzip with the version + actually being used and exit. Report any differences found. Exit with + error status 1 if differences are found. A mismatch may indicate that + lzlib is not correctly installed or that a different version of lzlib + has been installed after compiling the shared version of minilzip. + 'minilzip -v --check-lib' shows the version of lzlib being used and + the value of 'LZ_API_VERSION' (if defined). *Note Library version::. Numbers given as arguments to options may be followed by a multiplier @@ -770,10 +855,10 @@ Z zettabyte (10^21) | Zi zebibyte (2^70) Y yottabyte (10^24) | Yi yobibyte (2^80) - Exit status: 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 -caused minilzip to panic. + Exit status: 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 caused +minilzip to panic.  File: lzlib.info, Node: Data format, Next: Examples, Prev: Invoking minilzip, Up: Top @@ -787,11 +872,13 @@ when there is no longer anything to take away. In the diagram below, a box like this: + +---+ | | <-- the vertical bars might be missing +---+ represents one byte; a box like this: + +==============+ | | +==============+ @@ -799,11 +886,12 @@ when there is no longer anything to take away. represents a variable number of bytes. - A lzip data stream consists of a series of "members" (compressed -data sets). The members simply appear one after another in the data -stream, with no additional information before, between, or after them. + A lzip data stream consists of a series of "members" (compressed data +sets). The members simply appear one after another in the data stream, with +no additional information before, between, or after them. Each member has the following structure: + +--+--+--+--+----+----+=============+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ID string | VN | DS | LZMA stream | CRC32 | Data size | Member size | +--+--+--+--+----+----+=============+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -811,17 +899,16 @@ stream, with no additional information before, between, or after them. All multibyte values are stored in little endian order. 'ID string (the "magic" bytes)' - A four byte string, identifying the lzip format, with the value - "LZIP" (0x4C, 0x5A, 0x49, 0x50). + A four byte string, identifying the lzip format, with the value "LZIP" + (0x4C, 0x5A, 0x49, 0x50). 'VN (version number, 1 byte)' - Just in case something needs to be modified in the future. 1 for - now. + Just in case something needs to be modified in the future. 1 for now. 'DS (coded dictionary size, 1 byte)' The dictionary size is calculated by taking a power of 2 (the base - size) and subtracting from it a fraction between 0/16 and 7/16 of - the base size. + size) and subtracting from it a fraction between 0/16 and 7/16 of the + base size. Bits 4-0 contain the base 2 logarithm of the base size (12 to 29). Bits 7-5 contain the numerator of the fraction (0 to 7) to subtract from the base size to obtain the dictionary size. @@ -830,22 +917,23 @@ stream, with no additional information before, between, or after them. 'LZMA stream' The LZMA stream, finished by an end of stream marker. Uses default - values for encoder properties. *Note Stream format: (lzip)Stream + values for encoder properties. *Note Stream format: (lzip)Stream format, for a complete description. Lzip only uses the LZMA marker '2' ("End Of Stream" marker). Lzlib - also uses the LZMA marker '3' ("Sync Flush" marker). + also uses the LZMA marker '3' ("Sync Flush" marker). *Note + sync_flush::. 'CRC32 (4 bytes)' - CRC of the uncompressed original data. + Cyclic Redundancy Check (CRC) of the uncompressed original data. 'Data size (8 bytes)' Size of the uncompressed original data. 'Member size (8 bytes)' - Total size of the member, including header and trailer. This field - acts as a distributed index, allows the verification of stream - integrity, and facilitates safe recovery of undamaged members from - multimember files. + Total size of the member, including header and trailer. This field acts + as a distributed index, allows the verification of stream integrity, + and facilitates safe recovery of undamaged members from multimember + files.  @@ -854,115 +942,303 @@ File: lzlib.info, Node: Examples, Next: Problems, Prev: Data format, Up: Top 11 A small tutorial with examples ********************************* -This chapter shows the order in which the library functions should be -called depending on what kind of data stream you want to compress or -decompress. See the file 'bbexample.c' in the source distribution for -an example of how buffer-to-buffer compression/decompression can be -implemented using lzlib. +This chapter provides real code examples for the most common uses of the +library. See these examples in context in the files 'bbexample.c' and +'ffexample.c' from the source distribution of lzlib. - Note that lzlib's interface is symmetrical. That is, the code for -normal compression and decompression is identical except because one -calls LZ_compress* functions while the other calls LZ_decompress* -functions. + Note that the interface of lzlib is symmetrical. That is, the code for +normal compression and decompression is identical except because one calls +LZ_compress* functions while the other calls LZ_decompress* functions. + +* Menu: + +* Buffer compression:: Buffer-to-buffer single-member compression +* Buffer decompression:: Buffer-to-buffer decompression +* File compression:: File-to-file single-member compression +* File decompression:: File-to-file decompression +* File compression mm:: File-to-file multimember compression +* Skipping data errors:: Decompression with automatic resynchronization + + +File: lzlib.info, Node: Buffer compression, Next: Buffer decompression, Up: Examples + +11.1 Buffer compression +======================= + +Buffer-to-buffer single-member compression (MEMBER_SIZE > total output). + +/* Compresses 'insize' bytes from 'inbuf' to 'outbuf'. + Returns the size of the compressed data in '*outlenp'. + In case of error, or if 'outsize' is too small, returns false and does + not modify '*outlenp'. +*/ +bool bbcompress( const uint8_t * const inbuf, const int insize, + const int dictionary_size, const int match_len_limit, + uint8_t * const outbuf, const int outsize, + int * const outlenp ) + { + int inpos = 0, outpos = 0; + bool error = false; + struct LZ_Encoder * const encoder = + LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX ); + if( !encoder || LZ_compress_errno( encoder ) != LZ_ok ) + { LZ_compress_close( encoder ); return false; } + + while( true ) + { + int ret = LZ_compress_write( encoder, inbuf + inpos, insize - inpos ); + if( ret < 0 ) { error = true; break; } + inpos += ret; + if( inpos >= insize ) LZ_compress_finish( encoder ); + ret = LZ_compress_read( encoder, outbuf + outpos, outsize - outpos ); + if( ret < 0 ) { error = true; break; } + outpos += ret; + if( LZ_compress_finished( encoder ) == 1 ) break; + if( outpos >= outsize ) { error = true; break; } + } + + if( LZ_compress_close( encoder ) < 0 ) error = true; + if( error ) return false; + *outlenp = outpos; + return true; + } + + +File: lzlib.info, Node: Buffer decompression, Next: File compression, Prev: Buffer compression, Up: Examples + +11.2 Buffer decompression +========================= + +Buffer-to-buffer decompression. + +/* Decompresses 'insize' bytes from 'inbuf' to 'outbuf'. + Returns the size of the decompressed data in '*outlenp'. + In case of error, or if 'outsize' is too small, returns false and does + not modify '*outlenp'. +*/ +bool bbdecompress( const uint8_t * const inbuf, const int insize, + uint8_t * const outbuf, const int outsize, + int * const outlenp ) + { + int inpos = 0, outpos = 0; + bool error = false; + struct LZ_Decoder * const decoder = LZ_decompress_open(); + if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok ) + { LZ_decompress_close( decoder ); return false; } + + while( true ) + { + int ret = LZ_decompress_write( decoder, inbuf + inpos, insize - inpos ); + if( ret < 0 ) { error = true; break; } + inpos += ret; + if( inpos >= insize ) LZ_decompress_finish( decoder ); + ret = LZ_decompress_read( decoder, outbuf + outpos, outsize - outpos ); + if( ret < 0 ) { error = true; break; } + outpos += ret; + if( LZ_decompress_finished( decoder ) == 1 ) break; + if( outpos >= outsize ) { error = true; break; } + } + + if( LZ_decompress_close( decoder ) < 0 ) error = true; + if( error ) return false; + *outlenp = outpos; + return true; + } + + +File: lzlib.info, Node: File compression, Next: File decompression, Prev: Buffer decompression, Up: Examples + +11.3 File compression +===================== + +File-to-file compression using LZ_compress_write_size. + +int ffcompress( struct LZ_Encoder * const encoder, + FILE * const infile, FILE * const outfile ) + { + enum { buffer_size = 16384 }; + uint8_t buffer[buffer_size]; + while( true ) + { + int len, ret; + int size = min( buffer_size, LZ_compress_write_size( encoder ) ); + if( size > 0 ) + { + len = fread( buffer, 1, size, infile ); + ret = LZ_compress_write( encoder, buffer, len ); + if( ret < 0 || ferror( infile ) ) break; + if( feof( infile ) ) LZ_compress_finish( encoder ); + } + ret = LZ_compress_read( encoder, buffer, buffer_size ); + if( ret < 0 ) break; + len = fwrite( buffer, 1, ret, outfile ); + if( len < ret ) break; + if( LZ_compress_finished( encoder ) == 1 ) return 0; + } + return 1; + } + + +File: lzlib.info, Node: File decompression, Next: File compression mm, Prev: File compression, Up: Examples + +11.4 File decompression +======================= + +File-to-file decompression using LZ_decompress_write_size. + +int ffdecompress( struct LZ_Decoder * const decoder, + FILE * const infile, FILE * const outfile ) + { + enum { buffer_size = 16384 }; + uint8_t buffer[buffer_size]; + while( true ) + { + int len, ret; + int size = min( buffer_size, LZ_decompress_write_size( decoder ) ); + if( size > 0 ) + { + len = fread( buffer, 1, size, infile ); + ret = LZ_decompress_write( decoder, buffer, len ); + if( ret < 0 || ferror( infile ) ) break; + if( feof( infile ) ) LZ_decompress_finish( decoder ); + } + ret = LZ_decompress_read( decoder, buffer, buffer_size ); + if( ret < 0 ) break; + len = fwrite( buffer, 1, ret, outfile ); + if( len < ret ) break; + if( LZ_decompress_finished( decoder ) == 1 ) return 0; + } + return 1; + } + + +File: lzlib.info, Node: File compression mm, Next: Skipping data errors, Prev: File decompression, Up: Examples + +11.5 File-to-file multimember compression +========================================= + +Example 1: Multimember compression with members of fixed size +(MEMBER_SIZE < total output). + +int ffmmcompress( FILE * const infile, FILE * const outfile ) + { + enum { buffer_size = 16384, member_size = 4096 }; + uint8_t buffer[buffer_size]; + bool done = false; + struct LZ_Encoder * const encoder = + LZ_compress_open( 65535, 16, member_size ); + if( !encoder || LZ_compress_errno( encoder ) != LZ_ok ) + { fputs( "ffexample: Not enough memory.\n", stderr ); + LZ_compress_close( encoder ); return 1; } + while( true ) + { + int len, ret; + int size = min( buffer_size, LZ_compress_write_size( encoder ) ); + if( size > 0 ) + { + len = fread( buffer, 1, size, infile ); + ret = LZ_compress_write( encoder, buffer, len ); + if( ret < 0 || ferror( infile ) ) break; + if( feof( infile ) ) LZ_compress_finish( encoder ); + } + ret = LZ_compress_read( encoder, buffer, buffer_size ); + if( ret < 0 ) break; + len = fwrite( buffer, 1, ret, outfile ); + if( len < ret ) break; + if( LZ_compress_member_finished( encoder ) == 1 ) + { + if( LZ_compress_finished( encoder ) == 1 ) { done = true; break; } + if( LZ_compress_restart_member( encoder, member_size ) < 0 ) break; + } + } + if( LZ_compress_close( encoder ) < 0 ) done = false; + return done; + } -Example 1: Normal compression (MEMBER_SIZE > total output). +Example 2: Multimember compression (user-restarted members). (Call +LZ_compress_open with MEMBER_SIZE > largest member). - 1) LZ_compress_open - 2) LZ_compress_write - 3) if no more data to write, call LZ_compress_finish - 4) LZ_compress_read - 5) go back to step 2 until LZ_compress_finished returns 1 - 6) LZ_compress_close +/* Compresses 'infile' to 'outfile' as a multimember stream with one member + for each line of text terminated by a newline character or by EOF. + Returns 0 if success, 1 if error. +*/ +int fflfcompress( struct LZ_Encoder * const encoder, + FILE * const infile, FILE * const outfile ) + { + enum { buffer_size = 16384 }; + uint8_t buffer[buffer_size]; + while( true ) + { + int len, ret; + int size = min( buffer_size, LZ_compress_write_size( encoder ) ); + if( size > 0 ) + { + for( len = 0; len < size; ) + { + int ch = getc( infile ); + if( ch == EOF || ( buffer[len++] = ch ) == '\n' ) break; + } + /* avoid writing an empty member to outfile */ + if( len == 0 && LZ_compress_data_position( encoder ) == 0 ) return 0; + ret = LZ_compress_write( encoder, buffer, len ); + if( ret < 0 || ferror( infile ) ) break; + if( feof( infile ) || buffer[len-1] == '\n' ) + LZ_compress_finish( encoder ); + } + ret = LZ_compress_read( encoder, buffer, buffer_size ); + if( ret < 0 ) break; + len = fwrite( buffer, 1, ret, outfile ); + if( len < ret ) break; + if( LZ_compress_member_finished( encoder ) == 1 ) + { + if( feof( infile ) && LZ_compress_finished( encoder ) == 1 ) return 0; + if( LZ_compress_restart_member( encoder, INT64_MAX ) < 0 ) break; + } + } + return 1; + } + +File: lzlib.info, Node: Skipping data errors, Prev: File compression mm, Up: Examples -Example 2: Normal compression using LZ_compress_write_size. +11.6 Skipping data errors +========================= - 1) LZ_compress_open - 2) go to step 5 if LZ_compress_write_size returns 0 - 3) LZ_compress_write - 4) if no more data to write, call LZ_compress_finish - 5) LZ_compress_read - 6) go back to step 2 until LZ_compress_finished returns 1 - 7) LZ_compress_close - - -Example 3: Decompression. - - 1) LZ_decompress_open - 2) LZ_decompress_write - 3) if no more data to write, call LZ_decompress_finish - 4) LZ_decompress_read - 5) go back to step 2 until LZ_decompress_finished returns 1 - 6) LZ_decompress_close - - -Example 4: Decompression using LZ_decompress_write_size. - - 1) LZ_decompress_open - 2) go to step 5 if LZ_decompress_write_size returns 0 - 3) LZ_decompress_write - 4) if no more data to write, call LZ_decompress_finish - 5) LZ_decompress_read - 5a) optionally, if LZ_decompress_member_finished returns 1, read - final values for member with LZ_decompress_data_crc, etc. - 6) go back to step 2 until LZ_decompress_finished returns 1 - 7) LZ_decompress_close - - -Example 5: Multimember compression (MEMBER_SIZE < total output). - - 1) LZ_compress_open - 2) go to step 5 if LZ_compress_write_size returns 0 - 3) LZ_compress_write - 4) if no more data to write, call LZ_compress_finish - 5) LZ_compress_read - 6) go back to step 2 until LZ_compress_member_finished returns 1 - 7) go to step 10 if LZ_compress_finished() returns 1 - 8) LZ_compress_restart_member - 9) go back to step 2 - 10) LZ_compress_close - - -Example 6: Multimember compression (user-restarted members). - - 1) LZ_compress_open (with MEMBER_SIZE > largest member). - 2) LZ_compress_write - 3) LZ_compress_read - 4) go back to step 2 until member termination is desired - 5) LZ_compress_finish - 6) LZ_compress_read - 7) go back to step 6 until LZ_compress_member_finished returns 1 - 9) go to step 12 if all input data have been written and - LZ_compress_finished returns 1 - 10) LZ_compress_restart_member - 11) go back to step 2 - 12) LZ_compress_close - - -Example 7: Decompression with automatic removal of leading data. - - 1) LZ_decompress_open - 2) LZ_decompress_sync_to_member - 3) go to step 6 if LZ_decompress_write_size returns 0 - 4) LZ_decompress_write - 5) if no more data to write, call LZ_decompress_finish - 6) LZ_decompress_read - 7) go back to step 3 until LZ_decompress_finished returns 1 - 8) LZ_decompress_close - - -Example 8: Streamed decompression with automatic resynchronization to -next member in case of data error. - - 1) LZ_decompress_open - 2) go to step 5 if LZ_decompress_write_size returns 0 - 3) LZ_decompress_write - 4) if no more data to write, call LZ_decompress_finish - 5) if LZ_decompress_read produces LZ_header_error or LZ_data_error, - call LZ_decompress_sync_to_member - 6) go back to step 2 until LZ_decompress_finished returns 1 - 7) LZ_decompress_close +/* Decompresses 'infile' to 'outfile' with automatic resynchronization to + next member in case of data error, including the automatic removal of + leading garbage. +*/ +int ffrsdecompress( struct LZ_Decoder * const decoder, + FILE * const infile, FILE * const outfile ) + { + enum { buffer_size = 16384 }; + uint8_t buffer[buffer_size]; + while( true ) + { + int len, ret; + int size = min( buffer_size, LZ_decompress_write_size( decoder ) ); + if( size > 0 ) + { + len = fread( buffer, 1, size, infile ); + ret = LZ_decompress_write( decoder, buffer, len ); + if( ret < 0 || ferror( infile ) ) break; + if( feof( infile ) ) LZ_decompress_finish( decoder ); + } + ret = LZ_decompress_read( decoder, buffer, buffer_size ); + if( ret < 0 ) + { + if( LZ_decompress_errno( decoder ) == LZ_header_error || + LZ_decompress_errno( decoder ) == LZ_data_error ) + { LZ_decompress_sync_to_member( decoder ); continue; } + else break; + } + len = fwrite( buffer, 1, ret, outfile ); + if( len < ret ) break; + if( LZ_decompress_finished( decoder ) == 1 ) return 0; + } + return 1; + }  File: lzlib.info, Node: Problems, Next: Concept index, Prev: Examples, Up: Top @@ -970,15 +1246,14 @@ File: lzlib.info, Node: Problems, Next: Concept index, Prev: Examples, Up: T 12 Reporting bugs ***************** -There are probably bugs in lzlib. There are certainly errors and -omissions in this manual. If you report them, they will get fixed. If -you don't, no one will ever know about them and they will remain unfixed -for all eternity, if not longer. +There are probably bugs in lzlib. There are certainly errors and omissions +in this manual. If you report them, they will get fixed. If you don't, no +one will ever know about them and they will remain unfixed for all +eternity, if not longer. If you find a bug in lzlib, please send electronic mail to -. Include the version number, which you can find -by running 'minilzip --version' or in 'LZ_version_string' from -'lzlib.h'. +. Include the version number, which you can find by +running 'minilzip --version' or in 'LZ_version_string' from 'lzlib.h'.  File: lzlib.info, Node: Concept index, Prev: Problems, Up: Top @@ -989,41 +1264,53 @@ Concept index [index] * Menu: -* buffering: Buffering. (line 6) -* bugs: Problems. (line 6) -* compression functions: Compression functions. (line 6) -* data format: Data format. (line 6) -* decompression functions: Decompression functions. - (line 6) -* error codes: Error codes. (line 6) -* error messages: Error messages. (line 6) -* examples: Examples. (line 6) -* getting help: Problems. (line 6) -* introduction: Introduction. (line 6) -* invoking: Invoking minilzip. (line 6) -* library version: Library version. (line 6) -* options: Invoking minilzip. (line 6) -* parameter limits: Parameter limits. (line 6) +* buffer compression: Buffer compression. (line 6) +* buffer decompression: Buffer decompression. (line 6) +* buffering: Buffering. (line 6) +* bugs: Problems. (line 6) +* compression functions: Compression functions. (line 6) +* data format: Data format. (line 6) +* decompression functions: Decompression functions. (line 6) +* error codes: Error codes. (line 6) +* error messages: Error messages. (line 6) +* examples: Examples. (line 6) +* file compression: File compression. (line 6) +* file decompression: File decompression. (line 6) +* getting help: Problems. (line 6) +* introduction: Introduction. (line 6) +* invoking: Invoking minilzip. (line 6) +* library version: Library version. (line 6) +* multimember compression: File compression mm. (line 6) +* options: Invoking minilzip. (line 6) +* parameter limits: Parameter limits. (line 6) +* skipping data errors: Skipping data errors. (line 6)  Tag Table: Node: Top220 -Node: Introduction1341 -Node: Library version6397 -Node: Buffering7042 -Node: Parameter limits8267 -Node: Compression functions9226 -Node: Decompression functions16010 -Node: Error codes22599 -Node: Error messages24900 -Node: Invoking minilzip25485 -Ref: --trailing-error26243 -Node: Data format33248 -Ref: coded-dict-size34557 -Node: Examples35817 -Node: Problems39813 -Node: Concept index40385 +Node: Introduction1342 +Node: Library version6413 +Node: Buffering8918 +Node: Parameter limits10143 +Node: Compression functions11097 +Ref: member_size12907 +Ref: sync_flush14673 +Node: Decompression functions19493 +Node: Error codes27187 +Node: Error messages29478 +Node: Invoking minilzip30057 +Node: Data format39651 +Ref: coded-dict-size40957 +Node: Examples42267 +Node: Buffer compression43228 +Node: Buffer decompression44754 +Node: File compression46174 +Node: File decompression47157 +Node: File compression mm48161 +Node: Skipping data errors51193 +Node: Problems52505 +Node: Concept index53077  End Tag Table diff --git a/doc/lzlib.texi b/doc/lzlib.texi index 55e80c2..644a3d7 100644 --- a/doc/lzlib.texi +++ b/doc/lzlib.texi @@ -6,8 +6,8 @@ @finalout @c %**end of header -@set UPDATED 2 January 2019 -@set VERSION 1.11 +@set UPDATED 2 January 2021 +@set VERSION 1.12 @dircategory Data Compression @direntry @@ -29,6 +29,7 @@ @contents @end ifnothtml +@ifnottex @node Top @top @@ -51,20 +52,22 @@ This manual is for Lzlib (version @value{VERSION}, @value{UPDATED}). @end menu @sp 1 -Copyright @copyright{} 2009-2019 Antonio Diaz Diaz. +Copyright @copyright{} 2009-2021 Antonio Diaz Diaz. -This manual is free documentation: you have unlimited permission -to copy, distribute and modify it. +This manual is free documentation: you have unlimited permission to copy, +distribute, and modify it. +@end ifnottex @node Introduction @chapter Introduction @cindex introduction -@uref{http://www.nongnu.org/lzip/lzlib.html,,Lzlib} is a data compression -library providing in-memory LZMA compression and decompression functions, -including integrity checking of the decompressed data. The compressed data -format used by the library is the lzip format. Lzlib is written in C. +@uref{http://www.nongnu.org/lzip/lzlib.html,,Lzlib} +is a data compression library providing in-memory LZMA compression and +decompression functions, including integrity checking of the decompressed +data. The compressed data format used by the library is the lzip format. +Lzlib is written in C. The lzip file format is designed for data sharing and long-term archiving, taking into account both data integrity and decoder availability: @@ -72,9 +75,9 @@ taking into account both data integrity and decoder availability: @itemize @bullet @item The lzip format provides very safe integrity checking and some data -recovery means. The +recovery means. The program @uref{http://www.nongnu.org/lzip/manual/lziprecover_manual.html#Data-safety,,lziprecover} -program can repair bit flip errors (one of the most common forms of data +can repair bit flip errors (one of the most common forms of data corruption) in lzip files, and provides data recovery capabilities, including error-checked merging of damaged copies of a file. @ifnothtml @@ -94,42 +97,42 @@ Additionally the lzip reference implementation is copylefted, which guarantees that it will remain free forever. @end itemize -A nice feature of the lzip format is that a corrupt byte is easier to -repair the nearer it is from the beginning of the file. Therefore, with -the help of lziprecover, losing an entire archive just because of a -corrupt byte near the beginning is a thing of the past. +A nice feature of the lzip format is that a corrupt byte is easier to repair +the nearer it is from the beginning of the file. Therefore, with the help of +lziprecover, losing an entire archive just because of a corrupt byte near +the beginning is a thing of the past. -The functions and variables forming the interface of the compression -library are declared in the file @samp{lzlib.h}. Usage examples of the -library are given in the files @samp{main.c} and @samp{bbexample.c} from -the source distribution. +The functions and variables forming the interface of the compression library +are declared in the file @samp{lzlib.h}. Usage examples of the library are +given in the files @samp{bbexample.c}, @samp{ffexample.c}, and @samp{main.c} +from the source distribution. Compression/decompression is done by repeatedly calling a couple of -read/write functions until all the data have been processed by the -library. This interface is safer and less error prone than the -traditional zlib interface. +read/write functions until all the data have been processed by the library. +This interface is safer and less error prone than the traditional zlib +interface. Compression/decompression is done when the read function is called. This -means the value returned by the position functions will not be updated -until a read call, even if a lot of data are written. If you want the -data to be compressed in advance, just call the read function with a -@var{size} equal to 0. +means the value returned by the position functions will not be updated until +a read call, even if a lot of data are written. If you want the data to be +compressed in advance, just call the read function with a @var{size} equal +to 0. If all the data to be compressed are written in advance, lzlib will -automatically adjust the header of the compressed data to use the -largest dictionary size that does not exceed neither the data size nor -the limit given to @samp{LZ_compress_open}. This feature reduces the -amount of memory needed for decompression and allows minilzip to produce -identical compressed output as lzip. +automatically adjust the header of the compressed data to use the largest +dictionary size that does not exceed neither the data size nor the limit +given to @samp{LZ_compress_open}. This feature reduces the amount of memory +needed for decompression and allows minilzip to produce identical compressed +output as lzip. -Lzlib will correctly decompress a data stream which is the concatenation -of two or more compressed data streams. The result is the concatenation -of the corresponding decompressed data streams. Integrity testing of -concatenated compressed data streams is also supported. +Lzlib will correctly decompress a data stream which is the concatenation of +two or more compressed data streams. The result is the concatenation of the +corresponding decompressed data streams. Integrity testing of concatenated +compressed data streams is also supported. Lzlib is able to compress and decompress streams of unlimited size by -automatically creating multimember output. The members so created are -large, about @w{2 PiB} each. +automatically creating multimember output. The members so created are large, +about @w{2 PiB} each. All the library functions are thread safe. The library does not install any signal handler. The decoder checks the consistency of the compressed @@ -139,14 +142,14 @@ In spite of its name (Lempel-Ziv-Markov chain-Algorithm), LZMA is not a concrete algorithm; it is more like "any algorithm using the LZMA coding scheme". For example, the option @samp{-0} of lzip uses the scheme in almost the simplest way possible; issuing the longest match it can find, or a -literal byte if it can't find a match. Inversely, a much more elaborated -way of finding coding sequences of minimum size than the one currently -used by lzip could be developed, and the resulting sequence could also -be coded using the LZMA coding scheme. +literal byte if it can't find a match. Inversely, a much more elaborated way +of finding coding sequences of minimum size than the one currently used by +lzip could be developed, and the resulting sequence could also be coded +using the LZMA coding scheme. -Lzlib currently implements two variants of the LZMA algorithm; fast -(used by option @samp{-0} of minilzip) and normal (used by all other -compression levels). +Lzlib currently implements two variants of the LZMA algorithm; fast (used by +option @samp{-0} of minilzip) and normal (used by all other compression +levels). The high compression of LZMA comes from combining two basic, well-proven compression ideas: sliding dictionaries (LZ77/78) and markov models (the @@ -155,37 +158,74 @@ similar order-0 entropy coder as its last stage) with segregation of contexts according to what the bits are used for. The ideas embodied in lzlib are due to (at least) the following people: -Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for -the definition of Markov chains), G.N.N. Martin (for the definition of -range encoding), Igor Pavlov (for putting all the above together in -LZMA), and Julian Seward (for bzip2's CLI). +Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the +definition of Markov chains), G.N.N. Martin (for the definition of range +encoding), Igor Pavlov (for putting all the above together in LZMA), and +Julian Seward (for bzip2's CLI). -LANGUAGE NOTE: Uncompressed = not compressed = plain data; it may never -have been compressed. Decompressed is used to refer to data which have -undergone the process of decompression. +LANGUAGE NOTE: Uncompressed = not compressed = plain data; it may never have +been compressed. Decompressed is used to refer to data which have undergone +the process of decompression. @node Library version @chapter Library version @cindex library version -@deftypefun {const char *} LZ_version ( void ) -Returns the library version as a string. +One goal of lzlib is to keep perfect backward compatibility with older +versions of itself down to 1.0. Any application working with an older lzlib +should work with a newer lzlib. Installing a newer lzlib should not break +anything. This chapter describes the constants and functions that the +application can use to discover the version of the library being used. + +@defvr Constant LZ_API_VERSION +This constant is defined in @samp{lzlib.h} and works as a version test +macro. The application should verify at compile time that LZ_API_VERSION is +greater than or equal to the version required by the application: + +@example +#if !defined LZ_API_VERSION || LZ_API_VERSION < 1012 +#error "lzlib 1.12 or newer needed." +#endif +@end example + +Before version 1.8, lzlib didn't define LZ_API_VERSION.@* +LZ_API_VERSION was first defined in lzlib 1.8 to 1.@* +Since lzlib 1.12, LZ_API_VERSION is defined as (major * 1000 + minor). +@end defvr + +NOTE: Version test macros are the library's way of announcing functionality +to the application. They should not be confused with feature test macros, +which allow the application to announce to the library its desire to have +certain symbols and prototypes exposed. + +@deftypefun int LZ_api_version ( void ) +If LZ_API_VERSION >= 1012, this function is declared in @samp{lzlib.h} (else +it doesn't exist). It returns the LZ_API_VERSION of the library object code +being used. The application should verify at run time that the value +returned by @code{LZ_api_version} is greater than or equal to the version +required by the application. An application may be dinamically linked at run +time with a different version of lzlib than the one it was compiled for, and +this should not break the program as long as the library used provides the +functionality required by the application. + +@example +#if defined LZ_API_VERSION && LZ_API_VERSION >= 1012 + if( LZ_api_version() < 1012 ) + show_error( "lzlib 1.12 or newer needed." ); +#endif +@end example @end deftypefun @deftypevr Constant {const char *} LZ_version_string -This constant is defined in the header file @samp{lzlib.h}. +This string constant is defined in the header file @samp{lzlib.h} and +represents the version of the library being used at compile time. @end deftypevr -The application should compare LZ_version and LZ_version_string for -consistency. If the first character differs, the library code actually -used may be incompatible with the @samp{lzlib.h} header file used by the -application. - -@example -if( LZ_version()[0] != LZ_version_string[0] ) - error( "bad library version" ); -@end example +@deftypefun {const char *} LZ_version ( void ) +This function returns a string representing the version of the library being +used at run time. +@end deftypefun @node Buffering @@ -199,26 +239,23 @@ dictionary size. Finally, for safety reasons, lzlib uses two more internal buffers. -These are the four buffers used by lzlib, and their guaranteed minimum -sizes: +These are the four buffers used by lzlib, and their guaranteed minimum sizes: @itemize @bullet -@item Input compression buffer. Written to by the -@samp{LZ_compress_write} function. For the normal variant of LZMA, its -size is two times the dictionary size set with the -@samp{LZ_compress_open} function or @w{64 KiB}, whichever is larger. For -the fast variant, its size is @w{1 MiB}. +@item Input compression buffer. Written to by the function +@samp{LZ_compress_write}. For the normal variant of LZMA, its size is two +times the dictionary size set with the function @samp{LZ_compress_open} or +@w{64 KiB}, whichever is larger. For the fast variant, its size is @w{1 MiB}. -@item Output compression buffer. Read from by the -@samp{LZ_compress_read} function. Its size is @w{64 KiB}. +@item Output compression buffer. Read from by the function +@samp{LZ_compress_read}. Its size is @w{64 KiB}. -@item Input decompression buffer. Written to by the -@samp{LZ_decompress_write} function. Its size is @w{64 KiB}. +@item Input decompression buffer. Written to by the function +@samp{LZ_decompress_write}. Its size is @w{64 KiB}. -@item Output decompression buffer. Read from by the -@samp{LZ_decompress_read} function. Its size is the dictionary size set -in the header of the member currently being decompressed or @w{64 KiB}, -whichever is larger. +@item Output decompression buffer. Read from by the function +@samp{LZ_decompress_read}. Its size is the dictionary size set in the header +of the member currently being decompressed or @w{64 KiB}, whichever is larger. @end itemize @@ -277,26 +314,26 @@ should be freed with @samp{LZ_compress_close} to avoid memory leaks. @var{dictionary_size} sets the dictionary size to be used, in bytes. Valid values range from @w{4 KiB} to @w{512 MiB}. Note that dictionary -sizes are quantized. If the specified size does not match one of the +sizes are quantized. If the size specified does not match one of the valid sizes, it will be rounded upwards by adding up to @w{(@var{dictionary_size} / 8)} to it. @var{match_len_limit} sets the match length limit in bytes. Valid values -range from 5 to 273. Larger values usually give better compression -ratios but longer compression times. +range from 5 to 273. Larger values usually give better compression ratios +but longer compression times. -If @var{dictionary_size} is 65535 and @var{match_len_limit} is 16, the -fast variant of LZMA is chosen, which produces identical compressed -output as @code{lzip -0}. (The dictionary size used will be rounded -upwards to @w{64 KiB}). +If @var{dictionary_size} is 65535 and @var{match_len_limit} is 16, the fast +variant of LZMA is chosen, which produces identical compressed output as +@w{@samp{lzip -0}}. (The dictionary size used will be rounded upwards to +@w{64 KiB}). -@var{member_size} sets the member size limit in bytes. Valid values -range from @w{100 kB} to @w{2 PiB}. Small member size may degrade -compression ratio, so use it only when needed. To produce a -single-member data stream, give @var{member_size} a value larger than -the amount of data to be produced. Values larger than @w{2 PiB} will be -reduced to @w{2 PiB} to prevent the uncompressed size of the member from -overflowing. +@anchor{member_size} +@var{member_size} sets the member size limit in bytes. Valid values range +from @w{4 KiB} to @w{2 PiB}. A small member size may degrade compression +ratio, so use it only when needed. To produce a single-member data stream, +give @var{member_size} a value larger than the amount of data to be +produced. Values larger than @w{2 PiB} will be reduced to @w{2 PiB} to +prevent the uncompressed size of the member from overflowing. @end deftypefun @@ -305,53 +342,73 @@ Frees all dynamically allocated data structures for this stream. This function discards any unprocessed input and does not flush any pending output. After a call to @samp{LZ_compress_close}, @var{encoder} can no longer be used as an argument to any LZ_compress function. +It is safe to call @samp{LZ_compress_close} with a null argument. @end deftypefun @deftypefun int LZ_compress_finish ( struct LZ_Encoder * const @var{encoder} ) Use this function to tell @samp{lzlib} that all the data for this member -have already been written (with the @samp{LZ_compress_write} function). +have already been written (with the function @samp{LZ_compress_write}). It is safe to call @samp{LZ_compress_finish} as many times as needed. -After all the produced compressed data have been read with -@samp{LZ_compress_read} and @samp{LZ_compress_member_finished} returns -1, a new member can be started with @samp{LZ_compress_restart_member}. +After all the compressed data have been read with @samp{LZ_compress_read} +and @samp{LZ_compress_member_finished} returns 1, a new member can be +started with @samp{LZ_compress_restart_member}. @end deftypefun @deftypefun int LZ_compress_restart_member ( struct LZ_Encoder * const @var{encoder}, const unsigned long long @var{member_size} ) -Use this function to start a new member in a multimember data stream. -Call this function only after @samp{LZ_compress_member_finished} -indicates that the current member has been fully read (with the -@samp{LZ_compress_read} function). +Use this function to start a new member in a multimember data stream. Call +this function only after @samp{LZ_compress_member_finished} indicates that +the current member has been fully read (with the function +@samp{LZ_compress_read}). @xref{member_size}, for a description of +@var{member_size}. @end deftypefun +@anchor{sync_flush} @deftypefun int LZ_compress_sync_flush ( struct LZ_Encoder * const @var{encoder} ) -Use this function to make available to @samp{LZ_compress_read} all the -data already written with the @samp{LZ_compress_write} function. First -call @samp{LZ_compress_sync_flush}. Then call @samp{LZ_compress_read} -until it returns 0. +Use this function to make available to @samp{LZ_compress_read} all the data +already written with the function @samp{LZ_compress_write}. First call +@samp{LZ_compress_sync_flush}. Then call @samp{LZ_compress_read} until it +returns 0. + +This function writes a LZMA marker @samp{3} ("Sync Flush" marker) to the +compressed output. Note that the sync flush marker is not allowed in lzip +files; it is a device for interactive communication between applications +using lzlib, but is useless and wasteful in a file, and is excluded from the +media type @samp{application/lzip}. The LZMA marker @samp{2} ("End Of +Stream" marker) is the only marker allowed in lzip files. @xref{Data format}. Repeated use of @samp{LZ_compress_sync_flush} may degrade compression -ratio, so use it only when needed. +ratio, so use it only when needed. If the interval between calls to +@samp{LZ_compress_sync_flush} is large (comparable to dictionary size), +creating a multimember data stream with @samp{LZ_compress_restart_member} +may be an alternative. + +Combining multimember stream creation with flushing may be tricky. If there +are more bytes available than those needed to complete @var{member_size}, +@samp{LZ_compress_restart_member} needs to be called when +@samp{LZ_compress_member_finished} returns 1, followed by a new call to +@samp{LZ_compress_sync_flush}. @end deftypefun @deftypefun int LZ_compress_read ( struct LZ_Encoder * const @var{encoder}, uint8_t * const @var{buffer}, const int @var{size} ) -The @samp{LZ_compress_read} function reads up to @var{size} bytes from -the stream pointed to by @var{encoder}, storing the results in -@var{buffer}. +The function @samp{LZ_compress_read} reads up to @var{size} bytes from the +stream pointed to by @var{encoder}, storing the results in @var{buffer}. +If @w{LZ_API_VERSION >= 1012}, @var{buffer} may be a null pointer, in which +case the bytes read are discarded. -The return value is the number of bytes actually read. This might be -less than @var{size}; for example, if there aren't that many bytes left -in the stream or if more bytes have to be yet written with the -@samp{LZ_compress_write} function. Note that reading less than -@var{size} bytes is not an error. +The return value is the number of bytes actually read. This might be less +than @var{size}; for example, if there aren't that many bytes left in the +stream or if more bytes have to be yet written with the function +@samp{LZ_compress_write}. Note that reading less than @var{size} bytes is +not an error. @end deftypefun @deftypefun int LZ_compress_write ( struct LZ_Encoder * const @var{encoder}, uint8_t * const @var{buffer}, const int @var{size} ) -The @samp{LZ_compress_write} function writes up to @var{size} bytes from +The function @samp{LZ_compress_write} writes up to @var{size} bytes from @var{buffer} to the stream pointed to by @var{encoder}. The return value is the number of bytes actually written. This might be @@ -361,9 +418,13 @@ not an error. @deftypefun int LZ_compress_write_size ( struct LZ_Encoder * const @var{encoder} ) -The @samp{LZ_compress_write_size} function returns the maximum number of -bytes that can be immediately written through the @samp{LZ_compress_write} -function. +The function @samp{LZ_compress_write_size} returns the maximum number of +bytes that can be immediately written through @samp{LZ_compress_write}. +For efficiency reasons, once the input buffer is full and +@samp{LZ_compress_write_size} returns 0, almost all the buffer must be +compressed before a size greater than 0 is returned again. (This is done to +minimize the amount of data that must be copied to the beginning of the +buffer before new data can be accepted). It is guaranteed that an immediate call to @samp{LZ_compress_write} will accept a @var{size} up to the returned number of bytes. @@ -372,6 +433,8 @@ accept a @var{size} up to the returned number of bytes. @deftypefun {enum LZ_Errno} LZ_compress_errno ( struct LZ_Encoder * const @var{encoder} ) Returns the current error code for @var{encoder}. @xref{Error codes}. +It is safe to call @samp{LZ_compress_errno} with a null argument, in which +case it returns @samp{LZ_bad_argument}. @end deftypefun @@ -390,8 +453,7 @@ Otherwise it returns 0. @deftypefun {unsigned long long} LZ_compress_data_position ( struct LZ_Encoder * const @var{encoder} ) -Returns the number of input bytes already compressed in the current -member. +Returns the number of input bytes already compressed in the current member. @end deftypefun @@ -441,19 +503,23 @@ Frees all dynamically allocated data structures for this stream. This function discards any unprocessed input and does not flush any pending output. After a call to @samp{LZ_decompress_close}, @var{decoder} can no longer be used as an argument to any LZ_decompress function. +It is safe to call @samp{LZ_decompress_close} with a null argument. @end deftypefun @deftypefun int LZ_decompress_finish ( struct LZ_Decoder * const @var{decoder} ) Use this function to tell @samp{lzlib} that all the data for this stream -have already been written (with the @samp{LZ_decompress_write} function). +have already been written (with the function @samp{LZ_decompress_write}). It is safe to call @samp{LZ_decompress_finish} as many times as needed. +It is not required to call @samp{LZ_decompress_finish} if the input stream +only contains whole members, but not calling it prevents lzlib from +detecting a truncated member. @end deftypefun @deftypefun int LZ_decompress_reset ( struct LZ_Decoder * const @var{decoder} ) Resets the internal state of @var{decoder} as it was just after opening -it with the @samp{LZ_decompress_open} function. Data stored in the +it with the function @samp{LZ_decompress_open}. Data stored in the internal buffers is discarded. Position counters are set to 0. @end deftypefun @@ -473,19 +539,28 @@ function does nothing. @deftypefun int LZ_decompress_read ( struct LZ_Decoder * const @var{decoder}, uint8_t * const @var{buffer}, const int @var{size} ) -The @samp{LZ_decompress_read} function reads up to @var{size} bytes from -the stream pointed to by @var{decoder}, storing the results in -@var{buffer}. +The function @samp{LZ_decompress_read} reads up to @var{size} bytes from the +stream pointed to by @var{decoder}, storing the results in @var{buffer}. +If @w{LZ_API_VERSION >= 1012}, @var{buffer} may be a null pointer, in which +case the bytes read are discarded. -The return value is the number of bytes actually read. This might be -less than @var{size}; for example, if there aren't that many bytes left -in the stream or if more bytes have to be yet written with the -@samp{LZ_decompress_write} function. Note that reading less than -@var{size} bytes is not an error. +The return value is the number of bytes actually read. This might be less +than @var{size}; for example, if there aren't that many bytes left in the +stream or if more bytes have to be yet written with the function +@samp{LZ_decompress_write}. Note that reading less than @var{size} bytes is +not an error. + +@samp{LZ_decompress_read} returns at least once per member so that +@samp{LZ_decompress_member_finished} can be called (and trailer data +retrieved) for each member, even for empty members. Therefore, +@samp{LZ_decompress_read} returning 0 does not mean that the end of the +stream has been reached. The increase in the value returned by +@samp{LZ_decompress_total_in_size} can be used to tell the end of the stream +from an empty member. In case of decompression error caused by corrupt or truncated data, @samp{LZ_decompress_read} does not signal the error immediately to the -application, but waits until all decoded bytes have been read. This +application, but waits until all the bytes decoded have been read. This allows tools like @uref{http://www.nongnu.org/lzip/manual/tarlz_manual.html,,tarlz} to recover as much data as possible from each damaged member. @@ -496,7 +571,7 @@ recover as much data as possible from each damaged member. @deftypefun int LZ_decompress_write ( struct LZ_Decoder * const @var{decoder}, uint8_t * const @var{buffer}, const int @var{size} ) -The @samp{LZ_decompress_write} function writes up to @var{size} bytes from +The function @samp{LZ_decompress_write} writes up to @var{size} bytes from @var{buffer} to the stream pointed to by @var{decoder}. The return value is the number of bytes actually written. This might be @@ -506,32 +581,35 @@ not an error. @deftypefun int LZ_decompress_write_size ( struct LZ_Decoder * const @var{decoder} ) -The @samp{LZ_decompress_write_size} function returns the maximum number -of bytes that can be immediately written through the -@samp{LZ_decompress_write} function. +The function @samp{LZ_decompress_write_size} returns the maximum number of +bytes that can be immediately written through @samp{LZ_decompress_write}. +This number varies smoothly; each compressed byte consumed may be +overwritten immediately, increasing by 1 the value returned. -It is guaranteed that an immediate call to @samp{LZ_decompress_write} -will accept a @var{size} up to the returned number of bytes. +It is guaranteed that an immediate call to @samp{LZ_decompress_write} will +accept a @var{size} up to the returned number of bytes. @end deftypefun @deftypefun {enum LZ_Errno} LZ_decompress_errno ( struct LZ_Decoder * const @var{decoder} ) Returns the current error code for @var{decoder}. @xref{Error codes}. +It is safe to call @samp{LZ_decompress_errno} with a null argument, in which +case it returns @samp{LZ_bad_argument}. @end deftypefun @deftypefun int LZ_decompress_finished ( struct LZ_Decoder * const @var{decoder} ) Returns 1 if all the data have been read and @samp{LZ_decompress_close} -can be safely called. Otherwise it returns 0. +can be safely called. Otherwise it returns 0. @samp{LZ_decompress_finished} +does not imply @samp{LZ_decompress_member_finished}. @end deftypefun @deftypefun int LZ_decompress_member_finished ( struct LZ_Decoder * const @var{decoder} ) -Returns 1 if the previous call to @samp{LZ_decompress_read} finished -reading the current member, indicating that final values for member are -available through @samp{LZ_decompress_data_crc}, -@samp{LZ_decompress_data_position}, and -@samp{LZ_decompress_member_position}. Otherwise it returns 0. +Returns 1 if the previous call to @samp{LZ_decompress_read} finished reading +the current member, indicating that final values for member are available +through @samp{LZ_decompress_data_crc}, @samp{LZ_decompress_data_position}, +and @samp{LZ_decompress_member_position}. Otherwise it returns 0. @end deftypefun @@ -541,7 +619,8 @@ Returns the version of current member from member header. @deftypefun int LZ_decompress_dictionary_size ( struct LZ_Decoder * const @var{decoder} ) -Returns the dictionary size of current member from member header. +Returns the dictionary size of the current member, read from the member +header. @end deftypefun @@ -559,8 +638,7 @@ not yet read, in the current member. @deftypefun {unsigned long long} LZ_decompress_member_position ( struct LZ_Decoder * const @var{decoder} ) -Returns the number of input bytes already decompressed in the current -member. +Returns the number of input bytes already decompressed in the current member. @end deftypefun @@ -599,8 +677,7 @@ error. @end deftypevr @deftypevr Constant {enum LZ_Errno} LZ_bad_argument -At least one of the arguments passed to the library function was -invalid. +At least one of the arguments passed to the library function was invalid. @end deftypevr @deftypevr Constant {enum LZ_Errno} LZ_mem_error @@ -617,8 +694,7 @@ finished. @deftypevr Constant {enum LZ_Errno} LZ_header_error An invalid member header (one with the wrong magic bytes) was read. If -this happens at the end of the data stream it may indicate trailing -data. +this happens at the end of the data stream it may indicate trailing data. @end deftypevr @deftypevr Constant {enum LZ_Errno} LZ_unexpected_eof @@ -658,9 +734,20 @@ The value of @var{lz_errno} normally comes from a call to @cindex invoking @cindex options -Minilzip is a test program for the lzlib compression library, fully +Minilzip is a test program for the compression library lzlib, fully compatible with lzip 1.4 or newer. +@uref{http://www.nongnu.org/lzip/lzip.html,,Lzip} is a lossless data +compressor with a user interface similar to the one of gzip or bzip2. Lzip +uses a simplified form of the 'Lempel-Ziv-Markov chain-Algorithm' (LZMA) +stream format, chosen to maximize safety and interoperability. Lzip can +compress about as fast as gzip @w{(lzip -0)} or compress most files more +than bzip2 @w{(lzip -9)}. Decompression speed is intermediate between gzip +and bzip2. Lzip is better than gzip and bzip2 from a data recovery +perspective. Lzip has been designed, written, and tested with great care to +replace gzip and bzip2 as the standard general-purpose compressed format for +unix-like systems. + @noindent The format for running minilzip is: @@ -669,11 +756,16 @@ minilzip [@var{options}] [@var{files}] @end example @noindent -@samp{-} used as a @var{file} argument means standard input. It can be -mixed with other @var{files} and is read just once, the first time it -appears in the command line. +If no file names are specified, minilzip compresses (or decompresses) from +standard input to standard output. A hyphen @samp{-} used as a @var{file} +argument means standard input. It can be mixed with other @var{files} and is +read just once, the first time it appears in the command line. -minilzip supports the following options: +minilzip supports the following +@uref{http://www.nongnu.org/arg-parser/manual/arg_parser_manual.html#Argument-syntax,,options}: +@ifnothtml +@xref{Argument syntax,,,arg_parser}. +@end ifnothtml @table @code @item -h @@ -685,7 +777,6 @@ Print an informative help message describing the options and exit. Print the version number of minilzip on the standard output and exit. This version number should be included in all bug reports. -@anchor{--trailing-error} @item -a @itemx --trailing-error Exit with error status 2 if any remaining input is detected after @@ -694,21 +785,25 @@ garbage that can be safely ignored. @item -b @var{bytes} @itemx --member-size=@var{bytes} -When compressing, set the member size limit to @var{bytes}. A small -member size may degrade compression ratio, so use it only when needed. -Valid values range from @w{100 kB} to @w{2 PiB}. Defaults to @w{2 PiB}. +When compressing, set the member size limit to @var{bytes}. It is advisable +to keep members smaller than RAM size so that they can be repaired with +lziprecover in case of corruption. A small member size may degrade +compression ratio, so use it only when needed. Valid values range from +@w{100 kB} to @w{2 PiB}. Defaults to @w{2 PiB}. @item -c @itemx --stdout -Compress or decompress to standard output; keep input files unchanged. -If compressing several files, each file is compressed independently. -This option is needed when reading from a named pipe (fifo) or from a -device. Use it also to recover as much of the decompressed data as -possible when decompressing a corrupt file. +Compress or decompress to standard output; keep input files unchanged. If +compressing several files, each file is compressed independently. (The +output consists of a sequence of independently compressed members). This +option (or @samp{-o}) is needed when reading from a named pipe (fifo) or +from a device. Use it also to recover as much of the decompressed data as +possible when decompressing a corrupt file. @samp{-c} overrides @samp{-o} +and @samp{-S}. @samp{-c} has no effect when testing or listing. @item -d @itemx --decompress -Decompress the specified files. If a file does not exist or can't be +Decompress the files specified. If a file does not exist or can't be opened, minilzip continues decompressing the rest of the files. If a file fails to decompress, or is a terminal, minilzip exits immediately without decompressing the rest of the files. @@ -735,14 +830,17 @@ compression times. @item -o @var{file} @itemx --output=@var{file} -When reading from standard input and @samp{--stdout} has not been -specified, use @samp{@var{file}} as the virtual name of the uncompressed -file. This produces a file named @samp{@var{file}} when decompressing, -or a file named @samp{@var{file}.lz} when compressing. A second -@samp{.lz} extension is not added if @samp{@var{file}} already ends in -@samp{.lz} or @samp{.tlz}. When compressing and splitting the output in -volumes, several files named @samp{@var{file}00001.lz}, -@samp{@var{file}00002.lz}, etc, are created. +If @samp{-c} has not been also specified, write the (de)compressed output to +@var{file}; keep input files unchanged. If compressing several files, each +file is compressed independently. (The output consists of a sequence of +independently compressed members). This option (or @samp{-c}) is needed when +reading from a named pipe (fifo) or from a device. @w{@samp{-o -}} is +equivalent to @samp{-c}. @samp{-o} has no effect when testing or listing. + +When compressing and splitting the output in volumes, @var{file} is used as +a prefix, and several files named @samp{@var{file}00001.lz}, +@samp{@var{file}00002.lz}, etc, are created. In this case, only one input +file is allowed. @item -q @itemx --quiet @@ -755,7 +853,7 @@ for each file the largest dictionary size that does not exceed neither the file size nor this limit. Valid values range from @w{4 KiB} to @w{512 MiB}. Values 12 to 29 are interpreted as powers of two, meaning 2^12 to 2^29 bytes. Dictionary sizes are quantized so that they can be -coded in just one byte (@pxref{coded-dict-size}). If the specified size +coded in just one byte (@pxref{coded-dict-size}). If the size specified does not match one of the valid sizes, it will be rounded upwards by adding up to @w{(@var{bytes} / 8)} to it. @@ -765,16 +863,17 @@ is affected at compression time by the choice of dictionary size limit. @item -S @var{bytes} @itemx --volume-size=@var{bytes} -When compressing, split the compressed output into several volume files -with names @samp{original_name00001.lz}, @samp{original_name00002.lz}, -etc, and set the volume size limit to @var{bytes}. Input files are kept -unchanged. Each volume is a complete, maybe multimember, lzip file. A -small volume size may degrade compression ratio, so use it only when -needed. Valid values range from @w{100 kB} to @w{4 EiB}. +When compressing, and @samp{-c} has not been also specified, split the +compressed output into several volume files with names +@samp{original_name00001.lz}, @samp{original_name00002.lz}, etc, and set the +volume size limit to @var{bytes}. Input files are kept unchanged. Each +volume is a complete, maybe multimember, lzip file. A small volume size may +degrade compression ratio, so use it only when needed. Valid values range +from @w{100 kB} to @w{4 EiB}. @item -t @itemx --test -Check integrity of the specified files, but don't decompress them. This +Check integrity of the files specified, but don't decompress them. This really performs a trial decompression and throws away the result. Use it together with @samp{-v} to see information about the files. If a file fails the test, does not exist, can't be opened, or is a terminal, minilzip @@ -800,8 +899,8 @@ effect when decompressing or testing. The bidimensional parameter space of LZMA can't be mapped to a linear scale optimal for all files. If your files are large, very repetitive, -etc, you may need to use the @samp{--dictionary-size} and -@samp{--match-length} options directly to achieve optimal performance. +etc, you may need to use the options @samp{--dictionary-size} and +@samp{--match-length} directly to achieve optimal performance. If several compression levels or @samp{-s} or @samp{-m} options are given, the last setting is used. For example @w{@samp{-9 -s64MiB}} is @@ -831,6 +930,18 @@ so similar to the magic bytes of a lzip header that they can be confused with a corrupt header. Use this option if a file triggers a "corrupt header" error and the cause is not indeed a corrupt header. +@item --check-lib +Compare the @uref{#Library-version,,version of lzlib} used to compile +minilzip with the version actually being used and exit. Report any +differences found. Exit with error status 1 if differences are found. A +mismatch may indicate that lzlib is not correctly installed or that a +different version of lzlib has been installed after compiling the shared +version of minilzip. @w{@samp{minilzip -v --check-lib}} shows the version of +lzlib being used and the value of @samp{LZ_API_VERSION} (if defined). +@ifnothtml +@xref{Library version}. +@end ifnothtml + @end table Numbers given as arguments to options may be followed by a multiplier @@ -867,6 +978,7 @@ when there is no longer anything to take away.@* @sp 1 In the diagram below, a box like this: + @verbatim +---+ | | <-- the vertical bars might be missing @@ -874,6 +986,7 @@ In the diagram below, a box like this: @end verbatim represents one byte; a box like this: + @verbatim +==============+ | | @@ -888,6 +1001,7 @@ The members simply appear one after another in the data stream, with no additional information before, between, or after them. Each member has the following structure: + @verbatim +--+--+--+--+----+----+=============+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ID string | VN | DS | LZMA stream | CRC32 | Data size | Member size | @@ -907,8 +1021,7 @@ Just in case something needs to be modified in the future. 1 for now. @anchor{coded-dict-size} @item DS (coded dictionary size, 1 byte) The dictionary size is calculated by taking a power of 2 (the base size) -and subtracting from it a fraction between 0/16 and 7/16 of the base -size.@* +and subtracting from it a fraction between 0/16 and 7/16 of the base size.@* Bits 4-0 contain the base 2 logarithm of the base size (12 to 29).@* Bits 7-5 contain the numerator of the fraction (0 to 7) to subtract from the base size to obtain the dictionary size.@* @@ -916,8 +1029,8 @@ Example: 0xD3 = 2^19 - 6 * 2^15 = 512 KiB - 6 * 32 KiB = 320 KiB@* Valid values for dictionary size range from 4 KiB to 512 MiB. @item LZMA stream -The LZMA stream, finished by an end of stream marker. Uses default -values for encoder properties. +The LZMA stream, finished by an end of stream marker. Uses default values +for encoder properties. @ifnothtml @xref{Stream format,,,lzip}, @end ifnothtml @@ -927,10 +1040,10 @@ See @end ifhtml for a complete description.@* Lzip only uses the LZMA marker @samp{2} ("End Of Stream" marker). Lzlib -also uses the LZMA marker @samp{3} ("Sync Flush" marker). +also uses the LZMA marker @samp{3} ("Sync Flush" marker). @xref{sync_flush}. @item CRC32 (4 bytes) -CRC of the uncompressed original data. +Cyclic Redundancy Check (CRC) of the uncompressed original data. @item Data size (8 bytes) Size of the uncompressed original data. @@ -947,138 +1060,313 @@ facilitates safe recovery of undamaged members from multimember files. @chapter A small tutorial with examples @cindex examples -This chapter shows the order in which the library functions should be -called depending on what kind of data stream you want to compress or -decompress. See the file @samp{bbexample.c} in the source distribution -for an example of how buffer-to-buffer compression/decompression can be -implemented using lzlib. +This chapter provides real code examples for the most common uses of the +library. See these examples in context in the files @samp{bbexample.c} and +@samp{ffexample.c} from the source distribution of lzlib. -Note that lzlib's interface is symmetrical. That is, the code for normal -compression and decompression is identical except because one calls +Note that the interface of lzlib is symmetrical. That is, the code for +normal compression and decompression is identical except because one calls LZ_compress* functions while the other calls LZ_decompress* functions. -@sp 1 -@noindent -Example 1: Normal compression (@var{member_size} > total output). +@menu +* Buffer compression:: Buffer-to-buffer single-member compression +* Buffer decompression:: Buffer-to-buffer decompression +* File compression:: File-to-file single-member compression +* File decompression:: File-to-file decompression +* File compression mm:: File-to-file multimember compression +* Skipping data errors:: Decompression with automatic resynchronization +@end menu -@example -1) LZ_compress_open -2) LZ_compress_write -3) if no more data to write, call LZ_compress_finish -4) LZ_compress_read -5) go back to step 2 until LZ_compress_finished returns 1 -6) LZ_compress_close -@end example + +@node Buffer compression +@section Buffer compression +@cindex buffer compression + +Buffer-to-buffer single-member compression +@w{(@var{member_size} > total output)}. + +@verbatim +/* Compresses 'insize' bytes from 'inbuf' to 'outbuf'. + Returns the size of the compressed data in '*outlenp'. + In case of error, or if 'outsize' is too small, returns false and does + not modify '*outlenp'. +*/ +bool bbcompress( const uint8_t * const inbuf, const int insize, + const int dictionary_size, const int match_len_limit, + uint8_t * const outbuf, const int outsize, + int * const outlenp ) + { + int inpos = 0, outpos = 0; + bool error = false; + struct LZ_Encoder * const encoder = + LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX ); + if( !encoder || LZ_compress_errno( encoder ) != LZ_ok ) + { LZ_compress_close( encoder ); return false; } + + while( true ) + { + int ret = LZ_compress_write( encoder, inbuf + inpos, insize - inpos ); + if( ret < 0 ) { error = true; break; } + inpos += ret; + if( inpos >= insize ) LZ_compress_finish( encoder ); + ret = LZ_compress_read( encoder, outbuf + outpos, outsize - outpos ); + if( ret < 0 ) { error = true; break; } + outpos += ret; + if( LZ_compress_finished( encoder ) == 1 ) break; + if( outpos >= outsize ) { error = true; break; } + } + + if( LZ_compress_close( encoder ) < 0 ) error = true; + if( error ) return false; + *outlenp = outpos; + return true; + } +@end verbatim + + +@node Buffer decompression +@section Buffer decompression +@cindex buffer decompression + +Buffer-to-buffer decompression. + +@verbatim +/* Decompresses 'insize' bytes from 'inbuf' to 'outbuf'. + Returns the size of the decompressed data in '*outlenp'. + In case of error, or if 'outsize' is too small, returns false and does + not modify '*outlenp'. +*/ +bool bbdecompress( const uint8_t * const inbuf, const int insize, + uint8_t * const outbuf, const int outsize, + int * const outlenp ) + { + int inpos = 0, outpos = 0; + bool error = false; + struct LZ_Decoder * const decoder = LZ_decompress_open(); + if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok ) + { LZ_decompress_close( decoder ); return false; } + + while( true ) + { + int ret = LZ_decompress_write( decoder, inbuf + inpos, insize - inpos ); + if( ret < 0 ) { error = true; break; } + inpos += ret; + if( inpos >= insize ) LZ_decompress_finish( decoder ); + ret = LZ_decompress_read( decoder, outbuf + outpos, outsize - outpos ); + if( ret < 0 ) { error = true; break; } + outpos += ret; + if( LZ_decompress_finished( decoder ) == 1 ) break; + if( outpos >= outsize ) { error = true; break; } + } + + if( LZ_decompress_close( decoder ) < 0 ) error = true; + if( error ) return false; + *outlenp = outpos; + return true; + } +@end verbatim + + +@node File compression +@section File compression +@cindex file compression + +File-to-file compression using LZ_compress_write_size. + +@verbatim +int ffcompress( struct LZ_Encoder * const encoder, + FILE * const infile, FILE * const outfile ) + { + enum { buffer_size = 16384 }; + uint8_t buffer[buffer_size]; + while( true ) + { + int len, ret; + int size = min( buffer_size, LZ_compress_write_size( encoder ) ); + if( size > 0 ) + { + len = fread( buffer, 1, size, infile ); + ret = LZ_compress_write( encoder, buffer, len ); + if( ret < 0 || ferror( infile ) ) break; + if( feof( infile ) ) LZ_compress_finish( encoder ); + } + ret = LZ_compress_read( encoder, buffer, buffer_size ); + if( ret < 0 ) break; + len = fwrite( buffer, 1, ret, outfile ); + if( len < ret ) break; + if( LZ_compress_finished( encoder ) == 1 ) return 0; + } + return 1; + } +@end verbatim + + +@node File decompression +@section File decompression +@cindex file decompression + +File-to-file decompression using LZ_decompress_write_size. + +@verbatim +int ffdecompress( struct LZ_Decoder * const decoder, + FILE * const infile, FILE * const outfile ) + { + enum { buffer_size = 16384 }; + uint8_t buffer[buffer_size]; + while( true ) + { + int len, ret; + int size = min( buffer_size, LZ_decompress_write_size( decoder ) ); + if( size > 0 ) + { + len = fread( buffer, 1, size, infile ); + ret = LZ_decompress_write( decoder, buffer, len ); + if( ret < 0 || ferror( infile ) ) break; + if( feof( infile ) ) LZ_decompress_finish( decoder ); + } + ret = LZ_decompress_read( decoder, buffer, buffer_size ); + if( ret < 0 ) break; + len = fwrite( buffer, 1, ret, outfile ); + if( len < ret ) break; + if( LZ_decompress_finished( decoder ) == 1 ) return 0; + } + return 1; + } +@end verbatim + + +@node File compression mm +@section File-to-file multimember compression +@cindex multimember compression + +Example 1: Multimember compression with members of fixed size +@w{(@var{member_size} < total output)}. + +@verbatim +int ffmmcompress( FILE * const infile, FILE * const outfile ) + { + enum { buffer_size = 16384, member_size = 4096 }; + uint8_t buffer[buffer_size]; + bool done = false; + struct LZ_Encoder * const encoder = + LZ_compress_open( 65535, 16, member_size ); + if( !encoder || LZ_compress_errno( encoder ) != LZ_ok ) + { fputs( "ffexample: Not enough memory.\n", stderr ); + LZ_compress_close( encoder ); return 1; } + while( true ) + { + int len, ret; + int size = min( buffer_size, LZ_compress_write_size( encoder ) ); + if( size > 0 ) + { + len = fread( buffer, 1, size, infile ); + ret = LZ_compress_write( encoder, buffer, len ); + if( ret < 0 || ferror( infile ) ) break; + if( feof( infile ) ) LZ_compress_finish( encoder ); + } + ret = LZ_compress_read( encoder, buffer, buffer_size ); + if( ret < 0 ) break; + len = fwrite( buffer, 1, ret, outfile ); + if( len < ret ) break; + if( LZ_compress_member_finished( encoder ) == 1 ) + { + if( LZ_compress_finished( encoder ) == 1 ) { done = true; break; } + if( LZ_compress_restart_member( encoder, member_size ) < 0 ) break; + } + } + if( LZ_compress_close( encoder ) < 0 ) done = false; + return done; + } +@end verbatim @sp 1 @noindent -Example 2: Normal compression using LZ_compress_write_size. +Example 2: Multimember compression (user-restarted members). +(Call LZ_compress_open with @var{member_size} > largest member). -@example -1) LZ_compress_open -2) go to step 5 if LZ_compress_write_size returns 0 -3) LZ_compress_write -4) if no more data to write, call LZ_compress_finish -5) LZ_compress_read -6) go back to step 2 until LZ_compress_finished returns 1 -7) LZ_compress_close -@end example +@verbatim +/* Compresses 'infile' to 'outfile' as a multimember stream with one member + for each line of text terminated by a newline character or by EOF. + Returns 0 if success, 1 if error. +*/ +int fflfcompress( struct LZ_Encoder * const encoder, + FILE * const infile, FILE * const outfile ) + { + enum { buffer_size = 16384 }; + uint8_t buffer[buffer_size]; + while( true ) + { + int len, ret; + int size = min( buffer_size, LZ_compress_write_size( encoder ) ); + if( size > 0 ) + { + for( len = 0; len < size; ) + { + int ch = getc( infile ); + if( ch == EOF || ( buffer[len++] = ch ) == '\n' ) break; + } + /* avoid writing an empty member to outfile */ + if( len == 0 && LZ_compress_data_position( encoder ) == 0 ) return 0; + ret = LZ_compress_write( encoder, buffer, len ); + if( ret < 0 || ferror( infile ) ) break; + if( feof( infile ) || buffer[len-1] == '\n' ) + LZ_compress_finish( encoder ); + } + ret = LZ_compress_read( encoder, buffer, buffer_size ); + if( ret < 0 ) break; + len = fwrite( buffer, 1, ret, outfile ); + if( len < ret ) break; + if( LZ_compress_member_finished( encoder ) == 1 ) + { + if( feof( infile ) && LZ_compress_finished( encoder ) == 1 ) return 0; + if( LZ_compress_restart_member( encoder, INT64_MAX ) < 0 ) break; + } + } + return 1; + } +@end verbatim -@sp 1 -@noindent -Example 3: Decompression. -@example -1) LZ_decompress_open -2) LZ_decompress_write -3) if no more data to write, call LZ_decompress_finish -4) LZ_decompress_read -5) go back to step 2 until LZ_decompress_finished returns 1 -6) LZ_decompress_close -@end example +@node Skipping data errors +@section Skipping data errors +@cindex skipping data errors -@sp 1 -@noindent -Example 4: Decompression using LZ_decompress_write_size. - -@example -1) LZ_decompress_open -2) go to step 5 if LZ_decompress_write_size returns 0 -3) LZ_decompress_write -4) if no more data to write, call LZ_decompress_finish -5) LZ_decompress_read -5a) optionally, if LZ_decompress_member_finished returns 1, read - final values for member with LZ_decompress_data_crc, etc. -6) go back to step 2 until LZ_decompress_finished returns 1 -7) LZ_decompress_close -@end example - -@sp 1 -@noindent -Example 5: Multimember compression (@var{member_size} < total output). - -@example - 1) LZ_compress_open - 2) go to step 5 if LZ_compress_write_size returns 0 - 3) LZ_compress_write - 4) if no more data to write, call LZ_compress_finish - 5) LZ_compress_read - 6) go back to step 2 until LZ_compress_member_finished returns 1 - 7) go to step 10 if LZ_compress_finished() returns 1 - 8) LZ_compress_restart_member - 9) go back to step 2 -10) LZ_compress_close -@end example - -@sp 1 -@noindent -Example 6: Multimember compression (user-restarted members). - -@example - 1) LZ_compress_open (with @var{member_size} > largest member). - 2) LZ_compress_write - 3) LZ_compress_read - 4) go back to step 2 until member termination is desired - 5) LZ_compress_finish - 6) LZ_compress_read - 7) go back to step 6 until LZ_compress_member_finished returns 1 - 9) go to step 12 if all input data have been written and - LZ_compress_finished returns 1 -10) LZ_compress_restart_member -11) go back to step 2 -12) LZ_compress_close -@end example - -@sp 1 -@noindent -Example 7: Decompression with automatic removal of leading data. - -@example -1) LZ_decompress_open -2) LZ_decompress_sync_to_member -3) go to step 6 if LZ_decompress_write_size returns 0 -4) LZ_decompress_write -5) if no more data to write, call LZ_decompress_finish -6) LZ_decompress_read -7) go back to step 3 until LZ_decompress_finished returns 1 -8) LZ_decompress_close -@end example - -@sp 1 -@noindent -Example 8: Streamed decompression with automatic resynchronization to -next member in case of data error. - -@example -1) LZ_decompress_open -2) go to step 5 if LZ_decompress_write_size returns 0 -3) LZ_decompress_write -4) if no more data to write, call LZ_decompress_finish -5) if LZ_decompress_read produces LZ_header_error or LZ_data_error, - call LZ_decompress_sync_to_member -6) go back to step 2 until LZ_decompress_finished returns 1 -7) LZ_decompress_close -@end example +@verbatim +/* Decompresses 'infile' to 'outfile' with automatic resynchronization to + next member in case of data error, including the automatic removal of + leading garbage. +*/ +int ffrsdecompress( struct LZ_Decoder * const decoder, + FILE * const infile, FILE * const outfile ) + { + enum { buffer_size = 16384 }; + uint8_t buffer[buffer_size]; + while( true ) + { + int len, ret; + int size = min( buffer_size, LZ_decompress_write_size( decoder ) ); + if( size > 0 ) + { + len = fread( buffer, 1, size, infile ); + ret = LZ_decompress_write( decoder, buffer, len ); + if( ret < 0 || ferror( infile ) ) break; + if( feof( infile ) ) LZ_decompress_finish( decoder ); + } + ret = LZ_decompress_read( decoder, buffer, buffer_size ); + if( ret < 0 ) + { + if( LZ_decompress_errno( decoder ) == LZ_header_error || + LZ_decompress_errno( decoder ) == LZ_data_error ) + { LZ_decompress_sync_to_member( decoder ); continue; } + else break; + } + len = fwrite( buffer, 1, ret, outfile ); + if( len < ret ) break; + if( LZ_decompress_finished( decoder ) == 1 ) return 0; + } + return 1; + } +@end verbatim @node Problems @@ -1093,7 +1381,7 @@ for all eternity, if not longer. If you find a bug in lzlib, please send electronic mail to @email{lzip-bug@@nongnu.org}. Include the version number, which you can -find by running @w{@code{minilzip --version}} or in +find by running @w{@samp{minilzip --version}} or in @samp{LZ_version_string} from @samp{lzlib.h}. diff --git a/doc/minilzip.1 b/doc/minilzip.1 index adb6e33..13a2d6d 100644 --- a/doc/minilzip.1 +++ b/doc/minilzip.1 @@ -1,13 +1,23 @@ -.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.46.1. -.TH MINILZIP "1" "January 2019" "minilzip 1.11" "User Commands" +.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.16. +.TH MINILZIP "1" "January 2021" "minilzip 1.12" "User Commands" .SH NAME minilzip \- reduces the size of files .SH SYNOPSIS .B minilzip [\fI\,options\/\fR] [\fI\,files\/\fR] .SH DESCRIPTION -Minilzip is a test program for the lzlib compression library, fully +Minilzip is a test program for the compression library lzlib, fully compatible with lzip 1.4 or newer. +.PP +Lzip is a lossless data compressor with a user interface similar to the one +of gzip or bzip2. Lzip uses a simplified form of the 'Lempel\-Ziv\-Markov +chain\-Algorithm' (LZMA) stream format, chosen to maximize safety and +interoperability. Lzip can compress about as fast as gzip (lzip \fB\-0\fR) or +compress most files more than bzip2 (lzip \fB\-9\fR). Decompression speed is +intermediate between gzip and bzip2. Lzip is better than gzip and bzip2 from +a data recovery perspective. Lzip has been designed, written, and tested +with great care to replace gzip and bzip2 as the standard general\-purpose +compressed format for unix\-like systems. .SH OPTIONS .TP \fB\-h\fR, \fB\-\-help\fR @@ -41,7 +51,7 @@ keep (don't delete) input files set match length limit in bytes [36] .TP \fB\-o\fR, \fB\-\-output=\fR -if reading standard input, write to +write to , keep input files .TP \fB\-q\fR, \fB\-\-quiet\fR suppress all messages @@ -69,6 +79,9 @@ alias for \fB\-9\fR .TP \fB\-\-loose\-trailing\fR allow trailing data seeming corrupt header +.TP +\fB\-\-check\-lib\fR +compare version of lzlib.h with liblz.{a,so} .PP If no file names are given, or if a file is '\-', minilzip compresses or decompresses from standard input to standard output. @@ -79,20 +92,29 @@ to 2^29 bytes. .PP The bidimensional parameter space of LZMA can't be mapped to a linear scale optimal for all files. If your files are large, very repetitive, -etc, you may need to use the \fB\-\-dictionary\-size\fR and \fB\-\-match\-length\fR -options directly to achieve optimal performance. +etc, you may need to use the options \fB\-\-dictionary\-size\fR and \fB\-\-match\-length\fR +directly to achieve optimal performance. +.PP +To extract all the files from archive 'foo.tar.lz', use the commands +\&'tar \fB\-xf\fR foo.tar.lz' or 'minilzip \fB\-cd\fR foo.tar.lz | tar \fB\-xf\fR \-'. .PP Exit status: 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 caused minilzip to panic. +.PP +The ideas embodied in lzlib are due to (at least) the following people: +Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the +definition of Markov chains), G.N.N. Martin (for the definition of range +encoding), Igor Pavlov (for putting all the above together in LZMA), and +Julian Seward (for bzip2's CLI). .SH "REPORTING BUGS" Report bugs to lzip\-bug@nongnu.org .br Lzlib home page: http://www.nongnu.org/lzip/lzlib.html .SH COPYRIGHT -Copyright \(co 2019 Antonio Diaz Diaz. -Using lzlib 1.11 +Copyright \(co 2021 Antonio Diaz Diaz. +Using lzlib 1.12 License GPLv2+: GNU GPL version 2 or later .br This is free software: you are free to change and redistribute it. diff --git a/encoder.c b/encoder.c index 2ec587b..600a444 100644 --- a/encoder.c +++ b/encoder.c @@ -1,20 +1,20 @@ -/* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2019 Antonio Diaz Diaz. +/* Lzlib - Compression library for the lzip format + Copyright (C) 2009-2021 Antonio Diaz Diaz. - This library is free software. Redistribution and use in source and - binary forms, with or without modification, are permitted provided - that the following conditions are met: + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs ) @@ -23,7 +23,7 @@ static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs int32_t * ptr1 = ptr0 + 1; int32_t * newptr; int len = 0, len0 = 0, len1 = 0; - int maxlen = 0; + int maxlen = 3; /* only used if pairs != 0 */ int num_pairs = 0; const int pos1 = e->eb.mb.pos + 1; const int min_pos = ( e->eb.mb.pos > e->eb.mb.dictionary_size ) ? @@ -49,8 +49,8 @@ static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs if( pairs ) { - int np2 = e->eb.mb.prev_positions[key2]; - int np3 = e->eb.mb.prev_positions[key3]; + const int np2 = e->eb.mb.prev_positions[key2]; + const int np3 = e->eb.mb.prev_positions[key3]; if( np2 > min_pos && e->eb.mb.buffer[np2-1] == data[0] ) { pairs[0].dis = e->eb.mb.pos - np2; @@ -60,19 +60,17 @@ static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs if( np2 != np3 && np3 > min_pos && e->eb.mb.buffer[np3-1] == data[0] ) { maxlen = 3; - np2 = np3; - pairs[num_pairs].dis = e->eb.mb.pos - np2; - ++num_pairs; + pairs[num_pairs++].dis = e->eb.mb.pos - np3; } if( num_pairs > 0 ) { - const int delta = pos1 - np2; + const int delta = pairs[num_pairs-1].dis + 1; while( maxlen < len_limit && data[maxlen-delta] == data[maxlen] ) ++maxlen; pairs[num_pairs-1].len = maxlen; + if( maxlen < 3 ) maxlen = 3; if( maxlen >= len_limit ) pairs = 0; /* done. now just skip */ } - if( maxlen < 3 ) maxlen = 3; } e->eb.mb.prev_positions[key2] = pos1; diff --git a/encoder.h b/encoder.h index 8c096df..7a7ecaf 100644 --- a/encoder.h +++ b/encoder.h @@ -1,20 +1,20 @@ -/* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2019 Antonio Diaz Diaz. +/* Lzlib - Compression library for the lzip format + Copyright (C) 2009-2021 Antonio Diaz Diaz. - This library is free software. Redistribution and use in source and - binary forms, with or without modification, are permitted provided - that the following conditions are met: + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ struct Len_prices diff --git a/encoder_base.c b/encoder_base.c index d385f2c..c1ef9ef 100644 --- a/encoder_base.c +++ b/encoder_base.c @@ -1,20 +1,20 @@ -/* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2019 Antonio Diaz Diaz. +/* Lzlib - Compression library for the lzip format + Copyright (C) 2009-2021 Antonio Diaz Diaz. - This library is free software. Redistribution and use in source and - binary forms, with or without modification, are permitted provided - that the following conditions are met: + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ static bool Mb_normalize_pos( struct Matchfinder_base * const mb ) @@ -58,7 +58,7 @@ static bool Mb_init( struct Matchfinder_base * const mb, const int before_size, mb->stream_pos = 0; mb->num_prev_positions23 = num_prev_positions23; mb->at_stream_end = false; - mb->flushing = false; + mb->sync_flush_pending = false; mb->buffer_size = max( 65536, buffer_size_limit ); mb->buffer = (uint8_t *)malloc( mb->buffer_size ); @@ -69,7 +69,7 @@ static bool Mb_init( struct Matchfinder_base * const mb, const int before_size, size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 ); if( mb->dictionary_size > 1 << 26 ) /* 64 MiB */ size >>= 1; - mb->key4_mask = size - 1; + mb->key4_mask = size - 1; /* increases with dictionary size */ size += num_prev_positions23; mb->num_prev_positions = size; @@ -118,7 +118,7 @@ static void Mb_reset( struct Matchfinder_base * const mb ) mb->pos = 0; mb->cyclic_pos = 0; mb->at_stream_end = false; - mb->flushing = false; + mb->sync_flush_pending = false; mb->dictionary_size = mb->saved_dictionary_size; Mb_adjust_array( mb ); mb->pos_limit = mb->buffer_size - mb->after_size; @@ -126,7 +126,7 @@ static void Mb_reset( struct Matchfinder_base * const mb ) } - /* End Of Stream mark => (dis == 0xFFFFFFFFU, len == min_match_len) */ +/* End Of Stream marker => (dis == 0xFFFFFFFFU, len == min_match_len) */ static void LZeb_try_full_flush( struct LZ_encoder_base * const eb ) { int i; @@ -149,33 +149,36 @@ static void LZeb_try_full_flush( struct LZ_encoder_base * const eb ) } - /* Sync Flush mark => (dis == 0xFFFFFFFFU, len == min_match_len + 1) */ -static bool LZeb_sync_flush( struct LZ_encoder_base * const eb ) +/* Sync Flush marker => (dis == 0xFFFFFFFFU, len == min_match_len + 1) */ +static void LZeb_try_sync_flush( struct LZ_encoder_base * const eb ) { - int i; const int pos_state = Mb_data_position( &eb->mb ) & pos_state_mask; const State state = eb->state; + const unsigned min_size = eb->renc.ff_count + max_marker_size; if( eb->member_finished || - Cb_free_bytes( &eb->renc.cb ) < (2 * max_marker_size) + eb->renc.ff_count ) - return false; - for( i = 0; i < 2; ++i ) /* 2 consecutive markers guarantee decoding */ - { + Cb_free_bytes( &eb->renc.cb ) < min_size + max_marker_size ) return; + eb->mb.sync_flush_pending = false; + const unsigned long long old_mpos = Re_member_position( &eb->renc ); + do { /* size of markers must be >= rd_min_available_bytes + 5 */ Re_encode_bit( &eb->renc, &eb->bm_match[state][pos_state], 1 ); Re_encode_bit( &eb->renc, &eb->bm_rep[state], 0 ); LZeb_encode_pair( eb, 0xFFFFFFFFU, min_match_len + 1, pos_state ); Re_flush( &eb->renc ); } - return true; + while( Re_member_position( &eb->renc ) - old_mpos < min_size ); } static void LZeb_reset( struct LZ_encoder_base * const eb, const unsigned long long member_size ) { + const unsigned long long min_member_size = min_dictionary_size; + const unsigned long long max_member_size = 0x0008000000000000ULL; /* 2 PiB */ int i; Mb_reset( &eb->mb ); eb->member_size_limit = - min( member_size, 0x0008000000000000ULL ) - Lt_size - max_marker_size; + min( max( min_member_size, member_size ), max_member_size ) - + Lt_size - max_marker_size; eb->crc = 0xFFFFFFFFU; Bm_array_init( eb->bm_literal[0], (1 << literal_context_bits) * 0x300 ); Bm_array_init( eb->bm_match[0], states * pos_states ); diff --git a/encoder_base.h b/encoder_base.h index f0240cc..e727a7d 100644 --- a/encoder_base.h +++ b/encoder_base.h @@ -1,20 +1,20 @@ -/* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2019 Antonio Diaz Diaz. +/* Lzlib - Compression library for the lzip format + Copyright (C) 2009-2021 Antonio Diaz Diaz. - This library is free software. Redistribution and use in source and - binary forms, with or without modification, are permitted provided - that the following conditions are met: + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ enum { price_shift_bits = 6, @@ -197,7 +197,7 @@ static inline int price_symbol_reversed( const Bit_model bm[], int symbol, const bool bit = symbol & 1; symbol >>= 1; price += price_bit( bm[model], bit ); - model = ( model << 1 ) | bit; + model <<= 1; model |= bit; } return price; } @@ -240,7 +240,7 @@ struct Matchfinder_base int pos_array_size; int saved_dictionary_size; /* dictionary_size restored by Mb_reset */ bool at_stream_end; /* stream_pos shows real end of file */ - bool flushing; + bool sync_flush_pending; }; static bool Mb_normalize_pos( struct Matchfinder_base * const mb ); @@ -265,19 +265,20 @@ Mb_data_position( const struct Matchfinder_base * const mb ) { return mb->partial_data_pos + mb->pos; } static inline void Mb_finish( struct Matchfinder_base * const mb ) - { mb->at_stream_end = true; mb->flushing = false; } + { mb->at_stream_end = true; mb->sync_flush_pending = false; } static inline bool Mb_data_finished( const struct Matchfinder_base * const mb ) - { return mb->at_stream_end && !mb->flushing && mb->pos >= mb->stream_pos; } + { return mb->at_stream_end && mb->pos >= mb->stream_pos; } static inline bool Mb_flushing_or_end( const struct Matchfinder_base * const mb ) - { return mb->at_stream_end || mb->flushing; } + { return mb->at_stream_end || mb->sync_flush_pending; } static inline int Mb_free_bytes( const struct Matchfinder_base * const mb ) { if( Mb_flushing_or_end( mb ) ) return 0; return mb->buffer_size - mb->stream_pos; } -static inline bool Mb_enough_available_bytes( const struct Matchfinder_base * const mb ) +static inline bool +Mb_enough_available_bytes( const struct Matchfinder_base * const mb ) { return ( mb->pos + mb->after_size <= mb->stream_pos || ( Mb_flushing_or_end( mb ) && mb->pos < mb->stream_pos ) ); } @@ -426,28 +427,30 @@ static inline void Re_encode_bit( struct Range_encoder * const renc, static inline void Re_encode_tree3( struct Range_encoder * const renc, Bit_model bm[], const int symbol ) { - int model = 1; + int model; bool bit = ( symbol >> 2 ) & 1; - Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; + Re_encode_bit( renc, &bm[1], bit ); + model = 2 | bit; bit = ( symbol >> 1 ) & 1; - Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; + Re_encode_bit( renc, &bm[model], bit ); model <<= 1; model |= bit; Re_encode_bit( renc, &bm[model], symbol & 1 ); } static inline void Re_encode_tree6( struct Range_encoder * const renc, Bit_model bm[], const unsigned symbol ) { - int model = 1; + int model; bool bit = ( symbol >> 5 ) & 1; - Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; + Re_encode_bit( renc, &bm[1], bit ); + model = 2 | bit; bit = ( symbol >> 4 ) & 1; - Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; + Re_encode_bit( renc, &bm[model], bit ); model <<= 1; model |= bit; bit = ( symbol >> 3 ) & 1; - Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; + Re_encode_bit( renc, &bm[model], bit ); model <<= 1; model |= bit; bit = ( symbol >> 2 ) & 1; - Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; + Re_encode_bit( renc, &bm[model], bit ); model <<= 1; model |= bit; bit = ( symbol >> 1 ) & 1; - Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; + Re_encode_bit( renc, &bm[model], bit ); model <<= 1; model |= bit; Re_encode_bit( renc, &bm[model], symbol & 1 ); } @@ -460,7 +463,7 @@ static inline void Re_encode_tree8( struct Range_encoder * const renc, { const bool bit = ( symbol >> i ) & 1; Re_encode_bit( renc, &bm[model], bit ); - model = ( model << 1 ) | bit; + model <<= 1; model |= bit; } } @@ -474,7 +477,7 @@ static inline void Re_encode_tree_reversed( struct Range_encoder * const renc, const bool bit = symbol & 1; symbol >>= 1; Re_encode_bit( renc, &bm[model], bit ); - model = ( model << 1 ) | bit; + model <<= 1; model |= bit; } } @@ -561,7 +564,7 @@ static inline bool LZeb_init( struct LZ_encoder_base * const eb, } static inline bool LZeb_member_finished( const struct LZ_encoder_base * const eb ) - { return ( eb->member_finished && !Cb_used_bytes( &eb->renc.cb ) ); } + { return ( eb->member_finished && Cb_empty( &eb->renc.cb ) ); } static inline void LZeb_free( struct LZ_encoder_base * const eb ) { Re_free( &eb->renc ); Mb_free( &eb->mb ); } diff --git a/fast_encoder.c b/fast_encoder.c index 48f8368..bdcbb97 100644 --- a/fast_encoder.c +++ b/fast_encoder.c @@ -1,23 +1,23 @@ -/* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2019 Antonio Diaz Diaz. +/* Lzlib - Compression library for the lzip format + Copyright (C) 2009-2021 Antonio Diaz Diaz. - This library is free software. Redistribution and use in source and - binary forms, with or without modification, are permitted provided - that the following conditions are met: + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ -int FLZe_longest_match_len( struct FLZ_encoder * const fe, int * const distance ) +static int FLZe_longest_match_len( struct FLZ_encoder * const fe, int * const distance ) { enum { len_limit = 16 }; const uint8_t * const data = Mb_ptr_to_current_pos( &fe->eb.mb ); @@ -59,7 +59,7 @@ int FLZe_longest_match_len( struct FLZ_encoder * const fe, int * const distance } -bool FLZe_encode_member( struct FLZ_encoder * const fe ) +static bool FLZe_encode_member( struct FLZ_encoder * const fe ) { int rep = 0, i; State * const state = &fe->eb.state; @@ -86,7 +86,7 @@ bool FLZe_encode_member( struct FLZ_encoder * const fe ) while( !Mb_data_finished( &fe->eb.mb ) && Re_member_position( &fe->eb.renc ) < fe->eb.member_size_limit ) { - int match_distance; + int match_distance = 0; /* avoid warning from gcc 6.1.0 */ int main_len, pos_state; int len = 0; if( !Mb_enough_available_bytes( &fe->eb.mb ) || diff --git a/fast_encoder.h b/fast_encoder.h index 6066b85..1c3a6ff 100644 --- a/fast_encoder.h +++ b/fast_encoder.h @@ -1,20 +1,20 @@ -/* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2019 Antonio Diaz Diaz. +/* Lzlib - Compression library for the lzip format + Copyright (C) 2009-2021 Antonio Diaz Diaz. - This library is free software. Redistribution and use in source and - binary forms, with or without modification, are permitted provided - that the following conditions are met: + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ struct FLZ_encoder @@ -31,21 +31,19 @@ static inline void FLZe_reset_key4( struct FLZ_encoder * const fe ) fe->key4 = ( fe->key4 << 4 ) ^ fe->eb.mb.buffer[i]; } -int FLZe_longest_match_len( struct FLZ_encoder * const fe, int * const distance ); - static inline bool FLZe_update_and_move( struct FLZ_encoder * const fe, int n ) { + struct Matchfinder_base * const mb = &fe->eb.mb; while( --n >= 0 ) { - if( Mb_available_bytes( &fe->eb.mb ) >= 4 ) + if( Mb_available_bytes( mb ) >= 4 ) { - fe->key4 = ( ( fe->key4 << 4 ) ^ fe->eb.mb.buffer[fe->eb.mb.pos+3] ) & - fe->eb.mb.key4_mask; - fe->eb.mb.pos_array[fe->eb.mb.cyclic_pos] = fe->eb.mb.prev_positions[fe->key4]; - fe->eb.mb.prev_positions[fe->key4] = fe->eb.mb.pos + 1; + fe->key4 = ( ( fe->key4 << 4 ) ^ mb->buffer[mb->pos+3] ) & mb->key4_mask; + mb->pos_array[mb->cyclic_pos] = mb->prev_positions[fe->key4]; + mb->prev_positions[fe->key4] = mb->pos + 1; } - else fe->eb.mb.pos_array[fe->eb.mb.cyclic_pos] = 0; - if( !Mb_move_pos( &fe->eb.mb ) ) return false; + else mb->pos_array[mb->cyclic_pos] = 0; + if( !Mb_move_pos( mb ) ) return false; } return true; } diff --git a/ffexample.c b/ffexample.c new file mode 100644 index 0000000..2891f02 --- /dev/null +++ b/ffexample.c @@ -0,0 +1,300 @@ +/* File to file example - Test program for the library lzlib + Copyright (C) 2010-2021 Antonio Diaz Diaz. + + This program is free software: you have unlimited permission + to copy, distribute, and modify it. + + Try 'ffexample -h' for usage information. + + This program is an example of how file-to-file + compression/decompression can be implemented using lzlib. +*/ + +#define _FILE_OFFSET_BITS 64 + +#include +#include +#include +#include +#include +#include +#include +#include +#if defined(__MSVCRT__) || defined(__OS2__) || defined(__DJGPP__) +#include +#include +#endif + +#include "lzlib.h" + +#ifndef min + #define min(x,y) ((x) <= (y) ? (x) : (y)) +#endif + + +static void show_help( void ) + { + printf( "ffexample is an example program showing how file-to-file (de)compression can\n" + "be implemented using lzlib. The content of infile is compressed,\n" + "decompressed, or both, and then written to outfile.\n" + "\nUsage: ffexample operation [infile [outfile]]\n" ); + printf( "\nOperation:\n" + " -h display this help and exit\n" + " -c compress infile to outfile\n" + " -d decompress infile to outfile\n" + " -b both (compress then decompress) infile to outfile\n" + " -m compress (multimember) infile to outfile\n" + " -l compress (1 member per line) infile to outfile\n" + " -r decompress with resync if data error or leading garbage\n" + "\nIf infile or outfile are omitted, or are specified as '-', standard input or\n" + "standard output are used in their place respectively.\n" + "\nReport bugs to lzip-bug@nongnu.org\n" + "Lzlib home page: http://www.nongnu.org/lzip/lzlib.html\n" ); + } + + +int ffcompress( struct LZ_Encoder * const encoder, + FILE * const infile, FILE * const outfile ) + { + enum { buffer_size = 16384 }; + uint8_t buffer[buffer_size]; + while( true ) + { + int len, ret; + int size = min( buffer_size, LZ_compress_write_size( encoder ) ); + if( size > 0 ) + { + len = fread( buffer, 1, size, infile ); + ret = LZ_compress_write( encoder, buffer, len ); + if( ret < 0 || ferror( infile ) ) break; + if( feof( infile ) ) LZ_compress_finish( encoder ); + } + ret = LZ_compress_read( encoder, buffer, buffer_size ); + if( ret < 0 ) break; + len = fwrite( buffer, 1, ret, outfile ); + if( len < ret ) break; + if( LZ_compress_finished( encoder ) == 1 ) return 0; + } + return 1; + } + + +int ffdecompress( struct LZ_Decoder * const decoder, + FILE * const infile, FILE * const outfile ) + { + enum { buffer_size = 16384 }; + uint8_t buffer[buffer_size]; + while( true ) + { + int len, ret; + int size = min( buffer_size, LZ_decompress_write_size( decoder ) ); + if( size > 0 ) + { + len = fread( buffer, 1, size, infile ); + ret = LZ_decompress_write( decoder, buffer, len ); + if( ret < 0 || ferror( infile ) ) break; + if( feof( infile ) ) LZ_decompress_finish( decoder ); + } + ret = LZ_decompress_read( decoder, buffer, buffer_size ); + if( ret < 0 ) break; + len = fwrite( buffer, 1, ret, outfile ); + if( len < ret ) break; + if( LZ_decompress_finished( decoder ) == 1 ) return 0; + } + return 1; + } + + +int ffboth( struct LZ_Encoder * const encoder, + struct LZ_Decoder * const decoder, + FILE * const infile, FILE * const outfile ) + { + enum { buffer_size = 16384 }; + uint8_t buffer[buffer_size]; + while( true ) + { + int len, ret; + int size = min( buffer_size, LZ_compress_write_size( encoder ) ); + if( size > 0 ) + { + len = fread( buffer, 1, size, infile ); + ret = LZ_compress_write( encoder, buffer, len ); + if( ret < 0 || ferror( infile ) ) break; + if( feof( infile ) ) LZ_compress_finish( encoder ); + } + size = min( buffer_size, LZ_decompress_write_size( decoder ) ); + if( size > 0 ) + { + ret = LZ_compress_read( encoder, buffer, size ); + if( ret < 0 ) break; + ret = LZ_decompress_write( decoder, buffer, ret ); + if( ret < 0 ) break; + if( LZ_compress_finished( encoder ) == 1 ) + LZ_decompress_finish( decoder ); + } + ret = LZ_decompress_read( decoder, buffer, buffer_size ); + if( ret < 0 ) break; + len = fwrite( buffer, 1, ret, outfile ); + if( len < ret ) break; + if( LZ_decompress_finished( decoder ) == 1 ) return 0; + } + return 1; + } + + +int ffmmcompress( FILE * const infile, FILE * const outfile ) + { + enum { buffer_size = 16384, member_size = 4096 }; + uint8_t buffer[buffer_size]; + bool done = false; + struct LZ_Encoder * const encoder = + LZ_compress_open( 65535, 16, member_size ); + if( !encoder || LZ_compress_errno( encoder ) != LZ_ok ) + { fputs( "ffexample: Not enough memory.\n", stderr ); + LZ_compress_close( encoder ); return 1; } + while( true ) + { + int len, ret; + int size = min( buffer_size, LZ_compress_write_size( encoder ) ); + if( size > 0 ) + { + len = fread( buffer, 1, size, infile ); + ret = LZ_compress_write( encoder, buffer, len ); + if( ret < 0 || ferror( infile ) ) break; + if( feof( infile ) ) LZ_compress_finish( encoder ); + } + ret = LZ_compress_read( encoder, buffer, buffer_size ); + if( ret < 0 ) break; + len = fwrite( buffer, 1, ret, outfile ); + if( len < ret ) break; + if( LZ_compress_member_finished( encoder ) == 1 ) + { + if( LZ_compress_finished( encoder ) == 1 ) { done = true; break; } + if( LZ_compress_restart_member( encoder, member_size ) < 0 ) break; + } + } + if( LZ_compress_close( encoder ) < 0 ) done = false; + return done; + } + + +/* Compresses 'infile' to 'outfile' as a multimember stream with one member + for each line of text terminated by a newline character or by EOF. + Returns 0 if success, 1 if error. +*/ +int fflfcompress( struct LZ_Encoder * const encoder, + FILE * const infile, FILE * const outfile ) + { + enum { buffer_size = 16384 }; + uint8_t buffer[buffer_size]; + while( true ) + { + int len, ret; + int size = min( buffer_size, LZ_compress_write_size( encoder ) ); + if( size > 0 ) + { + for( len = 0; len < size; ) + { + int ch = getc( infile ); + if( ch == EOF || ( buffer[len++] = ch ) == '\n' ) break; + } + /* avoid writing an empty member to outfile */ + if( len == 0 && LZ_compress_data_position( encoder ) == 0 ) return 0; + ret = LZ_compress_write( encoder, buffer, len ); + if( ret < 0 || ferror( infile ) ) break; + if( feof( infile ) || buffer[len-1] == '\n' ) + LZ_compress_finish( encoder ); + } + ret = LZ_compress_read( encoder, buffer, buffer_size ); + if( ret < 0 ) break; + len = fwrite( buffer, 1, ret, outfile ); + if( len < ret ) break; + if( LZ_compress_member_finished( encoder ) == 1 ) + { + if( feof( infile ) && LZ_compress_finished( encoder ) == 1 ) return 0; + if( LZ_compress_restart_member( encoder, INT64_MAX ) < 0 ) break; + } + } + return 1; + } + + +/* Decompresses 'infile' to 'outfile' with automatic resynchronization to + next member in case of data error, including the automatic removal of + leading garbage. +*/ +int ffrsdecompress( struct LZ_Decoder * const decoder, + FILE * const infile, FILE * const outfile ) + { + enum { buffer_size = 16384 }; + uint8_t buffer[buffer_size]; + while( true ) + { + int len, ret; + int size = min( buffer_size, LZ_decompress_write_size( decoder ) ); + if( size > 0 ) + { + len = fread( buffer, 1, size, infile ); + ret = LZ_decompress_write( decoder, buffer, len ); + if( ret < 0 || ferror( infile ) ) break; + if( feof( infile ) ) LZ_decompress_finish( decoder ); + } + ret = LZ_decompress_read( decoder, buffer, buffer_size ); + if( ret < 0 ) + { + if( LZ_decompress_errno( decoder ) == LZ_header_error || + LZ_decompress_errno( decoder ) == LZ_data_error ) + { LZ_decompress_sync_to_member( decoder ); continue; } + else break; + } + len = fwrite( buffer, 1, ret, outfile ); + if( len < ret ) break; + if( LZ_decompress_finished( decoder ) == 1 ) return 0; + } + return 1; + } + + +int main( const int argc, const char * const argv[] ) + { +#if defined(__MSVCRT__) || defined(__OS2__) || defined(__DJGPP__) + setmode( STDIN_FILENO, O_BINARY ); + setmode( STDOUT_FILENO, O_BINARY ); +#endif + + struct LZ_Encoder * const encoder = LZ_compress_open( 65535, 16, INT64_MAX ); + struct LZ_Decoder * const decoder = LZ_decompress_open(); + FILE * const infile = ( argc >= 3 && strcmp( argv[2], "-" ) != 0 ) ? + fopen( argv[2], "rb" ) : stdin; + FILE * const outfile = ( argc >= 4 && strcmp( argv[3], "-" ) != 0 ) ? + fopen( argv[3], "wb" ) : stdout; + int retval; + + if( argc < 2 || argc > 4 || strlen( argv[1] ) != 2 || argv[1][0] != '-' ) + { show_help(); return 1; } + if( !encoder || LZ_compress_errno( encoder ) != LZ_ok || + !decoder || LZ_decompress_errno( decoder ) != LZ_ok ) + { fputs( "ffexample: Not enough memory.\n", stderr ); + LZ_compress_close( encoder ); LZ_decompress_close( decoder ); return 1; } + if( !infile ) + { fprintf( stderr, "ffexample: Can't open input file '%s': %s\n", + argv[2], strerror( errno ) ); return 1; } + if( !outfile ) + { fprintf( stderr, "ffexample: Can't open output file '%s': %s\n", + argv[3], strerror( errno ) ); return 1; } + + switch( argv[1][1] ) + { + case 'c': retval = ffcompress( encoder, infile, outfile ); break; + case 'd': retval = ffdecompress( decoder, infile, outfile ); break; + case 'b': retval = ffboth( encoder, decoder, infile, outfile ); break; + case 'm': retval = ffmmcompress( infile, outfile ); break; + case 'l': retval = fflfcompress( encoder, infile, outfile ); break; + case 'r': retval = ffrsdecompress( decoder, infile, outfile ); break; + default: show_help(); return ( argv[1][1] != 'h' ); + } + + if( LZ_decompress_close( decoder ) < 0 || LZ_compress_close( encoder ) < 0 || + fclose( outfile ) != 0 || fclose( infile ) != 0 ) retval = 1; + return retval; + } diff --git a/lzcheck.c b/lzcheck.c index deb4f2a..7e00e6c 100644 --- a/lzcheck.c +++ b/lzcheck.c @@ -1,15 +1,14 @@ -/* Lzcheck - Test program for the lzlib library - Copyright (C) 2009-2019 Antonio Diaz Diaz. +/* Lzcheck - Test program for the library lzlib + Copyright (C) 2009-2021 Antonio Diaz Diaz. - This program is free software: you have unlimited permission - to copy, distribute and modify it. + This program is free software: you have unlimited permission + to copy, distribute, and modify it. - Usage is: - lzcheck filename.txt... + Usage: lzcheck [-m|-s] filename.txt... - This program reads each specified text file and then compresses it, - line by line, to test the flushing mechanism and the member - restart/reset/sync functions. + This program reads each text file specified and then compresses it, + line by line, to test the flushing mechanism and the member + restart/reset/sync functions. */ #define _FILE_OFFSET_BITS 64 @@ -21,21 +20,19 @@ #include #include #include +#include #include "lzlib.h" -#ifndef min - #define min(x,y) ((x) <= (y) ? (x) : (y)) -#endif - +const unsigned long long member_size = INT64_MAX; enum { buffer_size = 32768 }; uint8_t in_buffer[buffer_size]; uint8_t mid_buffer[buffer_size]; uint8_t out_buffer[buffer_size]; -void show_line( const uint8_t * const buffer, const int size ) +static void show_line( const uint8_t * const buffer, const int size ) { int i; for( i = 0; i < size; ++i ) @@ -44,177 +41,281 @@ void show_line( const uint8_t * const buffer, const int size ) } -int lzcheck( FILE * const file, const int dictionary_size ) +static struct LZ_Encoder * xopen_encoder( const int dictionary_size ) { const int match_len_limit = 16; - const unsigned long long member_size = 0x7FFFFFFFFFFFFFFFULL; /* INT64_MAX */ - struct LZ_Encoder * encoder; - struct LZ_Decoder * decoder; - int retval = 0; - - encoder = LZ_compress_open( dictionary_size, match_len_limit, member_size ); + struct LZ_Encoder * const encoder = + LZ_compress_open( dictionary_size, match_len_limit, member_size ); if( !encoder || LZ_compress_errno( encoder ) != LZ_ok ) { - const bool mem_error = ( LZ_compress_errno( encoder ) == LZ_mem_error ); + const bool bad_arg = + encoder && ( LZ_compress_errno( encoder ) == LZ_bad_argument ); LZ_compress_close( encoder ); - if( mem_error ) + if( bad_arg ) { - fputs( "lzcheck: Not enough memory.\n", stderr ); - return 1; + fputs( "lzcheck: internal error: Invalid argument to encoder.\n", stderr ); + exit( 3 ); } - fputs( "lzcheck: internal error: Invalid argument to encoder.\n", stderr ); - return 3; + fputs( "lzcheck: Not enough memory.\n", stderr ); + exit( 1 ); } + return encoder; + } - decoder = LZ_decompress_open(); +static struct LZ_Decoder * xopen_decoder( void ) + { + struct LZ_Decoder * const decoder = LZ_decompress_open(); if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok ) { LZ_decompress_close( decoder ); fputs( "lzcheck: Not enough memory.\n", stderr ); - return 1; + exit( 1 ); + } + return decoder; + } + + +static void xclose_encoder( struct LZ_Encoder * const encoder, + const bool finish ) + { + if( finish ) + { + unsigned long long size = 0; + LZ_compress_finish( encoder ); + while( true ) + { + const int rd = LZ_compress_read( encoder, mid_buffer, buffer_size ); + if( rd < 0 ) + { + fprintf( stderr, "lzcheck: xclose: LZ_compress_read error: %s\n", + LZ_strerror( LZ_compress_errno( encoder ) ) ); + exit( 3 ); + } + size += rd; + if( LZ_compress_finished( encoder ) == 1 ) break; + } + if( size > 0 ) + { + fprintf( stderr, "lzcheck: %lld bytes remain in encoder.\n", size ); + exit( 3 ); + } + } + if( LZ_compress_close( encoder ) < 0 ) exit( 1 ); + } + + +static void xclose_decoder( struct LZ_Decoder * const decoder, + const bool finish ) + { + if( finish ) + { + unsigned long long size = 0; + LZ_decompress_finish( decoder ); + while( true ) + { + const int rd = LZ_decompress_read( decoder, out_buffer, buffer_size ); + if( rd < 0 ) + { + fprintf( stderr, "lzcheck: xclose: LZ_decompress_read error: %s\n", + LZ_strerror( LZ_decompress_errno( decoder ) ) ); + exit( 3 ); + } + size += rd; + if( LZ_decompress_finished( decoder ) == 1 ) break; + } + if( size > 0 ) + { + fprintf( stderr, "lzcheck: %lld bytes remain in decoder.\n", size ); + exit( 3 ); + } + } + if( LZ_decompress_close( decoder ) < 0 ) exit( 1 ); + } + + +/* Returns the next (usually newline-terminated) chunk of data from file. + The size returned in *sizep is always <= buffer_size. + If sizep is a null pointer, rewinds the file, resets state, and returns. + If file is at EOF, returns an empty line. */ +static const uint8_t * next_line( FILE * const file, int * const sizep ) + { + static int l = 0; + static int read_size = 0; + int r; + + if( !sizep ) { rewind( file ); l = read_size = 0; return in_buffer; } + if( l >= read_size ) + { + l = 0; read_size = fread( in_buffer, 1, buffer_size, file ); + if( l >= read_size ) { *sizep = 0; return in_buffer; } /* end of file */ } - while( retval <= 1 ) + for( r = l + 1; r < read_size && in_buffer[r-1] != '\n'; ++r ); + *sizep = r - l; l = r; + return in_buffer + l - *sizep; + } + + +static int check_sync_flush( FILE * const file, const int dictionary_size ) + { + struct LZ_Encoder * const encoder = xopen_encoder( dictionary_size ); + struct LZ_Decoder * const decoder = xopen_decoder(); + int retval = 0; + + while( retval <= 1 ) /* test LZ_compress_sync_flush */ { - int l, r; - const int read_size = fread( in_buffer, 1, buffer_size, file ); - if( read_size <= 0 ) break; /* end of file */ + int in_size, mid_size, out_size; + int line_size; + const uint8_t * const line_buf = next_line( file, &line_size ); + if( line_size <= 0 ) break; /* end of file */ - for( l = 0, r = 1; r <= read_size; l = r, ++r ) - { - int in_size, mid_size, out_size; - while( r < read_size && in_buffer[r-1] != '\n' ) ++r; - in_size = LZ_compress_write( encoder, in_buffer + l, r - l ); - if( in_size < r - l ) r = l + in_size; - LZ_compress_sync_flush( encoder ); + in_size = LZ_compress_write( encoder, line_buf, line_size ); + if( in_size < line_size ) + fprintf( stderr, "lzcheck: sync: LZ_compress_write only accepted %d of %d bytes\n", + in_size, line_size ); + LZ_compress_sync_flush( encoder ); + if( line_buf[0] & 1 ) /* read all data at once or byte by byte */ mid_size = LZ_compress_read( encoder, mid_buffer, buffer_size ); - if( mid_size < 0 ) - { - fprintf( stderr, "lzcheck: LZ_compress_read error: %s\n", - LZ_strerror( LZ_compress_errno( encoder ) ) ); - retval = 3; break; - } - LZ_decompress_write( decoder, mid_buffer, mid_size ); - out_size = LZ_decompress_read( decoder, out_buffer, buffer_size ); - if( out_size < 0 ) - { - fprintf( stderr, "lzcheck: LZ_decompress_read error: %s\n", - LZ_strerror( LZ_decompress_errno( decoder ) ) ); - retval = 3; break; - } + else for( mid_size = 0; mid_size < buffer_size; ) + { + const int rd = LZ_compress_read( encoder, mid_buffer + mid_size, 1 ); + if( rd > 0 ) mid_size += rd; + else { if( rd < 0 ) { mid_size = -1; } break; } + } + if( mid_size < 0 ) + { + fprintf( stderr, "lzcheck: LZ_compress_read error: %s\n", + LZ_strerror( LZ_compress_errno( encoder ) ) ); + retval = 3; break; + } + LZ_decompress_write( decoder, mid_buffer, mid_size ); + out_size = LZ_decompress_read( decoder, out_buffer, buffer_size ); + if( out_size < 0 ) + { + fprintf( stderr, "lzcheck: LZ_decompress_read error: %s\n", + LZ_strerror( LZ_decompress_errno( decoder ) ) ); + retval = 3; break; + } - if( out_size != in_size || memcmp( in_buffer + l, out_buffer, out_size ) ) - { - fprintf( stderr, "lzcheck: Sync error at pos %d in_size = %d, " - "out_size = %d\n", - l, in_size, out_size ); - show_line( in_buffer + l, in_size ); - show_line( out_buffer, out_size ); - retval = 1; - } + if( out_size != in_size || memcmp( line_buf, out_buffer, out_size ) ) + { + fprintf( stderr, "lzcheck: LZ_compress_sync_flush error: " + "in_size = %d, out_size = %d\n", in_size, out_size ); + show_line( line_buf, in_size ); + show_line( out_buffer, out_size ); + retval = 1; } } if( retval <= 1 ) { - rewind( file ); + int rd = 0; if( LZ_compress_finish( encoder ) < 0 || - LZ_compress_finish( encoder ) < 0 || - LZ_decompress_write( decoder, mid_buffer, - LZ_compress_read( encoder, mid_buffer, buffer_size ) ) < 0 || - LZ_decompress_read( decoder, out_buffer, buffer_size ) != 0 || - LZ_compress_finish( encoder ) < 0 || - LZ_compress_restart_member( encoder, member_size ) < 0 ) + ( rd = LZ_compress_read( encoder, mid_buffer, buffer_size ) ) < 0 ) { - fprintf( stderr, "lzcheck: Can't finish member: %s\n", - LZ_strerror( LZ_decompress_errno( decoder ) ) ); + fprintf( stderr, "lzcheck: Can't drain encoder: %s\n", + LZ_strerror( LZ_compress_errno( encoder ) ) ); retval = 3; } + LZ_decompress_write( decoder, mid_buffer, rd ); } - while( retval <= 1 ) - { - int l, r, size; - const int read_size = fread( in_buffer, 1, buffer_size / 2, file ); - if( read_size <= 0 ) break; /* end of file */ + xclose_decoder( decoder, retval == 0 ); + xclose_encoder( encoder, retval == 0 ); + return retval; + } - for( l = 0, r = 1; r <= read_size; l = r, ++r ) + +/* Test member by member decompression without calling LZ_decompress_finish, + inserting leading garbage before some members, and resetting the + decompressor sometimes. Test that the increase in total_in_size when + syncing to member is equal to the size of the leading garbage skipped. +*/ +static int check_members( FILE * const file, const int dictionary_size ) + { + struct LZ_Encoder * const encoder = xopen_encoder( dictionary_size ); + struct LZ_Decoder * const decoder = xopen_decoder(); + int retval = 0; + + while( retval <= 1 ) /* test LZ_compress_restart_member */ + { + unsigned long long garbage_begin = 0; /* avoid warning from gcc 3.3.6 */ + int leading_garbage, in_size, mid_size, out_size; + int line_size; + const uint8_t * const line_buf = next_line( file, &line_size ); + if( line_size <= 0 && /* end of file, write at least 1 member */ + LZ_decompress_total_in_size( decoder ) != 0 ) break; + + if( LZ_compress_finished( encoder ) == 1 ) { - int leading_garbage, in_size, mid_size, out_size; - while( r < read_size && in_buffer[r-1] != '\n' ) ++r; - leading_garbage = (l == 0) ? min( r, read_size ) / 2 : 0; - in_size = LZ_compress_write( encoder, in_buffer + l, r - l ); - if( in_size < r - l ) r = l + in_size; - LZ_compress_sync_flush( encoder ); - if( leading_garbage ) - memset( mid_buffer, in_buffer[0], leading_garbage ); - mid_size = LZ_compress_read( encoder, mid_buffer + leading_garbage, - buffer_size - leading_garbage ); - if( mid_size < 0 ) + if( LZ_compress_restart_member( encoder, member_size ) < 0 ) { - fprintf( stderr, "lzcheck: LZ_compress_read error: %s\n", + fprintf( stderr, "lzcheck: Can't restart member: %s\n", LZ_strerror( LZ_compress_errno( encoder ) ) ); retval = 3; break; } - LZ_decompress_write( decoder, mid_buffer, mid_size + leading_garbage ); - out_size = LZ_decompress_read( decoder, out_buffer, buffer_size ); - if( out_size < 0 ) + if( line_size >= 2 && line_buf[1] == 'h' ) + LZ_decompress_reset( decoder ); + } + in_size = LZ_compress_write( encoder, line_buf, line_size ); + if( in_size < line_size ) + fprintf( stderr, "lzcheck: member: LZ_compress_write only accepted %d of %d bytes\n", + in_size, line_size ); + LZ_compress_finish( encoder ); + if( line_size * 3 < buffer_size && line_buf[0] == 't' ) + { leading_garbage = line_size; + memset( mid_buffer, in_buffer[0], leading_garbage ); + garbage_begin = LZ_decompress_total_in_size( decoder ); } + else leading_garbage = 0; + mid_size = LZ_compress_read( encoder, mid_buffer + leading_garbage, + buffer_size - leading_garbage ); + if( mid_size < 0 ) + { + fprintf( stderr, "lzcheck: member: LZ_compress_read error: %s\n", + LZ_strerror( LZ_compress_errno( encoder ) ) ); + retval = 3; break; + } + LZ_decompress_write( decoder, mid_buffer, leading_garbage + mid_size ); + out_size = LZ_decompress_read( decoder, out_buffer, buffer_size ); + if( out_size < 0 ) + { + if( leading_garbage && + ( LZ_decompress_errno( decoder ) == LZ_header_error || + LZ_decompress_errno( decoder ) == LZ_data_error ) ) { - if( LZ_decompress_errno( decoder ) == LZ_header_error || - LZ_decompress_errno( decoder ) == LZ_data_error ) + LZ_decompress_sync_to_member( decoder ); /* skip leading garbage */ + const unsigned long long garbage_end = + LZ_decompress_total_in_size( decoder ); + if( garbage_end - garbage_begin != (unsigned)leading_garbage ) { - LZ_decompress_sync_to_member( decoder ); /* remove leading garbage */ - out_size = LZ_decompress_read( decoder, out_buffer, buffer_size ); - } - if( out_size < 0 ) - { - fprintf( stderr, "lzcheck: LZ_decompress_read error: %s\n", - LZ_strerror( LZ_decompress_errno( decoder ) ) ); + fprintf( stderr, "lzcheck: member: LZ_decompress_sync_to_member error:\n" + " garbage_begin = %llu garbage_end = %llu " + "difference = %llu expected = %d\n", garbage_begin, + garbage_end, garbage_end - garbage_begin, leading_garbage ); retval = 3; break; } + out_size = LZ_decompress_read( decoder, out_buffer, buffer_size ); } - - if( out_size != in_size || memcmp( in_buffer + l, out_buffer, out_size ) ) + if( out_size < 0 ) { - fprintf( stderr, "lzcheck: Sync error at pos %d in_size = %d, " - "out_size = %d, leading garbage = %d\n", - l, in_size, out_size, leading_garbage ); - show_line( in_buffer + l, in_size ); - show_line( out_buffer, out_size ); - retval = 1; + fprintf( stderr, "lzcheck: member: LZ_decompress_read error: %s\n", + LZ_strerror( LZ_decompress_errno( decoder ) ) ); + retval = 3; break; } } - if( retval >= 3 ) break; - if( LZ_compress_finish( encoder ) < 0 || - LZ_decompress_write( decoder, mid_buffer, - LZ_compress_read( encoder, mid_buffer, buffer_size ) ) < 0 || - LZ_decompress_read( decoder, out_buffer, buffer_size ) != 0 || - LZ_decompress_reset( decoder ) < 0 || - LZ_compress_restart_member( encoder, member_size ) < 0 ) + if( out_size != in_size || memcmp( line_buf, out_buffer, out_size ) ) { - fprintf( stderr, "lzcheck: Can't restart member: %s\n", - LZ_strerror( LZ_decompress_errno( decoder ) ) ); - retval = 3; break; - } - - size = min( 100, read_size ); - if( LZ_compress_write( encoder, in_buffer, size ) != size || - LZ_compress_finish( encoder ) < 0 || - LZ_decompress_write( decoder, mid_buffer, - LZ_compress_read( encoder, mid_buffer, buffer_size ) ) < 0 || - LZ_decompress_read( decoder, out_buffer, 0 ) != 0 || - LZ_decompress_sync_to_member( decoder ) < 0 || - LZ_compress_restart_member( encoder, member_size ) < 0 ) - { - fprintf( stderr, "lzcheck: Can't seek to next member: %s\n", - LZ_strerror( LZ_decompress_errno( decoder ) ) ); - retval = 3; break; + fprintf( stderr, "lzcheck: LZ_compress_restart_member error: " + "in_size = %d, out_size = %d\n", in_size, out_size ); + show_line( line_buf, in_size ); + show_line( out_buffer, out_size ); + retval = 1; } } - LZ_decompress_close( decoder ); - LZ_compress_close( encoder ); + xclose_decoder( decoder, retval == 0 ); + xclose_encoder( encoder, retval == 0 ); return retval; } @@ -223,7 +324,11 @@ int main( const int argc, const char * const argv[] ) { int retval = 0, i; int open_failures = 0; - const bool verbose = ( argc > 2 ); + const char opt = ( argc > 2 && + ( strcmp( argv[1], "-m" ) == 0 || strcmp( argv[1], "-s" ) == 0 ) ) ? + argv[1][1] : 0; + const int first = opt ? 2 : 1; + const bool verbose = ( opt != 0 || argc > first + 1 ); if( argc < 2 ) { @@ -231,8 +336,10 @@ int main( const int argc, const char * const argv[] ) return 1; } - for( i = 1; i < argc && retval == 0; ++ i ) + for( i = first; i < argc && retval == 0; ++i ) { + struct stat st; + if( stat( argv[i], &st ) != 0 || !S_ISREG( st.st_mode ) ) continue; FILE * file = fopen( argv[i], "rb" ); if( !file ) { @@ -241,9 +348,14 @@ int main( const int argc, const char * const argv[] ) } if( verbose ) fprintf( stderr, " Testing file '%s'\n", argv[i] ); - retval = lzcheck( file, 65535 ); /* 65535,16 chooses fast encoder */ - if( retval == 0 ) - { rewind( file ); retval = lzcheck( file, 1 << 20 ); } + /* 65535,16 chooses fast encoder */ + if( opt != 'm' ) retval = check_sync_flush( file, 65535 ); + if( retval == 0 && opt != 'm' ) + { next_line( file, 0 ); retval = check_sync_flush( file, 1 << 20 ); } + if( retval == 0 && opt != 's' ) + { next_line( file, 0 ); retval = check_members( file, 65535 ); } + if( retval == 0 && opt != 's' ) + { next_line( file, 0 ); retval = check_members( file, 1 << 20 ); } fclose( file ); } if( open_failures > 0 && verbose ) diff --git a/lzip.h b/lzip.h index c0ef9e8..3e3df2c 100644 --- a/lzip.h +++ b/lzip.h @@ -1,20 +1,20 @@ -/* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2019 Antonio Diaz Diaz. +/* Lzlib - Compression library for the lzip format + Copyright (C) 2009-2021 Antonio Diaz Diaz. - This library is free software. Redistribution and use in source and - binary forms, with or without modification, are permitted provided - that the following conditions are met: + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef max @@ -83,7 +83,7 @@ static inline int get_len_state( const int len ) { return min( len - min_match_len, len_states - 1 ); } static inline int get_lit_state( const uint8_t prev_byte ) - { return ( prev_byte >> ( 8 - literal_context_bits ) ); } + { return prev_byte >> ( 8 - literal_context_bits ); } enum { bit_model_move_bits = 5, @@ -197,7 +197,7 @@ static const uint8_t lzip_magic[4] = { 0x4C, 0x5A, 0x49, 0x50 }; /* "LZIP" */ typedef uint8_t Lzip_header[6]; /* 0-3 magic bytes */ /* 4 version */ - /* 5 coded_dict_size */ + /* 5 coded dictionary size */ enum { Lh_size = 6 }; static inline void Lh_set_magic( Lzip_header data ) @@ -255,9 +255,8 @@ static inline bool Lh_set_dictionary_size( Lzip_header data, const unsigned sz ) static inline bool Lh_verify( const Lzip_header data ) { - if( Lh_verify_magic( data ) && Lh_verify_version( data ) ) - return isvalid_ds( Lh_get_dictionary_size( data ) ); - return false; + return Lh_verify_magic( data ) && Lh_verify_version( data ) && + isvalid_ds( Lh_get_dictionary_size( data ) ); } diff --git a/lzlib.c b/lzlib.c index f9f7d2f..b7969f2 100644 --- a/lzlib.c +++ b/lzlib.c @@ -1,20 +1,20 @@ -/* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2019 Antonio Diaz Diaz. +/* Lzlib - Compression library for the lzip format + Copyright (C) 2009-2021 Antonio Diaz Diaz. - This library is free software. Redistribution and use in source and - binary forms, with or without modification, are permitted provided - that the following conditions are met: + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include @@ -105,11 +105,12 @@ static bool verify_decoder( struct LZ_Decoder * const d ) } -/*------------------------- Misc Functions -------------------------*/ +/* ------------------------- Misc Functions ------------------------- */ + +int LZ_api_version( void ) { return LZ_API_VERSION; } const char * LZ_version( void ) { return LZ_version_string; } - const char * LZ_strerror( const enum LZ_Errno lz_errno ) { switch( lz_errno ) @@ -135,7 +136,7 @@ int LZ_min_match_len_limit( void ) { return min_match_len_limit; } int LZ_max_match_len_limit( void ) { return max_match_len; } -/*---------------------- Compression Functions ----------------------*/ +/* --------------------- Compression Functions --------------------- */ struct LZ_Encoder * LZ_compress_open( const int dictionary_size, const int match_len_limit, @@ -226,8 +227,8 @@ int LZ_compress_restart_member( struct LZ_Encoder * const e, int LZ_compress_sync_flush( struct LZ_Encoder * const e ) { if( !verify_encoder( e ) || e->fatal ) return -1; - if( !Mb_flushing_or_end( &e->lz_encoder_base->mb ) ) - e->lz_encoder_base->mb.flushing = true; + if( !e->lz_encoder_base->mb.at_stream_end ) + e->lz_encoder_base->mb.sync_flush_pending = true; return 0; } @@ -235,24 +236,22 @@ int LZ_compress_sync_flush( struct LZ_Encoder * const e ) int LZ_compress_read( struct LZ_Encoder * const e, uint8_t * const buffer, const int size ) { - int out_size = 0; if( !verify_encoder( e ) || e->fatal ) return -1; if( size < 0 ) return 0; - do { + + { struct LZ_encoder_base * const eb = e->lz_encoder_base; + int out_size = Re_read_data( &eb->renc, buffer, size ); + /* minimize number of calls to encode_member */ + if( out_size < size || size == 0 ) + { if( ( e->flz_encoder && !FLZe_encode_member( e->flz_encoder ) ) || ( e->lz_encoder && !LZe_encode_member( e->lz_encoder ) ) ) { e->lz_errno = LZ_library_error; e->fatal = true; return -1; } - if( e->lz_encoder_base->mb.flushing && - Mb_available_bytes( &e->lz_encoder_base->mb ) <= 0 && - LZeb_sync_flush( e->lz_encoder_base ) ) - e->lz_encoder_base->mb.flushing = false; - out_size += Re_read_data( &e->lz_encoder_base->renc, - buffer + out_size, size - out_size ); + if( eb->mb.sync_flush_pending && Mb_available_bytes( &eb->mb ) <= 0 ) + LZeb_try_sync_flush( eb ); + out_size += Re_read_data( &eb->renc, buffer + out_size, size - out_size ); } - while( e->lz_encoder_base->mb.flushing && out_size < size && - Mb_enough_available_bytes( &e->lz_encoder_base->mb ) && - Re_enough_free_bytes( &e->lz_encoder_base->renc ) ); - return out_size; + return out_size; } } @@ -321,7 +320,7 @@ unsigned long long LZ_compress_total_out_size( struct LZ_Encoder * const e ) } -/*--------------------- Decompression Functions ---------------------*/ +/* -------------------- Decompression Functions -------------------- */ struct LZ_Decoder * LZ_decompress_open( void ) { @@ -401,10 +400,11 @@ int LZ_decompress_read( struct LZ_Decoder * const d, { int result; if( !verify_decoder( d ) ) return -1; + if( size < 0 ) return 0; if( d->fatal ) /* don't return error until pending bytes are read */ { if( d->lz_decoder && !Cb_empty( &d->lz_decoder->cb ) ) goto get_data; return -1; } - if( d->seeking || size < 0 ) return 0; + if( d->seeking ) return 0; if( d->lz_decoder && LZd_member_finished( d->lz_decoder ) ) { diff --git a/lzlib.h b/lzlib.h index 97672a0..b6374d8 100644 --- a/lzlib.h +++ b/lzlib.h @@ -1,35 +1,39 @@ -/* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2019 Antonio Diaz Diaz. +/* Lzlib - Compression library for the lzip format + Copyright (C) 2009-2021 Antonio Diaz Diaz. - This library is free software. Redistribution and use in source and - binary forms, with or without modification, are permitted provided - that the following conditions are met: + This library is free software. Redistribution and use in source and + binary forms, with or without modification, are permitted provided + that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #ifdef __cplusplus extern "C" { #endif -#define LZ_API_VERSION 1 +/* LZ_API_VERSION was first defined in lzlib 1.8 to 1. + Since lzlib 1.12, LZ_API_VERSION is defined as (major * 1000 + minor). */ -static const char * const LZ_version_string = "1.11"; +#define LZ_API_VERSION 1012 + +static const char * const LZ_version_string = "1.12"; enum LZ_Errno { LZ_ok = 0, LZ_bad_argument, LZ_mem_error, LZ_sequence_error, LZ_header_error, LZ_unexpected_eof, LZ_data_error, LZ_library_error }; +int LZ_api_version( void ); /* new in 1.12 */ const char * LZ_version( void ); const char * LZ_strerror( const enum LZ_Errno lz_errno ); @@ -41,7 +45,7 @@ int LZ_min_match_len_limit( void ); int LZ_max_match_len_limit( void ); -/*---------------------- Compression Functions ----------------------*/ +/* --------------------- Compression Functions --------------------- */ struct LZ_Encoder; @@ -71,7 +75,7 @@ unsigned long long LZ_compress_total_in_size( struct LZ_Encoder * const encoder unsigned long long LZ_compress_total_out_size( struct LZ_Encoder * const encoder ); -/*--------------------- Decompression Functions ---------------------*/ +/* -------------------- Decompression Functions -------------------- */ struct LZ_Decoder; diff --git a/main.c b/main.c index b6a13e9..c623d9b 100644 --- a/main.c +++ b/main.c @@ -1,24 +1,24 @@ -/* Minilzip - Test program for the lzlib library - Copyright (C) 2009-2019 Antonio Diaz Diaz. +/* Minilzip - Test program for the library lzlib + Copyright (C) 2009-2021 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 - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + 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 + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ /* - Exit status: 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 caused minilzip to panic. + Exit status: 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 caused minilzip to panic. */ #define _FILE_OFFSET_BITS 64 @@ -74,19 +74,21 @@ #define min(x,y) ((x) <= (y) ? (x) : (y)) #endif -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, - const int errcode ); -void internal_error( const char * const msg ); +static void cleanup_and_fail( const int retval ); +static void show_error( const char * const msg, const int errcode, + const bool help ); +static void show_file_error( const char * const filename, + const char * const msg, const int errcode ); +static void internal_error( const char * const msg ); +static const char * const mem_msg = "Not enough memory."; int verbosity = 0; -const char * const program_name = "minilzip"; -const char * const program_year = "2019"; -const char * invocation_name = 0; +static const char * const program_name = "minilzip"; +static const char * const program_year = "2021"; +static const char * invocation_name = "minilzip"; /* default value */ -const struct { const char * from; const char * to; } known_extensions[] = { +static const struct { const char * from; const char * to; } known_extensions[] = { { ".lz", "" }, { ".tlz", ".tar" }, { 0, 0 } }; @@ -101,15 +103,24 @@ enum Mode { m_compress, m_decompress, m_test }; /* Variables used in signal handler context. They are not declared volatile because the handler never returns. */ -char * output_filename = 0; -int outfd = -1; -bool delete_output_on_interrupt = false; +static char * output_filename = 0; +static int outfd = -1; +static bool delete_output_on_interrupt = false; static void show_help( void ) { - printf( "Minilzip is a test program for the lzlib compression library, fully\n" + printf( "Minilzip is a test program for the compression library lzlib, fully\n" "compatible with lzip 1.4 or newer.\n" + "\nLzip is a lossless data compressor with a user interface similar to the one\n" + "of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov\n" + "chain-Algorithm' (LZMA) stream format, chosen to maximize safety and\n" + "interoperability. Lzip can compress about as fast as gzip (lzip -0) or\n" + "compress most files more than bzip2 (lzip -9). Decompression speed is\n" + "intermediate between gzip and bzip2. Lzip is better than gzip and bzip2 from\n" + "a data recovery perspective. Lzip has been designed, written, and tested\n" + "with great care to replace gzip and bzip2 as the standard general-purpose\n" + "compressed format for unix-like systems.\n" "\nUsage: %s [options] [files]\n", invocation_name ); printf( "\nOptions:\n" " -h, --help display this help and exit\n" @@ -122,7 +133,7 @@ static void show_help( void ) " -F, --recompress force re-compression of compressed files\n" " -k, --keep keep (don't delete) input files\n" " -m, --match-length= set match length limit in bytes [36]\n" - " -o, --output= if reading standard input, write to \n" + " -o, --output= write to , keep input files\n" " -q, --quiet suppress all messages\n" " -s, --dictionary-size= set dictionary size limit in bytes [8 MiB]\n" " -S, --volume-size= set volume size limit in bytes\n" @@ -132,7 +143,8 @@ static void show_help( void ) " --fast alias for -0\n" " --best alias for -9\n" " --loose-trailing allow trailing data seeming corrupt header\n" - "If no file names are given, or if a file is '-', minilzip compresses or\n" + " --check-lib compare version of lzlib.h with liblz.{a,so}\n" + "\nIf no file names are given, or if a file is '-', minilzip compresses or\n" "decompresses from standard input to standard output.\n" "Numbers may be followed by a multiplier: k = kB = 10^3 = 1000,\n" "Ki = KiB = 2^10 = 1024, M = 10^6, Mi = 2^20, G = 10^9, Gi = 2^30, etc...\n" @@ -140,12 +152,19 @@ static void show_help( void ) "to 2^29 bytes.\n" "\nThe bidimensional parameter space of LZMA can't be mapped to a linear\n" "scale optimal for all files. If your files are large, very repetitive,\n" - "etc, you may need to use the --dictionary-size and --match-length\n" - "options directly to achieve optimal performance.\n" + "etc, you may need to use the options --dictionary-size and --match-length\n" + "directly to achieve optimal performance.\n" + "\nTo extract all the files from archive 'foo.tar.lz', use the commands\n" + "'tar -xf foo.tar.lz' or 'minilzip -cd foo.tar.lz | tar -xf -'.\n" "\nExit status: 0 for a normal exit, 1 for environmental problems (file\n" "not found, invalid flags, I/O errors, etc), 2 to indicate a corrupt or\n" "invalid input file, 3 for an internal consistency error (eg, bug) which\n" "caused minilzip to panic.\n" + "\nThe ideas embodied in lzlib are due to (at least) the following people:\n" + "Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the\n" + "definition of Markov chains), G.N.N. Martin (for the definition of range\n" + "encoding), Igor Pavlov (for putting all the above together in LZMA), and\n" + "Julian Seward (for bzip2's CLI).\n" "\nReport bugs to lzip-bug@nongnu.org\n" "Lzlib home page: http://www.nongnu.org/lzip/lzlib.html\n" ); } @@ -162,16 +181,43 @@ static void show_version( void ) } +int check_lib() + { + bool warning = false; + if( strcmp( LZ_version_string, LZ_version() ) != 0 ) + { warning = true; + if( verbosity >= 0 ) + printf( "warning: LZ_version_string != LZ_version() (%s vs %s)\n", + LZ_version_string, LZ_version() ); } +#if defined LZ_API_VERSION && LZ_API_VERSION >= 1012 + if( LZ_API_VERSION != LZ_api_version() ) + { warning = true; + if( verbosity >= 0 ) + printf( "warning: LZ_API_VERSION != LZ_api_version() (%u vs %u)\n", + LZ_API_VERSION, LZ_api_version() ); } +#endif + if( verbosity >= 1 ) + { + printf( "Using lzlib %s\n", LZ_version() ); +#if !defined LZ_API_VERSION + fputs( "LZ_API_VERSION is not defined.\n", stdout ); +#elif LZ_API_VERSION >= 1012 + printf( "Using LZ_API_VERSION = %u\n", LZ_api_version() ); +#else + printf( "Compiled with LZ_API_VERSION = %u. " + "Using an unknown LZ_API_VERSION\n", LZ_API_VERSION ); +#endif + } + return warning; + } + + /* assure at least a minimum size for buffer 'buf' */ static void * resize_buffer( void * buf, const unsigned 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 ); - } + if( !buf ) { show_error( mem_msg, 0, false ); cleanup_and_fail( 1 ); } return buf; } @@ -186,8 +232,7 @@ struct Pretty_print }; static void Pp_init( struct Pretty_print * const pp, - const char * const filenames[], - const int num_filenames ) + const char * const filenames[], const int num_filenames ) { unsigned stdin_name_len; int i; @@ -208,8 +253,8 @@ static void Pp_init( struct Pretty_print * const pp, if( pp->longest_name == 0 ) pp->longest_name = stdin_name_len; } -static inline void Pp_set_name( struct Pretty_print * const pp, - const char * const filename ) +static void Pp_set_name( struct Pretty_print * const pp, + const char * const filename ) { unsigned name_len, padded_name_len, i = 0; @@ -227,7 +272,7 @@ static inline void Pp_set_name( struct Pretty_print * const pp, pp->first_post = true; } -static inline void Pp_reset( struct Pretty_print * const pp ) +static void Pp_reset( struct Pretty_print * const pp ) { if( pp->name && pp->name[0] ) pp->first_post = true; } static void Pp_show_msg( struct Pretty_print * const pp, const char * const msg ) @@ -258,7 +303,7 @@ static void show_header( const unsigned dictionary_size ) int i; for( i = 0; i < 8 && ( num > 9999 || ( exact && num >= factor ) ); ++i ) { num /= factor; if( num % factor != 0 ) exact = false; p = prefix[i]; np = ""; } - fprintf( stderr, "dictionary %s%4u %sB, ", np, num, p ); + fprintf( stderr, "dict %s%4u %sB, ", np, num, p ); } @@ -321,7 +366,7 @@ static int get_dict_size( const char * const arg ) const long bits = strtol( arg, &tail, 0 ); if( bits >= LZ_min_dictionary_bits() && bits <= LZ_max_dictionary_bits() && *tail == 0 ) - return ( 1 << bits ); + return 1 << bits; dictionary_size = getnum( arg, LZ_min_dictionary_size(), LZ_max_dictionary_size() ); if( dictionary_size == 65535 ) ++dictionary_size; /* no fast encoder */ @@ -329,7 +374,7 @@ static int get_dict_size( const char * const arg ) } -void set_mode( enum Mode * const program_modep, const enum Mode new_mode ) +static void set_mode( enum Mode * const program_modep, const enum Mode new_mode ) { if( *program_modep != m_compress && *program_modep != new_mode ) { @@ -363,7 +408,7 @@ static void set_c_outname( const char * const name, const bool force_ext, strlen( known_extensions[0].from ) + 1 ); strcpy( output_filename, name ); if( multifile ) strcat( output_filename, "00001" ); - if( force_ext || multifile || extension_index( output_filename ) < 0 ) + if( force_ext || multifile ) strcat( output_filename, known_extensions[0].from ); } @@ -395,7 +440,7 @@ static void set_d_outname( const char * const name, const int eindex ) static int open_instream( const char * const name, struct stat * const in_statsp, const enum Mode program_mode, const int eindex, - const bool recompress, const bool to_stdout ) + const bool one_to_one, const bool recompress ) { int infd = -1; if( program_mode == m_compress && !recompress && eindex >= 0 ) @@ -416,14 +461,12 @@ static int open_instream( const char * const name, struct stat * const in_statsp const bool can_read = ( i == 0 && ( S_ISBLK( mode ) || S_ISCHR( mode ) || S_ISFIFO( mode ) || S_ISSOCK( mode ) ) ); - const bool no_ofile = ( to_stdout || program_mode == m_test ); - if( i != 0 || ( !S_ISREG( mode ) && ( !can_read || !no_ofile ) ) ) + if( i != 0 || ( !S_ISREG( mode ) && ( !can_read || one_to_one ) ) ) { if( verbosity >= 0 ) fprintf( stderr, "%s: Input file '%s' is not a regular file%s.\n", - program_name, name, - ( can_read && !no_ofile ) ? - ",\n and '--stdout' was not specified" : "" ); + program_name, name, ( can_read && one_to_one ) ? + ",\n and neither '-c' nor '-o' were specified" : "" ); close( infd ); infd = -1; } @@ -433,11 +476,11 @@ static int open_instream( const char * const name, struct stat * const in_statsp } -static bool open_outstream( const bool force, const bool from_stdin ) +static bool open_outstream( const bool force, const bool protect ) { const mode_t usr_rw = S_IRUSR | S_IWUSR; const mode_t all_rw = usr_rw | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; - const mode_t outfd_mode = from_stdin ? all_rw : usr_rw; + const mode_t outfd_mode = protect ? usr_rw : all_rw; int flags = O_CREAT | O_WRONLY | O_BINARY; if( force ) flags |= O_TRUNC; else flags |= O_EXCL; @@ -456,25 +499,6 @@ static bool open_outstream( const bool force, const bool from_stdin ) } -static bool check_tty( const char * const input_filename, const int infd, - const enum Mode program_mode ) - { - if( program_mode == m_compress && isatty( outfd ) ) - { - show_error( "I won't write compressed data to a terminal.", 0, true ); - return false; - } - if( ( program_mode == m_decompress || program_mode == m_test ) && - isatty( infd ) ) - { - show_file_error( input_filename, - "I won't read compressed data from a terminal.", 0 ); - return false; - } - return true; - } - - static void set_signals( void (*action)(int) ) { signal( SIGHUP, action ); @@ -483,7 +507,7 @@ static void set_signals( void (*action)(int) ) } -void cleanup_and_fail( const int retval ) +static void cleanup_and_fail( const int retval ) { set_signals( SIG_IGN ); /* ignore signals */ if( delete_output_on_interrupt ) @@ -500,7 +524,7 @@ void cleanup_and_fail( const int retval ) } -void signal_handler( int sig ) +static void signal_handler( int sig ) { if( sig ) {} /* keep compiler happy */ show_error( "Control-C or similar caught, quitting.", 0, false ); @@ -508,7 +532,35 @@ void signal_handler( int sig ) } - /* Set permissions, owner and times. */ +static inline void set_retval( int * retval, const int new_val ) + { if( *retval < new_val ) *retval = new_val; } + + +static bool check_tty_in( const char * const input_filename, const int infd, + const enum Mode program_mode, int * const retval ) + { + if( ( program_mode == m_decompress || program_mode == m_test ) && + isatty( infd ) ) /* for example /dev/tty */ + { show_file_error( input_filename, + "I won't read compressed data from a terminal.", 0 ); + close( infd ); set_retval( retval, 1 ); + if( program_mode != m_test ) cleanup_and_fail( *retval ); + return false; } + return true; + } + +static bool check_tty_out( const enum Mode program_mode ) + { + if( program_mode == m_compress && isatty( outfd ) ) + { show_file_error( output_filename[0] ? + output_filename : "(stdout)", + "I won't write compressed data to a terminal.", 0 ); + return false; } + return true; + } + + +/* Set permissions, owner, and times. */ static void close_and_set_permissions( const struct stat * const in_statsp ) { bool warning = false; @@ -602,7 +654,7 @@ static int do_compress( struct LZ_Encoder * const encoder, { unsigned long long partial_volume_size = 0; enum { buffer_size = 65536 }; - uint8_t buffer[buffer_size]; + uint8_t buffer[buffer_size]; /* read/write buffer */ if( verbosity >= 1 ) Pp_show_msg( pp, 0 ); while( true ) @@ -658,7 +710,7 @@ static int do_compress( struct LZ_Encoder * const encoder, close_and_set_permissions( in_statsp ); if( !next_filename() ) { Pp_show_msg( pp, "Too many volume files." ); return 1; } - if( !open_outstream( true, !in_statsp ) ) return 1; + if( !open_outstream( true, in_statsp ) ) return 1; } } size = min( member_size, volume_size - partial_volume_size ); @@ -726,7 +778,8 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd, const bool loose_trailing, const bool testing ) { enum { buffer_size = 65536 }; - uint8_t buffer[buffer_size]; + uint8_t buffer[buffer_size]; /* read/write buffer */ + unsigned long long total_in = 0; /* to detect library stall */ bool first_member; for( first_member = true; ; ) @@ -777,17 +830,16 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd, if( verbosity >= 4 ) show_header( LZ_decompress_dictionary_size( decoder ) ); if( data_size == 0 || member_size == 0 ) - fputs( "no data compressed. ", stderr ); + fputs( "no data compressed. ", stderr ); else - fprintf( stderr, "%6.3f:1, %5.2f%% ratio, %5.2f%% saved. ", + fprintf( stderr, "%6.3f:1, %5.2f%% ratio, %5.2f%% saved. ", (double)data_size / member_size, ( 100.0 * member_size ) / data_size, 100.0 - ( ( 100.0 * member_size ) / data_size ) ); if( verbosity >= 4 ) fprintf( stderr, "CRC %08X, ", LZ_decompress_data_crc( decoder ) ); if( verbosity >= 3 ) - fprintf( stderr, "decompressed %9llu, compressed %8llu. ", - data_size, member_size ); + fprintf( stderr, "%9llu out, %8llu in. ", data_size, member_size ); fputs( testing ? "ok\n" : "done\n", stderr ); Pp_reset( pp ); } } @@ -840,8 +892,7 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd, else break; /* trailing data */ return 2; } - if( lz_errno == LZ_mem_error ) - { Pp_show_msg( pp, "Not enough memory." ); return 1; } + if( lz_errno == LZ_mem_error ) { Pp_show_msg( pp, mem_msg ); return 1; } if( verbosity >= 0 ) { Pp_show_msg( pp, 0 ); @@ -853,7 +904,11 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd, } if( LZ_decompress_finished( decoder ) == 1 ) break; if( in_size == 0 && out_size == 0 ) - internal_error( "library error (stalled)." ); + { + const unsigned long long size = LZ_decompress_total_in_size( decoder ); + if( total_in == size ) internal_error( "library error (stalled)." ); + total_in = size; + } } if( verbosity == 1 ) fputs( testing ? "ok\n" : "done\n", stderr ); return 0; @@ -868,7 +923,7 @@ static int decompress( const int infd, struct Pretty_print * const pp, int retval; if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok ) - { Pp_show_msg( pp, "Not enough memory." ); retval = 1; } + { Pp_show_msg( pp, mem_msg ); retval = 1; } else retval = do_decompress( decoder, infd, pp, ignore_trailing, loose_trailing, testing ); LZ_decompress_close( decoder ); @@ -876,7 +931,8 @@ static int decompress( const int infd, struct Pretty_print * const pp, } -void show_error( const char * const msg, const int errcode, const bool help ) +static void show_error( const char * const msg, const int errcode, + const bool help ) { if( verbosity < 0 ) return; if( msg && msg[0] ) @@ -889,8 +945,8 @@ 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, - const int errcode ) +static void show_file_error( const char * const filename, + const char * const msg, const int errcode ) { if( verbosity >= 0 ) fprintf( stderr, "%s: %s: %s%s%s\n", program_name, filename, msg, @@ -899,7 +955,7 @@ void show_file_error( const char * const filename, const char * const msg, } -void internal_error( const char * const msg ) +static void internal_error( const char * const msg ) { if( verbosity >= 0 ) fprintf( stderr, "%s: internal error: %s\n", program_name, msg ); @@ -924,12 +980,14 @@ int main( const int argc, const char * const argv[] ) { 3 << 23, 132 }, /* -8 */ { 1 << 25, 273 } }; /* -9 */ struct Lzma_options encoder_options = option_mapping[6]; /* default = "-6" */ - const unsigned long long max_member_size = 0x0008000000000000ULL; - const unsigned long long max_volume_size = 0x4000000000000000ULL; + const unsigned long long max_member_size = 0x0008000000000000ULL; /* 2 PiB */ + const unsigned long long max_volume_size = 0x4000000000000000ULL; /* 4 EiB */ unsigned long long member_size = max_member_size; unsigned long long volume_size = 0; const char * default_output_filename = ""; - const char ** filenames = 0; + static struct Arg_parser parser; /* static because valgrind complains */ + static struct Pretty_print pp; /* and memory management in C sucks */ + static const char ** filenames = 0; int num_filenames = 0; enum Mode program_mode = m_compress; int argind = 0; @@ -944,20 +1002,19 @@ int main( const int argc, const char * const argv[] ) bool recompress = false; bool stdin_used = false; bool to_stdout = false; - struct Pretty_print pp; - enum { opt_lt = 256 }; + enum { opt_chk = 256, opt_lt }; const struct ap_Option options[] = { { '0', "fast", ap_no }, - { '1', 0, ap_no }, - { '2', 0, ap_no }, - { '3', 0, ap_no }, - { '4', 0, ap_no }, - { '5', 0, ap_no }, - { '6', 0, ap_no }, - { '7', 0, ap_no }, - { '8', 0, ap_no }, + { '1', 0, ap_no }, + { '2', 0, ap_no }, + { '3', 0, ap_no }, + { '4', 0, ap_no }, + { '5', 0, ap_no }, + { '6', 0, ap_no }, + { '7', 0, ap_no }, + { '8', 0, ap_no }, { '9', "best", ap_no }, { 'a', "trailing-error", ap_no }, { 'b', "member-size", ap_yes }, @@ -976,20 +1033,14 @@ int main( const int argc, const char * const argv[] ) { 't', "test", ap_no }, { 'v', "verbose", ap_no }, { 'V', "version", ap_no }, + { opt_chk, "check-lib", ap_no }, { opt_lt, "loose-trailing", ap_no }, - { 0 , 0, ap_no } }; + { 0, 0, ap_no } }; - struct Arg_parser parser; - - invocation_name = argv[0]; - - if( LZ_version()[0] != LZ_version_string[0] ) - internal_error( "bad library version." ); - if( strcmp( PROGVERSION, LZ_version_string ) != 0 ) - internal_error( "bad library version_string." ); + if( argc > 0 ) invocation_name = argv[0]; if( !ap_init( &parser, argc, argv, options, 0 ) ) - { show_error( "Not enough memory.", 0, false ); return 1; } + { show_error( mem_msg, 0, false ); return 1; } if( ap_error( &parser ) ) /* bad option */ { show_error( ap_error( &parser ), 0, true ); return 1; } @@ -1015,7 +1066,8 @@ int main( const int argc, const char * const argv[] ) getnum( arg, LZ_min_match_len_limit(), LZ_max_match_len_limit() ); break; case 'n': break; - case 'o': default_output_filename = arg; break; + case 'o': if( strcmp( arg, "-" ) == 0 ) to_stdout = true; + else { default_output_filename = arg; } break; case 'q': verbosity = -1; break; case 's': encoder_options.dictionary_size = get_dict_size( arg ); break; @@ -1023,11 +1075,27 @@ int main( const int argc, const char * const argv[] ) case 't': set_mode( &program_mode, m_test ); break; case 'v': if( verbosity < 4 ) ++verbosity; break; case 'V': show_version(); return 0; + case opt_chk: return check_lib(); case opt_lt: loose_trailing = true; break; default : internal_error( "uncaught option." ); } } /* end process options */ + if( strcmp( PROGVERSION, LZ_version_string ) != 0 ) + internal_error( "wrong PROGVERSION." ); +#if !defined LZ_API_VERSION || LZ_API_VERSION < 1012 +#error "lzlib 1.12 or newer needed." +#else + if( LZ_api_version() < 1012 ) /* minilzip passes null to LZ_decompress_read */ + { show_error( "lzlib 1.12 or newer needed. Try --check-lib.", 0, false ); + return 1; } + if( LZ_api_version() != LZ_API_VERSION ) show_error( + "warning: wrong library API version. Try --check-lib.", 0, false ); + else +#endif + if( strcmp( LZ_version_string, LZ_version() ) != 0 ) show_error( + "warning: wrong library version_string. Try --check-lib.", 0, false ); + #if defined(__MSVCRT__) || defined(__OS2__) || defined(__DJGPP__) setmode( STDIN_FILENO, O_BINARY ); setmode( STDOUT_FILENO, O_BINARY ); @@ -1043,16 +1111,31 @@ int main( const int argc, const char * const argv[] ) if( strcmp( filenames[i], "-" ) != 0 ) filenames_given = true; } - if( program_mode == m_test ) - outfd = -1; + if( program_mode == m_compress ) + { + if( volume_size > 0 && !to_stdout && default_output_filename[0] && + num_filenames > 1 ) + { show_error( "Only can compress one file when using '-o' and '-S'.", + 0, true ); return 1; } + } + else volume_size = 0; + if( program_mode == m_test ) to_stdout = false; /* apply overrides */ + if( program_mode == m_test || to_stdout ) default_output_filename = ""; - if( !to_stdout && program_mode != m_test && - ( filenames_given || default_output_filename[0] ) ) + output_filename = resize_buffer( output_filename, 1 ); + output_filename[0] = 0; + if( to_stdout && program_mode != m_test ) /* check tty only once */ + { outfd = STDOUT_FILENO; if( !check_tty_out( program_mode ) ) return 1; } + else outfd = -1; + + const bool to_file = !to_stdout && program_mode != m_test && + default_output_filename[0]; + if( !to_stdout && program_mode != m_test && ( filenames_given || to_file ) ) set_signals( signal_handler ); Pp_init( &pp, filenames, num_filenames ); - output_filename = resize_buffer( output_filename, 1 ); + const bool one_to_one = !to_stdout && program_mode != m_test && !to_file; for( i = 0; i < num_filenames; ++i ) { const char * input_filename = ""; @@ -1060,68 +1143,48 @@ int main( const int argc, const char * const argv[] ) int tmp; struct stat in_stats; const struct stat * in_statsp; - output_filename[0] = 0; - if( !filenames[i][0] || strcmp( filenames[i], "-" ) == 0 ) + Pp_set_name( &pp, filenames[i] ); + if( strcmp( filenames[i], "-" ) == 0 ) { if( stdin_used ) continue; else stdin_used = true; infd = STDIN_FILENO; - if( program_mode != m_test ) - { - if( to_stdout || !default_output_filename[0] ) - outfd = STDOUT_FILENO; - else - { - if( program_mode == m_compress ) - set_c_outname( default_output_filename, false, volume_size > 0 ); - else - { - output_filename = resize_buffer( output_filename, - strlen( default_output_filename ) + 1 ); - strcpy( output_filename, default_output_filename ); - } - if( !open_outstream( force, true ) ) - { - if( retval < 1 ) retval = 1; - close( infd ); - continue; - } - } - } + if( !check_tty_in( pp.name, infd, program_mode, &retval ) ) continue; + if( one_to_one ) { outfd = STDOUT_FILENO; output_filename[0] = 0; } } else { const int eindex = extension_index( input_filename = filenames[i] ); infd = open_instream( input_filename, &in_stats, program_mode, - eindex, recompress, to_stdout ); - if( infd < 0 ) { if( retval < 1 ) retval = 1; continue; } - if( program_mode != m_test ) + eindex, one_to_one, recompress ); + if( infd < 0 ) { set_retval( &retval, 1 ); continue; } + if( !check_tty_in( pp.name, infd, program_mode, &retval ) ) continue; + if( one_to_one ) /* open outfd after verifying infd */ { - if( to_stdout ) outfd = STDOUT_FILENO; - else - { - if( program_mode == m_compress ) - set_c_outname( input_filename, true, volume_size > 0 ); - else set_d_outname( input_filename, eindex ); - if( !open_outstream( force, false ) ) - { - if( retval < 1 ) retval = 1; - close( infd ); - continue; - } - } + if( program_mode == m_compress ) + set_c_outname( input_filename, true, volume_size > 0 ); + else set_d_outname( input_filename, eindex ); + if( !open_outstream( force, true ) ) + { close( infd ); set_retval( &retval, 1 ); continue; } } } - Pp_set_name( &pp, input_filename ); - if( !check_tty( pp.name, infd, program_mode ) ) + if( one_to_one && !check_tty_out( program_mode ) ) + { set_retval( &retval, 1 ); return retval; } /* don't delete a tty */ + + if( to_file && outfd < 0 ) /* open outfd after verifying infd */ { - if( retval < 1 ) retval = 1; - if( program_mode == m_test ) { close( infd ); continue; } - cleanup_and_fail( retval ); + if( program_mode == m_compress ) set_c_outname( default_output_filename, + false, volume_size > 0 ); + else + { output_filename = resize_buffer( output_filename, + strlen( default_output_filename ) + 1 ); + strcpy( output_filename, default_output_filename ); } + if( !open_outstream( force, false ) || !check_tty_out( program_mode ) ) + return 1; /* check tty only once and don't try to delete a tty */ } - in_statsp = input_filename[0] ? &in_stats : 0; + in_statsp = ( input_filename[0] && one_to_one ) ? &in_stats : 0; if( program_mode == m_compress ) tmp = compress( member_size, volume_size, infd, &encoder_options, &pp, in_statsp ); @@ -1129,29 +1192,24 @@ int main( const int argc, const char * const argv[] ) tmp = decompress( infd, &pp, ignore_trailing, loose_trailing, program_mode == m_test ); if( close( infd ) != 0 ) - { - show_error( input_filename[0] ? "Error closing input file" : - "Error closing stdin", errno, false ); - if( tmp < 1 ) tmp = 1; - } - if( tmp > retval ) retval = tmp; + { show_file_error( pp.name, "Error closing input file", errno ); + set_retval( &tmp, 1 ); } + set_retval( &retval, tmp ); if( tmp ) { if( program_mode != m_test ) cleanup_and_fail( retval ); else ++failed_tests; } - if( delete_output_on_interrupt ) + if( delete_output_on_interrupt && one_to_one ) close_and_set_permissions( in_statsp ); - if( input_filename[0] ) - { - if( !keep_input_files && !to_stdout && program_mode != m_test && - ( program_mode != m_compress || volume_size == 0 ) ) - remove( input_filename ); - } + if( input_filename[0] && !keep_input_files && one_to_one && + ( program_mode != m_compress || volume_size == 0 ) ) + remove( input_filename ); } - if( outfd >= 0 && close( outfd ) != 0 ) + if( delete_output_on_interrupt ) close_and_set_permissions( 0 ); /* -o */ + else if( outfd >= 0 && close( outfd ) != 0 ) /* -c */ { show_error( "Error closing stdout", errno, false ); - if( retval < 1 ) retval = 1; + set_retval( &retval, 1 ); } if( failed_tests > 0 && verbosity >= 1 && num_filenames > 1 ) fprintf( stderr, "%s: warning: %d %s failed the test.\n", diff --git a/testsuite/check.sh b/testsuite/check.sh index 026ea2b..44e2428 100755 --- a/testsuite/check.sh +++ b/testsuite/check.sh @@ -1,9 +1,9 @@ #! /bin/sh # check script for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2019 Antonio Diaz Diaz. +# Copyright (C) 2009-2021 Antonio Diaz Diaz. # # This script is free software: you have unlimited permission -# to copy, distribute and modify it. +# to copy, distribute, and modify it. LC_ALL=C export LC_ALL @@ -11,6 +11,7 @@ objdir=`pwd` testdir=`cd "$1" ; pwd` LZIP="${objdir}"/minilzip BBEXAMPLE="${objdir}"/bbexample +FFEXAMPLE="${objdir}"/ffexample LZCHECK="${objdir}"/lzcheck framework_failure() { echo "failure in testing framework" ; exit 1 ; } @@ -32,10 +33,13 @@ cd "${objdir}"/tmp || framework_failure cat "${testdir}"/test.txt > in || framework_failure in_lz="${testdir}"/test.txt.lz -test2="${testdir}"/test2.txt +in_em="${testdir}"/test_em.txt.lz +fox_lf="${testdir}"/fox_lf +fox_lz="${testdir}"/fox.lz fail=0 test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; } +"${LZIP}" --check-lib # just print warning printf "testing lzlib-%s..." "$2" "${LZIP}" -fkqm4 in @@ -59,10 +63,22 @@ done [ $? = 2 ] || test_failed $LINENO "${LZIP}" -dq -o in < "${in_lz}" [ $? = 1 ] || test_failed $LINENO +"${LZIP}" -dq -o in "${in_lz}" +[ $? = 1 ] || test_failed $LINENO +"${LZIP}" -dq -o out nx_file.lz +[ $? = 1 ] || test_failed $LINENO +[ ! -e out ] || test_failed $LINENO +"${LZIP}" -q -o out.lz nx_file +[ $? = 1 ] || test_failed $LINENO +[ ! -e out.lz ] || test_failed $LINENO +"${LZIP}" -qf -S100k -o out in in +[ $? = 1 ] || test_failed $LINENO # these are for code coverage "${LZIP}" -cdt "${in_lz}" > out 2> /dev/null [ $? = 1 ] || test_failed $LINENO -"${LZIP}" -t -- nx_file 2> /dev/null +"${LZIP}" -t -- nx_file.lz 2> /dev/null +[ $? = 1 ] || test_failed $LINENO +"${LZIP}" -t "" < /dev/null 2> /dev/null [ $? = 1 ] || test_failed $LINENO "${LZIP}" --help > /dev/null || test_failed $LINENO "${LZIP}" -n1 -V > /dev/null || test_failed $LINENO @@ -86,15 +102,22 @@ printf "LZIP\001+.............................." | "${LZIP}" -t 2> /dev/null printf "\ntesting decompression..." -"${LZIP}" -t "${in_lz}" || test_failed $LINENO -"${LZIP}" -cd "${in_lz}" > copy || test_failed $LINENO -cmp in copy || test_failed $LINENO +for i in "${in_lz}" "${in_em}" "${testdir}"/test_sync.lz ; do + "${LZIP}" -t "$i" || test_failed $LINENO "$i" + "${LZIP}" -d "$i" -o copy || test_failed $LINENO "$i" + cmp in copy || test_failed $LINENO "$i" + "${LZIP}" -cd "$i" > copy || test_failed $LINENO "$i" + cmp in copy || test_failed $LINENO "$i" + "${LZIP}" -d "$i" -o - > copy || test_failed $LINENO "$i" + cmp in copy || test_failed $LINENO "$i" + "${LZIP}" -d < "$i" > copy || test_failed $LINENO "$i" + cmp in copy || test_failed $LINENO "$i" + rm -f copy || framework_failure +done -"${LZIP}" -t "${testdir}"/test_sync.lz || test_failed $LINENO -"${LZIP}" -cd "${testdir}"/test_sync.lz > copy || test_failed $LINENO -cmp in copy || test_failed $LINENO +lines=$("${LZIP}" -tvv "${in_em}" 2>&1 | wc -l) || test_failed $LINENO +[ "${lines}" -eq 8 ] || test_failed $LINENO "${lines}" -rm -f copy || framework_failure cat "${in_lz}" > copy.lz || framework_failure "${LZIP}" -dk copy.lz || test_failed $LINENO cmp in copy || test_failed $LINENO @@ -112,12 +135,20 @@ cat "${in_lz}" > copy.lz || framework_failure cmp in copy || test_failed $LINENO printf "to be overwritten" > copy || framework_failure +"${LZIP}" -d -o copy < "${in_lz}" 2> /dev/null +[ $? = 1 ] || test_failed $LINENO "${LZIP}" -df -o copy < "${in_lz}" || test_failed $LINENO cmp in copy || test_failed $LINENO +rm -f out copy || framework_failure +"${LZIP}" -d -o ./- "${in_lz}" || test_failed $LINENO +cmp in ./- || test_failed $LINENO +rm -f ./- || framework_failure +"${LZIP}" -d -o ./- < "${in_lz}" || test_failed $LINENO +cmp in ./- || test_failed $LINENO +rm -f ./- || framework_failure -rm -f copy || framework_failure -"${LZIP}" -s16 < in > anyothername || test_failed $LINENO -"${LZIP}" -dv --output copy - anyothername - < "${in_lz}" 2> /dev/null || +cat "${in_lz}" > anyothername || framework_failure +"${LZIP}" -dv - anyothername - < "${in_lz}" > copy 2> /dev/null || test_failed $LINENO cmp in copy || test_failed $LINENO cmp in anyothername.out || test_failed $LINENO @@ -152,19 +183,18 @@ done cmp in copy || test_failed $LINENO cat in in > in2 || framework_failure -cat "${in_lz}" "${in_lz}" > in2.lz || framework_failure -"${LZIP}" -t in2.lz || test_failed $LINENO -"${LZIP}" -cd in2.lz > copy2 || test_failed $LINENO +"${LZIP}" -t "${in_lz}" "${in_lz}" || test_failed $LINENO +"${LZIP}" -cd "${in_lz}" "${in_lz}" -o out > copy2 || test_failed $LINENO +[ ! -e out ] || test_failed $LINENO # override -o cmp in2 copy2 || test_failed $LINENO - -"${LZIP}" -s16 --output=copy2.lz < in2 || test_failed $LINENO -"${LZIP}" -t copy2.lz || test_failed $LINENO -"${LZIP}" -cd copy2.lz > copy2 || test_failed $LINENO +rm -f copy2 || framework_failure +"${LZIP}" -d "${in_lz}" "${in_lz}" -o copy2 || test_failed $LINENO cmp in2 copy2 || test_failed $LINENO +rm -f copy2 || framework_failure +cat "${in_lz}" "${in_lz}" > copy2.lz || framework_failure printf "\ngarbage" >> copy2.lz || framework_failure "${LZIP}" -tvvvv copy2.lz 2> /dev/null || test_failed $LINENO -rm -f copy2 || framework_failure "${LZIP}" -atq copy2.lz [ $? = 2 ] || test_failed $LINENO "${LZIP}" -atq < copy2.lz @@ -178,68 +208,91 @@ rm -f copy2 || framework_failure printf "to be overwritten" > copy2 || framework_failure "${LZIP}" -df copy2.lz || test_failed $LINENO cmp in2 copy2 || test_failed $LINENO -rm -f in2 copy2 || framework_failure +rm -f copy2 || framework_failure printf "\ntesting compression..." +"${LZIP}" -c -0 in in in -S100k -o out3.lz > copy2.lz || test_failed $LINENO +[ ! -e out3.lz ] || test_failed $LINENO # override -o and -S +"${LZIP}" -0f in in --output=copy2.lz || test_failed $LINENO +"${LZIP}" -d copy2.lz -o out2 || test_failed $LINENO +cmp in2 out2 || test_failed $LINENO +rm -f out2 copy2.lz || framework_failure + "${LZIP}" -cf "${in_lz}" > out 2> /dev/null # /dev/null is a tty on OS/2 [ $? = 1 ] || test_failed $LINENO -"${LZIP}" -cFvvm36 -s16 "${in_lz}" > out 2> /dev/null || test_failed $LINENO +"${LZIP}" -Fvvm36 -o - -s16 "${in_lz}" > out 2> /dev/null || test_failed $LINENO "${LZIP}" -cd out | "${LZIP}" -d > copy || test_failed $LINENO cmp in copy || test_failed $LINENO +"${LZIP}" -0 -o ./- in || test_failed $LINENO +"${LZIP}" -cd ./- | cmp in - || test_failed $LINENO +rm -f ./- || framework_failure +"${LZIP}" -0 -o ./- < in || test_failed $LINENO # don't add .lz +[ ! -e ./-.lz ] || test_failed $LINENO +"${LZIP}" -cd ./- | cmp in - || test_failed $LINENO +rm -f ./- || framework_failure + for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do "${LZIP}" -k -$i -s16 in || test_failed $LINENO $i mv -f in.lz copy.lz || test_failed $LINENO $i printf "garbage" >> copy.lz || framework_failure "${LZIP}" -df copy.lz || test_failed $LINENO $i cmp in copy || test_failed $LINENO $i -done -for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do - "${LZIP}" -c -$i -s16 in > out || test_failed $LINENO $i + "${LZIP}" -$i -s16 in -c > out || test_failed $LINENO $i + "${LZIP}" -$i -s16 in -o o_out || test_failed $LINENO $i # don't add .lz + [ ! -e o_out.lz ] || test_failed $LINENO + cmp out o_out || test_failed $LINENO $i + rm -f o_out || framework_failure printf "g" >> out || framework_failure "${LZIP}" -cd out > copy || test_failed $LINENO $i cmp in copy || test_failed $LINENO $i -done -for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do "${LZIP}" -$i -s16 < in > out || test_failed $LINENO $i "${LZIP}" -d < out > copy || test_failed $LINENO $i cmp in copy || test_failed $LINENO $i -done -for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do + rm -f out.lz || framework_failure + printf "to be overwritten" > out || framework_failure # don't add .lz "${LZIP}" -f -$i -s16 -o out < in || test_failed $LINENO $i - "${LZIP}" -df -o copy < out.lz || test_failed $LINENO $i + [ ! -e out.lz ] || test_failed $LINENO + "${LZIP}" -df -o copy < out || test_failed $LINENO $i cmp in copy || test_failed $LINENO $i done -rm -f out.lz || framework_failure +rm -f out out.lz || framework_failure cat in in in in in in in in > in8 || framework_failure "${LZIP}" -1s12 -S100k in8 || test_failed $LINENO "${LZIP}" -t in800001.lz in800002.lz || test_failed $LINENO "${LZIP}" -cd in800001.lz in800002.lz | cmp in8 - || test_failed $LINENO +[ ! -e in800003.lz ] || test_failed $LINENO rm -f in800001.lz in800002.lz || framework_failure -"${LZIP}" -1s12 -S100k -o out.lz < in8 || test_failed $LINENO +"${LZIP}" -1s12 -S100k -o out.lz in8 || test_failed $LINENO +# ignore -S +"${LZIP}" -d out.lz00001.lz out.lz00002.lz -S100k -o out || test_failed $LINENO +cmp in8 out || test_failed $LINENO "${LZIP}" -t out.lz00001.lz out.lz00002.lz || test_failed $LINENO -"${LZIP}" -cd out.lz00001.lz out.lz00002.lz | cmp in8 - || test_failed $LINENO -rm -f out.lz00001.lz out.lz00002.lz || framework_failure +[ ! -e out.lz00003.lz ] || test_failed $LINENO +rm -f out out.lz00001.lz out.lz00002.lz || framework_failure "${LZIP}" -1ks4Ki -b100000 in8 || test_failed $LINENO "${LZIP}" -t in8.lz || test_failed $LINENO -"${LZIP}" -cd in8.lz | cmp in8 - || test_failed $LINENO -rm -f in8 || framework_failure +"${LZIP}" -cd in8.lz -o out | cmp in8 - || test_failed $LINENO # override -o +[ ! -e out ] || test_failed $LINENO "${LZIP}" -0 -S100k -o out < in8.lz || test_failed $LINENO "${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO "${LZIP}" -cd out00001.lz out00002.lz | cmp in8.lz - || test_failed $LINENO +[ ! -e out00003.lz ] || test_failed $LINENO rm -f out00001.lz || framework_failure "${LZIP}" -1 -S100k -o out < in8.lz || test_failed $LINENO "${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO "${LZIP}" -cd out00001.lz out00002.lz | cmp in8.lz - || test_failed $LINENO +[ ! -e out00003.lz ] || test_failed $LINENO rm -f out00001.lz out00002.lz || framework_failure "${LZIP}" -0 -F -S100k in8.lz || test_failed $LINENO "${LZIP}" -t in8.lz00001.lz in8.lz00002.lz || test_failed $LINENO "${LZIP}" -cd in8.lz00001.lz in8.lz00002.lz | cmp in8.lz - || test_failed $LINENO +[ ! -e in8.lz00003.lz ] || test_failed $LINENO rm -f in8.lz00001.lz in8.lz00002.lz || framework_failure "${LZIP}" -0kF -b100k in8.lz || test_failed $LINENO "${LZIP}" -t in8.lz.lz || test_failed $LINENO @@ -247,12 +300,33 @@ rm -f in8.lz00001.lz in8.lz00002.lz || framework_failure rm -f in8.lz in8.lz.lz || framework_failure "${BBEXAMPLE}" in || test_failed $LINENO -"${BBEXAMPLE}" out || test_failed $LINENO -"${BBEXAMPLE}" ${test2} || test_failed $LINENO +"${BBEXAMPLE}" "${in_lz}" || test_failed $LINENO +"${BBEXAMPLE}" "${fox_lf}" || test_failed $LINENO + +"${FFEXAMPLE}" -h > /dev/null || test_failed $LINENO +"${FFEXAMPLE}" > /dev/null && test_failed $LINENO +rm -f out || framework_failure +"${FFEXAMPLE}" -b in out || test_failed $LINENO +cmp in out || test_failed $LINENO +"${FFEXAMPLE}" -b in | cmp in - || test_failed $LINENO +"${FFEXAMPLE}" -b in8 | cmp in8 - || test_failed $LINENO +"${FFEXAMPLE}" -b "${fox_lf}" | cmp "${fox_lf}" - || test_failed $LINENO +"${FFEXAMPLE}" -d "${in_lz}" - | cmp in - || test_failed $LINENO +"${FFEXAMPLE}" -d "${in_em}" - | cmp in - || test_failed $LINENO +"${FFEXAMPLE}" -c in | "${FFEXAMPLE}" -d | cmp in - || test_failed $LINENO +"${FFEXAMPLE}" -m in | "${FFEXAMPLE}" -d | cmp in - || test_failed $LINENO +"${FFEXAMPLE}" -l in | "${FFEXAMPLE}" -d | cmp in - || test_failed $LINENO +cat "${fox_lf}" "${in_lz}" | "${FFEXAMPLE}" -r | cmp in - || test_failed $LINENO +cat in8 "${in_lz}" | "${FFEXAMPLE}" -r | cmp in - || test_failed $LINENO +cat "${in_lz}" "${fox_lf}" "${in_lz}" | "${FFEXAMPLE}" -r - | cmp in2 - || + test_failed $LINENO +cat "${in_lz}" in8 "${in_lz}" | "${FFEXAMPLE}" -r - - | cmp in2 - || + test_failed $LINENO "${LZCHECK}" in || test_failed $LINENO -"${LZCHECK}" out || test_failed $LINENO -"${LZCHECK}" ${test2} || test_failed $LINENO +"${LZCHECK}" "${in_lz}" || test_failed $LINENO +"${LZCHECK}" "${fox_lf}" || test_failed $LINENO +rm -f in8 || framework_failure printf "\ntesting bad input..." @@ -301,6 +375,21 @@ else fi rm -f int.lz || framework_failure +for i in fox_v2.lz fox_s11.lz fox_de20.lz \ + fox_bcrc.lz fox_crc0.lz fox_das46.lz fox_mes81.lz ; do + "${LZIP}" -tq "${testdir}"/$i + [ $? = 2 ] || test_failed $LINENO $i +done + +"${LZIP}" -cd "${fox_lz}" > fox || test_failed $LINENO +for i in fox_bcrc.lz fox_crc0.lz fox_das46.lz fox_mes81.lz ; do + "${LZIP}" -cdq "${testdir}"/$i > out + [ $? = 2 ] || test_failed $LINENO $i + cmp fox out || test_failed $LINENO $i +done +rm -f fox out || framework_failure + +cat "${in_lz}" "${in_lz}" > in2.lz || framework_failure cat "${in_lz}" "${in_lz}" "${in_lz}" > in3.lz || framework_failure if dd if=in3.lz of=trunc.lz bs=14752 count=1 2> /dev/null && [ -e trunc.lz ] && cmp in2.lz trunc.lz > /dev/null 2>&1 ; then @@ -323,13 +412,23 @@ rm -f in2.lz in3.lz trunc.lz out || framework_failure cat "${in_lz}" > ingin.lz || framework_failure printf "g" >> ingin.lz || framework_failure cat "${in_lz}" >> ingin.lz || framework_failure +"${LZIP}" -atq ingin.lz +[ $? = 2 ] || test_failed $LINENO +"${LZIP}" -atq < ingin.lz +[ $? = 2 ] || test_failed $LINENO +"${LZIP}" -acdq ingin.lz > out +[ $? = 2 ] || test_failed $LINENO +"${LZIP}" -adq < ingin.lz > out +[ $? = 2 ] || test_failed $LINENO "${LZIP}" -t ingin.lz || test_failed $LINENO +"${LZIP}" -t < ingin.lz || test_failed $LINENO "${LZIP}" -cd ingin.lz > copy || test_failed $LINENO cmp in copy || test_failed $LINENO -"${LZIP}" -t < ingin.lz || test_failed $LINENO "${LZIP}" -d < ingin.lz > copy || test_failed $LINENO cmp in copy || test_failed $LINENO -rm -f copy ingin.lz || framework_failure +"${FFEXAMPLE}" -d ingin.lz | cmp in - || test_failed $LINENO +"${FFEXAMPLE}" -r ingin.lz | cmp in2 - || test_failed $LINENO +rm -f copy ingin.lz in2 out || framework_failure echo if [ ${fail} = 0 ] ; then diff --git a/testsuite/fox.lz b/testsuite/fox.lz new file mode 100644 index 0000000000000000000000000000000000000000..509da8268a3fd054415089a646cdcfd00d3eee7a GIT binary patch literal 80 zcmeZ?@(f_)VbGG|Sj4QF_R+iI=pxqtde3fNQjl6}^5c>03rDkGci1v_+dL64QRjTU cIqmVA>95u)|NqywfFbKlz-wIw2nc}E07J|k>Hq)$ literal 0 HcmV?d00001 diff --git a/testsuite/fox_bcrc.lz b/testsuite/fox_bcrc.lz new file mode 100644 index 0000000000000000000000000000000000000000..8f6a7c4af4b808a1ed873b58d5d9a343a722edcd GIT binary patch literal 80 zcmeZ?@(f_)VbGG|Sj4QF_R+iI=pxqtde3fNQjl6}^5c>03rDkGci1v_+dL64QRjTU cIqmVA>95u)|NqywfFb)#z-wIw2nc}E07Kv&>i_@% literal 0 HcmV?d00001 diff --git a/testsuite/fox_crc0.lz b/testsuite/fox_crc0.lz new file mode 100644 index 0000000000000000000000000000000000000000..1abe92689f2fb57212633f41962e53f4297bd5a2 GIT binary patch literal 80 zcmeZ?@(f_)VbGG|Sj4QF_R+iI=pxqtde3fNQjl6}^5c>03rDkGci1v_+dL64QRjTU bIqmVA>95u)|NqywfB^(_!6XAi0F(v*7bP5d literal 0 HcmV?d00001 diff --git a/testsuite/fox_das46.lz b/testsuite/fox_das46.lz new file mode 100644 index 0000000000000000000000000000000000000000..43ed9f9503c4e8c298e6bf671f669b56e24162a2 GIT binary patch literal 80 zcmeZ?@(f_)VbGG|Sj4QF_R+iI=pxqtde3fNQjl6}^5c>03rDkGci1v_+dL64QRjTU cIqmVA>95u)|NqywfFbKlz-v7Q2nc}E07Kj!>i_@% literal 0 HcmV?d00001 diff --git a/testsuite/fox_de20.lz b/testsuite/fox_de20.lz new file mode 100644 index 0000000000000000000000000000000000000000..10949d888f0e1c630fc860b3a8c8eb0bee7f77bf GIT binary patch literal 80 zcmeZ?@(f_)VbGG|Sj4QF_R+iI=pxpCde3fNQjl6}^5c>03rDkGci1v_+dL64QRjTU cIqmVA>95u)|NqywfFbKlz-wIw2nc}E07H--=>Px# literal 0 HcmV?d00001 diff --git a/testsuite/test2.txt b/testsuite/fox_lf similarity index 100% rename from testsuite/test2.txt rename to testsuite/fox_lf diff --git a/testsuite/fox_mes81.lz b/testsuite/fox_mes81.lz new file mode 100644 index 0000000000000000000000000000000000000000..d50ef2e2fa7a5160a77c814344218585e865f266 GIT binary patch literal 80 zcmeZ?@(f_)VbGG|Sj4QF_R+iI=pxqtde3fNQjl6}^5c>03rDkGci1v_+dL64QRjTU cIqmVA>95u)|NqywfFbKlz-wIw2ndAI07KLs>i_@% literal 0 HcmV?d00001 diff --git a/testsuite/fox_s11.lz b/testsuite/fox_s11.lz new file mode 100644 index 0000000000000000000000000000000000000000..dca909c62a44e1b011404dbd5afe0af47c3bb6e7 GIT binary patch literal 80 zcmeZ?@(f_)X3&!2Sj4QF_R+iI=pxqtde3fNQjl6}^5c>03rDkGci1v_+dL64QRjTU cIqmVA>95u)|NqywfFbKlz-wIw2nc}E07HQu=>Px# literal 0 HcmV?d00001 diff --git a/testsuite/fox_v2.lz b/testsuite/fox_v2.lz new file mode 100644 index 0000000000000000000000000000000000000000..8620981714096152fff6673aa04060f251bdad44 GIT binary patch literal 80 zcmeZ?@(f_&VbGG|Sj4QF_R+iI=pxqtde3fNQjl6}^5c>03rDkGci1v_+dL64QRjTU cIqmVA>95u)|NqywfFbKlz-wIw2nc}E07Mub>i_@% literal 0 HcmV?d00001 diff --git a/testsuite/test_em.txt.lz b/testsuite/test_em.txt.lz new file mode 100644 index 0000000000000000000000000000000000000000..7e96250d9ec70bc7d8cb173f438c76be447e6b6f GIT binary patch literal 14024 zcmb7~Ly#~4lVsbrZQHhO+qP}nwr$(CZQJht_TQb^!`^1=Qc)3g%8I(YOc^an1wa^p z;D6u${tW>9zeV!jqs;%_i332e{Szlg{U9R$^emnpP=->;y-J2_NFLo;6abfiRy$%i z;1u`u$LCGROi}}VAX@hA><%1+po5w@DJyf3l$=$r?jKb!fSy)n`3%Yd=-O|aMmvx} z(_25sQF~*#S!d^N#(dfqI#&Mt6bCWEkcPQ-^@r`OYq8}?DB(W0u339!Bw(F*D} z9nEy7I3-T(Lf+Vw#Nyel4m`=31_S~|T628lhp|*6s(1GgF5#BXaWChE>-e>hLJxp< z80t5rbm`)E9A%~S4JrM~7v4zNn9js$&tkFrWD4)sNR|0OP$G52O(kc0yPk@p1auv$ z+H<3yS#I)!kx9%5t&20ww99~&=J`s#!=n}&t`76!suXV@dcSAT1R9~BE&Ueu8+txY zMFruAwF*@)jr4@CLGJaJ;R`JkS*9eQFP6^>X72c#itJq%0>1{PFFvsDV~V_&MGxA> z4bOf$Q?FhABF5DmYfl)CGR6#`S6;`GoBF9LXsU?-2H^LcPJ7_&KE2j(^?Y0|Iugb; z;tl2eepab=(&OV+o(>M~YFIzyD{hlgW+gZ?I7(Y@{QdqJc+#FY3;Xl9_gxE-!V7Y< zi|G2&c>25jureBCC!!|})?iTPVif*`bAr0t@u2%_7!xOrMELo2PYaEGEe~>_!nwBd zkX9wc9&H5w;$7B15WcKsh=HK`Ss}&Z+=-Vm-L5#w_CP0BT%HB~z(wqxr9-OfaH*hC zNP+mf^Qa%{V18r_>ulkj*w@VLhLh+kf#Ma6Emf1#*`KHu2Oq`YFWYBK5fNNJ!X*taZe9 zo;bClvb)Cw+o1sXDM3AGAy_pTV!!sZYFr`B4Of?zDk$J$p~zw;_#FLt%YxG9IrwPQ zf$28YD0X%WnY@o!zjD9Ub{PrqCC&BwdJ8oOY6l`_;!m>%kkEWK>i9aXH=f zV@#ph(h}@DF0@TlRtHA#DhF)yv6M~gG?hG*XB`KH2QebijyOJv!k=ynFBQQ65DU=d zB!4{2+12=HD0v;Fl!b}tcair%?D)GU448a=N9h7AP83zbyVVn1`s21MY%a6zTW8fbf)CKGj}??lh~_=SdZN`pW0hq z->*Oh!&#h292vOhogDRc+PA{cT|QXFxpa^g@D5KCEaw{j4ia8;!I8kgO0l17-%Hx^ zGO=Ui!|Mml@`gbjCasD<-eQG~lLkgk&1A ziPB^y4tS+G$@)=j{hJ2~NJe!R(TMouaf2lzZukvvceixpgH4+xcMo7QC0={uEJlhA z0TVUWTGbsyATsU0y*G1pf>?3^T;s$V1ehytYM5- zfaPtD`elj8?qv>)TpY8rk%Srt77+Kc#Pork1a3kwB99m`1T*T)oYqt+CJ{M59bXTn z3KVqMRd69B~o{#DEOJx)_KC0pPaz0r{y@@1DMU^j~aEjJwa{pFLDL5K}RqSA6 z95?jB=W(@}Eqgq;&6j9GqqEz5Ol4jl9;Nvt5&*;82s=JfE#Ffqxgx5%+0GM_N1mW` zkytzXAXb>A>m|#ffp;!s?ziOv-c0DEU`!!Qi~TzCth6U~aFc-99I(|=fp+U!A0P6% zuaOTqb9Jn)QeD@&kt_~u^Qr6{C~Pr5XE-5NgRou($-vr{C4Zpde9hLHMEf9#zP~RD z^SJb)8i8j^=xd6i>39$t=`XOuc+*uDqtr$~6dJ`UN9dwnEX+T6By<83lM@pafROv@ z?ZleCH5?jtBtO)1H3@E2;*Zj)@VSc%R>&u4%2goJMvx>oMX13G5CNZK-3V$=vo1ev zA8N1O7^vDa_p}5(oQDOnmub&X&V3 zYRJ-~*xGTG#gjsvK*nP}3dN(GZ*Qeal4a9pTLTlnoBf4vm$-*=qq7ut4i*QqTy05^ ztnm)XiP0&PzUv*RC`mqsg6g;CrIgRk`pn}tmHo>aqF!i<()goseV_z+fwfRRV^6-I*}N1-@*=jYOQtIjEm2P8MR*U#KZsDN{At%}x|h zt2%&uF1m~{K)uoQHsg8GWz3Z1e$fdi(+!%nYO&I;*4xmz2WwZh*mS!BK&Ie2!*TL2 zH^Masy8A`XFJQeMNcw2BrDg@D-{exY2W$I1Ro9aCDzhD?N49Yo>^VT}urLhj~i zSWOdAfvGa1A&|~}eSyhFO_KnSQXiBb1v+s1oA_l79B@cZ21V z4y@Yd#QjNYQC)~r1RhT6RM=pX>{6#fh&6w^&^{=CL1&&H~Axj1( zb#_8mz3AMB>c!#;Nbtzy9I%3K(^;gT5&id^}jom5aW14S$S|Z zdInxAbH2F?_5Ca9pqn!Pg8n=p7tsxOPu|f+)>taOO=X(BQbI?4szBzYCm&kl29vy8 zU@!ksQx#_~9zHx>O=h!m6`pFv<#`CJsYJt~Lad4?h*gO#TkDj19Z!yma;S53Gsv=& zqT`PR2I@ToOrg7=Hs9A7dMWzQWh{H(@d>koUqJJal2)qFwD7ZfHv4*ufvg;jjozy} zC5IGDRx9=dF{oH()g@s~{+KI@4j)y#9~$64N?6t=;NF!gMqB7}%I;B@)Zq*iwal3= zlqGZ|D8F1@VU5JnU4$ z3M>>(O zJYZDKK6S=3#4WxR)L0gnH|r)uB;1&}xx9~+E60m}XPlu-6k@X-Y4mjHhF8Dypc!{= zBden2MLZYN>j3Md!!{il<~j%aN=FL*8nhE9!fPLkCFfcia!i-vV?0C~Xvrp(NssLE z0%}jh@LIavg4ghbeb?V3B5&3j(_lBn_cWxZpLC2rgK8}fSe$bG@q3)sPU#}_V?_r^ zA;d^MJj-qK3&XM+U~)cY>zTg(q|bQ@-KkFxQcDWm`2jpOchN2XERdn>IQnDJAjsS& zj@|njY|x`&ve0@&81)V^5dPpIAjXPoDF!QjtC6XHw0~zz#Cv|+&#i@N4Yb+CLU!P~ zASFf@9bFwTo}B%R>UVT(307&MH&2-hl>1Qc+!63`U0^LC(2et6+yjFuuY-O#k-rqE zOt{K-F^Q-^W-|md61^3dh92o3vBNSMpJix4lgo|0!+H3^1UZGDJI8&dI#Zbw#?!4X z)k2ml5#%!#KI2UVexVR1_0)2#3>?WEZu0FZ)(_n>po;$}+Vn!W&=R53`mDH?U-I)G z_%}n=Jx*fN)OsFNI2<+bZHTJ3C=6q z;?bk|Z(zNsk~bUeA8k%tE^OJ)h4X*DdS+uoE~KypUf1AVg)rIALrvShUqeRc>C_~} zPLyu?@J}Uj9AwMHw!@N-o!tsTdZ)k#?_H}SekJBulY;v5!8T6sZAewbOtBRU5xWm)nQ`44OOBnlX&l)fqN5&b$=i$Wi;;_);bo@ z(-}Uoa}FL(#2ycAv$QMgI2nj}U6v=RxjgsPI20S66jgfyG#!g27MGv}7EG&pJ-%j7 z!iuCT(~X7|sm&q&__H%xKrsK))z|>o%(H4Lp zPP0#KuCbg4o~ULK*`^tx(Ab>ALFHxUt1JLPQM?z3#y%4xnf!7O8u@CP-P z|2k|$&o#W2I)4BqtI(vrJe6WzijQFL;?{t|g`fmR{|(+&6*~@6VH2z+2cKy@Dn10J z?#3G%90^*yCkiD^>g9f~UWA8xU5)FBU}k<>SH?ZvW$SjBNuZ^Il67LIdzT%jaOjY5 z<{Ccd7Jr=H&mJSg^l*2dEV=^l_4{oJH$N$8zUV6aTu0f%AA~ztq&`0t8Vj=yZ0A9UI z%L7p6&&G#i2>NcCGMCv5GSvWwA?A^MHj~1(gaSB*Dzy5@E$6;+G@;gVVBx`u^&k@s zNFN|CyI(OGwnoC06cuI8B7GEM;{ri&p}STKaDT3sV)*#bXGc6qEprsRcWl68H>wt^ z-8l_4i{^-aqQ#(kdQ^V{4KE9qRt8i`iI0gNdj{+H>{&+ZEei~Bs&Bakm!J?Ul6@4> z&>p!>&n7XYjc4~@=ty5kLBraMN*Q03mV&g?9EZ>Bc#+CwF+SXJnnQcOf3}Gh8bGbOffMN zJivC}Q}r{!_mq;QOiqWoG9F!Eu7oI0_|J=oj?_)8az-doVN=iKh`TSU!nc5;5N+OX zv>C}5rp?$fra@wj`|GHUD9Rp5%19DnWT-sIubUcHX&(n0Ifr0pw9c+DWP(R!g6GUF zb*oG$&BpBm@bQ6I=L8og7HgLHv0)G__(+8Vs4n-RXj|k`EKH94;X16o7WzVAVBy?_ z?G2eZqS>S_aVdTTikuWe$F+>7-LSE9f|oHWp1noYcSus-E_({Xl9oQPjW&K9$IwW@ zmbC%8Q^5WM7)Hyszw#AzvG+cy@&o?7#p+R!l<*5??{OPGTMEB-HKpw;4f|CXcAgzA zI1bfN`~vi()r0i2PE-N-ewrqjbjuLtf_&=Ljds*+?hou+g%QXjM`)rl4cCLbd7L4!ZRgc{h3dDQ7lmZgp#89LYFLyetH|*| z7-^0ry#>ZhZfHnL#ld9VJUsM{FyZq3SjV?Zr=i@8-RtKncEB)juPBqn3-m0~df^Oskf}zGD-?_<#Td^3 z9uAyESClMo;u2;{IZg&d_;vaeas|M&auoC==UPu^p4P5Xwzi;a%jq!#?U7VV1yVC0 z$n7*X1z`adpAj2|b{kaNsrvM8q^q6sVRbU#XPd&k`ylAGQUC0Eub5t+8ECDjCg+F5ij*KyOJDP|SI7CFl>CxjVq8zbXi1g}k1{hJdE zJN_oW1}ttOI6MOX#^ch`XRY~JuFDL|CkXJUgr<~nJF+=RNLd^Ww2u4Zi#tH%7?32R zU;1{L^N^!12dIKh^79;Q^y_C4HA}|KOZ%;rnK7-axM~i(HEHw!eGCI;lJk$}RylEr z4uT>(3_^EQvdhBj^m=r8ix>v3ad+w9I!<4Ji{~n4_#+^%2Fw@6G(Ieh1Aec)r@_Tz zA9>NrrD;`kx_Zd&SR$p+XrCgK{#^p@E?SA9HB2jIH{#DyECZ4EXZa)t*Ceh5`aIbF z7$FxHug_gd^aVS$QO*NImqr|&gE$IHdp^ztm=FRNDAVuZfdO)h$>jw=0gyZsBlmmk z<$c46V&LduOhY$qRB4U zHW{dzYB|}$40%0-<&2ng!hU1QK~-T-gv#$YmK#Af9}c)oHsG^IB+Jhm*eS=JxeDzf zqn%c$V`BWwjE53j{MKQtZWvbs8&R5TSo^Tmb32Au2pUy$viaZx==J2AWj_t>SniI| zh%;tk@)k6vHK|s95E>0tB`Tn#q0;=rD}PB=W7M^2(RnD2NHA+&&r= zUj%3ZS@d{%-}_}$a3l%z3B(85D6{DBQZeff*21L5(79!|VPbcGg=Yfa+AMfVXV8c^ z$`&no#z8W4#}C8(S`VC+6amRrEgZ@+_N|80ePm^*sbULIQr5@g23hJ%5ZTq!(ZqB4 zeN0cd=VhEeG$t;X=@j`0Ww`KoUK~2rri$Z-H?9vPbUWx%o#7+opk_RAHoJM8%h*5n zZA{N)59Ac|&&ST7AX@?+`;rqYC$bR@SG~l~c@yZ`6^Qnof6x;R*0|2)U0z z?M7X%{~VHy>l-|zsLD5z38*lu>9(;8yTSOvYS1SH`3|^D*RJII5~bvT#hrD*Y(}cu z8+yZxP=trqZy}`M=Y{djFT}~#lrxbbNyrDmO?eu!7b?REco60YVkz$s+zk^eU?wml zEJ=hVBY83kfrJF7pQKxyJ_cK6uPe$AbRdV>Xum2t@ecxHVa2Fc{ySRU5*wZmNtLMu zV1aET?_RGVLb_n&m3^!I)Adig@1%6?I;VqF~FRDiYBRHquSG_(lb>k-hhHS#f_Mw8Ce z>%3XwUV<`_ehYAsL*=wktg<;ZuQ0d1D#jM|SJTk(k>@7#VVCWL$b>q1QZ7q^HH+c} zUdKL#ux2v)3+wJ0p>v-&EnV}4_Cc!Y!oIe%pSxYv)qNno?7t&uy0|ZqHjqursL$_+ zeHv3hN|I%ZamVbKe|C}@njK#g)InlnG`~$8Em7jgnU8z{nLjqn>VxF2x-{Xl(9l9E zqdE$JDS%ez}?8ot+=)RV$dp@fII`b*JU24j@N8}suibTZFkoDk+TncAE{9U z8Bu{2kkTEp+*lOHa-@0A)_$?GY&Iu#xm!^ltIx8pC(Z){H?USWq%y#E@O&KY8_P_B z`LT;Astpd11SU&4lEQHEMey@^CjyEin{>>rkDhhfvBK4lbPbY?O`qy0C#bP(Q85%0)U`K6;P3L63N=)cID_=Q{~f!Rx74P%Wv zbC4QzbP9ozCN{J;7Q?4xSb15y5@P?d8DY!PkChD*cWOPMlMl&8!Z@bjb+oU}X?4m~oG&lUF>FdqwH*Au1$M{M%rG)rF?S zJXz0kX@M!Ke(LVdFo@rK^^L#jI}VL}Q37#WL>WhBJUy&MqoR+C7k_QK`0G%%D>dWBHJ1(FYU#R0%vtM1w=3DIEi}u(S_J-cQIAwy&MvAr9HBC z$T^Kp(&S7*QGWBxp@E)JUXwzU#Pb{Dz%k!-k2zqA8qXq<_Sm+uZeyPt4v`#RDk){w^859`&-T^e_S zSj(Z9qXwPStb0&{Z%wWOw&RfJF8Iu?{JjekfXSJoAx|&tr*8^viiKvJgN+NZ#AKW* zOJ(L&SRGMlI3NLU_fm%~Q=j$0Yaw-pK$I}-Kf*fp9^}T|)LD%?37X~|LM@??4o_S4 z$3rgPTSOXOW^kK`iqy>A;;HF#=pURe?ESYI1B*_ZZm{zNbHcK!l~e`R(MnVmAduU^ zA+w`0vhk{JiTAe<$01nW86=U*ID{iCD0NZO9g|D7c+b{>5LOnWNkk&!4qaX0%vg*|8oR+KR3s!Wp(9v8_g!0u<5!wjtx;PdrYCszEk zNupQ0o!jq)f=sG2LIB!F&e6{}siZzxrHE@}g7N7^`bDDjHKBsuXK)ceha5D=&S5-z=G1R60IfNY8jDE~{;88n%MOcwQ z`O_oA%HYYT5DD-x@bS1h)XWybv2cH*9}qhn^YwM4 zF&c_6UKyoiXa>cZ-(iWO&cE`#>KYhhx|a`^e9lGqm;-SRF<3+5D7f`_CeA9J^S%NmM^7 z4hjy*EWX}uN&LD3(q9Y~vD^2#K4kRi$Qt%$%%FapqLZ*e7_M2=vWKWYB^%s%ogzhAJVL4x-qyq*;DFBzh8;_DH^sn9! z0qW6Zp4&a>jT)aDDCVkZp4nQM>Bc?!KO7Gju=d2J3g0v)2vmkot82#8P}XH?JY^{I zf*wPSbAkv2(|_pHR#w!T?P|^$wF&^-);_SYUN5sKvRfyjF<|OQEGGj_epRFU z>mcsM=LhuF@$2V~LC}W)Thm~xkLb^v{_R-Ve-&HHuG zD0_8T78R@&tyI0C(h+NhOJqNh{M!@&Y#b=02_I!&IUqj}g{3&|DJaLwolwuQbGr|$ zp{JSf7=PJ(qiS8%dA-DDBNntzh>rjMux)WfQ>BIY%@V$PzC{5<6$jx#@~bp6 zgFe)NWO1X;GR3QCbk(Jnk}a)+L#uU)5SG_!3D|rv|7Zb;5_K0=VUc%`uyysv-Lq-m zBm1+9Iwk%omoo2XRkz9x%dP99*G}9%KyYG$`ShTyJmESO)k=44@N1$*zWLTTq zRk8b9bEytkJW?CjkmX9#u_yiPbwV1l(`(QjXqA7yUhk^s&k$F%l4rsIse34INo<{Y zz>v{`DOFTpxC6VQiIY~$)^o0Zsmgy=|C-TnTIt!*G<>oK0EfUKug3G&?tC$7do%eU z!*u2SLam6x)(C008ac4`wvjm)6dn>U(wCo|#`5YMF1g;=ntS@R!K+*ocelMdhO9}= zv2xtNNZK@mpji?zs^j7OB858uDRsX@$YVqH#=82rf6eEJ9hi_ZC2E4YyMImYC^GKa zzSUDdZ0Q>FAz^Rs``72jO<^7MeA{2JBn|eSKN|6>oKcp0c!iqnenQ!S_!at6*Qxzd z5Py5RJa}&e-CXLb)#Gc`B$%f>=%EGmQYZ%5$2xMBh=}{BmkfmM$Ns@s`Cfe=x1f4)T6)wh;D8$B3BRb$$I9&0Jo@xr^( z+${%0z6=J7|1)zeepQ4gq2cK_E^PsSmVJ>lTVwbg$h1)}q&Jm;xUcb-5#Hg-8HJeh z*p!WfH~hQ-8A4|3hrUxe#xO~bj9$6k!`di+f7sa77V&gqaRI}h zGr;#%ZR=`zUBv(g1GwT!G0tD@T?e|BqZ^I*{=om} zeq+7K^0k;qNc0g?;}SvNpbsZGmWp>crl5nYnCUtUf==G&xs7FQ%)4ihgj~y|RTTpg3#*sEzh%dWi zh;MxCpZuzl+_|BOO487fb|a`Uj*iQeN2j`%!ZMW?XQa|Gq0bpL!W?{q=uI12-^z&kf;A_2|S~OiC_{F2?WMam> znt~~Pa?}l{)DO^?@wZESx|ag@TDo$p#~OrNLiGdtU(x7V;+yAj$&t=r6cDi%mIQw; z)yV~UMKf?Adl0c1DK#3)ix?6OT11(3Yl#{l!c~BX@x0yjaDc zo1PX|@+pe>7;dlDruFz(K${;_P6-K1vP5r;aIPI0(>4GQ_mp_bw9U9E0eX7wWIr)Y>73nfY}hA$lLjX@XiN zQJ`fl>h98SYRnjtJ?eXZM2tu?)O5U^LM}hHkiT^6>dKW1n*!5oZfF7++XaEL*VzT` z`%4Qp3VNrmTX1vUC!joY^t3vs9!Z@>QjJB~JGXKTyUOt0JkV5uL}GU`vwe@1DEC%t zxJGB8H%92zjG+iQI$PpO(SF*QQ0)Q|`D}XO`kLn5b(7H5=?7KSr>>^qdDC^ij$1iegb>qL6kV7d6y+Cw);2Hm#!Tn=h;_sdM zO%3Ggg_CW;<h zvu>j@d659Yd|?fRVbkxDA+~khtTEC57LW~FDn*QV0^d?2K=lvxKp_+$A%7Y0Rx%5f zg&u`-_z>ytx!pedsRv%q=Rgv7t*={t839=*rt-8Qxto(*z$4)&TR3rm83YteI~8XW zj*_2Lg^a`%lJHj5)w_@?dyAS!qo^!4A{U0IuKeqFq|H|^hkSHJP2Cl=pgS$vCZ}Hw zhc)aV&IU}vm47M%!D9c3K_%|Whw*H4?Yy&z8{MHeK_?zo;dI2HM>6!&ZDUob)K`;M z&C8_o1aSc8k{BpdJvB5sS%~%eq%ui?*jwPT0qGutuxR9>bqhOIG4#cuxR4j*#OMn+ z^&|eqdZs*rnkjcRLw2*A{n~07x}1FN4Bz>r;phZJ z#c71zSPV}d4j3lt?H+wF?UPMZIqUXWt&^k_eAwGK-fSB5BfczdsS^ zCpq*>Cv$fF^}d;a7Zv>SADpLH!du^?J6}N&X^@PXlpe`RasEl#87(J~Y=07tq%a-l zg7!cCyZR6VdM3PCxGxc6oZ#DhctlLI)nLFX&t(uAP4USpQfT1e zv^FK`-qg?O{#7vOqY5KZJibD2Q_0!8?!Iww)+rqp7L#*VuVohn!sQbV%{g>l^`}Ug zF*^Hu##kXIGglv3B_SqspE^3NX=%IK}ri!P1c! z@amIW0!WTy%3Q4#+1PR`CJ?sy%Z(`K#y=>3AoZvnZUC4kDI<#FXp`bfjx*@<{Pk!f%Edl9u}g&Z0M2;t+xt-Rk*3V%`_y3W^E=Po+Yt&u4no3i8p|q>DpblDpLW4 zBRVZljPXg&IP|&VutC=P+t0IPj!NdZJq?B1>cnZ6vKpZJspn zL4O(P_U^iCQ>mb<%Ifa8HRryIOmEhn)4cB?zX_O@3puXW!Rb?&9qkgJviGj`Az;0` zgIv~PzbO~-ghRaHg{9GhGuBQ-r0Ax>#a>WicZ|xS4=k?{4 zZR(~xR9ori>wdMvUN5absJ1!?<%U-kLPf3FD-*1x`Nzn8g$T*JDl#p*RWy|PcQ=#- zTLW&2Fex?v{!V+fKZv%#js81LW&i(y Gt^OBPlQ$#) literal 0 HcmV?d00001 From 03a9d0ba58d468c8c6eec0247b72514eba434180 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 20 Feb 2025 21:31:52 +0100 Subject: [PATCH 05/10] Adding upstream version 1.13. Signed-off-by: Daniel Baumann --- ChangeLog | 17 ++- INSTALL | 4 +- Makefile.in | 23 ++-- NEWS | 97 ++-------------- README | 14 +-- bbexample.c | 34 +++--- carg_parser.c | 110 ++++++++++++------- carg_parser.h | 14 ++- cbuffer.c | 10 +- configure | 16 ++- decoder.c | 21 ++-- decoder.h | 123 ++++++++++++++------- doc/lzlib.info | 239 ++++++++++++++++++++-------------------- doc/lzlib.texi | 240 ++++++++++++++++++++-------------------- doc/minilzip.1 | 35 ++++-- encoder.c | 127 ++++++++++----------- encoder.h | 5 +- encoder_base.c | 23 ++-- encoder_base.h | 22 ++-- fast_encoder.c | 35 +++--- fast_encoder.h | 2 +- ffexample.c | 12 +- lzcheck.c | 11 +- lzip.h | 3 +- lzlib.c | 2 +- lzlib.h | 6 +- main.c => minilzip.c | 256 +++++++++++++++++++++++++++---------------- testsuite/check.sh | 22 ++-- 28 files changed, 803 insertions(+), 720 deletions(-) rename main.c => minilzip.c (86%) diff --git a/ChangeLog b/ChangeLog index e38a855..8d7da96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2022-01-23 Antonio Diaz Diaz + + * Version 1.13 released. + * Set variables AR and ARFLAGS from configure. + (Reported by Hoël Bézier). + * main.c: Rename to minilzip.c. + * minilzip.c (getnum): Show option name and valid range if error. + (check_lib): Check that LZ_API_VERSION and LZ_version_string match. + * Improve several descriptions in manual, '--help', and man page. + * lzlib.texi: Change GNU Texinfo category to 'Compression'. + (Reported by Alfred M. Szmidt). + 2021-01-02 Antonio Diaz Diaz * Version 1.12 released. @@ -48,7 +60,7 @@ * main.c: Compile on DOS with DJGPP. * lzlib.texi: Improve descriptions of '-0..-9', '-m', and '-s'. Document that 'LZ_(de)compress_finish' can be called repeatedly. - * configure: Accept appending to CFLAGS, 'CFLAGS+=OPTIONS'. + * configure: Accept appending to CFLAGS; 'CFLAGS+=OPTIONS'. * Makefile.in: Rename targets 'install-bin*' to 'install-lib*'. * Makefile.in: Targets 'install-bin*' now install minilzip. * INSTALL: Document use of CFLAGS+='-D __USE_MINGW_ANSI_STDIO'. @@ -57,6 +69,7 @@ * Version 1.10 released. * LZ_compress_finish now adjusts dictionary size for each member. + (Older versions can adjust dictionary size only once). * lzlib.c (LZ_decompress_read): Detect corrupt header with HD=3. * main.c: New option '--loose-trailing'. * main.c (main): Option '-S, --volume-size' now keeps input files. @@ -235,7 +248,7 @@ * Version 0.1 released. -Copyright (C) 2009-2021 Antonio Diaz Diaz. +Copyright (C) 2009-2022 Antonio Diaz Diaz. This file is a collection of facts, and thus it is not copyrightable, but just in case, you have unlimited permission to copy, distribute, and diff --git a/INSTALL b/INSTALL index a9a870e..f3b0b94 100644 --- a/INSTALL +++ b/INSTALL @@ -1,7 +1,7 @@ Requirements ------------ You will need a C99 compiler. (gcc 3.3.6 or newer is recommended). -I use gcc 6.1.0 and 4.1.2, but the code should compile with any standards +I use gcc 6.1.0 and 3.3.6, but the code should compile with any standards compliant compiler. Gcc is available at http://gcc.gnu.org. @@ -74,7 +74,7 @@ After running 'configure', you can run 'make' and 'make install' as explained above. -Copyright (C) 2009-2021 Antonio Diaz Diaz. +Copyright (C) 2009-2022 Antonio Diaz Diaz. This file is free documentation: you have unlimited permission to copy, distribute, and modify it. diff --git a/Makefile.in b/Makefile.in index 94e3770..81b404b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,6 +1,5 @@ DISTNAME = $(pkgname)-$(pkgversion) -AR = ar INSTALL = install INSTALL_PROGRAM = $(INSTALL) -m 755 INSTALL_DATA = $(INSTALL) -m 644 @@ -9,7 +8,7 @@ LDCONFIG = /sbin/ldconfig SHELL = /bin/sh CAN_RUN_INSTALLINFO = $(SHELL) -c "install-info --version" > /dev/null 2>&1 -objs = carg_parser.o main.o +objs = carg_parser.o minilzip.o .PHONY : all install install-bin install-info install-man \ @@ -24,27 +23,27 @@ objs = carg_parser.o main.o all : $(progname_static) $(progname_shared) lib$(libname).a : lzlib.o - $(AR) -rcs $@ $< + $(AR) $(ARFLAGS) $@ $< lib$(libname).so.$(pkgversion) : lzlib_sh.o - $(CC) $(LDFLAGS) $(CFLAGS) -fpic -fPIC -shared -Wl,--soname=lib$(libname).so.$(soversion) -o $@ $< + $(CC) $(CFLAGS) $(LDFLAGS) -fpic -fPIC -shared -Wl,--soname=lib$(libname).so.$(soversion) -o $@ $< $(progname) : $(objs) lib$(libname).a - $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(objs) lib$(libname).a + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(objs) lib$(libname).a $(progname)_shared : $(objs) lib$(libname).so.$(pkgversion) - $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(objs) lib$(libname).so.$(pkgversion) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(objs) lib$(libname).so.$(pkgversion) bbexample : bbexample.o lib$(libname).a - $(CC) $(LDFLAGS) $(CFLAGS) -o $@ bbexample.o lib$(libname).a + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ bbexample.o lib$(libname).a ffexample : ffexample.o lib$(libname).a - $(CC) $(LDFLAGS) $(CFLAGS) -o $@ ffexample.o lib$(libname).a + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ ffexample.o lib$(libname).a lzcheck : lzcheck.o lib$(libname).a - $(CC) $(LDFLAGS) $(CFLAGS) -o $@ lzcheck.o lib$(libname).a + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ lzcheck.o lib$(libname).a -main.o : main.c +minilzip.o : minilzip.c $(CC) $(CPPFLAGS) $(CFLAGS) -DPROGVERSION=\"$(pkgversion)\" -c -o $@ $< lzlib_sh.o : lzlib.c @@ -60,7 +59,7 @@ $(objs) : Makefile carg_parser.o : carg_parser.h lzlib.o : Makefile $(lzdeps) lzlib_sh.o : Makefile $(lzdeps) -main.o : carg_parser.h lzlib.h +minilzip.o : carg_parser.h lzlib.h bbexample.o : Makefile lzlib.h ffexample.o : Makefile lzlib.h lzcheck.o : Makefile lzlib.h @@ -76,7 +75,7 @@ $(VPATH)/doc/$(pkgname).info : $(VPATH)/doc/$(pkgname).texi man : $(VPATH)/doc/$(progname).1 $(VPATH)/doc/$(progname).1 : $(progname) - help2man -n 'reduces the size of files' -o $@ --no-info ./$(progname) + help2man -n 'reduces the size of files' -o $@ --info-page=$(pkgname) ./$(progname) Makefile : $(VPATH)/configure $(VPATH)/Makefile.in ./config.status diff --git a/NEWS b/NEWS index 7b01d52..e2ceb38 100644 --- a/NEWS +++ b/NEWS @@ -1,92 +1,15 @@ -Changes in version 1.12: +Changes in version 1.13: -The value of the version test macro 'LZ_API_VERSION' is now defined as -1000 * major + minor. For version 1.12 it is 1012. -This change does not affect the soversion. +The variables AR and ARFLAGS can now be set from configure. (Before you +needed to run 'make AR='. (Reported by Hoël Bézier). -The new function 'LZ_api_version', which returns the LZ_API_VERSION of the -library object code being used, has been added to lzlib. +In case of error in a numerical argument to a command line option, minilzip +now shows the name of the option and the range of valid values. -If end of file is found at member trailer or EOS marker, -'LZ_decompress_errno' now returns 'LZ_unexpected_eof' instead of -'LZ_data_error'. +'minilzip --check-lib' now checks that LZ_API_VERSION and LZ_version_string +match. -Decompression speed has been slightly increased. +Several descriptions have been improved in manual, '--help', and man page. -A bug has been fixed in minilzip that falsely reported a library stall when -decompressing a file with empty members. - -The new option '--check-lib', which compares the version of lzlib used to -compile minilzip with the version actually being used, has been added to -minilzip. - -Minilzip now reports an error if a file name is empty (minilzip -t ""). - -Option '-o, --output' now behaves like '-c, --stdout', but sending the -output unconditionally to a file instead of to standard output. See the new -description of '-o' in the manual. This change is not backwards compatible. -Therefore commands like: - minilzip -o foo.lz - bar < foo -must now be split into: - minilzip -o foo.lz - < foo - minilzip bar -or rewritten as: - minilzip - bar < foo > foo.lz - -When using '-c' or '-o', minilzip now checks whether the output is a -terminal only once. - -Minilzip now does not even open the output file if the input file is a terminal. - -The words 'decompressed' and 'compressed' have been replaced with the -shorter 'out' and 'in' in the verbose output of minilzip when decompressing -or testing. - -It has been documented in the manual that 'LZ_(de)compress_close' and -'LZ_(de)compress_errno' can be called with a null argument. - -It has been documented in the manual that the LZMA marker '3' ("Sync Flush" -marker) is not allowed in lzip files. Marker '3' is a device for interactive -communication between applications using lzlib, but is useless and wasteful -in a file, and is excluded from the media type 'application/lzip'. The LZMA -marker '2' ("End Of Stream" marker) is the only marker allowed in lzip -files. - -It has been documented in the manual that not calling 'LZ_decompress_finish' -prevents lzlib from detecting a truncated member. - -It has been documented in the manual that 'LZ_decompress_read' returns at -least once per member so that 'LZ_decompress_member_finished' can be called -(and trailer data retrieved) for each member, even for empty members. -Therefore, 'LZ_decompress_read' returning 0 does not mean that the end of -the stream has been reached. - -It has been documented in the manual that 'LZ_(de)compress_read' can be -called with a null buffer pointer argument. - -Real code examples for the most common uses of the library have been added -to the tutorial. - -'bbexample.c' has been simplified to not use 'LZ_(de)compress_write_size'. - -'lzcheck' now accepts options '-s' (to check LZ_compress_sync_flush) and -'-m' (to check member by member decompression). - -'lzcheck.c' now also tests member by member decompression without -intermediate calls to 'LZ_decompress_finish'. - -The new file 'ffexample.c', containing example functions for file-to-file -compression/decompression, has been added to the distribution. - -The commands needed to extract files from a tar.lz archive have been -documented in the output of 'minilzip --help' and in the man page. - -'make install-bin' no longer installs the minilzip man page. This is to -prevent 'make install-bin install-man-compress' from installing the man page -twice before compressing it. - -The new targets 'install-bin-compress' and 'install-bin-strip-compress', -which install a (stripped) minilzip and a compressed man page, have been -added to the Makefile. - -9 new test files have been added to the testsuite. +The texinfo category of the manual has been changed from 'Data Compression' +to 'Compression' to match that of gzip. (Reported by Alfred M. Szmidt). diff --git a/README b/README index ee6e6d7..86a0cb5 100644 --- a/README +++ b/README @@ -31,9 +31,13 @@ the beginning is a thing of the past. The functions and variables forming the interface of the compression library are declared in the file 'lzlib.h'. Usage examples of the library are given -in the files 'bbexample.c', 'ffexample.c', and 'main.c' from the source +in the files 'bbexample.c', 'ffexample.c', and 'minilzip.c' from the source distribution. +All the library functions are thread safe. The library does not install any +signal handler. The decoder checks the consistency of the compressed data, +so the library should never crash even in case of corrupted input. + Compression/decompression is done by repeatedly calling a couple of read/write functions until all the data have been processed by the library. This interface is safer and less error prone than the traditional zlib @@ -60,10 +64,6 @@ Lzlib is able to compress and decompress streams of unlimited size by automatically creating multimember output. The members so created are large, about 2 PiB each. -All the library functions are thread safe. The library does not install -any signal handler. The decoder checks the consistency of the compressed -data, so the library should never crash even in case of corrupted input. - In spite of its name (Lempel-Ziv-Markov chain-Algorithm), LZMA is not a concrete algorithm; it is more like "any algorithm using the LZMA coding scheme". For example, the option '-0' of lzip uses the scheme in almost the @@ -73,7 +73,7 @@ finding coding sequences of minimum size than the one currently used by lzip could be developed, and the resulting sequence could also be coded using the LZMA coding scheme. -Lzlib currently implements two variants of the LZMA algorithm; fast (used by +Lzlib currently implements two variants of the LZMA algorithm: fast (used by option '-0' of minilzip) and normal (used by all other compression levels). The high compression of LZMA comes from combining two basic, well-proven @@ -93,7 +93,7 @@ been compressed. Decompressed is used to refer to data which have undergone the process of decompression. -Copyright (C) 2009-2021 Antonio Diaz Diaz. +Copyright (C) 2009-2022 Antonio Diaz Diaz. This file is free documentation: you have unlimited permission to copy, distribute, and modify it. diff --git a/bbexample.c b/bbexample.c index 96257ee..074f7ae 100644 --- a/bbexample.c +++ b/bbexample.c @@ -1,5 +1,5 @@ /* Buffer to buffer example - Test program for the library lzlib - Copyright (C) 2010-2021 Antonio Diaz Diaz. + Copyright (C) 2010-2022 Antonio Diaz Diaz. This program is free software: you have unlimited permission to copy, distribute, and modify it. @@ -28,9 +28,9 @@ #endif -/* Returns the address of a malloc'd buffer containing the file data and +/* Return the address of a malloc'd buffer containing the file data and the file size in '*file_sizep'. - In case of error, returns 0 and does not modify '*file_sizep'. + In case of error, return 0 and do not modify '*file_sizep'. */ uint8_t * read_file( const char * const name, long * const file_sizep ) { @@ -73,10 +73,10 @@ uint8_t * read_file( const char * const name, long * const file_sizep ) } -/* Compresses 'insize' bytes from 'inbuf'. - Returns the address of a malloc'd buffer containing the compressed data, +/* Compress 'insize' bytes from 'inbuf'. + Return the address of a malloc'd buffer containing the compressed data, and the size of the data in '*outlenp'. - In case of error, returns 0 and does not modify '*outlenp'. + In case of error, return 0 and do not modify '*outlenp'. */ uint8_t * bbcompressl( const uint8_t * const inbuf, const long insize, const int level, long * const outlenp ) @@ -152,10 +152,10 @@ uint8_t * bbcompressl( const uint8_t * const inbuf, const long insize, } -/* Decompresses 'insize' bytes from 'inbuf'. - Returns the address of a malloc'd buffer containing the decompressed +/* Decompress 'insize' bytes from 'inbuf'. + Return the address of a malloc'd buffer containing the decompressed data, and the size of the data in '*outlenp'. - In case of error, returns 0 and does not modify '*outlenp'. + In case of error, return 0 and do not modify '*outlenp'. */ uint8_t * bbdecompressl( const uint8_t * const inbuf, const long insize, long * const outlenp ) @@ -230,10 +230,10 @@ int full_test( const uint8_t * const inbuf, const long insize ) } -/* Compresses 'insize' bytes from 'inbuf' to 'outbuf'. - Returns the size of the compressed data in '*outlenp'. - In case of error, or if 'outsize' is too small, returns false and does - not modify '*outlenp'. +/* Compress 'insize' bytes from 'inbuf' to 'outbuf'. + Return the size of the compressed data in '*outlenp'. + In case of error, or if 'outsize' is too small, return false and do not + modify '*outlenp'. */ bool bbcompress( const uint8_t * const inbuf, const int insize, const int dictionary_size, const int match_len_limit, @@ -267,10 +267,10 @@ bool bbcompress( const uint8_t * const inbuf, const int insize, } -/* Decompresses 'insize' bytes from 'inbuf' to 'outbuf'. - Returns the size of the decompressed data in '*outlenp'. - In case of error, or if 'outsize' is too small, returns false and does - not modify '*outlenp'. +/* Decompress 'insize' bytes from 'inbuf' to 'outbuf'. + Return the size of the decompressed data in '*outlenp'. + In case of error, or if 'outsize' is too small, return false and do not + modify '*outlenp'. */ bool bbdecompress( const uint8_t * const inbuf, const int insize, uint8_t * const outbuf, const int outsize, diff --git a/carg_parser.c b/carg_parser.c index d0c05d5..181ba23 100644 --- a/carg_parser.c +++ b/carg_parser.c @@ -1,5 +1,5 @@ /* Arg_parser - POSIX/GNU command line argument parser. (C version) - Copyright (C) 2006-2021 Antonio Diaz Diaz. + Copyright (C) 2006-2022 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -32,10 +32,10 @@ static void * ap_resize_buffer( void * buf, const int min_size ) } -static char push_back_record( struct Arg_parser * const ap, - const int code, const char * const argument ) +static char push_back_record( struct Arg_parser * const ap, const int code, + const char * const long_name, + const char * const argument ) { - const int len = strlen( argument ); struct ap_Record * p; void * tmp = ap_resize_buffer( ap->data, ( ap->data_size + 1 ) * sizeof (struct ap_Record) ); @@ -43,11 +43,29 @@ static char push_back_record( struct Arg_parser * const ap, ap->data = (struct ap_Record *)tmp; p = &(ap->data[ap->data_size]); p->code = code; - p->argument = 0; - tmp = ap_resize_buffer( p->argument, len + 1 ); - if( !tmp ) return 0; - p->argument = (char *)tmp; - strncpy( p->argument, argument, len + 1 ); + if( long_name ) + { + const int len = strlen( long_name ); + p->parsed_name = (char *)malloc( len + 2 + 1 ); + if( !p->parsed_name ) return 0; + p->parsed_name[0] = p->parsed_name[1] = '-'; + strncpy( p->parsed_name + 2, long_name, len + 1 ); + } + else if( code > 0 && code < 256 ) + { + p->parsed_name = (char *)malloc( 2 + 1 ); + if( !p->parsed_name ) return 0; + p->parsed_name[0] = '-'; p->parsed_name[1] = code; p->parsed_name[2] = 0; + } + else p->parsed_name = 0; + if( argument ) + { + const int len = strlen( argument ); + p->argument = (char *)malloc( len + 1 ); + if( !p->argument ) { free( p->parsed_name ); return 0; } + strncpy( p->argument, argument, len + 1 ); + } + else p->argument = 0; ++ap->data_size; return 1; } @@ -68,12 +86,14 @@ static char add_error( struct Arg_parser * const ap, const char * const msg ) static void free_data( struct Arg_parser * const ap ) { int i; - for( i = 0; i < ap->data_size; ++i ) free( ap->data[i].argument ); + for( i = 0; i < ap->data_size; ++i ) + { free( ap->data[i].argument ); free( ap->data[i].parsed_name ); } if( ap->data ) { free( ap->data ); ap->data = 0; } ap->data_size = 0; } +/* Return 0 only if out of memory. */ static char parse_long_option( struct Arg_parser * const ap, const char * const opt, const char * const arg, const struct ap_Option options[], @@ -87,9 +107,10 @@ static char parse_long_option( struct Arg_parser * const ap, /* Test all long options for either exact match or abbreviated matches. */ for( i = 0; options[i].code != 0; ++i ) - if( options[i].name && strncmp( options[i].name, &opt[2], len ) == 0 ) + if( options[i].long_name && + strncmp( options[i].long_name, &opt[2], len ) == 0 ) { - if( strlen( options[i].name ) == len ) /* Exact match found */ + if( strlen( options[i].long_name ) == len ) /* Exact match found */ { index = i; exact = 1; break; } else if( index < 0 ) index = i; /* First nonexact match found */ else if( options[index].code != options[i].code || @@ -117,35 +138,39 @@ static char parse_long_option( struct Arg_parser * const ap, { if( options[index].has_arg == ap_no ) { - add_error( ap, "option '--" ); add_error( ap, options[index].name ); + add_error( ap, "option '--" ); add_error( ap, options[index].long_name ); add_error( ap, "' doesn't allow an argument" ); return 1; } if( options[index].has_arg == ap_yes && !opt[len+3] ) { - add_error( ap, "option '--" ); add_error( ap, options[index].name ); + add_error( ap, "option '--" ); add_error( ap, options[index].long_name ); add_error( ap, "' requires an argument" ); return 1; } - return push_back_record( ap, options[index].code, &opt[len+3] ); + return push_back_record( ap, options[index].code, + options[index].long_name, &opt[len+3] ); } if( options[index].has_arg == ap_yes ) { if( !arg || !arg[0] ) { - add_error( ap, "option '--" ); add_error( ap, options[index].name ); + add_error( ap, "option '--" ); add_error( ap, options[index].long_name ); add_error( ap, "' requires an argument" ); return 1; } ++*argindp; - return push_back_record( ap, options[index].code, arg ); + return push_back_record( ap, options[index].code, + options[index].long_name, arg ); } - return push_back_record( ap, options[index].code, "" ); + return push_back_record( ap, options[index].code, + options[index].long_name, 0 ); } +/* Return 0 only if out of memory. */ static char parse_short_option( struct Arg_parser * const ap, const char * const opt, const char * const arg, const struct ap_Option options[], @@ -156,13 +181,13 @@ static char parse_short_option( struct Arg_parser * const ap, while( cind > 0 ) { int index = -1, i; - const unsigned char code = opt[cind]; + const unsigned char c = opt[cind]; char code_str[2]; - code_str[0] = code; code_str[1] = 0; + code_str[0] = c; code_str[1] = 0; - if( code != 0 ) + if( c != 0 ) for( i = 0; options[i].code; ++i ) - if( code == options[i].code ) + if( c == options[i].code ) { index = i; break; } if( index < 0 ) @@ -176,7 +201,7 @@ static char parse_short_option( struct Arg_parser * const ap, if( options[index].has_arg != ap_no && cind > 0 && opt[cind] ) { - if( !push_back_record( ap, code, &opt[cind] ) ) return 0; + if( !push_back_record( ap, c, 0, &opt[cind] ) ) return 0; ++*argindp; cind = 0; } else if( options[index].has_arg == ap_yes ) @@ -188,9 +213,9 @@ static char parse_short_option( struct Arg_parser * const ap, return 1; } ++*argindp; cind = 0; - if( !push_back_record( ap, code, arg ) ) return 0; + if( !push_back_record( ap, c, 0, arg ) ) return 0; } - else if( !push_back_record( ap, code, "" ) ) return 0; + else if( !push_back_record( ap, c, 0, 0 ) ) return 0; } return 1; } @@ -203,7 +228,7 @@ char ap_init( struct Arg_parser * const ap, const char ** non_options = 0; /* skipped non-options */ int non_options_size = 0; /* number of skipped non-options */ int argind = 1; /* index in argv */ - int i; + char done = 0; /* false until success */ ap->data = 0; ap->error = 0; @@ -223,20 +248,20 @@ char ap_init( struct Arg_parser * const ap, if( ch2 == '-' ) { if( !argv[argind][2] ) { ++argind; break; } /* we found "--" */ - else if( !parse_long_option( ap, opt, arg, options, &argind ) ) return 0; + else if( !parse_long_option( ap, opt, arg, options, &argind ) ) goto out; } - else if( !parse_short_option( ap, opt, arg, options, &argind ) ) return 0; + else if( !parse_short_option( ap, opt, arg, options, &argind ) ) goto out; if( ap->error ) break; } else { if( in_order ) - { if( !push_back_record( ap, 0, argv[argind++] ) ) return 0; } + { if( !push_back_record( ap, 0, 0, argv[argind++] ) ) goto out; } else { void * tmp = ap_resize_buffer( non_options, ( non_options_size + 1 ) * sizeof *non_options ); - if( !tmp ) return 0; + if( !tmp ) goto out; non_options = (const char **)tmp; non_options[non_options_size++] = argv[argind++]; } @@ -245,13 +270,15 @@ char ap_init( struct Arg_parser * const ap, if( ap->error ) free_data( ap ); else { + int i; for( i = 0; i < non_options_size; ++i ) - if( !push_back_record( ap, 0, non_options[i] ) ) return 0; + if( !push_back_record( ap, 0, 0, non_options[i] ) ) goto out; while( argind < argc ) - if( !push_back_record( ap, 0, argv[argind++] ) ) return 0; + if( !push_back_record( ap, 0, 0, argv[argind++] ) ) goto out; } - if( non_options ) free( non_options ); - return 1; + done = 1; +out: if( non_options ) free( non_options ); + return done; } @@ -273,13 +300,20 @@ int ap_arguments( const struct Arg_parser * const ap ) int ap_code( const struct Arg_parser * const ap, const int i ) { - if( i >= 0 && i < ap_arguments( ap ) ) return ap->data[i].code; - else return 0; + if( i < 0 || i >= ap_arguments( ap ) ) return 0; + return ap->data[i].code; + } + + +const char * ap_parsed_name( const struct Arg_parser * const ap, const int i ) + { + if( i < 0 || i >= ap_arguments( ap ) || !ap->data[i].parsed_name ) return ""; + return ap->data[i].parsed_name; } const char * ap_argument( const struct Arg_parser * const ap, const int i ) { - if( i >= 0 && i < ap_arguments( ap ) ) return ap->data[i].argument; - else return ""; + if( i < 0 || i >= ap_arguments( ap ) || !ap->data[i].argument ) return ""; + return ap->data[i].argument; } diff --git a/carg_parser.h b/carg_parser.h index c5f2352..0c64861 100644 --- a/carg_parser.h +++ b/carg_parser.h @@ -1,5 +1,5 @@ /* Arg_parser - POSIX/GNU command line argument parser. (C version) - Copyright (C) 2006-2021 Antonio Diaz Diaz. + Copyright (C) 2006-2022 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -24,9 +24,9 @@ message. 'options' is an array of 'struct ap_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. + containing a code which is zero. A null long_name means a short-only + option. A code value outside the unsigned char range means a long-only + option. Arg_parser normally makes it appear as if all the option arguments were specified before all the non-option arguments for the purposes @@ -50,7 +50,7 @@ enum ap_Has_arg { ap_no, ap_yes, ap_maybe }; struct ap_Option { int code; /* Short option letter or code ( code != 0 ) */ - const char * name; /* Long option name (maybe null) */ + const char * long_name; /* Long option name (maybe null) */ enum ap_Has_arg has_arg; }; @@ -58,6 +58,7 @@ struct ap_Option struct ap_Record { int code; + char * parsed_name; char * argument; }; @@ -86,6 +87,9 @@ int ap_arguments( const struct Arg_parser * const ap ); Else ap_argument( i ) is the option's argument (or empty). */ int ap_code( const struct Arg_parser * const ap, const int i ); +/* Full name of the option parsed (short or long). */ +const char * ap_parsed_name( const struct Arg_parser * const ap, const int i ); + const char * ap_argument( const struct Arg_parser * const ap, const int i ); #ifdef __cplusplus diff --git a/cbuffer.c b/cbuffer.c index ee54131..812de42 100644 --- a/cbuffer.c +++ b/cbuffer.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2021 Antonio Diaz Diaz. + Copyright (C) 2009-2022 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -76,9 +76,9 @@ static bool Cb_unread_data( struct Circular_buffer * const cb, } -/* Copies up to 'out_size' bytes to 'out_buffer' and updates 'get'. +/* Copy up to 'out_size' bytes to 'out_buffer' and update 'get'. If 'out_buffer' is null, the bytes are discarded. - Returns the number of bytes copied or discarded. + Return the number of bytes copied or discarded. */ static unsigned Cb_read_data( struct Circular_buffer * const cb, uint8_t * const out_buffer, @@ -110,8 +110,8 @@ static unsigned Cb_read_data( struct Circular_buffer * const cb, } -/* Copies up to 'in_size' bytes from 'in_buffer' and updates 'put'. - Returns the number of bytes copied. +/* Copy up to 'in_size' bytes from 'in_buffer' and update 'put'. + Return the number of bytes copied. */ static unsigned Cb_write_data( struct Circular_buffer * const cb, const uint8_t * const in_buffer, diff --git a/configure b/configure index d74cf5d..4060472 100755 --- a/configure +++ b/configure @@ -1,12 +1,12 @@ #! /bin/sh # configure script for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2021 Antonio Diaz Diaz. +# Copyright (C) 2009-2022 Antonio Diaz Diaz. # # This configure script is free software: you have unlimited permission # to copy, distribute, and modify it. pkgname=lzlib -pkgversion=1.12 +pkgversion=1.13 soversion=1 progname=minilzip progname_static=${progname} @@ -29,9 +29,11 @@ infodir='$(datarootdir)/info' libdir='$(exec_prefix)/lib' mandir='$(datarootdir)/man' CC=gcc +AR=ar CPPFLAGS= CFLAGS='-Wall -W -O2' LDFLAGS= +ARFLAGS=-rcs # checking whether we are using GNU C. /bin/sh -c "${CC} --version" > /dev/null 2>&1 || { CC=cc ; CFLAGS=-O2 ; } @@ -79,10 +81,12 @@ while [ $# != 0 ] ; do echo " --enable-shared build also a shared library [disable]" echo " --disable-ldconfig don't run ldconfig after install" echo " CC=COMPILER C compiler to use [${CC}]" + echo " AR=ARCHIVER library archiver to use [${AR}]" echo " CPPFLAGS=OPTIONS command line options for the preprocessor [${CPPFLAGS}]" echo " CFLAGS=OPTIONS command line options for the C compiler [${CFLAGS}]" echo " CFLAGS+=OPTIONS append options to the current value of CFLAGS" echo " LDFLAGS=OPTIONS command line options for the linker [${LDFLAGS}]" + echo " ARFLAGS=OPTIONS command line options for the library archiver [${ARFLAGS}]" echo exit 0 ;; --version | -V) @@ -118,10 +122,12 @@ while [ $# != 0 ] ; do --disable-ldconfig) disable_ldconfig=yes ;; CC=*) CC=${optarg} ;; + AR=*) AR=${optarg} ;; CPPFLAGS=*) CPPFLAGS=${optarg} ;; CFLAGS=*) CFLAGS=${optarg} ;; CFLAGS+=*) CFLAGS="${CFLAGS} ${optarg}" ;; LDFLAGS=*) LDFLAGS=${optarg} ;; + ARFLAGS=*) ARFLAGS=${optarg} ;; --*) echo "configure: WARNING: unrecognized option: '${option}'" 1>&2 ;; @@ -189,13 +195,15 @@ echo "infodir = ${infodir}" echo "libdir = ${libdir}" echo "mandir = ${mandir}" echo "CC = ${CC}" +echo "AR = ${AR}" echo "CPPFLAGS = ${CPPFLAGS}" echo "CFLAGS = ${CFLAGS}" echo "LDFLAGS = ${LDFLAGS}" +echo "ARFLAGS = ${ARFLAGS}" rm -f Makefile cat > Makefile << EOF # Makefile for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2021 Antonio Diaz Diaz. +# Copyright (C) 2009-2022 Antonio Diaz Diaz. # This file was generated automatically by configure. Don't edit. # # This Makefile is free software: you have unlimited permission @@ -220,9 +228,11 @@ infodir = ${infodir} libdir = ${libdir} mandir = ${mandir} CC = ${CC} +AR = ${AR} CPPFLAGS = ${CPPFLAGS} CFLAGS = ${CFLAGS} LDFLAGS = ${LDFLAGS} +ARFLAGS = ${ARFLAGS} EOF cat "${srcdir}/Makefile.in" >> Makefile diff --git a/decoder.c b/decoder.c index 82472b3..16f6532 100644 --- a/decoder.c +++ b/decoder.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2021 Antonio Diaz Diaz. + Copyright (C) 2009-2022 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -49,8 +49,6 @@ static int LZd_decode_member( struct LZ_decoder * const d ) while( !Rd_finished( rdec ) ) { - int len; - const int pos_state = LZd_data_position( d ) & pos_state_mask; /* const unsigned mpos = rdec->member_position; if( mpos - old_mpos > rd_min_available_bytes ) return 5; old_mpos = mpos; */ @@ -58,23 +56,19 @@ static int LZd_decode_member( struct LZ_decoder * const d ) { if( !rdec->at_stream_end ) return 0; if( Cb_empty( &rdec->cb ) ) break; } /* decode until EOF */ if( !LZd_enough_free_bytes( d ) ) return 0; + const int pos_state = LZd_data_position( d ) & pos_state_mask; if( Rd_decode_bit( rdec, &d->bm_match[*state][pos_state] ) == 0 ) /* 1st bit */ { /* literal byte */ Bit_model * const bm = d->bm_literal[get_lit_state(LZd_peek_prev( d ))]; - if( St_is_char( *state ) ) - { - *state -= ( *state < 4 ) ? *state : 3; + if( ( *state = St_set_char( *state ) ) < 4 ) LZd_put_byte( d, Rd_decode_tree8( rdec, bm ) ); - } else - { - *state -= ( *state < 10 ) ? 3 : 6; LZd_put_byte( d, Rd_decode_matched( rdec, bm, LZd_peek( d, d->rep0 ) ) ); - } continue; } /* match or repeated match */ + int len; if( Rd_decode_bit( rdec, &d->bm_rep[*state] ) != 0 ) /* 2nd bit */ { if( Rd_decode_bit( rdec, &d->bm_rep0[*state] ) == 0 ) /* 3rd bit */ @@ -100,13 +94,12 @@ static int LZd_decode_member( struct LZ_decoder * const d ) d->rep0 = distance; } *state = St_set_rep( *state ); - len = min_match_len + Rd_decode_len( rdec, &d->rep_len_model, pos_state ); + len = Rd_decode_len( rdec, &d->rep_len_model, pos_state ); } else /* match */ { - unsigned distance; - len = min_match_len + Rd_decode_len( rdec, &d->match_len_model, pos_state ); - distance = Rd_decode_tree6( rdec, d->bm_dis_slot[get_len_state(len)] ); + len = Rd_decode_len( rdec, &d->match_len_model, pos_state ); + unsigned distance = Rd_decode_tree6( rdec, d->bm_dis_slot[get_len_state(len)] ); if( distance >= start_dis_model ) { const unsigned dis_slot = distance; diff --git a/decoder.h b/decoder.h index 15d5dfb..27de9cb 100644 --- a/decoder.h +++ b/decoder.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2021 Antonio Diaz Diaz. + Copyright (C) 2009-2022 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -72,8 +72,8 @@ static inline void Rd_reset( struct Range_decoder * const rdec ) rdec->member_position = 0; rdec->at_stream_end = false; } -/* Seeks a member header and updates 'get'. '*skippedp' is set to the - number of bytes skipped. Returns true if it finds a valid header. +/* Seek for a member header and update 'get'. Set '*skippedp' to the number + of bytes skipped. Return true if a valid header is found. */ static bool Rd_find_header( struct Range_decoder * const rdec, unsigned * const skippedp ) @@ -140,8 +140,7 @@ static bool Rd_try_reload( struct Range_decoder * const rdec ) int i; rdec->reload_pending = false; rdec->code = 0; - for( i = 0; i < 5; ++i ) - rdec->code = (rdec->code << 8) | Rd_get_byte( rdec ); + for( i = 0; i < 5; ++i ) rdec->code = (rdec->code << 8) | Rd_get_byte( rdec ); rdec->range = 0xFFFFFFFFU; rdec->code &= rdec->range; /* make sure that first byte is discarded */ } @@ -161,12 +160,11 @@ static inline unsigned Rd_decode( struct Range_decoder * const rdec, int i; for( i = num_bits; i > 0; --i ) { - bool bit; Rd_normalize( rdec ); rdec->range >>= 1; /* symbol <<= 1; */ /* if( rdec->code >= rdec->range ) { rdec->code -= rdec->range; symbol |= 1; } */ - bit = ( rdec->code >= rdec->range ); + const bool bit = ( rdec->code >= rdec->range ); symbol <<= 1; symbol += bit; rdec->code -= rdec->range & ( 0U - bit ); } @@ -176,42 +174,75 @@ static inline unsigned Rd_decode( struct Range_decoder * const rdec, static inline unsigned Rd_decode_bit( struct Range_decoder * const rdec, Bit_model * const probability ) { - uint32_t bound; Rd_normalize( rdec ); - bound = ( rdec->range >> bit_model_total_bits ) * *probability; + const uint32_t bound = ( rdec->range >> bit_model_total_bits ) * *probability; if( rdec->code < bound ) { - *probability += (bit_model_total - *probability) >> bit_model_move_bits; rdec->range = bound; + *probability += ( bit_model_total - *probability ) >> bit_model_move_bits; return 0; } else { - *probability -= *probability >> bit_model_move_bits; rdec->code -= bound; rdec->range -= bound; + *probability -= *probability >> bit_model_move_bits; return 1; } } -static inline unsigned Rd_decode_tree3( struct Range_decoder * const rdec, - Bit_model bm[] ) +static inline void Rd_decode_symbol_bit( struct Range_decoder * const rdec, + Bit_model * const probability, unsigned * symbol ) { - unsigned symbol = 2 | Rd_decode_bit( rdec, &bm[1] ); - symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); - symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); - return symbol & 7; + Rd_normalize( rdec ); + *symbol <<= 1; + const uint32_t bound = ( rdec->range >> bit_model_total_bits ) * *probability; + if( rdec->code < bound ) + { + rdec->range = bound; + *probability += ( bit_model_total - *probability ) >> bit_model_move_bits; + } + else + { + rdec->code -= bound; + rdec->range -= bound; + *probability -= *probability >> bit_model_move_bits; + *symbol |= 1; + } + } + +static inline void Rd_decode_symbol_bit_reversed( struct Range_decoder * const rdec, + Bit_model * const probability, unsigned * model, + unsigned * symbol, const int i ) + { + Rd_normalize( rdec ); + *model <<= 1; + const uint32_t bound = ( rdec->range >> bit_model_total_bits ) * *probability; + if( rdec->code < bound ) + { + rdec->range = bound; + *probability += ( bit_model_total - *probability ) >> bit_model_move_bits; + } + else + { + rdec->code -= bound; + rdec->range -= bound; + *probability -= *probability >> bit_model_move_bits; + *model |= 1; + *symbol |= 1 << i; + } } static inline unsigned Rd_decode_tree6( struct Range_decoder * const rdec, Bit_model bm[] ) { - unsigned symbol = 2 | Rd_decode_bit( rdec, &bm[1] ); - symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); - symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); - symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); - symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); - symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); + unsigned symbol = 1; + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); return symbol & 0x3F; } @@ -219,9 +250,14 @@ static inline unsigned Rd_decode_tree8( struct Range_decoder * const rdec, Bit_model bm[] ) { unsigned symbol = 1; - int i; - for( i = 0; i < 8; ++i ) - symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); return symbol & 0xFF; } @@ -233,21 +269,19 @@ Rd_decode_tree_reversed( struct Range_decoder * const rdec, unsigned symbol = 0; int i; for( i = 0; i < num_bits; ++i ) - { - const unsigned bit = Rd_decode_bit( rdec, &bm[model] ); - model <<= 1; model += bit; - symbol |= ( bit << i ); - } + Rd_decode_symbol_bit_reversed( rdec, &bm[model], &model, &symbol, i ); return symbol; } static inline unsigned Rd_decode_tree_reversed4( struct Range_decoder * const rdec, Bit_model bm[] ) { - unsigned symbol = Rd_decode_bit( rdec, &bm[1] ); - symbol += Rd_decode_bit( rdec, &bm[2+symbol] ) << 1; - symbol += Rd_decode_bit( rdec, &bm[4+symbol] ) << 2; - symbol += Rd_decode_bit( rdec, &bm[8+symbol] ) << 3; + unsigned model = 1; + unsigned symbol = 0; + Rd_decode_symbol_bit_reversed( rdec, &bm[model], &model, &symbol, 0 ); + Rd_decode_symbol_bit_reversed( rdec, &bm[model], &model, &symbol, 1 ); + Rd_decode_symbol_bit_reversed( rdec, &bm[model], &model, &symbol, 2 ); + Rd_decode_symbol_bit_reversed( rdec, &bm[model], &model, &symbol, 3 ); return symbol; } @@ -270,11 +304,24 @@ static inline unsigned Rd_decode_len( struct Range_decoder * const rdec, struct Len_model * const lm, const int pos_state ) { + Bit_model * bm; + unsigned mask, offset, symbol = 1; + if( Rd_decode_bit( rdec, &lm->choice1 ) == 0 ) - return Rd_decode_tree3( rdec, lm->bm_low[pos_state] ); + { bm = lm->bm_low[pos_state]; mask = 7; offset = 0; goto len3; } if( Rd_decode_bit( rdec, &lm->choice2 ) == 0 ) - return len_low_symbols + Rd_decode_tree3( rdec, lm->bm_mid[pos_state] ); - return len_low_symbols + len_mid_symbols + Rd_decode_tree8( rdec, lm->bm_high ); + { bm = lm->bm_mid[pos_state]; mask = 7; offset = len_low_symbols; goto len3; } + bm = lm->bm_high; mask = 0xFF; offset = len_low_symbols + len_mid_symbols; + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); +len3: + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + Rd_decode_symbol_bit( rdec, &bm[symbol], &symbol ); + return ( symbol & mask ) + min_match_len + offset; } diff --git a/doc/lzlib.info b/doc/lzlib.info index bef1859..d81bc88 100644 --- a/doc/lzlib.info +++ b/doc/lzlib.info @@ -1,6 +1,6 @@ This is lzlib.info, produced by makeinfo version 4.13+ from lzlib.texi. -INFO-DIR-SECTION Data Compression +INFO-DIR-SECTION Compression START-INFO-DIR-ENTRY * Lzlib: (lzlib). Compression library for the lzip format END-INFO-DIR-ENTRY @@ -11,7 +11,7 @@ File: lzlib.info, Node: Top, Next: Introduction, Up: (dir) Lzlib Manual ************ -This manual is for Lzlib (version 1.12, 2 January 2021). +This manual is for Lzlib (version 1.13, 23 January 2022). * Menu: @@ -30,7 +30,7 @@ This manual is for Lzlib (version 1.12, 2 January 2021). * Concept index:: Index of concepts - Copyright (C) 2009-2021 Antonio Diaz Diaz. + Copyright (C) 2009-2022 Antonio Diaz Diaz. This manual is free documentation: you have unlimited permission to copy, distribute, and modify it. @@ -73,8 +73,12 @@ byte near the beginning is a thing of the past. The functions and variables forming the interface of the compression library are declared in the file 'lzlib.h'. Usage examples of the library -are given in the files 'bbexample.c', 'ffexample.c', and 'main.c' from the -source distribution. +are given in the files 'bbexample.c', 'ffexample.c', and 'minilzip.c' from +the source distribution. + + All the library functions are thread safe. The library does not install +any signal handler. The decoder checks the consistency of the compressed +data, so the library should never crash even in case of corrupted input. Compression/decompression is done by repeatedly calling a couple of read/write functions until all the data have been processed by the library. @@ -102,20 +106,16 @@ concatenated compressed data streams is also supported. automatically creating multimember output. The members so created are large, about 2 PiB each. - All the library functions are thread safe. The library does not install -any signal handler. The decoder checks the consistency of the compressed -data, so the library should never crash even in case of corrupted input. - In spite of its name (Lempel-Ziv-Markov chain-Algorithm), LZMA is not a concrete algorithm; it is more like "any algorithm using the LZMA coding scheme". For example, the option '-0' of lzip uses the scheme in almost the simplest way possible; issuing the longest match it can find, or a literal byte if it can't find a match. Inversely, a much more elaborated way of -finding coding sequences of minimum size than the one currently used by -lzip could be developed, and the resulting sequence could also be coded -using the LZMA coding scheme. +finding coding sequences of minimum size than the one currently used by lzip +could be developed, and the resulting sequence could also be coded using the +LZMA coding scheme. - Lzlib currently implements two variants of the LZMA algorithm; fast + Lzlib currently implements two variants of the LZMA algorithm: fast (used by option '-0' of minilzip) and normal (used by all other compression levels). @@ -145,7 +145,8 @@ One goal of lzlib is to keep perfect backward compatibility with older versions of itself down to 1.0. Any application working with an older lzlib should work with a newer lzlib. Installing a newer lzlib should not break anything. This chapter describes the constants and functions that the -application can use to discover the version of the library being used. +application can use to discover the version of the library being used. All +of them are declared in 'lzlib.h'. -- Constant: LZ_API_VERSION This constant is defined in 'lzlib.h' and works as a version test @@ -325,13 +326,13 @@ except 'LZ_compress_open' whose return value must be verified by calling 'LZ_compress_sync_flush'. Then call 'LZ_compress_read' until it returns 0. - This function writes a LZMA marker '3' ("Sync Flush" marker) to the - compressed output. Note that the sync flush marker is not allowed in - lzip files; it is a device for interactive communication between - applications using lzlib, but is useless and wasteful in a file, and - is excluded from the media type 'application/lzip'. The LZMA marker - '2' ("End Of Stream" marker) is the only marker allowed in lzip files. - *Note Data format::. + This function writes at least one LZMA marker '3' ("Sync Flush" marker) + to the compressed output. Note that the sync flush marker is not + allowed in lzip files; it is a device for interactive communication + between applications using lzlib, but is useless and wasteful in a + file, and is excluded from the media type 'application/lzip'. The LZMA + marker '2' ("End Of Stream" marker) is the only marker allowed in lzip + files. *Note Data format::. Repeated use of 'LZ_compress_sync_flush' may degrade compression ratio, so use it only when needed. If the interval between calls to @@ -347,34 +348,30 @@ except 'LZ_compress_open' whose return value must be verified by calling -- Function: int LZ_compress_read ( struct LZ_Encoder * const ENCODER, uint8_t * const BUFFER, const int SIZE ) - The function 'LZ_compress_read' reads up to SIZE bytes from the stream - pointed to by ENCODER, storing the results in BUFFER. If - LZ_API_VERSION >= 1012, BUFFER may be a null pointer, in which case - the bytes read are discarded. + Reads up to SIZE bytes from the stream pointed to by ENCODER, storing + the results in BUFFER. If LZ_API_VERSION >= 1012, BUFFER may be a null + pointer, in which case the bytes read are discarded. - The return value is the number of bytes actually read. This might be - less than SIZE; for example, if there aren't that many bytes left in - the stream or if more bytes have to be yet written with the function + Returns the number of bytes actually read. This might be less than + SIZE; for example, if there aren't that many bytes left in the stream + or if more bytes have to be yet written with the function 'LZ_compress_write'. Note that reading less than SIZE bytes is not an error. -- Function: int LZ_compress_write ( struct LZ_Encoder * const ENCODER, uint8_t * const BUFFER, const int SIZE ) - The function 'LZ_compress_write' writes up to SIZE bytes from BUFFER - to the stream pointed to by ENCODER. - - The return value is the number of bytes actually written. This might be + Writes up to SIZE bytes from BUFFER to the stream pointed to by + ENCODER. Returns the number of bytes actually written. This might be less than SIZE. Note that writing less than SIZE bytes is not an error. -- Function: int LZ_compress_write_size ( struct LZ_Encoder * const ENCODER ) - The function 'LZ_compress_write_size' returns the maximum number of - bytes that can be immediately written through 'LZ_compress_write'. For - efficiency reasons, once the input buffer is full and - 'LZ_compress_write_size' returns 0, almost all the buffer must be - compressed before a size greater than 0 is returned again. (This is - done to minimize the amount of data that must be copied to the - beginning of the buffer before new data can be accepted). + Returns the maximum number of bytes that can be immediately written + through 'LZ_compress_write'. For efficiency reasons, once the input + buffer is full and 'LZ_compress_write_size' returns 0, almost all the + buffer must be compressed before a size greater than 0 is returned + again. (This is done to minimize the amount of data that must be + copied to the beginning of the buffer before new data can be accepted). It is guaranteed that an immediate call to 'LZ_compress_write' will accept a SIZE up to the returned number of bytes. @@ -472,14 +469,13 @@ except 'LZ_decompress_open' whose return value must be verified by calling -- Function: int LZ_decompress_read ( struct LZ_Decoder * const DECODER, uint8_t * const BUFFER, const int SIZE ) - The function 'LZ_decompress_read' reads up to SIZE bytes from the - stream pointed to by DECODER, storing the results in BUFFER. If - LZ_API_VERSION >= 1012, BUFFER may be a null pointer, in which case - the bytes read are discarded. + Reads up to SIZE bytes from the stream pointed to by DECODER, storing + the results in BUFFER. If LZ_API_VERSION >= 1012, BUFFER may be a null + pointer, in which case the bytes read are discarded. - The return value is the number of bytes actually read. This might be - less than SIZE; for example, if there aren't that many bytes left in - the stream or if more bytes have to be yet written with the function + Returns the number of bytes actually read. This might be less than + SIZE; for example, if there aren't that many bytes left in the stream + or if more bytes have to be yet written with the function 'LZ_decompress_write'. Note that reading less than SIZE bytes is not an error. @@ -499,18 +495,16 @@ except 'LZ_decompress_open' whose return value must be verified by calling -- Function: int LZ_decompress_write ( struct LZ_Decoder * const DECODER, uint8_t * const BUFFER, const int SIZE ) - The function 'LZ_decompress_write' writes up to SIZE bytes from BUFFER - to the stream pointed to by DECODER. - - The return value is the number of bytes actually written. This might be + Writes up to SIZE bytes from BUFFER to the stream pointed to by + DECODER. Returns the number of bytes actually written. This might be less than SIZE. Note that writing less than SIZE bytes is not an error. -- Function: int LZ_decompress_write_size ( struct LZ_Decoder * const DECODER ) - The function 'LZ_decompress_write_size' returns the maximum number of - bytes that can be immediately written through 'LZ_decompress_write'. - This number varies smoothly; each compressed byte consumed may be - overwritten immediately, increasing by 1 the value returned. + Returns the maximum number of bytes that can be immediately written + through 'LZ_decompress_write'. This number varies smoothly; each + compressed byte consumed may be overwritten immediately, increasing by + 1 the value returned. It is guaranteed that an immediate call to 'LZ_decompress_write' will accept a SIZE up to the returned number of bytes. @@ -530,24 +524,24 @@ except 'LZ_decompress_open' whose return value must be verified by calling -- Function: int LZ_decompress_member_finished ( struct LZ_Decoder * const DECODER ) Returns 1 if the previous call to 'LZ_decompress_read' finished reading - the current member, indicating that final values for member are + the current member, indicating that final values for the member are available through 'LZ_decompress_data_crc', 'LZ_decompress_data_position', and 'LZ_decompress_member_position'. Otherwise it returns 0. -- Function: int LZ_decompress_member_version ( struct LZ_Decoder * const DECODER ) - Returns the version of current member from member header. + Returns the version of the current member, read from the member header. -- Function: int LZ_decompress_dictionary_size ( struct LZ_Decoder * const DECODER ) - Returns the dictionary size of the current member, read from the member - header. + Returns the dictionary size of the current member, read from the + member header. -- Function: unsigned LZ_decompress_data_crc ( struct LZ_Decoder * const DECODER ) Returns the 32 bit Cyclic Redundancy Check of the data decompressed - from the current member. The returned value is valid only when + from the current member. The value returned is valid only when 'LZ_decompress_member_finished' returns 1. -- Function: unsigned long long LZ_decompress_data_position ( struct @@ -650,13 +644,14 @@ compatible with lzip 1.4 or newer. Lzip is a lossless data compressor with a user interface similar to the one of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov -chain-Algorithm' (LZMA) stream format, chosen to maximize safety and -interoperability. Lzip can compress about as fast as gzip (lzip -0) or -compress most files more than bzip2 (lzip -9). Decompression speed is -intermediate between gzip and bzip2. Lzip is better than gzip and bzip2 -from a data recovery perspective. Lzip has been designed, written, and -tested with great care to replace gzip and bzip2 as the standard -general-purpose compressed format for unix-like systems. +chain-Algorithm' (LZMA) stream format and provides a 3 factor integrity +checking to maximize interoperability and optimize safety. Lzip can compress +about as fast as gzip (lzip -0) or compress most files more than bzip2 +(lzip -9). Decompression speed is intermediate between gzip and bzip2. Lzip +is better than gzip and bzip2 from a data recovery perspective. Lzip has +been designed, written, and tested with great care to replace gzip and +bzip2 as the standard general-purpose compressed format for unix-like +systems. The format for running minilzip is: @@ -705,10 +700,13 @@ once, the first time it appears in the command line. '-d' '--decompress' - Decompress the files specified. If a file does not exist or can't be - opened, minilzip continues decompressing the rest of the files. If a - file fails to decompress, or is a terminal, minilzip exits immediately - without decompressing the rest of the files. + Decompress the files specified. If a file does not exist, can't be + opened, or the destination file already exists and '--force' has not + been specified, minilzip continues decompressing the rest of the files + and exits with error status 1. If a file fails to decompress, or is a + terminal, minilzip exits immediately with error status 2 without + decompressing the rest of the files. A terminal is considered an + uncompressed file, and therefore invalid. '-f' '--force' @@ -831,12 +829,14 @@ once, the first time it appears in the command line. '--check-lib' Compare the version of lzlib used to compile minilzip with the version - actually being used and exit. Report any differences found. Exit with - error status 1 if differences are found. A mismatch may indicate that - lzlib is not correctly installed or that a different version of lzlib - has been installed after compiling the shared version of minilzip. - 'minilzip -v --check-lib' shows the version of lzlib being used and - the value of 'LZ_API_VERSION' (if defined). *Note Library version::. + actually being used at run time and exit. Report any differences + found. Exit with error status 1 if differences are found. A mismatch + may indicate that lzlib is not correctly installed or that a different + version of lzlib has been installed after compiling the shared version + of minilzip. Exit with error status 2 if LZ_API_VERSION and + LZ_version_string don't match. 'minilzip -v --check-lib' shows the + version of lzlib being used and the value of LZ_API_VERSION (if + defined). *Note Library version::. Numbers given as arguments to options may be followed by a multiplier @@ -857,7 +857,7 @@ Y yottabyte (10^24) | Yi yobibyte (2^80) Exit status: 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 caused +input file, 3 for an internal consistency error (e.g., bug) which caused minilzip to panic.  @@ -886,9 +886,11 @@ when there is no longer anything to take away. represents a variable number of bytes. - A lzip data stream consists of a series of "members" (compressed data + Lzip data consist of a series of independent "members" (compressed data sets). The members simply appear one after another in the data stream, with -no additional information before, between, or after them. +no additional information before, between, or after them. Each member can +encode in compressed form up to 16 EiB - 1 byte of uncompressed data. The +size of a multimember data stream is unlimited. Each member has the following structure: @@ -916,7 +918,7 @@ no additional information before, between, or after them. Valid values for dictionary size range from 4 KiB to 512 MiB. 'LZMA stream' - The LZMA stream, finished by an end of stream marker. Uses default + The LZMA stream, finished by an "End Of Stream" marker. Uses default values for encoder properties. *Note Stream format: (lzip)Stream format, for a complete description. Lzip only uses the LZMA marker '2' ("End Of Stream" marker). Lzlib @@ -924,16 +926,17 @@ no additional information before, between, or after them. sync_flush::. 'CRC32 (4 bytes)' - Cyclic Redundancy Check (CRC) of the uncompressed original data. + Cyclic Redundancy Check (CRC) of the original uncompressed data. 'Data size (8 bytes)' - Size of the uncompressed original data. + Size of the original uncompressed data. 'Member size (8 bytes)' Total size of the member, including header and trailer. This field acts as a distributed index, allows the verification of stream integrity, - and facilitates safe recovery of undamaged members from multimember - files. + and facilitates the safe recovery of undamaged members from + multimember files. Member size should be limited to 2 PiB to prevent + the data size field from overflowing.  @@ -967,10 +970,10 @@ File: lzlib.info, Node: Buffer compression, Next: Buffer decompression, Up: E Buffer-to-buffer single-member compression (MEMBER_SIZE > total output). -/* Compresses 'insize' bytes from 'inbuf' to 'outbuf'. - Returns the size of the compressed data in '*outlenp'. - In case of error, or if 'outsize' is too small, returns false and does - not modify '*outlenp'. +/* Compress 'insize' bytes from 'inbuf' to 'outbuf'. + Return the size of the compressed data in '*outlenp'. + In case of error, or if 'outsize' is too small, return false and do not + modify '*outlenp'. */ bool bbcompress( const uint8_t * const inbuf, const int insize, const int dictionary_size, const int match_len_limit, @@ -1011,10 +1014,10 @@ File: lzlib.info, Node: Buffer decompression, Next: File compression, Prev: B Buffer-to-buffer decompression. -/* Decompresses 'insize' bytes from 'inbuf' to 'outbuf'. - Returns the size of the decompressed data in '*outlenp'. - In case of error, or if 'outsize' is too small, returns false and does - not modify '*outlenp'. +/* Decompress 'insize' bytes from 'inbuf' to 'outbuf'. + Return the size of the decompressed data in '*outlenp'. + In case of error, or if 'outsize' is too small, return false and do not + modify '*outlenp'. */ bool bbdecompress( const uint8_t * const inbuf, const int insize, uint8_t * const outbuf, const int outsize, @@ -1159,9 +1162,9 @@ int ffmmcompress( FILE * const infile, FILE * const outfile ) Example 2: Multimember compression (user-restarted members). (Call LZ_compress_open with MEMBER_SIZE > largest member). -/* Compresses 'infile' to 'outfile' as a multimember stream with one member +/* Compress 'infile' to 'outfile' as a multimember stream with one member for each line of text terminated by a newline character or by EOF. - Returns 0 if success, 1 if error. + Return 0 if success, 1 if error. */ int fflfcompress( struct LZ_Encoder * const encoder, FILE * const infile, FILE * const outfile ) @@ -1205,7 +1208,7 @@ File: lzlib.info, Node: Skipping data errors, Prev: File compression mm, Up: 11.6 Skipping data errors ========================= -/* Decompresses 'infile' to 'outfile' with automatic resynchronization to +/* Decompress 'infile' to 'outfile' with automatic resynchronization to next member in case of data error, including the automatic removal of leading garbage. */ @@ -1253,7 +1256,7 @@ eternity, if not longer. If you find a bug in lzlib, please send electronic mail to . Include the version number, which you can find by -running 'minilzip --version' or in 'LZ_version_string' from 'lzlib.h'. +running 'minilzip --version' and 'minilzip -v --check-lib'.  File: lzlib.info, Node: Concept index, Prev: Problems, Up: Top @@ -1288,29 +1291,29 @@ Concept index  Tag Table: -Node: Top220 -Node: Introduction1342 +Node: Top215 +Node: Introduction1338 Node: Library version6413 -Node: Buffering8918 -Node: Parameter limits10143 -Node: Compression functions11097 -Ref: member_size12907 -Ref: sync_flush14673 -Node: Decompression functions19493 -Node: Error codes27187 -Node: Error messages29478 -Node: Invoking minilzip30057 -Node: Data format39651 -Ref: coded-dict-size40957 -Node: Examples42267 -Node: Buffer compression43228 -Node: Buffer decompression44754 -Node: File compression46174 -Node: File decompression47157 -Node: File compression mm48161 -Node: Skipping data errors51193 -Node: Problems52505 -Node: Concept index53077 +Node: Buffering8957 +Node: Parameter limits10182 +Node: Compression functions11136 +Ref: member_size12946 +Ref: sync_flush14712 +Node: Decompression functions19400 +Node: Error codes26968 +Node: Error messages29259 +Node: Invoking minilzip29838 +Node: Data format39786 +Ref: coded-dict-size41232 +Node: Examples42641 +Node: Buffer compression43602 +Node: Buffer decompression45122 +Node: File compression46536 +Node: File decompression47519 +Node: File compression mm48523 +Node: Skipping data errors51552 +Node: Problems52862 +Node: Concept index53423  End Tag Table diff --git a/doc/lzlib.texi b/doc/lzlib.texi index 644a3d7..3caf9dd 100644 --- a/doc/lzlib.texi +++ b/doc/lzlib.texi @@ -6,10 +6,10 @@ @finalout @c %**end of header -@set UPDATED 2 January 2021 -@set VERSION 1.12 +@set UPDATED 23 January 2022 +@set VERSION 1.13 -@dircategory Data Compression +@dircategory Compression @direntry * Lzlib: (lzlib). Compression library for the lzip format @end direntry @@ -52,7 +52,7 @@ This manual is for Lzlib (version @value{VERSION}, @value{UPDATED}). @end menu @sp 1 -Copyright @copyright{} 2009-2021 Antonio Diaz Diaz. +Copyright @copyright{} 2009-2022 Antonio Diaz Diaz. This manual is free documentation: you have unlimited permission to copy, distribute, and modify it. @@ -77,9 +77,9 @@ taking into account both data integrity and decoder availability: The lzip format provides very safe integrity checking and some data recovery means. The program @uref{http://www.nongnu.org/lzip/manual/lziprecover_manual.html#Data-safety,,lziprecover} -can repair bit flip errors (one of the most common forms of data -corruption) in lzip files, and provides data recovery capabilities, -including error-checked merging of damaged copies of a file. +can repair bit flip errors (one of the most common forms of data corruption) +in lzip files, and provides data recovery capabilities, including +error-checked merging of damaged copies of a file. @ifnothtml @xref{Data safety,,,lziprecover}. @end ifnothtml @@ -89,8 +89,8 @@ The lzip format is as simple as possible (but not simpler). The lzip manual provides the source code of a simple decompressor along with a detailed explanation of how it works, so that with the only help of the lzip manual it would be possible for a digital archaeologist to extract -the data from a lzip file long after quantum computers eventually render -LZMA obsolete. +the data from a lzip file long after quantum computers eventually +render LZMA obsolete. @item Additionally the lzip reference implementation is copylefted, which @@ -104,8 +104,12 @@ the beginning is a thing of the past. The functions and variables forming the interface of the compression library are declared in the file @samp{lzlib.h}. Usage examples of the library are -given in the files @samp{bbexample.c}, @samp{ffexample.c}, and @samp{main.c} -from the source distribution. +given in the files @samp{bbexample.c}, @samp{ffexample.c}, and +@samp{minilzip.c} from the source distribution. + +All the library functions are thread safe. The library does not install any +signal handler. The decoder checks the consistency of the compressed data, +so the library should never crash even in case of corrupted input. Compression/decompression is done by repeatedly calling a couple of read/write functions until all the data have been processed by the library. @@ -134,22 +138,17 @@ Lzlib is able to compress and decompress streams of unlimited size by automatically creating multimember output. The members so created are large, about @w{2 PiB} each. -All the library functions are thread safe. The library does not install -any signal handler. The decoder checks the consistency of the compressed -data, so the library should never crash even in case of corrupted input. - In spite of its name (Lempel-Ziv-Markov chain-Algorithm), LZMA is not a concrete algorithm; it is more like "any algorithm using the LZMA coding -scheme". For example, the option @samp{-0} of lzip uses the scheme in almost -the simplest way possible; issuing the longest match it can find, or a -literal byte if it can't find a match. Inversely, a much more elaborated way -of finding coding sequences of minimum size than the one currently used by -lzip could be developed, and the resulting sequence could also be coded -using the LZMA coding scheme. +scheme". For example, the option @samp{-0} of lzip uses the scheme in almost the +simplest way possible; issuing the longest match it can find, or a literal +byte if it can't find a match. Inversely, a much more elaborated way of +finding coding sequences of minimum size than the one currently used by lzip +could be developed, and the resulting sequence could also be coded using the +LZMA coding scheme. -Lzlib currently implements two variants of the LZMA algorithm; fast (used by -option @samp{-0} of minilzip) and normal (used by all other compression -levels). +Lzlib currently implements two variants of the LZMA algorithm: fast (used by +option @samp{-0} of minilzip) and normal (used by all other compression levels). The high compression of LZMA comes from combining two basic, well-proven compression ideas: sliding dictionaries (LZ77/78) and markov models (the @@ -176,7 +175,8 @@ One goal of lzlib is to keep perfect backward compatibility with older versions of itself down to 1.0. Any application working with an older lzlib should work with a newer lzlib. Installing a newer lzlib should not break anything. This chapter describes the constants and functions that the -application can use to discover the version of the library being used. +application can use to discover the version of the library being used. All +of them are declared in @samp{lzlib.h}. @defvr Constant LZ_API_VERSION This constant is defined in @samp{lzlib.h} and works as a version test @@ -372,12 +372,13 @@ already written with the function @samp{LZ_compress_write}. First call @samp{LZ_compress_sync_flush}. Then call @samp{LZ_compress_read} until it returns 0. -This function writes a LZMA marker @samp{3} ("Sync Flush" marker) to the -compressed output. Note that the sync flush marker is not allowed in lzip -files; it is a device for interactive communication between applications -using lzlib, but is useless and wasteful in a file, and is excluded from the -media type @samp{application/lzip}. The LZMA marker @samp{2} ("End Of -Stream" marker) is the only marker allowed in lzip files. @xref{Data format}. +This function writes at least one LZMA marker @samp{3} ("Sync Flush" marker) +to the compressed output. Note that the sync flush marker is not allowed in +lzip files; it is a device for interactive communication between +applications using lzlib, but is useless and wasteful in a file, and is +excluded from the media type @samp{application/lzip}. The LZMA marker +@samp{2} ("End Of Stream" marker) is the only marker allowed in lzip files. +@xref{Data format}. Repeated use of @samp{LZ_compress_sync_flush} may degrade compression ratio, so use it only when needed. If the interval between calls to @@ -394,36 +395,33 @@ are more bytes available than those needed to complete @var{member_size}, @deftypefun int LZ_compress_read ( struct LZ_Encoder * const @var{encoder}, uint8_t * const @var{buffer}, const int @var{size} ) -The function @samp{LZ_compress_read} reads up to @var{size} bytes from the -stream pointed to by @var{encoder}, storing the results in @var{buffer}. -If @w{LZ_API_VERSION >= 1012}, @var{buffer} may be a null pointer, in which -case the bytes read are discarded. +Reads up to @var{size} bytes from the stream pointed to by @var{encoder}, +storing the results in @var{buffer}. If @w{LZ_API_VERSION >= 1012}, +@var{buffer} may be a null pointer, in which case the bytes read are +discarded. -The return value is the number of bytes actually read. This might be less -than @var{size}; for example, if there aren't that many bytes left in the -stream or if more bytes have to be yet written with the function +Returns the number of bytes actually read. This might be less than +@var{size}; for example, if there aren't that many bytes left in the stream +or if more bytes have to be yet written with the function @samp{LZ_compress_write}. Note that reading less than @var{size} bytes is not an error. @end deftypefun @deftypefun int LZ_compress_write ( struct LZ_Encoder * const @var{encoder}, uint8_t * const @var{buffer}, const int @var{size} ) -The function @samp{LZ_compress_write} writes up to @var{size} bytes from -@var{buffer} to the stream pointed to by @var{encoder}. - -The return value is the number of bytes actually written. This might be -less than @var{size}. Note that writing less than @var{size} bytes is -not an error. +Writes up to @var{size} bytes from @var{buffer} to the stream pointed to by +@var{encoder}. Returns the number of bytes actually written. This might be +less than @var{size}. Note that writing less than @var{size} bytes is not an +error. @end deftypefun @deftypefun int LZ_compress_write_size ( struct LZ_Encoder * const @var{encoder} ) -The function @samp{LZ_compress_write_size} returns the maximum number of -bytes that can be immediately written through @samp{LZ_compress_write}. -For efficiency reasons, once the input buffer is full and -@samp{LZ_compress_write_size} returns 0, almost all the buffer must be -compressed before a size greater than 0 is returned again. (This is done to -minimize the amount of data that must be copied to the beginning of the +Returns the maximum number of bytes that can be immediately written through +@samp{LZ_compress_write}. For efficiency reasons, once the input buffer is +full and @samp{LZ_compress_write_size} returns 0, almost all the buffer must +be compressed before a size greater than 0 is returned again. (This is done +to minimize the amount of data that must be copied to the beginning of the buffer before new data can be accepted). It is guaranteed that an immediate call to @samp{LZ_compress_write} will @@ -478,10 +476,10 @@ perhaps not yet read. @chapter Decompression functions @cindex decompression functions -These are the functions used to decompress data. In case of error, all -of them return -1 or 0, for signed and unsigned return values -respectively, except @samp{LZ_decompress_open} whose return value must -be verified by calling @samp{LZ_decompress_errno} before using it. +These are the functions used to decompress data. In case of error, all of +them return -1 or 0, for signed and unsigned return values respectively, +except @samp{LZ_decompress_open} whose return value must be verified by +calling @samp{LZ_decompress_errno} before using it. @deftypefun {struct LZ_Decoder *} LZ_decompress_open ( void ) @@ -539,14 +537,14 @@ function does nothing. @deftypefun int LZ_decompress_read ( struct LZ_Decoder * const @var{decoder}, uint8_t * const @var{buffer}, const int @var{size} ) -The function @samp{LZ_decompress_read} reads up to @var{size} bytes from the -stream pointed to by @var{decoder}, storing the results in @var{buffer}. -If @w{LZ_API_VERSION >= 1012}, @var{buffer} may be a null pointer, in which -case the bytes read are discarded. +Reads up to @var{size} bytes from the stream pointed to by @var{decoder}, +storing the results in @var{buffer}. If @w{LZ_API_VERSION >= 1012}, +@var{buffer} may be a null pointer, in which case the bytes read are +discarded. -The return value is the number of bytes actually read. This might be less -than @var{size}; for example, if there aren't that many bytes left in the -stream or if more bytes have to be yet written with the function +Returns the number of bytes actually read. This might be less than +@var{size}; for example, if there aren't that many bytes left in the stream +or if more bytes have to be yet written with the function @samp{LZ_decompress_write}. Note that reading less than @var{size} bytes is not an error. @@ -571,20 +569,18 @@ recover as much data as possible from each damaged member. @deftypefun int LZ_decompress_write ( struct LZ_Decoder * const @var{decoder}, uint8_t * const @var{buffer}, const int @var{size} ) -The function @samp{LZ_decompress_write} writes up to @var{size} bytes from -@var{buffer} to the stream pointed to by @var{decoder}. - -The return value is the number of bytes actually written. This might be -less than @var{size}. Note that writing less than @var{size} bytes is -not an error. +Writes up to @var{size} bytes from @var{buffer} to the stream pointed to by +@var{decoder}. Returns the number of bytes actually written. This might be +less than @var{size}. Note that writing less than @var{size} bytes is not an +error. @end deftypefun @deftypefun int LZ_decompress_write_size ( struct LZ_Decoder * const @var{decoder} ) -The function @samp{LZ_decompress_write_size} returns the maximum number of -bytes that can be immediately written through @samp{LZ_decompress_write}. -This number varies smoothly; each compressed byte consumed may be -overwritten immediately, increasing by 1 the value returned. +Returns the maximum number of bytes that can be immediately written through +@samp{LZ_decompress_write}. This number varies smoothly; each compressed +byte consumed may be overwritten immediately, increasing by 1 the value +returned. It is guaranteed that an immediate call to @samp{LZ_decompress_write} will accept a @var{size} up to the returned number of bytes. @@ -607,26 +603,25 @@ does not imply @samp{LZ_decompress_member_finished}. @deftypefun int LZ_decompress_member_finished ( struct LZ_Decoder * const @var{decoder} ) Returns 1 if the previous call to @samp{LZ_decompress_read} finished reading -the current member, indicating that final values for member are available +the current member, indicating that final values for the member are available through @samp{LZ_decompress_data_crc}, @samp{LZ_decompress_data_position}, and @samp{LZ_decompress_member_position}. Otherwise it returns 0. @end deftypefun @deftypefun int LZ_decompress_member_version ( struct LZ_Decoder * const @var{decoder} ) -Returns the version of current member from member header. +Returns the version of the current member, read from the member header. @end deftypefun @deftypefun int LZ_decompress_dictionary_size ( struct LZ_Decoder * const @var{decoder} ) -Returns the dictionary size of the current member, read from the member -header. +Returns the dictionary size of the current member, read from the member header. @end deftypefun @deftypefun {unsigned} LZ_decompress_data_crc ( struct LZ_Decoder * const @var{decoder} ) Returns the 32 bit Cyclic Redundancy Check of the data decompressed from -the current member. The returned value is valid only when +the current member. The value returned is valid only when @samp{LZ_decompress_member_finished} returns 1. @end deftypefun @@ -672,8 +667,7 @@ examine @samp{LZ_(de)compress_errno}. The error codes are defined in the header file @samp{lzlib.h}. @deftypevr Constant {enum LZ_Errno} LZ_ok -The value of this constant is 0 and is used to indicate that there is no -error. +The value of this constant is 0 and is used to indicate that there is no error. @end deftypevr @deftypevr Constant {enum LZ_Errno} LZ_bad_argument @@ -737,16 +731,17 @@ The value of @var{lz_errno} normally comes from a call to Minilzip is a test program for the compression library lzlib, fully compatible with lzip 1.4 or newer. -@uref{http://www.nongnu.org/lzip/lzip.html,,Lzip} is a lossless data -compressor with a user interface similar to the one of gzip or bzip2. Lzip -uses a simplified form of the 'Lempel-Ziv-Markov chain-Algorithm' (LZMA) -stream format, chosen to maximize safety and interoperability. Lzip can -compress about as fast as gzip @w{(lzip -0)} or compress most files more -than bzip2 @w{(lzip -9)}. Decompression speed is intermediate between gzip -and bzip2. Lzip is better than gzip and bzip2 from a data recovery -perspective. Lzip has been designed, written, and tested with great care to -replace gzip and bzip2 as the standard general-purpose compressed format for -unix-like systems. +@uref{http://www.nongnu.org/lzip/lzip.html,,Lzip} +is a lossless data compressor with a user interface similar to the one +of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov +chain-Algorithm' (LZMA) stream format and provides a 3 factor integrity +checking to maximize interoperability and optimize safety. Lzip can compress +about as fast as gzip @w{(lzip -0)} or compress most files more than bzip2 +@w{(lzip -9)}. Decompression speed is intermediate between gzip and bzip2. +Lzip is better than gzip and bzip2 from a data recovery perspective. Lzip +has been designed, written, and tested with great care to replace gzip and +bzip2 as the standard general-purpose compressed format for unix-like +systems. @noindent The format for running minilzip is: @@ -803,10 +798,12 @@ and @samp{-S}. @samp{-c} has no effect when testing or listing. @item -d @itemx --decompress -Decompress the files specified. If a file does not exist or can't be -opened, minilzip continues decompressing the rest of the files. If a file -fails to decompress, or is a terminal, minilzip exits immediately without -decompressing the rest of the files. +Decompress the files specified. If a file does not exist, can't be opened, +or the destination file already exists and @samp{--force} has not been +specified, minilzip continues decompressing the rest of the files and exits with +error status 1. If a file fails to decompress, or is a terminal, minilzip exits +immediately with error status 2 without decompressing the rest of the files. +A terminal is considered an uncompressed file, and therefore invalid. @item -f @itemx --force @@ -932,12 +929,13 @@ header" error and the cause is not indeed a corrupt header. @item --check-lib Compare the @uref{#Library-version,,version of lzlib} used to compile -minilzip with the version actually being used and exit. Report any -differences found. Exit with error status 1 if differences are found. A +minilzip with the version actually being used at run time and exit. Report +any differences found. Exit with error status 1 if differences are found. A mismatch may indicate that lzlib is not correctly installed or that a different version of lzlib has been installed after compiling the shared -version of minilzip. @w{@samp{minilzip -v --check-lib}} shows the version of -lzlib being used and the value of @samp{LZ_API_VERSION} (if defined). +version of minilzip. Exit with error status 2 if LZ_API_VERSION and +LZ_version_string don't match. @w{@samp{minilzip -v --check-lib}} shows the +version of lzlib being used and the value of LZ_API_VERSION (if defined). @ifnothtml @xref{Library version}. @end ifnothtml @@ -963,9 +961,9 @@ Table of SI and binary prefixes (unit multipliers): @sp 1 Exit status: 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 -caused minilzip to panic. +found, invalid flags, I/O errors, etc), 2 to indicate a corrupt or invalid +input file, 3 for an internal consistency error (e.g., bug) which caused +minilzip to panic. @node Data format @@ -996,9 +994,11 @@ represents one byte; a box like this: represents a variable number of bytes. @sp 1 -A lzip data stream consists of a series of "members" (compressed data sets). -The members simply appear one after another in the data stream, with no -additional information before, between, or after them. +Lzip data consist of a series of independent "members" (compressed data +sets). The members simply appear one after another in the data stream, with +no additional information before, between, or after them. Each member can +encode in compressed form up to @w{16 EiB - 1 byte} of uncompressed data. +The size of a multimember data stream is unlimited. Each member has the following structure: @@ -1029,7 +1029,7 @@ Example: 0xD3 = 2^19 - 6 * 2^15 = 512 KiB - 6 * 32 KiB = 320 KiB@* Valid values for dictionary size range from 4 KiB to 512 MiB. @item LZMA stream -The LZMA stream, finished by an end of stream marker. Uses default values +The LZMA stream, finished by an "End Of Stream" marker. Uses default values for encoder properties. @ifnothtml @xref{Stream format,,,lzip}, @@ -1043,15 +1043,17 @@ Lzip only uses the LZMA marker @samp{2} ("End Of Stream" marker). Lzlib also uses the LZMA marker @samp{3} ("Sync Flush" marker). @xref{sync_flush}. @item CRC32 (4 bytes) -Cyclic Redundancy Check (CRC) of the uncompressed original data. +Cyclic Redundancy Check (CRC) of the original uncompressed data. @item Data size (8 bytes) -Size of the uncompressed original data. +Size of the original uncompressed data. @item Member size (8 bytes) Total size of the member, including header and trailer. This field acts as a distributed index, allows the verification of stream integrity, and -facilitates safe recovery of undamaged members from multimember files. +facilitates the safe recovery of undamaged members from multimember files. +Member size should be limited to @w{2 PiB} to prevent the data size field +from overflowing. @end table @@ -1086,10 +1088,10 @@ Buffer-to-buffer single-member compression @w{(@var{member_size} > total output)}. @verbatim -/* Compresses 'insize' bytes from 'inbuf' to 'outbuf'. - Returns the size of the compressed data in '*outlenp'. - In case of error, or if 'outsize' is too small, returns false and does - not modify '*outlenp'. +/* Compress 'insize' bytes from 'inbuf' to 'outbuf'. + Return the size of the compressed data in '*outlenp'. + In case of error, or if 'outsize' is too small, return false and do not + modify '*outlenp'. */ bool bbcompress( const uint8_t * const inbuf, const int insize, const int dictionary_size, const int match_len_limit, @@ -1131,10 +1133,10 @@ bool bbcompress( const uint8_t * const inbuf, const int insize, Buffer-to-buffer decompression. @verbatim -/* Decompresses 'insize' bytes from 'inbuf' to 'outbuf'. - Returns the size of the decompressed data in '*outlenp'. - In case of error, or if 'outsize' is too small, returns false and does - not modify '*outlenp'. +/* Decompress 'insize' bytes from 'inbuf' to 'outbuf'. + Return the size of the decompressed data in '*outlenp'. + In case of error, or if 'outsize' is too small, return false and do not + modify '*outlenp'. */ bool bbdecompress( const uint8_t * const inbuf, const int insize, uint8_t * const outbuf, const int outsize, @@ -1285,9 +1287,9 @@ Example 2: Multimember compression (user-restarted members). (Call LZ_compress_open with @var{member_size} > largest member). @verbatim -/* Compresses 'infile' to 'outfile' as a multimember stream with one member +/* Compress 'infile' to 'outfile' as a multimember stream with one member for each line of text terminated by a newline character or by EOF. - Returns 0 if success, 1 if error. + Return 0 if success, 1 if error. */ int fflfcompress( struct LZ_Encoder * const encoder, FILE * const infile, FILE * const outfile ) @@ -1332,7 +1334,7 @@ int fflfcompress( struct LZ_Encoder * const encoder, @cindex skipping data errors @verbatim -/* Decompresses 'infile' to 'outfile' with automatic resynchronization to +/* Decompress 'infile' to 'outfile' with automatic resynchronization to next member in case of data error, including the automatic removal of leading garbage. */ @@ -1381,8 +1383,8 @@ for all eternity, if not longer. If you find a bug in lzlib, please send electronic mail to @email{lzip-bug@@nongnu.org}. Include the version number, which you can -find by running @w{@samp{minilzip --version}} or in -@samp{LZ_version_string} from @samp{lzlib.h}. +find by running @w{@samp{minilzip --version}} and +@w{@samp{minilzip -v --check-lib}}. @node Concept index diff --git a/doc/minilzip.1 b/doc/minilzip.1 index 13a2d6d..0c4c06d 100644 --- a/doc/minilzip.1 +++ b/doc/minilzip.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.16. -.TH MINILZIP "1" "January 2021" "minilzip 1.12" "User Commands" +.TH MINILZIP "1" "January 2022" "minilzip 1.13" "User Commands" .SH NAME minilzip \- reduces the size of files .SH SYNOPSIS @@ -11,13 +11,14 @@ compatible with lzip 1.4 or newer. .PP Lzip is a lossless data compressor with a user interface similar to the one of gzip or bzip2. Lzip uses a simplified form of the 'Lempel\-Ziv\-Markov -chain\-Algorithm' (LZMA) stream format, chosen to maximize safety and -interoperability. Lzip can compress about as fast as gzip (lzip \fB\-0\fR) or -compress most files more than bzip2 (lzip \fB\-9\fR). Decompression speed is -intermediate between gzip and bzip2. Lzip is better than gzip and bzip2 from -a data recovery perspective. Lzip has been designed, written, and tested -with great care to replace gzip and bzip2 as the standard general\-purpose -compressed format for unix\-like systems. +chain\-Algorithm' (LZMA) stream format and provides a 3 factor integrity +checking to maximize interoperability and optimize safety. Lzip can compress +about as fast as gzip (lzip \fB\-0\fR) or compress most files more than bzip2 +(lzip \fB\-9\fR). Decompression speed is intermediate between gzip and bzip2. +Lzip is better than gzip and bzip2 from a data recovery perspective. Lzip +has been designed, written, and tested with great care to replace gzip and +bzip2 as the standard general\-purpose compressed format for unix\-like +systems. .SH OPTIONS .TP \fB\-h\fR, \fB\-\-help\fR @@ -100,7 +101,7 @@ To extract all the files from archive 'foo.tar.lz', use the commands .PP Exit status: 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 +invalid input file, 3 for an internal consistency error (e.g., bug) which caused minilzip to panic. .PP The ideas embodied in lzlib are due to (at least) the following people: @@ -113,9 +114,21 @@ Report bugs to lzip\-bug@nongnu.org .br Lzlib home page: http://www.nongnu.org/lzip/lzlib.html .SH COPYRIGHT -Copyright \(co 2021 Antonio Diaz Diaz. -Using lzlib 1.12 +Copyright \(co 2022 Antonio Diaz Diaz. +Using lzlib 1.13 License GPLv2+: GNU GPL version 2 or later .br This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. +.SH "SEE ALSO" +The full documentation for +.B minilzip +is maintained as a Texinfo manual. If the +.B info +and +.B minilzip +programs are properly installed at your site, the command +.IP +.B info lzlib +.PP +should give you access to the complete manual. diff --git a/encoder.c b/encoder.c index 600a444..b76dafa 100644 --- a/encoder.c +++ b/encoder.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2021 Antonio Diaz Diaz. + Copyright (C) 2009-2022 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -21,18 +21,7 @@ static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs { int32_t * ptr0 = e->eb.mb.pos_array + ( e->eb.mb.cyclic_pos << 1 ); int32_t * ptr1 = ptr0 + 1; - int32_t * newptr; - int len = 0, len0 = 0, len1 = 0; - int maxlen = 3; /* only used if pairs != 0 */ - int num_pairs = 0; - const int pos1 = e->eb.mb.pos + 1; - const int min_pos = ( e->eb.mb.pos > e->eb.mb.dictionary_size ) ? - e->eb.mb.pos - e->eb.mb.dictionary_size : 0; - const uint8_t * const data = Mb_ptr_to_current_pos( &e->eb.mb ); - int count, key2, key3, key4, newpos1; - unsigned tmp; int len_limit = e->match_len_limit; - if( len_limit > Mb_available_bytes( &e->eb.mb ) ) { e->been_flushed = true; @@ -40,12 +29,18 @@ static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs if( len_limit < 4 ) { *ptr0 = *ptr1 = 0; return 0; } } - tmp = crc32[data[0]] ^ data[1]; - key2 = tmp & ( num_prev_positions2 - 1 ); + int maxlen = 3; /* only used if pairs != 0 */ + int num_pairs = 0; + const int min_pos = ( e->eb.mb.pos > e->eb.mb.dictionary_size ) ? + e->eb.mb.pos - e->eb.mb.dictionary_size : 0; + const uint8_t * const data = Mb_ptr_to_current_pos( &e->eb.mb ); + + unsigned tmp = crc32[data[0]] ^ data[1]; + const int key2 = tmp & ( num_prev_positions2 - 1 ); tmp ^= (unsigned)data[2] << 8; - key3 = num_prev_positions2 + ( tmp & ( num_prev_positions3 - 1 ) ); - key4 = num_prev_positions2 + num_prev_positions3 + - ( ( tmp ^ ( crc32[data[3]] << 5 ) ) & e->eb.mb.key4_mask ); + const int key3 = num_prev_positions2 + ( tmp & ( num_prev_positions3 - 1 ) ); + const int key4 = num_prev_positions2 + num_prev_positions3 + + ( ( tmp ^ ( crc32[data[3]] << 5 ) ) & e->eb.mb.key4_mask ); if( pairs ) { @@ -54,7 +49,7 @@ static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs if( np2 > min_pos && e->eb.mb.buffer[np2-1] == data[0] ) { pairs[0].dis = e->eb.mb.pos - np2; - pairs[0].len = maxlen = 2; + pairs[0].len = maxlen = 2 + ( np2 == np3 ); num_pairs = 1; } if( np2 != np3 && np3 > min_pos && e->eb.mb.buffer[np3-1] == data[0] ) @@ -73,19 +68,22 @@ static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs } } + const int pos1 = e->eb.mb.pos + 1; e->eb.mb.prev_positions[key2] = pos1; e->eb.mb.prev_positions[key3] = pos1; - newpos1 = e->eb.mb.prev_positions[key4]; + int newpos1 = e->eb.mb.prev_positions[key4]; e->eb.mb.prev_positions[key4] = pos1; + int len = 0, len0 = 0, len1 = 0; + + int count; for( count = e->cycles; ; ) { - int delta; if( newpos1 <= min_pos || --count < 0 ) { *ptr0 = *ptr1 = 0; break; } if( e->been_flushed ) len = 0; - delta = pos1 - newpos1; - newptr = e->eb.mb.pos_array + + const int delta = pos1 - newpos1; + int32_t * const newptr = e->eb.mb.pos_array + ( ( e->eb.mb.cyclic_pos - delta + ( (e->eb.mb.cyclic_pos >= delta) ? 0 : e->eb.mb.dictionary_size + 1 ) ) << 1 ); if( data[len-delta] == data[len] ) @@ -140,7 +138,6 @@ static void LZe_update_distance_prices( struct LZ_encoder * const e ) for( len_state = 0; len_state < len_states; ++len_state ) { int * const dsp = e->dis_slot_prices[len_state]; - int * const dp = e->dis_prices[len_state]; const Bit_model * const bmds = e->eb.bm_dis_slot[len_state]; int slot = 0; for( ; slot < end_dis_model; ++slot ) @@ -149,6 +146,7 @@ static void LZe_update_distance_prices( struct LZ_encoder * const e ) dsp[slot] = price_symbol6( bmds, slot ) + (((( slot >> 1 ) - 1 ) - dis_align_bits ) << price_shift_bits ); + int * const dp = e->dis_prices[len_state]; for( dis = 0; dis < start_dis_model; ++dis ) dp[dis] = dsp[dis]; for( ; dis < modeled_distances; ++dis ) @@ -157,7 +155,7 @@ static void LZe_update_distance_prices( struct LZ_encoder * const e ) } -/* Returns the number of bytes advanced (ahead). +/* Return the number of bytes advanced (ahead). trials[0]..trials[ahead-1] contain the steps to encode. ( trials[0].dis4 == -1 ) means literal. A match/rep longer or equal than match_len_limit finishes the sequence. @@ -166,9 +164,8 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, const int reps[num_rep_distances], const State state ) { - int main_len, num_pairs, i, rep, num_trials, len; - int rep_index = 0, cur = 0; - int replens[num_rep_distances]; + int num_pairs, num_trials; + int i, rep, len; if( e->pending_num_pairs > 0 ) /* from previous call */ { @@ -177,8 +174,10 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, } else num_pairs = LZe_read_match_distances( e ); - main_len = ( num_pairs > 0 ) ? e->pairs[num_pairs-1].len : 0; + const int main_len = ( num_pairs > 0 ) ? e->pairs[num_pairs-1].len : 0; + int replens[num_rep_distances]; + int rep_index = 0; for( i = 0; i < num_rep_distances; ++i ) { replens[i] = Mb_true_match_len( &e->eb.mb, 0, reps[i] + 1 ); @@ -200,7 +199,6 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, return main_len; } - { const int pos_state = Mb_data_position( &e->eb.mb ) & pos_state_mask; const int match_price = price1( e->eb.bm_match[state][pos_state] ); const int rep_match_price = match_price + price1( e->eb.bm_rep[state] ); @@ -238,9 +236,8 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, for( rep = 0; rep < num_rep_distances; ++rep ) { - int price; if( replens[rep] < min_match_len ) continue; - price = rep_match_price + LZeb_price_rep( &e->eb, rep, state, pos_state ); + const int price = rep_match_price + LZeb_price_rep( &e->eb, rep, state, pos_state ); for( len = min_match_len; len <= replens[rep]; ++len ) Tr_update( &e->trials[len], price + Lp_price( &e->rep_len_prices, len, pos_state ), rep, 0 ); @@ -260,17 +257,10 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, if( ++len > e->pairs[i].len && ++i >= num_pairs ) break; } } - } + int cur = 0; while( true ) /* price optimization loop */ { - struct Trial *cur_trial, *next_trial; - int newlen, pos_state, triable_bytes, len_limit; - int start_len = min_match_len; - int next_price, match_price, rep_match_price; - State cur_state; - uint8_t prev_byte, cur_byte, match_byte; - if( !Mb_move_pos( &e->eb.mb ) ) return 0; if( ++cur >= num_trials ) /* no more initialized trials */ { @@ -278,8 +268,8 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, return cur; } - num_pairs = LZe_read_match_distances( e ); - newlen = ( num_pairs > 0 ) ? e->pairs[num_pairs-1].len : 0; + const int num_pairs = LZe_read_match_distances( e ); + const int newlen = ( num_pairs > 0 ) ? e->pairs[num_pairs-1].len : 0; if( newlen >= e->match_len_limit ) { e->pending_num_pairs = num_pairs; @@ -288,7 +278,8 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, } /* give final values to current trial */ - cur_trial = &e->trials[cur]; + struct Trial * cur_trial = &e->trials[cur]; + State cur_state; { const int dis4 = cur_trial->dis4; int prev_index = cur_trial->prev_index; @@ -319,25 +310,25 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, mtf_reps( dis4, cur_trial->reps ); /* literal is ignored */ } - pos_state = Mb_data_position( &e->eb.mb ) & pos_state_mask; - prev_byte = Mb_peek( &e->eb.mb, 1 ); - cur_byte = Mb_peek( &e->eb.mb, 0 ); - match_byte = Mb_peek( &e->eb.mb, cur_trial->reps[0] + 1 ); + const int pos_state = Mb_data_position( &e->eb.mb ) & pos_state_mask; + const uint8_t prev_byte = Mb_peek( &e->eb.mb, 1 ); + const uint8_t cur_byte = Mb_peek( &e->eb.mb, 0 ); + const uint8_t match_byte = Mb_peek( &e->eb.mb, cur_trial->reps[0] + 1 ); - next_price = cur_trial->price + - price0( e->eb.bm_match[cur_state][pos_state] ); + int next_price = cur_trial->price + + price0( e->eb.bm_match[cur_state][pos_state] ); if( St_is_char( cur_state ) ) next_price += LZeb_price_literal( &e->eb, prev_byte, cur_byte ); else next_price += LZeb_price_matched( &e->eb, prev_byte, cur_byte, match_byte ); /* try last updates to next trial */ - next_trial = &e->trials[cur+1]; + struct Trial * next_trial = &e->trials[cur+1]; Tr_update( next_trial, next_price, -1, cur ); /* literal */ - match_price = cur_trial->price + price1( e->eb.bm_match[cur_state][pos_state] ); - rep_match_price = match_price + price1( e->eb.bm_rep[cur_state] ); + const int match_price = cur_trial->price + price1( e->eb.bm_match[cur_state][pos_state] ); + const int rep_match_price = match_price + price1( e->eb.bm_rep[cur_state] ); if( match_byte == cur_byte && next_trial->dis4 != 0 && next_trial->prev_index2 == single_step_trial ) @@ -352,11 +343,11 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, } } - triable_bytes = + const int triable_bytes = min( Mb_available_bytes( &e->eb.mb ), max_num_trials - 1 - cur ); if( triable_bytes < min_match_len ) continue; - len_limit = min( e->match_len_limit, triable_bytes ); + const int len_limit = min( e->match_len_limit, triable_bytes ); /* try literal + rep0 */ if( match_byte != cur_byte && next_trial->prev_index != cur ) @@ -380,19 +371,20 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, } } + int start_len = min_match_len; + /* try rep distances */ for( rep = 0; rep < num_rep_distances; ++rep ) { const uint8_t * const data = Mb_ptr_to_current_pos( &e->eb.mb ); const int dis = cur_trial->reps[rep] + 1; - int price; if( data[0-dis] != data[0] || data[1-dis] != data[1] ) continue; for( len = min_match_len; len < len_limit; ++len ) if( data[len-dis] != data[len] ) break; while( num_trials < cur + len ) e->trials[++num_trials].price = infinite_price; - price = rep_match_price + LZeb_price_rep( &e->eb, rep, cur_state, pos_state ); + int price = rep_match_price + LZeb_price_rep( &e->eb, rep, cur_state, pos_state ); for( i = min_match_len; i <= len; ++i ) Tr_update( &e->trials[cur+i], price + Lp_price( &e->rep_len_prices, i, pos_state ), rep, cur ); @@ -400,17 +392,14 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, if( rep == 0 ) start_len = len + 1; /* discard shorter matches */ /* try rep + literal + rep0 */ - { int len2 = len + 1; const int limit = min( e->match_len_limit + len2, triable_bytes ); - int pos_state2; - State state2; while( len2 < limit && data[len2-dis] == data[len2] ) ++len2; len2 -= len + 1; if( len2 < min_match_len ) continue; - pos_state2 = ( pos_state + len ) & pos_state_mask; - state2 = St_set_rep( cur_state ); + int pos_state2 = ( pos_state + len ) & pos_state_mask; + State state2 = St_set_rep( cur_state ); price += Lp_price( &e->rep_len_prices, len, pos_state ) + price0( e->eb.bm_match[state2][pos_state2] ) + LZeb_price_matched( &e->eb, data[len-1], data[len], data[len-dis] ); @@ -423,21 +412,19 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, e->trials[++num_trials].price = infinite_price; Tr_update3( &e->trials[cur+len+1+len2], price, rep, cur + len + 1, cur ); } - } /* try matches */ if( newlen >= start_len && newlen <= len_limit ) { - int dis; const int normal_match_price = match_price + price0( e->eb.bm_rep[cur_state] ); while( num_trials < cur + newlen ) e->trials[++num_trials].price = infinite_price; - i = 0; + int i = 0; while( e->pairs[i].len < start_len ) ++i; - dis = e->pairs[i].dis; + int dis = e->pairs[i].dis; for( len = start_len; ; ++len ) { int price = normal_match_price + LZe_price_pair( e, dis, len, pos_state ); @@ -484,7 +471,7 @@ static bool LZe_encode_member( struct LZ_encoder * const e ) const int dis_price_count = best ? 1 : 512; const int align_price_count = best ? 1 : dis_align_size; const int price_count = ( e->match_len_limit > 36 ) ? 1013 : 4093; - int ahead, i; + int i; State * const state = &e->eb.state; if( e->eb.member_finished ) return true; @@ -494,11 +481,10 @@ static bool LZe_encode_member( struct LZ_encoder * const e ) if( Mb_data_position( &e->eb.mb ) == 0 && !Mb_data_finished( &e->eb.mb ) ) /* encode first byte */ { - const uint8_t prev_byte = 0; - uint8_t cur_byte; if( !Mb_enough_available_bytes( &e->eb.mb ) || !Re_enough_free_bytes( &e->eb.renc ) ) return true; - cur_byte = Mb_peek( &e->eb.mb, 0 ); + const uint8_t prev_byte = 0; + const uint8_t cur_byte = Mb_peek( &e->eb.mb, 0 ); Re_encode_bit( &e->eb.renc, &e->eb.bm_match[*state][0], 0 ); LZeb_encode_literal( &e->eb, prev_byte, cur_byte ); CRC32_update_byte( &e->eb.crc, cur_byte ); @@ -525,7 +511,7 @@ static bool LZe_encode_member( struct LZ_encoder * const e ) Lp_update_prices( &e->rep_len_prices ); } - ahead = LZe_sequence_optimizer( e, e->eb.reps, *state ); + int ahead = LZe_sequence_optimizer( e, e->eb.reps, *state ); e->price_counter -= ahead; for( i = 0; ahead > 0; ) @@ -542,14 +528,13 @@ static bool LZe_encode_member( struct LZ_encoder * const e ) const uint8_t prev_byte = Mb_peek( &e->eb.mb, ahead + 1 ); const uint8_t cur_byte = Mb_peek( &e->eb.mb, ahead ); CRC32_update_byte( &e->eb.crc, cur_byte ); - if( St_is_char( *state ) ) + if( ( *state = St_set_char( *state ) ) < 4 ) LZeb_encode_literal( &e->eb, prev_byte, cur_byte ); else { const uint8_t match_byte = Mb_peek( &e->eb.mb, ahead + e->eb.reps[0] + 1 ); LZeb_encode_matched( &e->eb, prev_byte, cur_byte, match_byte ); } - *state = St_set_char( *state ); } else /* match or repeated match */ { diff --git a/encoder.h b/encoder.h index 7a7ecaf..f17bb99 100644 --- a/encoder.h +++ b/encoder.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2021 Antonio Diaz Diaz. + Copyright (C) 2009-2022 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -194,10 +194,9 @@ static inline int LZeb_price_rep( const struct LZ_encoder_base * const eb, const int rep, const State state, const int pos_state ) { - int price; if( rep == 0 ) return price0( eb->bm_rep0[state] ) + price1( eb->bm_len[state][pos_state] ); - price = price1( eb->bm_rep0[state] ); + int price = price1( eb->bm_rep0[state] ); if( rep == 1 ) price += price0( eb->bm_rep1[state] ); else diff --git a/encoder_base.c b/encoder_base.c index c1ef9ef..4535352 100644 --- a/encoder_base.c +++ b/encoder_base.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2021 Antonio Diaz Diaz. + Copyright (C) 2009-2022 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -47,7 +47,6 @@ static bool Mb_init( struct Matchfinder_base * const mb, const int before_size, { const int buffer_size_limit = ( dict_factor * dict_size ) + before_size + after_size; - unsigned size; int i; mb->partial_data_pos = 0; @@ -66,9 +65,8 @@ static bool Mb_init( struct Matchfinder_base * const mb, const int before_size, mb->saved_dictionary_size = dict_size; mb->dictionary_size = dict_size; mb->pos_limit = mb->buffer_size - after_size; - size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 ); - if( mb->dictionary_size > 1 << 26 ) /* 64 MiB */ - size >>= 1; + unsigned size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 ); + if( mb->dictionary_size > 1 << 26 ) size >>= 1; /* 64 MiB */ mb->key4_mask = size - 1; /* increases with dictionary size */ size += num_prev_positions23; mb->num_prev_positions = size; @@ -88,8 +86,7 @@ static bool Mb_init( struct Matchfinder_base * const mb, const int before_size, static void Mb_adjust_array( struct Matchfinder_base * const mb ) { int size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 ); - if( mb->dictionary_size > 1 << 26 ) /* 64 MiB */ - size >>= 1; + if( mb->dictionary_size > 1 << 26 ) size >>= 1; /* 64 MiB */ mb->key4_mask = size - 1; size += mb->num_prev_positions23; mb->num_prev_positions = size; @@ -129,21 +126,21 @@ static void Mb_reset( struct Matchfinder_base * const mb ) /* End Of Stream marker => (dis == 0xFFFFFFFFU, len == min_match_len) */ static void LZeb_try_full_flush( struct LZ_encoder_base * const eb ) { - int i; - const int pos_state = Mb_data_position( &eb->mb ) & pos_state_mask; - const State state = eb->state; - Lzip_trailer trailer; if( eb->member_finished || Cb_free_bytes( &eb->renc.cb ) < max_marker_size + eb->renc.ff_count + Lt_size ) return; eb->member_finished = true; + const int pos_state = Mb_data_position( &eb->mb ) & pos_state_mask; + const State state = eb->state; Re_encode_bit( &eb->renc, &eb->bm_match[state][pos_state], 1 ); Re_encode_bit( &eb->renc, &eb->bm_rep[state], 0 ); LZeb_encode_pair( eb, 0xFFFFFFFFU, min_match_len, pos_state ); Re_flush( &eb->renc ); + Lzip_trailer trailer; Lt_set_data_crc( trailer, LZeb_crc( eb ) ); Lt_set_data_size( trailer, Mb_data_position( &eb->mb ) ); Lt_set_member_size( trailer, Re_member_position( &eb->renc ) + Lt_size ); + int i; for( i = 0; i < Lt_size; ++i ) Cb_put_byte( &eb->renc.cb, trailer[i] ); } @@ -152,13 +149,13 @@ static void LZeb_try_full_flush( struct LZ_encoder_base * const eb ) /* Sync Flush marker => (dis == 0xFFFFFFFFU, len == min_match_len + 1) */ static void LZeb_try_sync_flush( struct LZ_encoder_base * const eb ) { - const int pos_state = Mb_data_position( &eb->mb ) & pos_state_mask; - const State state = eb->state; const unsigned min_size = eb->renc.ff_count + max_marker_size; if( eb->member_finished || Cb_free_bytes( &eb->renc.cb ) < min_size + max_marker_size ) return; eb->mb.sync_flush_pending = false; const unsigned long long old_mpos = Re_member_position( &eb->renc ); + const int pos_state = Mb_data_position( &eb->mb ) & pos_state_mask; + const State state = eb->state; do { /* size of markers must be >= rd_min_available_bytes + 5 */ Re_encode_bit( &eb->renc, &eb->bm_match[state][pos_state], 1 ); Re_encode_bit( &eb->renc, &eb->bm_rep[state], 0 ); diff --git a/encoder_base.h b/encoder_base.h index e727a7d..17ffc93 100644 --- a/encoder_base.h +++ b/encoder_base.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2021 Antonio Diaz Diaz. + Copyright (C) 2009-2022 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -147,10 +147,9 @@ static inline int price_bit( const Bit_model bm, const bool bit ) static inline int price_symbol3( const Bit_model bm[], int symbol ) { - int price; bool bit = symbol & 1; symbol |= 8; symbol >>= 1; - price = price_bit( bm[symbol], bit ); + int price = price_bit( bm[symbol], bit ); bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); return price + price_bit( bm[1], symbol & 1 ); } @@ -158,10 +157,9 @@ static inline int price_symbol3( const Bit_model bm[], int symbol ) static inline int price_symbol6( const Bit_model bm[], unsigned symbol ) { - int price; bool bit = symbol & 1; symbol |= 64; symbol >>= 1; - price = price_bit( bm[symbol], bit ); + int price = price_bit( bm[symbol], bit ); bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); @@ -172,10 +170,9 @@ static inline int price_symbol6( const Bit_model bm[], unsigned symbol ) static inline int price_symbol8( const Bit_model bm[], int symbol ) { - int price; bool bit = symbol & 1; symbol |= 0x100; symbol >>= 1; - price = price_bit( bm[symbol], bit ); + int price = price_bit( bm[symbol], bit ); bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); bit = symbol & 1; symbol >>= 1; price += price_bit( bm[symbol], bit ); @@ -427,10 +424,9 @@ static inline void Re_encode_bit( struct Range_encoder * const renc, static inline void Re_encode_tree3( struct Range_encoder * const renc, Bit_model bm[], const int symbol ) { - int model; bool bit = ( symbol >> 2 ) & 1; Re_encode_bit( renc, &bm[1], bit ); - model = 2 | bit; + int model = 2 | bit; bit = ( symbol >> 1 ) & 1; Re_encode_bit( renc, &bm[model], bit ); model <<= 1; model |= bit; Re_encode_bit( renc, &bm[model], symbol & 1 ); @@ -439,10 +435,9 @@ static inline void Re_encode_tree3( struct Range_encoder * const renc, static inline void Re_encode_tree6( struct Range_encoder * const renc, Bit_model bm[], const unsigned symbol ) { - int model; bool bit = ( symbol >> 5 ) & 1; Re_encode_bit( renc, &bm[1], bit ); - model = 2 | bit; + int model = 2 | bit; bit = ( symbol >> 4 ) & 1; Re_encode_bit( renc, &bm[model], bit ); model <<= 1; model |= bit; bit = ( symbol >> 3 ) & 1; @@ -583,8 +578,7 @@ static inline int LZeb_price_matched( const struct LZ_encoder_base * const eb, static inline void LZeb_encode_literal( struct LZ_encoder_base * const eb, const uint8_t prev_byte, const uint8_t symbol ) - { Re_encode_tree8( &eb->renc, eb->bm_literal[get_lit_state(prev_byte)], - symbol ); } + { Re_encode_tree8( &eb->renc, eb->bm_literal[get_lit_state(prev_byte)], symbol ); } static inline void LZeb_encode_matched( struct LZ_encoder_base * const eb, const uint8_t prev_byte, const uint8_t symbol, const uint8_t match_byte ) @@ -595,8 +589,8 @@ static inline void LZeb_encode_pair( struct LZ_encoder_base * const eb, const unsigned dis, const int len, const int pos_state ) { - const unsigned dis_slot = get_slot( dis ); Re_encode_len( &eb->renc, &eb->match_len_model, len, pos_state ); + const unsigned dis_slot = get_slot( dis ); Re_encode_tree6( &eb->renc, eb->bm_dis_slot[get_len_state(len)], dis_slot ); if( dis_slot >= start_dis_model ) diff --git a/fast_encoder.c b/fast_encoder.c index bdcbb97..618c3d6 100644 --- a/fast_encoder.c +++ b/fast_encoder.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2021 Antonio Diaz Diaz. + Copyright (C) 2009-2022 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -20,25 +20,24 @@ static int FLZe_longest_match_len( struct FLZ_encoder * const fe, int * const distance ) { enum { len_limit = 16 }; - const uint8_t * const data = Mb_ptr_to_current_pos( &fe->eb.mb ); int32_t * ptr0 = fe->eb.mb.pos_array + fe->eb.mb.cyclic_pos; - const int pos1 = fe->eb.mb.pos + 1; - int maxlen = 0, newpos1, count; const int available = min( Mb_available_bytes( &fe->eb.mb ), max_match_len ); if( available < len_limit ) { *ptr0 = 0; return 0; } + const uint8_t * const data = Mb_ptr_to_current_pos( &fe->eb.mb ); fe->key4 = ( ( fe->key4 << 4 ) ^ data[3] ) & fe->eb.mb.key4_mask; - newpos1 = fe->eb.mb.prev_positions[fe->key4]; + const int pos1 = fe->eb.mb.pos + 1; + int newpos1 = fe->eb.mb.prev_positions[fe->key4]; fe->eb.mb.prev_positions[fe->key4] = pos1; + int maxlen = 0, count; for( count = 4; ; ) { - int32_t * newptr; int delta; if( newpos1 <= 0 || --count < 0 || ( delta = pos1 - newpos1 ) > fe->eb.mb.dictionary_size ) { *ptr0 = 0; break; } - newptr = fe->eb.mb.pos_array + + int32_t * const newptr = fe->eb.mb.pos_array + ( fe->eb.mb.cyclic_pos - delta + ( ( fe->eb.mb.cyclic_pos >= delta ) ? 0 : fe->eb.mb.dictionary_size + 1 ) ); @@ -71,11 +70,10 @@ static bool FLZe_encode_member( struct FLZ_encoder * const fe ) if( Mb_data_position( &fe->eb.mb ) == 0 && !Mb_data_finished( &fe->eb.mb ) ) /* encode first byte */ { - const uint8_t prev_byte = 0; - uint8_t cur_byte; if( !Mb_enough_available_bytes( &fe->eb.mb ) || !Re_enough_free_bytes( &fe->eb.renc ) ) return true; - cur_byte = Mb_peek( &fe->eb.mb, 0 ); + const uint8_t prev_byte = 0; + const uint8_t cur_byte = Mb_peek( &fe->eb.mb, 0 ); Re_encode_bit( &fe->eb.renc, &fe->eb.bm_match[*state][0], 0 ); LZeb_encode_literal( &fe->eb, prev_byte, cur_byte ); CRC32_update_byte( &fe->eb.crc, cur_byte ); @@ -86,13 +84,12 @@ static bool FLZe_encode_member( struct FLZ_encoder * const fe ) while( !Mb_data_finished( &fe->eb.mb ) && Re_member_position( &fe->eb.renc ) < fe->eb.member_size_limit ) { - int match_distance = 0; /* avoid warning from gcc 6.1.0 */ - int main_len, pos_state; - int len = 0; if( !Mb_enough_available_bytes( &fe->eb.mb ) || !Re_enough_free_bytes( &fe->eb.renc ) ) return true; - main_len = FLZe_longest_match_len( fe, &match_distance ); - pos_state = Mb_data_position( &fe->eb.mb ) & pos_state_mask; + int match_distance = 0; /* avoid warning from gcc 6.1.0 */ + const int main_len = FLZe_longest_match_len( fe, &match_distance ); + const int pos_state = Mb_data_position( &fe->eb.mb ) & pos_state_mask; + int len = 0; for( i = 0; i < num_rep_distances; ++i ) { @@ -109,11 +106,10 @@ static bool FLZe_encode_member( struct FLZ_encoder * const fe ) Re_encode_bit( &fe->eb.renc, &fe->eb.bm_len[*state][pos_state], 1 ); else { - int distance; Re_encode_bit( &fe->eb.renc, &fe->eb.bm_rep1[*state], rep > 1 ); if( rep > 1 ) Re_encode_bit( &fe->eb.renc, &fe->eb.bm_rep2[*state], rep > 2 ); - distance = fe->eb.reps[rep]; + const int distance = fe->eb.reps[rep]; for( i = rep; i > 0; --i ) fe->eb.reps[i] = fe->eb.reps[i-1]; fe->eb.reps[0] = distance; } @@ -138,7 +134,6 @@ static bool FLZe_encode_member( struct FLZ_encoder * const fe ) continue; } - { const uint8_t prev_byte = Mb_peek( &fe->eb.mb, 1 ); const uint8_t cur_byte = Mb_peek( &fe->eb.mb, 0 ); const uint8_t match_byte = Mb_peek( &fe->eb.mb, fe->eb.reps[0] + 1 ); @@ -169,12 +164,10 @@ static bool FLZe_encode_member( struct FLZ_encoder * const fe ) /* literal byte */ Re_encode_bit( &fe->eb.renc, &fe->eb.bm_match[*state][pos_state], 0 ); - if( St_is_char( *state ) ) + if( ( *state = St_set_char( *state ) ) < 4 ) LZeb_encode_literal( &fe->eb, prev_byte, cur_byte ); else LZeb_encode_matched( &fe->eb, prev_byte, cur_byte, match_byte ); - *state = St_set_char( *state ); - } } LZeb_try_full_flush( &fe->eb ); diff --git a/fast_encoder.h b/fast_encoder.h index 1c3a6ff..54756bd 100644 --- a/fast_encoder.h +++ b/fast_encoder.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2021 Antonio Diaz Diaz. + Copyright (C) 2009-2022 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/ffexample.c b/ffexample.c index 2891f02..59345ee 100644 --- a/ffexample.c +++ b/ffexample.c @@ -1,5 +1,5 @@ /* File to file example - Test program for the library lzlib - Copyright (C) 2010-2021 Antonio Diaz Diaz. + Copyright (C) 2010-2022 Antonio Diaz Diaz. This program is free software: you have unlimited permission to copy, distribute, and modify it. @@ -20,7 +20,7 @@ #include #include #include -#if defined(__MSVCRT__) || defined(__OS2__) || defined(__DJGPP__) +#if defined __MSVCRT__ || defined __OS2__ || defined __DJGPP__ #include #include #endif @@ -178,9 +178,9 @@ int ffmmcompress( FILE * const infile, FILE * const outfile ) } -/* Compresses 'infile' to 'outfile' as a multimember stream with one member +/* Compress 'infile' to 'outfile' as a multimember stream with one member for each line of text terminated by a newline character or by EOF. - Returns 0 if success, 1 if error. + Return 0 if success, 1 if error. */ int fflfcompress( struct LZ_Encoder * const encoder, FILE * const infile, FILE * const outfile ) @@ -219,7 +219,7 @@ int fflfcompress( struct LZ_Encoder * const encoder, } -/* Decompresses 'infile' to 'outfile' with automatic resynchronization to +/* Decompress 'infile' to 'outfile' with automatic resynchronization to next member in case of data error, including the automatic removal of leading garbage. */ @@ -257,7 +257,7 @@ int ffrsdecompress( struct LZ_Decoder * const decoder, int main( const int argc, const char * const argv[] ) { -#if defined(__MSVCRT__) || defined(__OS2__) || defined(__DJGPP__) +#if defined __MSVCRT__ || defined __OS2__ || defined __DJGPP__ setmode( STDIN_FILENO, O_BINARY ); setmode( STDOUT_FILENO, O_BINARY ); #endif diff --git a/lzcheck.c b/lzcheck.c index 7e00e6c..88dd4c9 100644 --- a/lzcheck.c +++ b/lzcheck.c @@ -1,5 +1,5 @@ /* Lzcheck - Test program for the library lzlib - Copyright (C) 2009-2021 Antonio Diaz Diaz. + Copyright (C) 2009-2022 Antonio Diaz Diaz. This program is free software: you have unlimited permission to copy, distribute, and modify it. @@ -133,10 +133,11 @@ static void xclose_decoder( struct LZ_Decoder * const decoder, } -/* Returns the next (usually newline-terminated) chunk of data from file. +/* Return the next (usually newline-terminated) chunk of data from file. The size returned in *sizep is always <= buffer_size. - If sizep is a null pointer, rewinds the file, resets state, and returns. - If file is at EOF, returns an empty line. */ + If sizep is a null pointer, rewind the file, reset state, and return. + If file is at EOF, return an empty line. +*/ static const uint8_t * next_line( FILE * const file, int * const sizep ) { static int l = 0; @@ -332,7 +333,7 @@ int main( const int argc, const char * const argv[] ) if( argc < 2 ) { - fputs( "Usage: lzcheck filename.txt...\n", stderr ); + fputs( "Usage: lzcheck [-m|-s] filename.txt...\n", stderr ); return 1; } diff --git a/lzip.h b/lzip.h index 3e3df2c..aad7e00 100644 --- a/lzip.h +++ b/lzip.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2021 Antonio Diaz Diaz. + Copyright (C) 2009-2022 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -168,6 +168,7 @@ static const uint32_t crc32[256] = static inline void CRC32_update_byte( uint32_t * const crc, const uint8_t byte ) { *crc = crc32[(*crc^byte)&0xFF] ^ ( *crc >> 8 ); } +/* about as fast as it is possible without messing with endianness */ static inline void CRC32_update_buf( uint32_t * const crc, const uint8_t * const buffer, const int size ) diff --git a/lzlib.c b/lzlib.c index b7969f2..3084fbd 100644 --- a/lzlib.c +++ b/lzlib.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2021 Antonio Diaz Diaz. + Copyright (C) 2009-2022 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/lzlib.h b/lzlib.h index b6374d8..ba29f97 100644 --- a/lzlib.h +++ b/lzlib.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2021 Antonio Diaz Diaz. + Copyright (C) 2009-2022 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -24,9 +24,9 @@ extern "C" { /* LZ_API_VERSION was first defined in lzlib 1.8 to 1. Since lzlib 1.12, LZ_API_VERSION is defined as (major * 1000 + minor). */ -#define LZ_API_VERSION 1012 +#define LZ_API_VERSION 1013 -static const char * const LZ_version_string = "1.12"; +static const char * const LZ_version_string = "1.13"; enum LZ_Errno { LZ_ok = 0, LZ_bad_argument, LZ_mem_error, LZ_sequence_error, LZ_header_error, LZ_unexpected_eof, diff --git a/main.c b/minilzip.c similarity index 86% rename from main.c rename to minilzip.c index c623d9b..f9313b2 100644 --- a/main.c +++ b/minilzip.c @@ -1,5 +1,5 @@ /* Minilzip - Test program for the library lzlib - Copyright (C) 2009-2021 Antonio Diaz Diaz. + Copyright (C) 2009-2022 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 @@ -18,11 +18,12 @@ Exit status: 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 caused minilzip to panic. + (e.g., bug) which caused minilzip to panic. */ #define _FILE_OFFSET_BITS 64 +#include #include #include #include @@ -35,9 +36,9 @@ #include #include #include -#if defined(__MSVCRT__) || defined(__OS2__) || defined(__DJGPP__) +#if defined __MSVCRT__ || defined __OS2__ || defined __DJGPP__ #include -#if defined(__MSVCRT__) +#if defined __MSVCRT__ #define fchmod(x,y) 0 #define fchown(x,y,z) 0 #define strtoull strtoul @@ -50,7 +51,7 @@ #define S_IWOTH 0 #endif #endif -#if defined(__DJGPP__) +#if defined __DJGPP__ #define S_ISSOCK(x) 0 #define S_ISVTX 0 #endif @@ -67,6 +68,11 @@ #error "Environments where CHAR_BIT != 8 are not supported." #endif +#if ( defined SIZE_MAX && SIZE_MAX < UINT_MAX ) || \ + ( defined SSIZE_MAX && SSIZE_MAX < INT_MAX ) +#error "Environments where 'size_t' is narrower than 'int' are not supported." +#endif + #ifndef max #define max(x,y) ((x) >= (y) ? (x) : (y)) #endif @@ -85,7 +91,7 @@ static const char * const mem_msg = "Not enough memory."; int verbosity = 0; static const char * const program_name = "minilzip"; -static const char * const program_year = "2021"; +static const char * const program_year = "2022"; static const char * invocation_name = "minilzip"; /* default value */ static const struct { const char * from; const char * to; } known_extensions[] = { @@ -114,13 +120,14 @@ static void show_help( void ) "compatible with lzip 1.4 or newer.\n" "\nLzip is a lossless data compressor with a user interface similar to the one\n" "of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov\n" - "chain-Algorithm' (LZMA) stream format, chosen to maximize safety and\n" - "interoperability. Lzip can compress about as fast as gzip (lzip -0) or\n" - "compress most files more than bzip2 (lzip -9). Decompression speed is\n" - "intermediate between gzip and bzip2. Lzip is better than gzip and bzip2 from\n" - "a data recovery perspective. Lzip has been designed, written, and tested\n" - "with great care to replace gzip and bzip2 as the standard general-purpose\n" - "compressed format for unix-like systems.\n" + "chain-Algorithm' (LZMA) stream format and provides a 3 factor integrity\n" + "checking to maximize interoperability and optimize safety. Lzip can compress\n" + "about as fast as gzip (lzip -0) or compress most files more than bzip2\n" + "(lzip -9). Decompression speed is intermediate between gzip and bzip2.\n" + "Lzip is better than gzip and bzip2 from a data recovery perspective. Lzip\n" + "has been designed, written, and tested with great care to replace gzip and\n" + "bzip2 as the standard general-purpose compressed format for unix-like\n" + "systems.\n" "\nUsage: %s [options] [files]\n", invocation_name ); printf( "\nOptions:\n" " -h, --help display this help and exit\n" @@ -158,7 +165,7 @@ static void show_help( void ) "'tar -xf foo.tar.lz' or 'minilzip -cd foo.tar.lz | tar -xf -'.\n" "\nExit status: 0 for a normal exit, 1 for environmental problems (file\n" "not found, invalid flags, I/O errors, etc), 2 to indicate a corrupt or\n" - "invalid input file, 3 for an internal consistency error (eg, bug) which\n" + "invalid input file, 3 for an internal consistency error (e.g., bug) which\n" "caused minilzip to panic.\n" "\nThe ideas embodied in lzlib are due to (at least) the following people:\n" "Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the\n" @@ -181,17 +188,48 @@ static void show_version( void ) } -int check_lib() +static inline void set_retval( int * retval, const int new_val ) + { if( *retval < new_val ) *retval = new_val; } + + +static int check_lzlib_ver() /* . or .[a-z.-]* */ { - bool warning = false; +#if defined LZ_API_VERSION && LZ_API_VERSION >= 1012 + const unsigned char * p = (unsigned char *)LZ_version_string; + unsigned major = 0, minor = 0; + while( major < 100000 && isdigit( *p ) ) + { major *= 10; major += *p - '0'; ++p; } + if( *p == '.' ) ++p; + else +out: { show_error( "Invalid LZ_version_string in lzlib.h", 0, false ); return 2; } + while( minor < 100 && isdigit( *p ) ) + { minor *= 10; minor += *p - '0'; ++p; } + if( *p && *p != '-' && *p != '.' && !islower( *p ) ) goto out; + const unsigned version = major * 1000 + minor; + if( LZ_API_VERSION != version ) + { + if( verbosity >= 0 ) + fprintf( stderr, "%s: Version mismatch in lzlib.h: " + "LZ_API_VERSION = %u, should be %u.\n", + program_name, LZ_API_VERSION, version ); + return 2; + } +#endif + return 0; + } + + +static int check_lib() + { + int retval = check_lzlib_ver(); if( strcmp( LZ_version_string, LZ_version() ) != 0 ) - { warning = true; + { set_retval( &retval, 1 ); if( verbosity >= 0 ) printf( "warning: LZ_version_string != LZ_version() (%s vs %s)\n", LZ_version_string, LZ_version() ); } #if defined LZ_API_VERSION && LZ_API_VERSION >= 1012 if( LZ_API_VERSION != LZ_api_version() ) - { warning = true; + { set_retval( &retval, 1 ); if( verbosity >= 0 ) printf( "warning: LZ_API_VERSION != LZ_api_version() (%u vs %u)\n", LZ_API_VERSION, LZ_api_version() ); } @@ -208,7 +246,7 @@ int check_lib() "Using an unknown LZ_API_VERSION\n", LZ_API_VERSION ); #endif } - return warning; + return retval; } @@ -234,8 +272,6 @@ struct Pretty_print static void Pp_init( struct Pretty_print * const pp, const char * const filenames[], const int num_filenames ) { - unsigned stdin_name_len; - int i; pp->name = 0; pp->padded_name = 0; pp->stdin_name = "(stdin)"; @@ -243,7 +279,8 @@ static void Pp_init( struct Pretty_print * const pp, pp->first_post = false; if( verbosity <= 0 ) return; - stdin_name_len = strlen( pp->stdin_name ); + const unsigned stdin_name_len = strlen( pp->stdin_name ); + int i; for( i = 0; i < num_filenames; ++i ) { const char * const s = filenames[i]; @@ -277,16 +314,14 @@ static void Pp_reset( struct Pretty_print * const pp ) static void Pp_show_msg( struct Pretty_print * const pp, const char * const msg ) { - if( verbosity >= 0 ) + if( verbosity < 0 ) return; + if( pp->first_post ) { - if( pp->first_post ) - { - pp->first_post = false; - fputs( pp->padded_name, stderr ); - if( !msg ) fflush( stderr ); - } - if( msg ) fprintf( stderr, "%s\n", msg ); + pp->first_post = false; + fputs( pp->padded_name, stderr ); + if( !msg ) fflush( stderr ); } + if( msg ) fprintf( stderr, "%s\n", msg ); } @@ -307,17 +342,53 @@ static void show_header( const unsigned dictionary_size ) } -static unsigned long long getnum( const char * const ptr, +/* separate large numbers >= 100_000 in groups of 3 digits using '_' */ +static const char * format_num3( unsigned long long num ) + { + const char * const si_prefix = "kMGTPEZY"; + const char * const binary_prefix = "KMGTPEZY"; + enum { buffers = 8, bufsize = 4 * sizeof (long long) }; + static char buffer[buffers][bufsize]; /* circle of static buffers for printf */ + static int current = 0; + int i; + char * const buf = buffer[current++]; current %= buffers; + char * p = buf + bufsize - 1; /* fill the buffer backwards */ + *p = 0; /* terminator */ + if( num > 1024 ) + { + char prefix = 0; /* try binary first, then si */ + for( i = 0; i < 8 && num >= 1024 && num % 1024 == 0; ++i ) + { num /= 1024; prefix = binary_prefix[i]; } + if( prefix ) *(--p) = 'i'; + else + for( i = 0; i < 8 && num >= 1000 && num % 1000 == 0; ++i ) + { num /= 1000; prefix = si_prefix[i]; } + if( prefix ) *(--p) = prefix; + } + const bool split = num >= 100000; + + for( i = 0; ; ) + { + *(--p) = num % 10 + '0'; num /= 10; if( num == 0 ) break; + if( split && ++i >= 3 ) { i = 0; *(--p) = '_'; } + } + return p; + } + + +static unsigned long long getnum( const char * const arg, + const char * const option_name, const unsigned long long llimit, const unsigned long long ulimit ) { - unsigned long long result; char * tail; errno = 0; - result = strtoull( ptr, &tail, 0 ); - if( tail == ptr ) + unsigned long long result = strtoull( arg, &tail, 0 ); + if( tail == arg ) { - show_error( "Bad or missing numerical argument.", 0, true ); + if( verbosity >= 0 ) + fprintf( stderr, "%s: Bad or missing numerical argument in " + "option '%s'.\n", program_name, option_name ); exit( 1 ); } @@ -340,7 +411,9 @@ static unsigned long long getnum( const char * const ptr, } if( exponent <= 0 ) { - show_error( "Bad multiplier in numerical argument.", 0, true ); + if( verbosity >= 0 ) + fprintf( stderr, "%s: Bad multiplier in numerical argument of " + "option '%s'.\n", program_name, option_name ); exit( 1 ); } for( i = 0; i < exponent; ++i ) @@ -352,23 +425,25 @@ static unsigned long long getnum( const char * const ptr, if( !errno && ( result < llimit || result > ulimit ) ) errno = ERANGE; if( errno ) { - show_error( "Numerical argument out of limits.", 0, false ); + if( verbosity >= 0 ) + fprintf( stderr, "%s: Numerical argument out of limits [%s,%s] " + "in option '%s'.\n", program_name, format_num3( llimit ), + format_num3( ulimit ), option_name ); exit( 1 ); } return result; } -static int get_dict_size( const char * const arg ) +static int get_dict_size( const char * const arg, const char * const option_name ) { char * tail; - int dictionary_size; const long bits = strtol( arg, &tail, 0 ); if( bits >= LZ_min_dictionary_bits() && bits <= LZ_max_dictionary_bits() && *tail == 0 ) return 1 << bits; - dictionary_size = getnum( arg, LZ_min_dictionary_size(), - LZ_max_dictionary_size() ); + int dictionary_size = getnum( arg, option_name, LZ_min_dictionary_size(), + LZ_max_dictionary_size() ); if( dictionary_size == 65535 ) ++dictionary_size; /* no fast encoder */ return dictionary_size; } @@ -442,34 +517,31 @@ static int open_instream( const char * const name, struct stat * const in_statsp const enum Mode program_mode, const int eindex, const bool one_to_one, const bool recompress ) { - int infd = -1; if( program_mode == m_compress && !recompress && eindex >= 0 ) { if( verbosity >= 0 ) fprintf( stderr, "%s: Input file '%s' already has '%s' suffix.\n", program_name, name, known_extensions[eindex].from ); + return -1; } + int infd = open( name, O_RDONLY | O_BINARY ); + if( infd < 0 ) + show_file_error( name, "Can't open input file", errno ); else { - infd = open( name, O_RDONLY | O_BINARY ); - if( infd < 0 ) - show_file_error( name, "Can't open input file", errno ); - else + const int i = fstat( infd, in_statsp ); + const mode_t mode = in_statsp->st_mode; + const bool can_read = ( i == 0 && + ( S_ISBLK( mode ) || S_ISCHR( mode ) || + S_ISFIFO( mode ) || S_ISSOCK( mode ) ) ); + if( i != 0 || ( !S_ISREG( mode ) && ( !can_read || one_to_one ) ) ) { - const int i = fstat( infd, in_statsp ); - const mode_t mode = in_statsp->st_mode; - const bool can_read = ( i == 0 && - ( S_ISBLK( mode ) || S_ISCHR( mode ) || - S_ISFIFO( mode ) || S_ISSOCK( mode ) ) ); - if( i != 0 || ( !S_ISREG( mode ) && ( !can_read || one_to_one ) ) ) - { - if( verbosity >= 0 ) - fprintf( stderr, "%s: Input file '%s' is not a regular file%s.\n", - program_name, name, ( can_read && one_to_one ) ? - ",\n and neither '-c' nor '-o' were specified" : "" ); - close( infd ); - infd = -1; - } + if( verbosity >= 0 ) + fprintf( stderr, "%s: Input file '%s' is not a regular file%s.\n", + program_name, name, ( can_read && one_to_one ) ? + ",\n and neither '-c' nor '-o' were specified" : "" ); + close( infd ); + infd = -1; } } return infd; @@ -532,10 +604,6 @@ static void signal_handler( int sig ) } -static inline void set_retval( int * retval, const int new_val ) - { if( *retval < new_val ) *retval = new_val; } - - static bool check_tty_in( const char * const input_filename, const int infd, const enum Mode program_mode, int * const retval ) { @@ -543,7 +611,7 @@ static bool check_tty_in( const char * const input_filename, const int infd, isatty( infd ) ) /* for example /dev/tty */ { show_file_error( input_filename, "I won't read compressed data from a terminal.", 0 ); - close( infd ); set_retval( retval, 1 ); + close( infd ); set_retval( retval, 2 ); if( program_mode != m_test ) cleanup_and_fail( *retval ); return false; } return true; @@ -594,8 +662,8 @@ static void close_and_set_permissions( const struct stat * const in_statsp ) } -/* Returns the number of bytes really read. - If (returned value < size) and (errno == 0), means EOF was reached. +/* Return the number of bytes really read. + If (value returned < size) and (errno == 0), means EOF was reached. */ static int readblock( const int fd, uint8_t * const buf, const int size ) { @@ -613,8 +681,8 @@ static int readblock( const int fd, uint8_t * const buf, const int size ) } -/* Returns the number of bytes really written. - If (returned value < size), it is always an error. +/* Return the number of bytes really written. + If (value returned < size), it is always an error. */ static int writeblock( const int fd, const uint8_t * const buf, const int size ) { @@ -659,7 +727,7 @@ static int do_compress( struct LZ_Encoder * const encoder, while( true ) { - int in_size = 0, out_size; + int in_size = 0; while( LZ_compress_write_size( encoder ) > 0 ) { const int size = min( LZ_compress_write_size( encoder ), buffer_size ); @@ -675,7 +743,7 @@ static int do_compress( struct LZ_Encoder * const encoder, /* else LZ_compress_sync_flush( encoder ); */ in_size += rd; } - out_size = LZ_compress_read( encoder, buffer, buffer_size ); + const int out_size = LZ_compress_read( encoder, buffer, buffer_size ); if( out_size < 0 ) { Pp_show_msg( pp, 0 ); @@ -843,7 +911,7 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd, fputs( testing ? "ok\n" : "done\n", stderr ); Pp_reset( pp ); } } - first_member = false; + first_member = false; /* member decompressed successfully */ } if( rd <= 0 ) break; } @@ -985,23 +1053,15 @@ int main( const int argc, const char * const argv[] ) unsigned long long member_size = max_member_size; unsigned long long volume_size = 0; const char * default_output_filename = ""; - static struct Arg_parser parser; /* static because valgrind complains */ - static struct Pretty_print pp; /* and memory management in C sucks */ - static const char ** filenames = 0; - int num_filenames = 0; enum Mode program_mode = m_compress; - int argind = 0; - int failed_tests = 0; - int retval = 0; int i; - bool filenames_given = false; bool force = false; bool ignore_trailing = true; bool keep_input_files = false; bool loose_trailing = false; bool recompress = false; - bool stdin_used = false; bool to_stdout = false; + if( argc > 0 ) invocation_name = argv[0]; enum { opt_chk = 256, opt_lt }; const struct ap_Option options[] = @@ -1037,25 +1097,27 @@ int main( const int argc, const char * const argv[] ) { opt_lt, "loose-trailing", ap_no }, { 0, 0, ap_no } }; - if( argc > 0 ) invocation_name = argv[0]; - + /* static because valgrind complains and memory management in C sucks */ + static struct Arg_parser parser; if( !ap_init( &parser, argc, argv, options, 0 ) ) { show_error( mem_msg, 0, false ); return 1; } if( ap_error( &parser ) ) /* bad option */ { show_error( ap_error( &parser ), 0, true ); return 1; } + int argind = 0; for( ; argind < ap_arguments( &parser ); ++argind ) { const int code = ap_code( &parser, argind ); - const char * const arg = ap_argument( &parser, argind ); if( !code ) break; /* no more options */ + const char * const pn = ap_parsed_name( &parser, argind ); + const char * const arg = ap_argument( &parser, argind ); switch( code ) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': encoder_options = option_mapping[code-'0']; break; case 'a': ignore_trailing = false; break; - case 'b': member_size = getnum( arg, 100000, max_member_size ); break; + case 'b': member_size = getnum( arg, pn, 100000, max_member_size ); break; case 'c': to_stdout = true; break; case 'd': set_mode( &program_mode, m_decompress ); break; case 'f': force = true; break; @@ -1063,15 +1125,15 @@ int main( const int argc, const char * const argv[] ) case 'h': show_help(); return 0; case 'k': keep_input_files = true; break; case 'm': encoder_options.match_len_limit = - getnum( arg, LZ_min_match_len_limit(), - LZ_max_match_len_limit() ); break; + getnum( arg, pn, LZ_min_match_len_limit(), + LZ_max_match_len_limit() ); break; case 'n': break; case 'o': if( strcmp( arg, "-" ) == 0 ) to_stdout = true; else { default_output_filename = arg; } break; case 'q': verbosity = -1; break; - case 's': encoder_options.dictionary_size = get_dict_size( arg ); + case 's': encoder_options.dictionary_size = get_dict_size( arg, pn ); break; - case 'S': volume_size = getnum( arg, 100000, max_volume_size ); break; + case 'S': volume_size = getnum( arg, pn, 100000, max_volume_size ); break; case 't': set_mode( &program_mode, m_test ); break; case 'v': if( verbosity < 4 ) ++verbosity; break; case 'V': show_version(); return 0; @@ -1096,15 +1158,17 @@ int main( const int argc, const char * const argv[] ) if( strcmp( LZ_version_string, LZ_version() ) != 0 ) show_error( "warning: wrong library version_string. Try --check-lib.", 0, false ); -#if defined(__MSVCRT__) || defined(__OS2__) || defined(__DJGPP__) +#if defined __MSVCRT__ || defined __OS2__ || defined __DJGPP__ setmode( STDIN_FILENO, O_BINARY ); setmode( STDOUT_FILENO, O_BINARY ); #endif - num_filenames = max( 1, ap_arguments( &parser ) - argind ); + static const char ** filenames = 0; + int num_filenames = max( 1, ap_arguments( &parser ) - argind ); filenames = resize_buffer( filenames, num_filenames * sizeof filenames[0] ); filenames[0] = "-"; + bool filenames_given = false; for( i = 0; argind + i < ap_arguments( &parser ); ++i ) { filenames[i] = ap_argument( &parser, argind + i ); @@ -1133,16 +1197,18 @@ int main( const int argc, const char * const argv[] ) if( !to_stdout && program_mode != m_test && ( filenames_given || to_file ) ) set_signals( signal_handler ); + static struct Pretty_print pp; Pp_init( &pp, filenames, num_filenames ); + int failed_tests = 0; + int retval = 0; const bool one_to_one = !to_stdout && program_mode != m_test && !to_file; + bool stdin_used = false; for( i = 0; i < num_filenames; ++i ) { const char * input_filename = ""; int infd; - int tmp; struct stat in_stats; - const struct stat * in_statsp; Pp_set_name( &pp, filenames[i] ); if( strcmp( filenames[i], "-" ) == 0 ) @@ -1184,7 +1250,9 @@ int main( const int argc, const char * const argv[] ) return 1; /* check tty only once and don't try to delete a tty */ } - in_statsp = ( input_filename[0] && one_to_one ) ? &in_stats : 0; + const struct stat * const in_statsp = + ( input_filename[0] && one_to_one ) ? &in_stats : 0; + int tmp; if( program_mode == m_compress ) tmp = compress( member_size, volume_size, infd, &encoder_options, &pp, in_statsp ); diff --git a/testsuite/check.sh b/testsuite/check.sh index 44e2428..e93697e 100755 --- a/testsuite/check.sh +++ b/testsuite/check.sh @@ -1,6 +1,6 @@ #! /bin/sh # check script for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2021 Antonio Diaz Diaz. +# Copyright (C) 2009-2022 Antonio Diaz Diaz. # # This script is free software: you have unlimited permission # to copy, distribute, and modify it. @@ -39,7 +39,8 @@ fox_lz="${testdir}"/fox.lz fail=0 test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; } -"${LZIP}" --check-lib # just print warning +"${LZIP}" --check-lib # just print warning +[ $? != 2 ] || { test_failed $LINENO ; exit 2 ; } # unless bad lzlib.h printf "testing lzlib-%s..." "$2" "${LZIP}" -fkqm4 in @@ -99,6 +100,7 @@ done printf "LZIP\001-.............................." | "${LZIP}" -t 2> /dev/null printf "LZIP\002-.............................." | "${LZIP}" -t 2> /dev/null printf "LZIP\001+.............................." | "${LZIP}" -t 2> /dev/null +rm -f out || framework_failure printf "\ntesting decompression..." @@ -118,25 +120,28 @@ done lines=$("${LZIP}" -tvv "${in_em}" 2>&1 | wc -l) || test_failed $LINENO [ "${lines}" -eq 8 ] || test_failed $LINENO "${lines}" +"${LZIP}" -cd "${fox_lz}" > fox || test_failed $LINENO cat "${in_lz}" > copy.lz || framework_failure "${LZIP}" -dk copy.lz || test_failed $LINENO cmp in copy || test_failed $LINENO -printf "to be overwritten" > copy || framework_failure -"${LZIP}" -d copy.lz 2> /dev/null +cat fox > copy || framework_failure +cat "${in_lz}" > out.lz || framework_failure +rm -f out || framework_failure +"${LZIP}" -d copy.lz out.lz 2> /dev/null # skip copy, decompress out [ $? = 1 ] || test_failed $LINENO +cmp fox copy || test_failed $LINENO +cmp in out || test_failed $LINENO "${LZIP}" -df copy.lz || test_failed $LINENO [ ! -e copy.lz ] || test_failed $LINENO cmp in copy || test_failed $LINENO +rm -f copy out || framework_failure -rm -f copy || framework_failure cat "${in_lz}" > copy.lz || framework_failure "${LZIP}" -d -S100k copy.lz || test_failed $LINENO # ignore -S [ ! -e copy.lz ] || test_failed $LINENO cmp in copy || test_failed $LINENO printf "to be overwritten" > copy || framework_failure -"${LZIP}" -d -o copy < "${in_lz}" 2> /dev/null -[ $? = 1 ] || test_failed $LINENO "${LZIP}" -df -o copy < "${in_lz}" || test_failed $LINENO cmp in copy || test_failed $LINENO rm -f out copy || framework_failure @@ -160,7 +165,7 @@ rm -f copy anyothername.out || framework_failure [ $? = 1 ] || test_failed $LINENO "${LZIP}" -cdq in "${in_lz}" > copy [ $? = 2 ] || test_failed $LINENO -cat copy in | cmp in - || test_failed $LINENO +cat copy in | cmp in - || test_failed $LINENO # copy must be empty "${LZIP}" -cdq nx_file.lz "${in_lz}" > copy [ $? = 1 ] || test_failed $LINENO cmp in copy || test_failed $LINENO @@ -381,7 +386,6 @@ for i in fox_v2.lz fox_s11.lz fox_de20.lz \ [ $? = 2 ] || test_failed $LINENO $i done -"${LZIP}" -cd "${fox_lz}" > fox || test_failed $LINENO for i in fox_bcrc.lz fox_crc0.lz fox_das46.lz fox_mes81.lz ; do "${LZIP}" -cdq "${testdir}"/$i > out [ $? = 2 ] || test_failed $LINENO $i From 7684d13d23d4fcefed9cd5d9d9723ef74854a27e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 20 Feb 2025 21:33:36 +0100 Subject: [PATCH 06/10] Adding upstream version 1.14. Signed-off-by: Daniel Baumann --- AUTHORS | 2 +- ChangeLog | 23 +++- INSTALL | 17 ++- Makefile.in | 7 +- NEWS | 24 ++-- README | 41 ++++--- bbexample.c | 12 +- carg_parser.c | 4 +- carg_parser.h | 4 +- cbuffer.c | 4 +- configure | 27 +++-- decoder.c | 14 +-- decoder.h | 18 +-- doc/lzlib.info | 251 +++++++++++++++++++++-------------------- doc/lzlib.texi | 270 +++++++++++++++++++++++---------------------- doc/minilzip.1 | 54 ++++----- encoder.c | 7 +- encoder.h | 2 +- encoder_base.c | 6 +- encoder_base.h | 17 ++- fast_encoder.c | 2 +- fast_encoder.h | 2 +- ffexample.c | 10 +- lzcheck.c | 57 ++++++++-- lzip.h | 48 ++++---- lzlib.c | 80 +++++++------- lzlib.h | 6 +- minilzip.c | 202 ++++++++++++++++----------------- testsuite/check.sh | 185 ++++++++++++++++--------------- 29 files changed, 744 insertions(+), 652 deletions(-) diff --git a/AUTHORS b/AUTHORS index 03a0e01..dfd16e1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,7 +1,7 @@ Lzlib was written by Antonio Diaz Diaz. The ideas embodied in lzlib are due to (at least) the following people: -Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the +Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrei Markov (for the definition of Markov chains), G.N.N. Martin (for the definition of range encoding), Igor Pavlov (for putting all the above together in LZMA), and Julian Seward (for bzip2's CLI). diff --git a/ChangeLog b/ChangeLog index 8d7da96..f178fe7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,19 @@ +2024-01-20 Antonio Diaz Diaz + + * Version 1.14 released. + * minilzip.c: Reformat file diagnostics as 'PROGRAM: FILE: MESSAGE'. + (show_option_error): New function showing argument and option name. + (main): Make -o preserve date/mode/owner if 1 input file. + * lzip.h: Rename verify_* to check_*. + * lzlib.texi: Document the need to declare uint8_t before lzlib.h. + (Reported by Michal Górny). + * configure, Makefile.in: New variable 'MAKEINFO'. + * INSTALL: Document use of CFLAGS+='--std=c99 -D_XOPEN_SOURCE=500'. + 2022-01-23 Antonio Diaz Diaz * Version 1.13 released. - * Set variables AR and ARFLAGS from configure. - (Reported by Hoël Bézier). + * configure: Set variables AR and ARFLAGS. (Reported by Hoël Bézier). * main.c: Rename to minilzip.c. * minilzip.c (getnum): Show option name and valid range if error. (check_lib): Check that LZ_API_VERSION and LZ_version_string match. @@ -29,7 +40,7 @@ Do not open output if input is a terminal. Replace 'decompressed', 'compressed' with 'out', 'in' in output. Set a valid invocation_name even if argc == 0. - * lzlib.texi: Document the new way of verifying the library version. + * lzlib.texi: Document the new way of checking the library version. Document that 'LZ_(de)compress_close' and 'LZ_(de)compress_errno' can be called with a null argument. Document that sync flush marker is not allowed in lzip files. @@ -158,8 +169,8 @@ * encoder.h, encoder.cc: Optimize pair price calculations, reducing compression time for large values of '--match-length' by up to 6%. * main.cc: New option '-F, --recompress'. - * Makefile.in: 'make install' no longer tries to run - '/sbin/ldconfig' on systems lacking it. + * Makefile.in: 'make install' no longer tries to run '/sbin/ldconfig' + on systems lacking it. 2011-01-03 Antonio Diaz Diaz @@ -248,7 +259,7 @@ * Version 0.1 released. -Copyright (C) 2009-2022 Antonio Diaz Diaz. +Copyright (C) 2009-2024 Antonio Diaz Diaz. This file is a collection of facts, and thus it is not copyrightable, but just in case, you have unlimited permission to copy, distribute, and diff --git a/INSTALL b/INSTALL index f3b0b94..275b69b 100644 --- a/INSTALL +++ b/INSTALL @@ -18,8 +18,8 @@ Procedure or lzip -cd lzlib[version].tar.lz | tar -xf - -This creates the directory ./lzlib[version] containing the source from -the main archive. +This creates the directory ./lzlib[version] containing the source code +extracted from the archive. 2. Change to lzlib directory and run configure. (Try 'configure --help' for usage instructions). @@ -27,6 +27,10 @@ the main archive. cd lzlib[version] ./configure + If you choose a C standard, enable the POSIX features explicitly: + + ./configure CFLAGS+='--std=c99 -D_XOPEN_SOURCE=500' + If you are compiling on MinGW, use: ./configure CFLAGS+='-D __USE_MINGW_ANSI_STDIO' @@ -38,7 +42,8 @@ the main archive. 4. Optionally, type 'make check' to run the tests that come with lzlib. 5. Type 'make install' to install the library and any data files and - documentation. (You may need to run ldconfig also). + documentation. You need root privileges to install into a prefix owned + by root. (You may need to run ldconfig also). Or type 'make install-compress', which additionally compresses the info manual after installation. @@ -66,15 +71,15 @@ object files and executables to go and run the 'configure' script. 'configure' automatically checks for the source code in '.', in '..', and in the directory that 'configure' is in. -'configure' recognizes the option '--srcdir=DIR' to control where to -look for the sources. Usually 'configure' can determine that directory +'configure' recognizes the option '--srcdir=DIR' to control where to look +for the source code. Usually 'configure' can determine that directory automatically. After running 'configure', you can run 'make' and 'make install' as explained above. -Copyright (C) 2009-2022 Antonio Diaz Diaz. +Copyright (C) 2009-2024 Antonio Diaz Diaz. This file is free documentation: you have unlimited permission to copy, distribute, and modify it. diff --git a/Makefile.in b/Makefile.in index 81b404b..de54626 100644 --- a/Makefile.in +++ b/Makefile.in @@ -52,6 +52,10 @@ lzlib_sh.o : lzlib.c %.o : %.c $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< +# prevent 'make' from trying to remake source files +$(VPATH)/configure $(VPATH)/Makefile.in $(VPATH)/doc/$(pkgname).texi : ; +%.h %.c : ; + lzdeps = lzlib.h lzip.h cbuffer.c decoder.h decoder.c encoder_base.h \ encoder_base.c encoder.h encoder.c fast_encoder.h fast_encoder.c @@ -64,13 +68,12 @@ bbexample.o : Makefile lzlib.h ffexample.o : Makefile lzlib.h lzcheck.o : Makefile lzlib.h - doc : info man info : $(VPATH)/doc/$(pkgname).info $(VPATH)/doc/$(pkgname).info : $(VPATH)/doc/$(pkgname).texi - cd $(VPATH)/doc && makeinfo $(pkgname).texi + cd $(VPATH)/doc && $(MAKEINFO) $(pkgname).texi man : $(VPATH)/doc/$(progname).1 diff --git a/NEWS b/NEWS index e2ceb38..101b35a 100644 --- a/NEWS +++ b/NEWS @@ -1,15 +1,19 @@ -Changes in version 1.13: +Changes in version 1.14: -The variables AR and ARFLAGS can now be set from configure. (Before you -needed to run 'make AR='. (Reported by Hoël Bézier). +In minilzip, file diagnostics have been reformatted as 'PROGRAM: FILE: MESSAGE'. -In case of error in a numerical argument to a command line option, minilzip -now shows the name of the option and the range of valid values. +In minilzip, diagnostics caused by invalid arguments to command-line options +now show the argument and the name of the option. -'minilzip --check-lib' now checks that LZ_API_VERSION and LZ_version_string -match. +The option '-o, --output' of minilzip now preserves dates, permissions, and +ownership of the file, when (de)compressing exactly one file. -Several descriptions have been improved in manual, '--help', and man page. +It has been documented in the manual that it is the responsibility of the +program using lzlib to include before 'lzlib.h' some header that declares +the type 'uint8_t'. (Reported by Michal Górny). -The texinfo category of the manual has been changed from 'Data Compression' -to 'Compression' to match that of gzip. (Reported by Alfred M. Szmidt). +The variable MAKEINFO has been added to configure and Makefile.in. + +It has been documented in INSTALL that when choosing a C standard, the POSIX +features need to be enabled explicitly: + ./configure CFLAGS+='--std=c99 -D_XOPEN_SOURCE=500' diff --git a/README b/README index 86a0cb5..7dc2950 100644 --- a/README +++ b/README @@ -34,6 +34,12 @@ are declared in the file 'lzlib.h'. Usage examples of the library are given in the files 'bbexample.c', 'ffexample.c', and 'minilzip.c' from the source distribution. +As 'lzlib.h' can be used by C and C++ programs, it must not impose a choice +of system headers on the program by including one of them. Therefore it is +the responsibility of the program using lzlib to include before 'lzlib.h' +some header that declares the type 'uint8_t'. There are at least four such +headers in C and C++: 'stdint.h', 'cstdint', 'inttypes.h', and 'cinttypes'. + All the library functions are thread safe. The library does not install any signal handler. The decoder checks the consistency of the compressed data, so the library should never crash even in case of corrupted input. @@ -44,18 +50,18 @@ This interface is safer and less error prone than the traditional zlib interface. Compression/decompression is done when the read function is called. This -means the value returned by the position functions will not be updated until -a read call, even if a lot of data are written. If you want the data to be +means the value returned by the position functions is not updated until a +read call, even if a lot of data are written. If you want the data to be compressed in advance, just call the read function with a size equal to 0. -If all the data to be compressed are written in advance, lzlib will -automatically adjust the header of the compressed data to use the largest -dictionary size that does not exceed neither the data size nor the limit -given to 'LZ_compress_open'. This feature reduces the amount of memory -needed for decompression and allows minilzip to produce identical compressed -output as lzip. +If all the data to be compressed are written in advance, lzlib automatically +adjusts the header of the compressed data to use the largest dictionary size +that does not exceed neither the data size nor the limit given to +'LZ_compress_open'. This feature reduces the amount of memory needed for +decompression and allows minilzip to produce identical compressed output as +lzip. -Lzlib will correctly decompress a data stream which is the concatenation of +Lzlib correctly decompresses a data stream which is the concatenation of two or more compressed data streams. The result is the concatenation of the corresponding decompressed data streams. Integrity testing of concatenated compressed data streams is also supported. @@ -77,13 +83,13 @@ Lzlib currently implements two variants of the LZMA algorithm: fast (used by option '-0' of minilzip) and normal (used by all other compression levels). The high compression of LZMA comes from combining two basic, well-proven -compression ideas: sliding dictionaries (LZ77/78) and markov models (the -thing used by every compression algorithm that uses a range encoder or -similar order-0 entropy coder as its last stage) with segregation of -contexts according to what the bits are used for. +compression ideas: sliding dictionaries (LZ77) and markov models (the thing +used by every compression algorithm that uses a range encoder or similar +order-0 entropy coder as its last stage) with segregation of contexts +according to what the bits are used for. The ideas embodied in lzlib are due to (at least) the following people: -Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the +Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrei Markov (for the definition of Markov chains), G.N.N. Martin (for the definition of range encoding), Igor Pavlov (for putting all the above together in LZMA), and Julian Seward (for bzip2's CLI). @@ -93,11 +99,10 @@ been compressed. Decompressed is used to refer to data which have undergone the process of decompression. -Copyright (C) 2009-2022 Antonio Diaz Diaz. +Copyright (C) 2009-2024 Antonio Diaz Diaz. This file is free documentation: you have unlimited permission to copy, distribute, and modify it. -The file Makefile.in is a data file used by configure to produce the -Makefile. It has the same copyright owner and permissions that configure -itself. +The file Makefile.in is a data file used by configure to produce the Makefile. +It has the same copyright owner and permissions that configure itself. diff --git a/bbexample.c b/bbexample.c index 074f7ae..50ccf33 100644 --- a/bbexample.c +++ b/bbexample.c @@ -1,5 +1,5 @@ /* Buffer to buffer example - Test program for the library lzlib - Copyright (C) 2010-2022 Antonio Diaz Diaz. + Copyright (C) 2010-2024 Antonio Diaz Diaz. This program is free software: you have unlimited permission to copy, distribute, and modify it. @@ -38,7 +38,7 @@ uint8_t * read_file( const char * const name, long * const file_sizep ) uint8_t * buffer, * tmp; FILE * const f = fopen( name, "rb" ); if( !f ) - { fprintf( stderr, "bbexample: Can't open input file '%s': %s\n", + { fprintf( stderr, "bbexample: %s: Can't open input file: %s\n", name, strerror( errno ) ); return 0; } buffer = (uint8_t *)malloc( buffer_size ); @@ -50,7 +50,7 @@ uint8_t * read_file( const char * const name, long * const file_sizep ) { if( buffer_size >= LONG_MAX ) { - fprintf( stderr, "bbexample: Input file '%s' is too large.\n", name ); + fprintf( stderr, "bbexample: %s: Input file is too large.\n", name ); free( buffer ); fclose( f ); return 0; } buffer_size = ( buffer_size <= LONG_MAX / 2 ) ? 2 * buffer_size : LONG_MAX; @@ -63,7 +63,7 @@ uint8_t * read_file( const char * const name, long * const file_sizep ) } if( ferror( f ) || !feof( f ) ) { - fprintf( stderr, "bbexample: Error reading file '%s': %s\n", + fprintf( stderr, "bbexample: %s: Error reading file: %s\n", name, strerror( errno ) ); free( buffer ); fclose( f ); return 0; } @@ -86,8 +86,8 @@ uint8_t * bbcompressl( const uint8_t * const inbuf, const long insize, int dictionary_size; /* 4 KiB .. 512 MiB */ int match_len_limit; /* 5 .. 273 */ }; - /* Mapping from gzip/bzip2 style 1..9 compression modes - to the corresponding LZMA compression modes. */ + /* Mapping from gzip/bzip2 style 0..9 compression levels to the + corresponding LZMA compression parameters. */ const struct Lzma_options option_mapping[] = { { 65535, 16 }, /* -0 (65535,16 chooses fast encoder) */ diff --git a/carg_parser.c b/carg_parser.c index 181ba23..edb4eb9 100644 --- a/carg_parser.c +++ b/carg_parser.c @@ -1,5 +1,5 @@ -/* Arg_parser - POSIX/GNU command line argument parser. (C version) - Copyright (C) 2006-2022 Antonio Diaz Diaz. +/* Arg_parser - POSIX/GNU command-line argument parser. (C version) + Copyright (C) 2006-2024 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/carg_parser.h b/carg_parser.h index 0c64861..69ce271 100644 --- a/carg_parser.h +++ b/carg_parser.h @@ -1,5 +1,5 @@ -/* Arg_parser - POSIX/GNU command line argument parser. (C version) - Copyright (C) 2006-2022 Antonio Diaz Diaz. +/* Arg_parser - POSIX/GNU command-line argument parser. (C version) + Copyright (C) 2006-2024 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/cbuffer.c b/cbuffer.c index 812de42..4cadc1e 100644 --- a/cbuffer.c +++ b/cbuffer.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2022 Antonio Diaz Diaz. + Copyright (C) 2009-2024 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -33,7 +33,7 @@ static inline bool Cb_init( struct Circular_buffer * const cb, cb->put = 0; cb->buffer = ( cb->buffer_size > 1 ) ? (uint8_t *)malloc( cb->buffer_size ) : 0; - return ( cb->buffer != 0 ); + return cb->buffer != 0; } static inline void Cb_free( struct Circular_buffer * const cb ) diff --git a/configure b/configure index 4060472..ec5c149 100755 --- a/configure +++ b/configure @@ -1,12 +1,12 @@ #! /bin/sh # configure script for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2022 Antonio Diaz Diaz. +# Copyright (C) 2009-2024 Antonio Diaz Diaz. # # This configure script is free software: you have unlimited permission # to copy, distribute, and modify it. pkgname=lzlib -pkgversion=1.13 +pkgversion=1.14 soversion=1 progname=minilzip progname_static=${progname} @@ -34,6 +34,7 @@ CPPFLAGS= CFLAGS='-Wall -W -O2' LDFLAGS= ARFLAGS=-rcs +MAKEINFO=makeinfo # checking whether we are using GNU C. /bin/sh -c "${CC} --version" > /dev/null 2>&1 || { CC=cc ; CFLAGS=-O2 ; } @@ -67,7 +68,7 @@ while [ $# != 0 ] ; do echo "Options and variables: [defaults in brackets]" echo " -h, --help display this help and exit" echo " -V, --version output version information and exit" - echo " --srcdir=DIR find the sources in DIR [. or ..]" + echo " --srcdir=DIR find the source code in DIR [. or ..]" 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}]" @@ -82,11 +83,12 @@ while [ $# != 0 ] ; do echo " --disable-ldconfig don't run ldconfig after install" echo " CC=COMPILER C compiler to use [${CC}]" echo " AR=ARCHIVER library archiver to use [${AR}]" - echo " CPPFLAGS=OPTIONS command line options for the preprocessor [${CPPFLAGS}]" - echo " CFLAGS=OPTIONS command line options for the C compiler [${CFLAGS}]" + echo " CPPFLAGS=OPTIONS command-line options for the preprocessor [${CPPFLAGS}]" + echo " CFLAGS=OPTIONS command-line options for the C compiler [${CFLAGS}]" echo " CFLAGS+=OPTIONS append options to the current value of CFLAGS" - echo " LDFLAGS=OPTIONS command line options for the linker [${LDFLAGS}]" - echo " ARFLAGS=OPTIONS command line options for the library archiver [${ARFLAGS}]" + echo " LDFLAGS=OPTIONS command-line options for the linker [${LDFLAGS}]" + echo " ARFLAGS=OPTIONS command-line options for the library archiver [${ARFLAGS}]" + echo " MAKEINFO=NAME makeinfo program to use [${MAKEINFO}]" echo exit 0 ;; --version | -V) @@ -128,6 +130,7 @@ while [ $# != 0 ] ; do CFLAGS+=*) CFLAGS="${CFLAGS} ${optarg}" ;; LDFLAGS=*) LDFLAGS=${optarg} ;; ARFLAGS=*) ARFLAGS=${optarg} ;; + MAKEINFO=*) MAKEINFO=${optarg} ;; --*) echo "configure: WARNING: unrecognized option: '${option}'" 1>&2 ;; @@ -147,7 +150,7 @@ while [ $# != 0 ] ; do fi done -# Find the source files, if location was not specified. +# Find the source code, if location was not specified. srcdirtext= if [ -z "${srcdir}" ] ; then srcdirtext="or . or .." ; srcdir=. @@ -159,7 +162,7 @@ if [ -z "${srcdir}" ] ; then fi if [ ! -r "${srcdir}/${srctrigger}" ] ; then - echo "configure: Can't find sources in ${srcdir} ${srcdirtext}" 1>&2 + echo "configure: Can't find source code in ${srcdir} ${srcdirtext}" 1>&2 echo "configure: (At least ${srctrigger} is missing)." 1>&2 exit 1 fi @@ -179,7 +182,7 @@ if [ -z "${no_create}" ] ; then # This script is free software: you have unlimited permission # to copy, distribute, and modify it. -exec /bin/sh $0 ${args} --no-create +exec /bin/sh "$0" ${args} --no-create EOF chmod +x config.status fi @@ -200,10 +203,11 @@ echo "CPPFLAGS = ${CPPFLAGS}" echo "CFLAGS = ${CFLAGS}" echo "LDFLAGS = ${LDFLAGS}" echo "ARFLAGS = ${ARFLAGS}" +echo "MAKEINFO = ${MAKEINFO}" rm -f Makefile cat > Makefile << EOF # Makefile for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2022 Antonio Diaz Diaz. +# Copyright (C) 2009-2024 Antonio Diaz Diaz. # This file was generated automatically by configure. Don't edit. # # This Makefile is free software: you have unlimited permission @@ -233,6 +237,7 @@ CPPFLAGS = ${CPPFLAGS} CFLAGS = ${CFLAGS} LDFLAGS = ${LDFLAGS} ARFLAGS = ${ARFLAGS} +MAKEINFO = ${MAKEINFO} EOF cat "${srcdir}/Makefile.in" >> Makefile diff --git a/decoder.c b/decoder.c index 16f6532..6544ec6 100644 --- a/decoder.c +++ b/decoder.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2022 Antonio Diaz Diaz. + Copyright (C) 2009-2024 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -17,12 +17,12 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ -static int LZd_try_verify_trailer( struct LZ_decoder * const d ) +static int LZd_try_check_trailer( struct LZ_decoder * const d ) { Lzip_trailer trailer; if( Rd_available_bytes( d->rdec ) < Lt_size ) { if( !d->rdec->at_stream_end ) return 0; else return 2; } - d->verify_trailer_pending = false; + d->check_trailer_pending = false; d->member_finished = true; if( Rd_read_data( d->rdec, trailer, Lt_size ) == Lt_size && @@ -45,7 +45,7 @@ static int LZd_decode_member( struct LZ_decoder * const d ) if( d->member_finished ) return 0; if( !Rd_try_reload( rdec ) ) { if( !rdec->at_stream_end ) return 0; else return 2; } - if( d->verify_trailer_pending ) return LZd_try_verify_trailer( d ); + if( d->check_trailer_pending ) return LZd_try_check_trailer( d ); while( !Rd_finished( rdec ) ) { @@ -121,14 +121,14 @@ static int LZd_decode_member( struct LZ_decoder * const d ) old_mpos = mpos; */ if( len == min_match_len ) /* End Of Stream marker */ { - d->verify_trailer_pending = true; - return LZd_try_verify_trailer( d ); + d->check_trailer_pending = true; + return LZd_try_check_trailer( d ); } if( len == min_match_len + 1 ) /* Sync Flush marker */ { rdec->reload_pending = true; if( Rd_try_reload( rdec ) ) continue; - else { if( !rdec->at_stream_end ) return 0; else break; } + if( !rdec->at_stream_end ) return 0; else break; } return 4; } diff --git a/decoder.h b/decoder.h index 27de9cb..4b91fec 100644 --- a/decoder.h +++ b/decoder.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2022 Antonio Diaz Diaz. + Copyright (C) 2009-2024 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -50,7 +50,7 @@ static inline void Rd_finish( struct Range_decoder * const rdec ) { rdec->at_stream_end = true; } static inline bool Rd_enough_available_bytes( const struct Range_decoder * const rdec ) - { return ( Cb_used_bytes( &rdec->cb ) >= rd_min_available_bytes ); } + { return Cb_used_bytes( &rdec->cb ) >= rd_min_available_bytes; } static inline unsigned Rd_available_bytes( const struct Range_decoder * const rdec ) { return Cb_used_bytes( &rdec->cb ); } @@ -92,7 +92,7 @@ static bool Rd_find_header( struct Range_decoder * const rdec, header[i] = rdec->cb.buffer[get]; if( ++get >= rdec->cb.buffer_size ) get = 0; } - if( Lh_verify( header ) ) return true; + if( Lh_check( header ) ) return true; } if( ++rdec->cb.get >= rdec->cb.buffer_size ) rdec->cb.get = 0; ++*skippedp; @@ -137,12 +137,12 @@ static bool Rd_try_reload( struct Range_decoder * const rdec ) { if( rdec->reload_pending && Rd_available_bytes( rdec ) >= 5 ) { - int i; rdec->reload_pending = false; rdec->code = 0; - for( i = 0; i < 5; ++i ) rdec->code = (rdec->code << 8) | Rd_get_byte( rdec ); rdec->range = 0xFFFFFFFFU; - rdec->code &= rdec->range; /* make sure that first byte is discarded */ + Rd_get_byte( rdec ); /* discard first byte of the LZMA stream */ + int i; for( i = 0; i < 4; ++i ) + rdec->code = (rdec->code << 8) | Rd_get_byte( rdec ); } return !rdec->reload_pending; } @@ -334,8 +334,8 @@ struct LZ_decoder struct Range_decoder * rdec; unsigned dictionary_size; uint32_t crc; + bool check_trailer_pending; bool member_finished; - bool verify_trailer_pending; bool pos_wrapped; unsigned rep0; /* rep[0-3] latest four distances */ unsigned rep1; /* used for efficient coding of */ @@ -423,8 +423,8 @@ static inline bool LZd_init( struct LZ_decoder * const d, d->rdec = rde; d->dictionary_size = dict_size; d->crc = 0xFFFFFFFFU; + d->check_trailer_pending = false; d->member_finished = false; - d->verify_trailer_pending = false; d->pos_wrapped = false; /* prev_byte of first byte; also for LZd_peek( 0 ) on corrupt file */ d->cb.buffer[d->cb.buffer_size-1] = 0; @@ -453,7 +453,7 @@ static inline void LZd_free( struct LZ_decoder * const d ) { Cb_free( &d->cb ); } static inline bool LZd_member_finished( const struct LZ_decoder * const d ) - { return ( d->member_finished && Cb_empty( &d->cb ) ); } + { return d->member_finished && Cb_empty( &d->cb ); } static inline unsigned LZd_crc( const struct LZ_decoder * const d ) { return d->crc ^ 0xFFFFFFFFU; } diff --git a/doc/lzlib.info b/doc/lzlib.info index d81bc88..979c477 100644 --- a/doc/lzlib.info +++ b/doc/lzlib.info @@ -11,7 +11,7 @@ File: lzlib.info, Node: Top, Next: Introduction, Up: (dir) Lzlib Manual ************ -This manual is for Lzlib (version 1.13, 23 January 2022). +This manual is for Lzlib (version 1.14, 20 January 2024). * Menu: @@ -23,14 +23,14 @@ This manual is for Lzlib (version 1.13, 23 January 2022). * Decompression functions:: Descriptions of the decompression functions * Error codes:: Meaning of codes returned by functions * Error messages:: Error messages corresponding to error codes -* Invoking minilzip:: Command line interface of the test program +* Invoking minilzip:: Command-line interface of the test program * Data format:: Detailed format of the compressed data * Examples:: A small tutorial with examples * Problems:: Reporting bugs * Concept index:: Index of concepts - Copyright (C) 2009-2022 Antonio Diaz Diaz. + Copyright (C) 2009-2024 Antonio Diaz Diaz. This manual is free documentation: you have unlimited permission to copy, distribute, and modify it. @@ -76,6 +76,13 @@ library are declared in the file 'lzlib.h'. Usage examples of the library are given in the files 'bbexample.c', 'ffexample.c', and 'minilzip.c' from the source distribution. + As 'lzlib.h' can be used by C and C++ programs, it must not impose a +choice of system headers on the program by including one of them. Therefore +it is the responsibility of the program using lzlib to include before +'lzlib.h' some header that declares the type 'uint8_t'. There are at least +four such headers in C and C++: 'stdint.h', 'cstdint', 'inttypes.h', and +'cinttypes'. + All the library functions are thread safe. The library does not install any signal handler. The decoder checks the consistency of the compressed data, so the library should never crash even in case of corrupted input. @@ -86,21 +93,21 @@ This interface is safer and less error prone than the traditional zlib interface. Compression/decompression is done when the read function is called. This -means the value returned by the position functions will not be updated until -a read call, even if a lot of data are written. If you want the data to be +means the value returned by the position functions is not updated until a +read call, even if a lot of data are written. If you want the data to be compressed in advance, just call the read function with a SIZE equal to 0. - If all the data to be compressed are written in advance, lzlib will -automatically adjust the header of the compressed data to use the largest + If all the data to be compressed are written in advance, lzlib +automatically adjusts the header of the compressed data to use the largest dictionary size that does not exceed neither the data size nor the limit given to 'LZ_compress_open'. This feature reduces the amount of memory -needed for decompression and allows minilzip to produce identical compressed -output as lzip. +needed for decompression and allows minilzip to produce identical +compressed output as lzip. - Lzlib will correctly decompress a data stream which is the concatenation -of two or more compressed data streams. The result is the concatenation of -the corresponding decompressed data streams. Integrity testing of -concatenated compressed data streams is also supported. + Lzlib correctly decompresses a data stream which is the concatenation of +two or more compressed data streams. The result is the concatenation of the +corresponding decompressed data streams. Integrity testing of concatenated +compressed data streams is also supported. Lzlib is able to compress and decompress streams of unlimited size by automatically creating multimember output. The members so created are large, @@ -111,22 +118,22 @@ concrete algorithm; it is more like "any algorithm using the LZMA coding scheme". For example, the option '-0' of lzip uses the scheme in almost the simplest way possible; issuing the longest match it can find, or a literal byte if it can't find a match. Inversely, a much more elaborated way of -finding coding sequences of minimum size than the one currently used by lzip -could be developed, and the resulting sequence could also be coded using the -LZMA coding scheme. +finding coding sequences of minimum size than the one currently used by +lzip could be developed, and the resulting sequence could also be coded +using the LZMA coding scheme. Lzlib currently implements two variants of the LZMA algorithm: fast (used by option '-0' of minilzip) and normal (used by all other compression levels). The high compression of LZMA comes from combining two basic, well-proven -compression ideas: sliding dictionaries (LZ77/78) and markov models (the -thing used by every compression algorithm that uses a range encoder or -similar order-0 entropy coder as its last stage) with segregation of -contexts according to what the bits are used for. +compression ideas: sliding dictionaries (LZ77) and markov models (the thing +used by every compression algorithm that uses a range encoder or similar +order-0 entropy coder as its last stage) with segregation of contexts +according to what the bits are used for. The ideas embodied in lzlib are due to (at least) the following people: -Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the +Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrei Markov (for the definition of Markov chains), G.N.N. Martin (for the definition of range encoding), Igor Pavlov (for putting all the above together in LZMA), and Julian Seward (for bzip2's CLI). @@ -150,7 +157,7 @@ of them are declared in 'lzlib.h'. -- Constant: LZ_API_VERSION This constant is defined in 'lzlib.h' and works as a version test - macro. The application should verify at compile time that + macro. The application should check at compile time that LZ_API_VERSION is greater than or equal to the version required by the application: @@ -170,12 +177,13 @@ desire to have certain symbols and prototypes exposed. -- Function: int LZ_api_version ( void ) If LZ_API_VERSION >= 1012, this function is declared in 'lzlib.h' (else it doesn't exist). It returns the LZ_API_VERSION of the library object - code being used. The application should verify at run time that the + code being used. The application should check at run time that the value returned by 'LZ_api_version' is greater than or equal to the - version required by the application. An application may be dinamically + version required by the application. An application may be dynamically linked at run time with a different version of lzlib than the one it - was compiled for, and this should not break the program as long as the - library used provides the functionality required by the application. + was compiled for, and this should not break the application as long as + the library used provides the functionality required by the + application. #if defined LZ_API_VERSION && LZ_API_VERSION >= 1012 if( LZ_api_version() < 1012 ) @@ -258,7 +266,7 @@ File: lzlib.info, Node: Compression functions, Next: Decompression functions, These are the functions used to compress data. In case of error, all of them return -1 or 0, for signed and unsigned return values respectively, -except 'LZ_compress_open' whose return value must be verified by calling +except 'LZ_compress_open' whose return value must be checked by calling 'LZ_compress_errno' before using it. -- Function: struct LZ_Encoder * LZ_compress_open ( const int @@ -269,7 +277,7 @@ except 'LZ_compress_open' whose return value must be verified by calling LZ_compress functions, or a null pointer if the encoder could not be allocated. - The returned pointer must be verified by calling 'LZ_compress_errno' + The returned pointer must be checked by calling 'LZ_compress_errno' before using it. If 'LZ_compress_errno' does not return 'LZ_ok', the returned pointer must not be used and should be freed with 'LZ_compress_close' to avoid memory leaks. @@ -277,8 +285,8 @@ except 'LZ_compress_open' whose return value must be verified by calling DICTIONARY_SIZE sets the dictionary size to be used, in bytes. Valid values range from 4 KiB to 512 MiB. Note that dictionary sizes are quantized. If the size specified does not match one of the valid - sizes, it will be rounded upwards by adding up to - (DICTIONARY_SIZE / 8) to it. + sizes, it is rounded upwards by adding up to (DICTIONARY_SIZE / 8) to + it. MATCH_LEN_LIMIT sets the match length limit in bytes. Valid values range from 5 to 273. Larger values usually give better compression @@ -286,15 +294,14 @@ except 'LZ_compress_open' whose return value must be verified by calling If DICTIONARY_SIZE is 65535 and MATCH_LEN_LIMIT is 16, the fast variant of LZMA is chosen, which produces identical compressed output - as 'lzip -0'. (The dictionary size used will be rounded upwards to - 64 KiB). + as 'lzip -0'. (The dictionary size used is rounded upwards to 64 KiB). MEMBER_SIZE sets the member size limit in bytes. Valid values range from 4 KiB to 2 PiB. A small member size may degrade compression ratio, so use it only when needed. To produce a single-member data stream, give MEMBER_SIZE a value larger than the amount of data to be - produced. Values larger than 2 PiB will be reduced to 2 PiB to prevent - the uncompressed size of the member from overflowing. + produced. Values larger than 2 PiB are reduced to 2 PiB to prevent the + uncompressed size of the member from overflowing. -- Function: int LZ_compress_close ( struct LZ_Encoder * const ENCODER ) Frees all dynamically allocated data structures for this stream. This @@ -420,7 +427,7 @@ File: lzlib.info, Node: Decompression functions, Next: Error codes, Prev: Com These are the functions used to decompress data. In case of error, all of them return -1 or 0, for signed and unsigned return values respectively, -except 'LZ_decompress_open' whose return value must be verified by calling +except 'LZ_decompress_open' whose return value must be checked by calling 'LZ_decompress_errno' before using it. -- Function: struct LZ_Decoder * LZ_decompress_open ( void ) @@ -429,7 +436,7 @@ except 'LZ_decompress_open' whose return value must be verified by calling LZ_decompress functions, or a null pointer if the decoder could not be allocated. - The returned pointer must be verified by calling 'LZ_decompress_errno' + The returned pointer must be checked by calling 'LZ_decompress_errno' before using it. If 'LZ_decompress_errno' does not return 'LZ_ok', the returned pointer must not be used and should be freed with 'LZ_decompress_close' to avoid memory leaks. @@ -459,13 +466,13 @@ except 'LZ_decompress_open' whose return value must be verified by calling Resets the error state of DECODER and enters a search state that lasts until a new member header (or the end of the stream) is found. After a successful call to 'LZ_decompress_sync_to_member', data written with - 'LZ_decompress_write' will be consumed and 'LZ_decompress_read' will - return 0 until a header is found. + 'LZ_decompress_write' is consumed and 'LZ_decompress_read' returns 0 + until a header is found. - This function is useful to discard any data preceding the first member, - or to discard the rest of the current member, for example in case of a - data error. If the decoder is already at the beginning of a member, - this function does nothing. + This function is useful to discard any data preceding the first + member, or to discard the rest of the current member, for example in + case of a data error. If the decoder is already at the beginning of a + member, this function does nothing. -- Function: int LZ_decompress_read ( struct LZ_Decoder * const DECODER, uint8_t * const BUFFER, const int SIZE ) @@ -571,7 +578,7 @@ File: lzlib.info, Node: Error codes, Next: Error messages, Prev: Decompressio Most library functions return -1 to indicate that they have failed. But this return value only tells you that an error has occurred. To find out -what kind of error it was, you need to verify the error code by calling +what kind of error it was, you need to check the error code by calling 'LZ_(de)compress_errno'. Library functions don't change the value returned by @@ -639,19 +646,20 @@ File: lzlib.info, Node: Invoking minilzip, Next: Data format, Prev: Error mes 9 Invoking minilzip ******************* -Minilzip is a test program for the compression library lzlib, fully -compatible with lzip 1.4 or newer. +Minilzip is a test program for the compression library lzlib, compatible +with lzip 1.4 or newer. Lzip is a lossless data compressor with a user interface similar to the one of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov -chain-Algorithm' (LZMA) stream format and provides a 3 factor integrity -checking to maximize interoperability and optimize safety. Lzip can compress -about as fast as gzip (lzip -0) or compress most files more than bzip2 -(lzip -9). Decompression speed is intermediate between gzip and bzip2. Lzip -is better than gzip and bzip2 from a data recovery perspective. Lzip has -been designed, written, and tested with great care to replace gzip and -bzip2 as the standard general-purpose compressed format for unix-like -systems. +chain-Algorithm' (LZMA) stream format to maximize interoperability. The +maximum dictionary size is 512 MiB so that any lzip file can be decompressed +on 32-bit machines. Lzip provides accurate and robust 3-factor integrity +checking. Lzip can compress about as fast as gzip (lzip -0) or compress most +files more than bzip2 (lzip -9). Decompression speed is intermediate between +gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery +perspective. Lzip has been designed, written, and tested with great care to +replace gzip and bzip2 as the standard general-purpose compressed format for +Unix-like systems. The format for running minilzip is: @@ -660,7 +668,8 @@ The format for running minilzip is: If no file names are specified, minilzip compresses (or decompresses) from standard input to standard output. A hyphen '-' used as a FILE argument means standard input. It can be mixed with other FILES and is read just -once, the first time it appears in the command line. +once, the first time it appears in the command line. Remember to prepend +'./' to any file name beginning with a hyphen, or use '--'. minilzip supports the following options: *Note Argument syntax: (arg_parser)Argument syntax. @@ -696,17 +705,18 @@ once, the first time it appears in the command line. members). This option (or '-o') is needed when reading from a named pipe (fifo) or from a device. Use it also to recover as much of the decompressed data as possible when decompressing a corrupt file. '-c' - overrides '-o' and '-S'. '-c' has no effect when testing or listing. + overrides '-o' and '-S'. '-c' has no effect when testing. '-d' '--decompress' - Decompress the files specified. If a file does not exist, can't be - opened, or the destination file already exists and '--force' has not - been specified, minilzip continues decompressing the rest of the files - and exits with error status 1. If a file fails to decompress, or is a - terminal, minilzip exits immediately with error status 2 without - decompressing the rest of the files. A terminal is considered an - uncompressed file, and therefore invalid. + Decompress the files specified. The integrity of the files specified is + checked. If a file does not exist, can't be opened, or the destination + file already exists and '--force' has not been specified, minilzip + continues decompressing the rest of the files and exits with error + status 1. If a file fails to decompress, or is a terminal, minilzip + exits immediately with error status 2 without decompressing the rest + of the files. A terminal is considered an uncompressed file, and + therefore invalid. '-f' '--force' @@ -725,17 +735,17 @@ once, the first time it appears in the command line. '--match-length=BYTES' When compressing, set the match length limit in bytes. After a match this long is found, the search is finished. Valid values range from 5 - to 273. Larger values usually give better compression ratios but longer - compression times. + to 273. Larger values usually give better compression ratios but + longer compression times. '-o FILE' '--output=FILE' - If '-c' has not been also specified, write the (de)compressed output to - FILE; keep input files unchanged. If compressing several files, each - file is compressed independently. (The output consists of a sequence of - independently compressed members). This option (or '-c') is needed when - reading from a named pipe (fifo) or from a device. '-o -' is - equivalent to '-c'. '-o' has no effect when testing or listing. + If '-c' has not been also specified, write the (de)compressed output + to FILE; keep input files unchanged. If compressing several files, + each file is compressed independently. (The output consists of a + sequence of independently compressed members). This option (or '-c') + is needed when reading from a named pipe (fifo) or from a device. + '-o -' is equivalent to '-c'. '-o' has no effect when testing. When compressing and splitting the output in volumes, FILE is used as a prefix, and several files named 'FILE00001.lz', 'FILE00002.lz', etc, @@ -748,13 +758,13 @@ once, the first time it appears in the command line. '-s BYTES' '--dictionary-size=BYTES' When compressing, set the dictionary size limit in bytes. Minilzip - will use for each file the largest dictionary size that does not - exceed neither the file size nor this limit. Valid values range from - 4 KiB to 512 MiB. Values 12 to 29 are interpreted as powers of two, - meaning 2^12 to 2^29 bytes. Dictionary sizes are quantized so that - they can be coded in just one byte (*note coded-dict-size::). If the - size specified does not match one of the valid sizes, it will be - rounded upwards by adding up to (BYTES / 8) to it. + uses for each file the largest dictionary size that does not exceed + neither the file size nor this limit. Valid values range from 4 KiB to + 512 MiB. Values 12 to 29 are interpreted as powers of two, meaning + 2^12 to 2^29 bytes. Dictionary sizes are quantized so that they can be + coded in just one byte (*note coded-dict-size::). If the size + specified does not match one of the valid sizes, it is rounded upwards + by adding up to (BYTES / 8) to it. For maximum compression you should use a dictionary size limit as large as possible, but keep in mind that the decompression memory requirement @@ -776,7 +786,7 @@ once, the first time it appears in the command line. really performs a trial decompression and throws away the result. Use it together with '-v' to see information about the files. If a file fails the test, does not exist, can't be opened, or is a terminal, - minilzip continues checking the rest of the files. A final diagnostic + minilzip continues testing the rest of the files. A final diagnostic is shown at verbosity level 1 or higher if any file fails the test when testing multiple files. @@ -839,26 +849,29 @@ once, the first time it appears in the command line. defined). *Note Library version::. - Numbers given as arguments to options may be followed by a multiplier -and an optional 'B' for "byte". + Numbers given as arguments to options may be expressed in decimal, +hexadecimal, or octal (using the same syntax as integer constants in C++), +and may be followed by a multiplier and an optional 'B' for "byte". Table of SI and binary prefixes (unit multipliers): -Prefix Value | Prefix Value -k kilobyte (10^3 = 1000) | Ki kibibyte (2^10 = 1024) -M megabyte (10^6) | Mi mebibyte (2^20) -G gigabyte (10^9) | Gi gibibyte (2^30) -T terabyte (10^12) | Ti tebibyte (2^40) -P petabyte (10^15) | Pi pebibyte (2^50) -E exabyte (10^18) | Ei exbibyte (2^60) -Z zettabyte (10^21) | Zi zebibyte (2^70) -Y yottabyte (10^24) | Yi yobibyte (2^80) +Prefix Value | Prefix Value +k kilobyte (10^3 = 1000) | Ki kibibyte (2^10 = 1024) +M megabyte (10^6) | Mi mebibyte (2^20) +G gigabyte (10^9) | Gi gibibyte (2^30) +T terabyte (10^12) | Ti tebibyte (2^40) +P petabyte (10^15) | Pi pebibyte (2^50) +E exabyte (10^18) | Ei exbibyte (2^60) +Z zettabyte (10^21) | Zi zebibyte (2^70) +Y yottabyte (10^24) | Yi yobibyte (2^80) +R ronnabyte (10^27) | Ri robibyte (2^90) +Q quettabyte (10^30) | Qi quebibyte (2^100) Exit status: 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 (e.g., bug) which caused -minilzip to panic. +found, invalid command-line options, I/O errors, etc), 2 to indicate a +corrupt or invalid input file, 3 for an internal consistency error (e.g., +bug) which caused minilzip to panic.  File: lzlib.info, Node: Data format, Next: Examples, Prev: Invoking minilzip, Up: Top @@ -886,7 +899,7 @@ when there is no longer anything to take away. represents a variable number of bytes. - Lzip data consist of a series of independent "members" (compressed data + Lzip data consist of one or more independent "members" (compressed data sets). The members simply appear one after another in the data stream, with no additional information before, between, or after them. Each member can encode in compressed form up to 16 EiB - 1 byte of uncompressed data. The @@ -933,10 +946,10 @@ size of a multimember data stream is unlimited. 'Member size (8 bytes)' Total size of the member, including header and trailer. This field acts - as a distributed index, allows the verification of stream integrity, - and facilitates the safe recovery of undamaged members from - multimember files. Member size should be limited to 2 PiB to prevent - the data size field from overflowing. + as a distributed index, improves the checking of stream integrity, and + facilitates the safe recovery of undamaged members from multimember + files. Lzip limits the member size to 2 PiB to prevent the data size + field from overflowing.  @@ -1234,7 +1247,7 @@ int ffrsdecompress( struct LZ_Decoder * const decoder, if( LZ_decompress_errno( decoder ) == LZ_header_error || LZ_decompress_errno( decoder ) == LZ_data_error ) { LZ_decompress_sync_to_member( decoder ); continue; } - else break; + break; } len = fwrite( buffer, 1, ret, outfile ); if( len < ret ) break; @@ -1293,27 +1306,27 @@ Concept index Tag Table: Node: Top215 Node: Introduction1338 -Node: Library version6413 -Node: Buffering8957 -Node: Parameter limits10182 -Node: Compression functions11136 -Ref: member_size12946 -Ref: sync_flush14712 -Node: Decompression functions19400 -Node: Error codes26968 -Node: Error messages29259 -Node: Invoking minilzip29838 -Node: Data format39786 -Ref: coded-dict-size41232 -Node: Examples42641 -Node: Buffer compression43602 -Node: Buffer decompression45122 -Node: File compression46536 -Node: File decompression47519 -Node: File compression mm48523 -Node: Skipping data errors51552 -Node: Problems52862 -Node: Concept index53423 +Node: Library version6778 +Node: Buffering9329 +Node: Parameter limits10554 +Node: Compression functions11508 +Ref: member_size13301 +Ref: sync_flush15063 +Node: Decompression functions19751 +Node: Error codes27308 +Node: Error messages29598 +Node: Invoking minilzip30177 +Node: Data format40595 +Ref: coded-dict-size42041 +Node: Examples43446 +Node: Buffer compression44407 +Node: Buffer decompression45927 +Node: File compression47341 +Node: File decompression48324 +Node: File compression mm49328 +Node: Skipping data errors52357 +Node: Problems53662 +Node: Concept index54223  End Tag Table diff --git a/doc/lzlib.texi b/doc/lzlib.texi index 3caf9dd..75cb7ba 100644 --- a/doc/lzlib.texi +++ b/doc/lzlib.texi @@ -6,8 +6,8 @@ @finalout @c %**end of header -@set UPDATED 23 January 2022 -@set VERSION 1.13 +@set UPDATED 20 January 2024 +@set VERSION 1.14 @dircategory Compression @direntry @@ -44,7 +44,7 @@ This manual is for Lzlib (version @value{VERSION}, @value{UPDATED}). * Decompression functions:: Descriptions of the decompression functions * Error codes:: Meaning of codes returned by functions * Error messages:: Error messages corresponding to error codes -* Invoking minilzip:: Command line interface of the test program +* Invoking minilzip:: Command-line interface of the test program * Data format:: Detailed format of the compressed data * Examples:: A small tutorial with examples * Problems:: Reporting bugs @@ -52,7 +52,7 @@ This manual is for Lzlib (version @value{VERSION}, @value{UPDATED}). @end menu @sp 1 -Copyright @copyright{} 2009-2022 Antonio Diaz Diaz. +Copyright @copyright{} 2009-2024 Antonio Diaz Diaz. This manual is free documentation: you have unlimited permission to copy, distribute, and modify it. @@ -107,6 +107,13 @@ are declared in the file @samp{lzlib.h}. Usage examples of the library are given in the files @samp{bbexample.c}, @samp{ffexample.c}, and @samp{minilzip.c} from the source distribution. +As @samp{lzlib.h} can be used by C and C++ programs, it must not impose a +choice of system headers on the program by including one of them. Therefore +it is the responsibility of the program using lzlib to include before +@samp{lzlib.h} some header that declares the type @samp{uint8_t}. There are +at least four such headers in C and C++: @samp{stdint.h}, @samp{cstdint}, +@samp{inttypes.h}, and @samp{cinttypes}. + All the library functions are thread safe. The library does not install any signal handler. The decoder checks the consistency of the compressed data, so the library should never crash even in case of corrupted input. @@ -117,19 +124,19 @@ This interface is safer and less error prone than the traditional zlib interface. Compression/decompression is done when the read function is called. This -means the value returned by the position functions will not be updated until -a read call, even if a lot of data are written. If you want the data to be +means the value returned by the position functions is not updated until a +read call, even if a lot of data are written. If you want the data to be compressed in advance, just call the read function with a @var{size} equal to 0. -If all the data to be compressed are written in advance, lzlib will -automatically adjust the header of the compressed data to use the largest -dictionary size that does not exceed neither the data size nor the limit -given to @samp{LZ_compress_open}. This feature reduces the amount of memory -needed for decompression and allows minilzip to produce identical compressed -output as lzip. +If all the data to be compressed are written in advance, lzlib automatically +adjusts the header of the compressed data to use the largest dictionary size +that does not exceed neither the data size nor the limit given to +@samp{LZ_compress_open}. This feature reduces the amount of memory needed for +decompression and allows minilzip to produce identical compressed output as +lzip. -Lzlib will correctly decompress a data stream which is the concatenation of +Lzlib correctly decompresses a data stream which is the concatenation of two or more compressed data streams. The result is the concatenation of the corresponding decompressed data streams. Integrity testing of concatenated compressed data streams is also supported. @@ -140,24 +147,24 @@ about @w{2 PiB} each. In spite of its name (Lempel-Ziv-Markov chain-Algorithm), LZMA is not a concrete algorithm; it is more like "any algorithm using the LZMA coding -scheme". For example, the option @samp{-0} of lzip uses the scheme in almost the -simplest way possible; issuing the longest match it can find, or a literal -byte if it can't find a match. Inversely, a much more elaborated way of -finding coding sequences of minimum size than the one currently used by lzip -could be developed, and the resulting sequence could also be coded using the -LZMA coding scheme. +scheme". For example, the option @option{-0} of lzip uses the scheme in +almost the simplest way possible; issuing the longest match it can find, or +a literal byte if it can't find a match. Inversely, a much more elaborated +way of finding coding sequences of minimum size than the one currently used +by lzip could be developed, and the resulting sequence could also be coded +using the LZMA coding scheme. Lzlib currently implements two variants of the LZMA algorithm: fast (used by -option @samp{-0} of minilzip) and normal (used by all other compression levels). +option @option{-0} of minilzip) and normal (used by all other compression levels). The high compression of LZMA comes from combining two basic, well-proven -compression ideas: sliding dictionaries (LZ77/78) and markov models (the -thing used by every compression algorithm that uses a range encoder or -similar order-0 entropy coder as its last stage) with segregation of -contexts according to what the bits are used for. +compression ideas: sliding dictionaries (LZ77) and markov models (the thing +used by every compression algorithm that uses a range encoder or similar +order-0 entropy coder as its last stage) with segregation of contexts +according to what the bits are used for. The ideas embodied in lzlib are due to (at least) the following people: -Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the +Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrei Markov (for the definition of Markov chains), G.N.N. Martin (for the definition of range encoding), Igor Pavlov (for putting all the above together in LZMA), and Julian Seward (for bzip2's CLI). @@ -180,7 +187,7 @@ of them are declared in @samp{lzlib.h}. @defvr Constant LZ_API_VERSION This constant is defined in @samp{lzlib.h} and works as a version test -macro. The application should verify at compile time that LZ_API_VERSION is +macro. The application should check at compile time that LZ_API_VERSION is greater than or equal to the version required by the application: @example @@ -202,12 +209,12 @@ certain symbols and prototypes exposed. @deftypefun int LZ_api_version ( void ) If LZ_API_VERSION >= 1012, this function is declared in @samp{lzlib.h} (else it doesn't exist). It returns the LZ_API_VERSION of the library object code -being used. The application should verify at run time that the value +being used. The application should check at run time that the value returned by @code{LZ_api_version} is greater than or equal to the version -required by the application. An application may be dinamically linked at run +required by the application. An application may be dynamically linked at run time with a different version of lzlib than the one it was compiled for, and -this should not break the program as long as the library used provides the -functionality required by the application. +this should not break the application as long as the library used provides +the functionality required by the application. @example #if defined LZ_API_VERSION && LZ_API_VERSION >= 1012 @@ -297,7 +304,7 @@ Returns the largest valid match length limit [273]. These are the functions used to compress data. In case of error, all of them return -1 or 0, for signed and unsigned return values respectively, -except @samp{LZ_compress_open} whose return value must be verified by +except @samp{LZ_compress_open} whose return value must be checked by calling @samp{LZ_compress_errno} before using it. @@ -307,15 +314,15 @@ pointer that can only be used as the @var{encoder} argument for the other LZ_compress functions, or a null pointer if the encoder could not be allocated. -The returned pointer must be verified by calling -@samp{LZ_compress_errno} before using it. If @samp{LZ_compress_errno} -does not return @samp{LZ_ok}, the returned pointer must not be used and -should be freed with @samp{LZ_compress_close} to avoid memory leaks. +The returned pointer must be checked by calling @samp{LZ_compress_errno} +before using it. If @samp{LZ_compress_errno} does not return @samp{LZ_ok}, +the returned pointer must not be used and should be freed with +@samp{LZ_compress_close} to avoid memory leaks. @var{dictionary_size} sets the dictionary size to be used, in bytes. Valid values range from @w{4 KiB} to @w{512 MiB}. Note that dictionary sizes are quantized. If the size specified does not match one of the -valid sizes, it will be rounded upwards by adding up to +valid sizes, it is rounded upwards by adding up to @w{(@var{dictionary_size} / 8)} to it. @var{match_len_limit} sets the match length limit in bytes. Valid values @@ -324,7 +331,7 @@ but longer compression times. If @var{dictionary_size} is 65535 and @var{match_len_limit} is 16, the fast variant of LZMA is chosen, which produces identical compressed output as -@w{@samp{lzip -0}}. (The dictionary size used will be rounded upwards to +@w{@samp{lzip -0}}. (The dictionary size used is rounded upwards to @w{64 KiB}). @anchor{member_size} @@ -332,8 +339,8 @@ variant of LZMA is chosen, which produces identical compressed output as from @w{4 KiB} to @w{2 PiB}. A small member size may degrade compression ratio, so use it only when needed. To produce a single-member data stream, give @var{member_size} a value larger than the amount of data to be -produced. Values larger than @w{2 PiB} will be reduced to @w{2 PiB} to -prevent the uncompressed size of the member from overflowing. +produced. Values larger than @w{2 PiB} are reduced to @w{2 PiB} to prevent +the uncompressed size of the member from overflowing. @end deftypefun @@ -478,20 +485,19 @@ perhaps not yet read. These are the functions used to decompress data. In case of error, all of them return -1 or 0, for signed and unsigned return values respectively, -except @samp{LZ_decompress_open} whose return value must be verified by +except @samp{LZ_decompress_open} whose return value must be checked by calling @samp{LZ_decompress_errno} before using it. @deftypefun {struct LZ_Decoder *} LZ_decompress_open ( void ) Initializes the internal stream state for decompression and returns a -pointer that can only be used as the @var{decoder} argument for the -other LZ_decompress functions, or a null pointer if the decoder could -not be allocated. +pointer that can only be used as the @var{decoder} argument for the other +LZ_decompress functions, or a null pointer if the decoder could not be +allocated. -The returned pointer must be verified by calling -@samp{LZ_decompress_errno} before using it. If -@samp{LZ_decompress_errno} does not return @samp{LZ_ok}, the returned -pointer must not be used and should be freed with +The returned pointer must be checked by calling @samp{LZ_decompress_errno} +before using it. If @samp{LZ_decompress_errno} does not return @samp{LZ_ok}, +the returned pointer must not be used and should be freed with @samp{LZ_decompress_close} to avoid memory leaks. @end deftypefun @@ -523,16 +529,16 @@ internal buffers is discarded. Position counters are set to 0. @deftypefun int LZ_decompress_sync_to_member ( struct LZ_Decoder * const @var{decoder} ) -Resets the error state of @var{decoder} and enters a search state that -lasts until a new member header (or the end of the stream) is found. -After a successful call to @samp{LZ_decompress_sync_to_member}, data -written with @samp{LZ_decompress_write} will be consumed and -@samp{LZ_decompress_read} will return 0 until a header is found. +Resets the error state of @var{decoder} and enters a search state that lasts +until a new member header (or the end of the stream) is found. After a +successful call to @samp{LZ_decompress_sync_to_member}, data written with +@samp{LZ_decompress_write} is consumed and @samp{LZ_decompress_read} returns +0 until a header is found. -This function is useful to discard any data preceding the first member, -or to discard the rest of the current member, for example in case of a -data error. If the decoder is already at the beginning of a member, this -function does nothing. +This function is useful to discard any data preceding the first member, or +to discard the rest of the current member, for example in case of a data +error. If the decoder is already at the beginning of a member, this function +does nothing. @end deftypefun @@ -654,7 +660,7 @@ perhaps not yet read. Most library functions return -1 to indicate that they have failed. But this return value only tells you that an error has occurred. To find out -what kind of error it was, you need to verify the error code by calling +what kind of error it was, you need to check the error code by calling @samp{LZ_(de)compress_errno}. Library functions don't change the value returned by @@ -728,20 +734,21 @@ The value of @var{lz_errno} normally comes from a call to @cindex invoking @cindex options -Minilzip is a test program for the compression library lzlib, fully -compatible with lzip 1.4 or newer. +Minilzip is a test program for the compression library lzlib, compatible +with lzip 1.4 or newer. @uref{http://www.nongnu.org/lzip/lzip.html,,Lzip} is a lossless data compressor with a user interface similar to the one of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov -chain-Algorithm' (LZMA) stream format and provides a 3 factor integrity -checking to maximize interoperability and optimize safety. Lzip can compress -about as fast as gzip @w{(lzip -0)} or compress most files more than bzip2 -@w{(lzip -9)}. Decompression speed is intermediate between gzip and bzip2. -Lzip is better than gzip and bzip2 from a data recovery perspective. Lzip -has been designed, written, and tested with great care to replace gzip and -bzip2 as the standard general-purpose compressed format for unix-like -systems. +chain-Algorithm' (LZMA) stream format to maximize interoperability. The +maximum dictionary size is 512 MiB so that any lzip file can be decompressed +on 32-bit machines. Lzip provides accurate and robust 3-factor integrity +checking. Lzip can compress about as fast as gzip @w{(lzip -0)} or compress most +files more than bzip2 @w{(lzip -9)}. Decompression speed is intermediate between +gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery +perspective. Lzip has been designed, written, and tested with great care to +replace gzip and bzip2 as the standard general-purpose compressed format for +Unix-like systems. @noindent The format for running minilzip is: @@ -754,7 +761,8 @@ minilzip [@var{options}] [@var{files}] If no file names are specified, minilzip compresses (or decompresses) from standard input to standard output. A hyphen @samp{-} used as a @var{file} argument means standard input. It can be mixed with other @var{files} and is -read just once, the first time it appears in the command line. +read just once, the first time it appears in the command line. Remember to +prepend @file{./} to any file name beginning with a hyphen, or use @samp{--}. minilzip supports the following @uref{http://www.nongnu.org/arg-parser/manual/arg_parser_manual.html#Argument-syntax,,options}: @@ -791,19 +799,20 @@ compression ratio, so use it only when needed. Valid values range from Compress or decompress to standard output; keep input files unchanged. If compressing several files, each file is compressed independently. (The output consists of a sequence of independently compressed members). This -option (or @samp{-o}) is needed when reading from a named pipe (fifo) or +option (or @option{-o}) is needed when reading from a named pipe (fifo) or from a device. Use it also to recover as much of the decompressed data as -possible when decompressing a corrupt file. @samp{-c} overrides @samp{-o} -and @samp{-S}. @samp{-c} has no effect when testing or listing. +possible when decompressing a corrupt file. @option{-c} overrides @option{-o} +and @option{-S}. @option{-c} has no effect when testing. @item -d @itemx --decompress -Decompress the files specified. If a file does not exist, can't be opened, -or the destination file already exists and @samp{--force} has not been -specified, minilzip continues decompressing the rest of the files and exits with -error status 1. If a file fails to decompress, or is a terminal, minilzip exits -immediately with error status 2 without decompressing the rest of the files. -A terminal is considered an uncompressed file, and therefore invalid. +Decompress the files specified. The integrity of the files specified is +checked. If a file does not exist, can't be opened, or the destination file +already exists and @option{--force} has not been specified, minilzip continues +decompressing the rest of the files and exits with error status 1. If a file +fails to decompress, or is a terminal, minilzip exits immediately with error +status 2 without decompressing the rest of the files. A terminal is +considered an uncompressed file, and therefore invalid. @item -f @itemx --force @@ -820,19 +829,19 @@ Keep (don't delete) input files during compression or decompression. @item -m @var{bytes} @itemx --match-length=@var{bytes} -When compressing, set the match length limit in bytes. After a match -this long is found, the search is finished. Valid values range from 5 to -273. Larger values usually give better compression ratios but longer -compression times. +When compressing, set the match length limit in bytes. After a match this +long is found, the search is finished. Valid values range from 5 to 273. +Larger values usually give better compression ratios but longer compression +times. @item -o @var{file} @itemx --output=@var{file} -If @samp{-c} has not been also specified, write the (de)compressed output to -@var{file}; keep input files unchanged. If compressing several files, each -file is compressed independently. (The output consists of a sequence of -independently compressed members). This option (or @samp{-c}) is needed when -reading from a named pipe (fifo) or from a device. @w{@samp{-o -}} is -equivalent to @samp{-c}. @samp{-o} has no effect when testing or listing. +If @option{-c} has not been also specified, write the (de)compressed output +to @var{file}; keep input files unchanged. If compressing several files, +each file is compressed independently. (The output consists of a sequence of +independently compressed members). This option (or @option{-c}) is needed +when reading from a named pipe (fifo) or from a device. @w{@option{-o -}} is +equivalent to @option{-c}. @option{-o} has no effect when testing. When compressing and splitting the output in volumes, @var{file} is used as a prefix, and several files named @samp{@var{file}00001.lz}, @@ -845,14 +854,14 @@ Quiet operation. Suppress all messages. @item -s @var{bytes} @itemx --dictionary-size=@var{bytes} -When compressing, set the dictionary size limit in bytes. Minilzip will use -for each file the largest dictionary size that does not exceed neither -the file size nor this limit. Valid values range from @w{4 KiB} to -@w{512 MiB}. Values 12 to 29 are interpreted as powers of two, meaning -2^12 to 2^29 bytes. Dictionary sizes are quantized so that they can be -coded in just one byte (@pxref{coded-dict-size}). If the size specified -does not match one of the valid sizes, it will be rounded upwards by -adding up to @w{(@var{bytes} / 8)} to it. +When compressing, set the dictionary size limit in bytes. Minilzip uses for +each file the largest dictionary size that does not exceed neither the file +size nor this limit. Valid values range from @w{4 KiB} to @w{512 MiB}. +Values 12 to 29 are interpreted as powers of two, meaning 2^12 to 2^29 +bytes. Dictionary sizes are quantized so that they can be coded in just one +byte (@pxref{coded-dict-size}). If the size specified does not match one of +the valid sizes, it is rounded upwards by adding up to @w{(@var{bytes} / 8)} +to it. For maximum compression you should use a dictionary size limit as large as possible, but keep in mind that the decompression memory requirement @@ -860,7 +869,7 @@ is affected at compression time by the choice of dictionary size limit. @item -S @var{bytes} @itemx --volume-size=@var{bytes} -When compressing, and @samp{-c} has not been also specified, split the +When compressing, and @option{-c} has not been also specified, split the compressed output into several volume files with names @samp{original_name00001.lz}, @samp{original_name00002.lz}, etc, and set the volume size limit to @var{bytes}. Input files are kept unchanged. Each @@ -872,11 +881,11 @@ from @w{100 kB} to @w{4 EiB}. @itemx --test Check integrity of the files specified, but don't decompress them. This really performs a trial decompression and throws away the result. Use it -together with @samp{-v} to see information about the files. If a file +together with @option{-v} to see information about the files. If a file fails the test, does not exist, can't be opened, or is a terminal, minilzip -continues checking the rest of the files. A final diagnostic is shown at -verbosity level 1 or higher if any file fails the test when testing -multiple files. +continues testing the rest of the files. A final diagnostic is shown at +verbosity level 1 or higher if any file fails the test when testing multiple +files. @item -v @itemx --verbose @@ -890,18 +899,18 @@ and trailer contents (CRC, data size, member size). @item -0 .. -9 Compression level. Set the compression parameters (dictionary size and match length limit) as shown in the table below. The default compression -level is @samp{-6}, equivalent to @w{@samp{-s8MiB -m36}}. Note that -@samp{-9} can be much slower than @samp{-0}. These options have no +level is @option{-6}, equivalent to @w{@option{-s8MiB -m36}}. Note that +@option{-9} can be much slower than @option{-0}. These options have no effect when decompressing or testing. -The bidimensional parameter space of LZMA can't be mapped to a linear -scale optimal for all files. If your files are large, very repetitive, -etc, you may need to use the options @samp{--dictionary-size} and -@samp{--match-length} directly to achieve optimal performance. +The bidimensional parameter space of LZMA can't be mapped to a linear scale +optimal for all files. If your files are large, very repetitive, etc, you +may need to use the options @option{--dictionary-size} and +@option{--match-length} directly to achieve optimal performance. -If several compression levels or @samp{-s} or @samp{-m} options are -given, the last setting is used. For example @w{@samp{-9 -s64MiB}} is -equivalent to @w{@samp{-s64MiB -m273}} +If several compression levels or @option{-s} or @option{-m} options are +given, the last setting is used. For example @w{@option{-9 -s64MiB}} is +equivalent to @w{@option{-s64MiB -m273}} @multitable {Level} {Dictionary size (-s)} {Match length limit (-m)} @item Level @tab Dictionary size (-s) @tab Match length limit (-m) @@ -942,28 +951,31 @@ version of lzlib being used and the value of LZ_API_VERSION (if defined). @end table -Numbers given as arguments to options may be followed by a multiplier -and an optional @samp{B} for "byte". +Numbers given as arguments to options may be expressed in decimal, +hexadecimal, or octal (using the same syntax as integer constants in C++), +and may be followed by a multiplier and an optional @samp{B} for "byte". Table of SI and binary prefixes (unit multipliers): -@multitable {Prefix} {kilobyte (10^3 = 1000)} {|} {Prefix} {kibibyte (2^10 = 1024)} +@multitable {Prefix} {kilobyte (10^3 = 1000)} {|} {Prefix} {kibibyte (2^10 = 1024)} @item Prefix @tab Value @tab | @tab Prefix @tab Value -@item k @tab kilobyte (10^3 = 1000) @tab | @tab Ki @tab kibibyte (2^10 = 1024) -@item M @tab megabyte (10^6) @tab | @tab Mi @tab mebibyte (2^20) -@item G @tab gigabyte (10^9) @tab | @tab Gi @tab gibibyte (2^30) -@item T @tab terabyte (10^12) @tab | @tab Ti @tab tebibyte (2^40) -@item P @tab petabyte (10^15) @tab | @tab Pi @tab pebibyte (2^50) -@item E @tab exabyte (10^18) @tab | @tab Ei @tab exbibyte (2^60) -@item Z @tab zettabyte (10^21) @tab | @tab Zi @tab zebibyte (2^70) -@item Y @tab yottabyte (10^24) @tab | @tab Yi @tab yobibyte (2^80) +@item k @tab kilobyte (10^3 = 1000) @tab | @tab Ki @tab kibibyte (2^10 = 1024) +@item M @tab megabyte (10^6) @tab | @tab Mi @tab mebibyte (2^20) +@item G @tab gigabyte (10^9) @tab | @tab Gi @tab gibibyte (2^30) +@item T @tab terabyte (10^12) @tab | @tab Ti @tab tebibyte (2^40) +@item P @tab petabyte (10^15) @tab | @tab Pi @tab pebibyte (2^50) +@item E @tab exabyte (10^18) @tab | @tab Ei @tab exbibyte (2^60) +@item Z @tab zettabyte (10^21) @tab | @tab Zi @tab zebibyte (2^70) +@item Y @tab yottabyte (10^24) @tab | @tab Yi @tab yobibyte (2^80) +@item R @tab ronnabyte (10^27) @tab | @tab Ri @tab robibyte (2^90) +@item Q @tab quettabyte (10^30) @tab | @tab Qi @tab quebibyte (2^100) @end multitable @sp 1 -Exit status: 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 (e.g., bug) which caused -minilzip to panic. +Exit status: 0 for a normal exit, 1 for environmental problems +(file not found, invalid command-line options, I/O errors, etc), 2 to +indicate a corrupt or invalid input file, 3 for an internal consistency +error (e.g., bug) which caused minilzip to panic. @node Data format @@ -994,7 +1006,7 @@ represents one byte; a box like this: represents a variable number of bytes. @sp 1 -Lzip data consist of a series of independent "members" (compressed data +Lzip data consist of one or more independent "members" (compressed data sets). The members simply appear one after another in the data stream, with no additional information before, between, or after them. Each member can encode in compressed form up to @w{16 EiB - 1 byte} of uncompressed data. @@ -1050,10 +1062,10 @@ Size of the original uncompressed data. @item Member size (8 bytes) Total size of the member, including header and trailer. This field acts -as a distributed index, allows the verification of stream integrity, and +as a distributed index, improves the checking of stream integrity, and facilitates the safe recovery of undamaged members from multimember files. -Member size should be limited to @w{2 PiB} to prevent the data size field -from overflowing. +Lzip limits the member size to @w{2 PiB} to prevent the data size field from +overflowing. @end table @@ -1360,7 +1372,7 @@ int ffrsdecompress( struct LZ_Decoder * const decoder, if( LZ_decompress_errno( decoder ) == LZ_header_error || LZ_decompress_errno( decoder ) == LZ_data_error ) { LZ_decompress_sync_to_member( decoder ); continue; } - else break; + break; } len = fwrite( buffer, 1, ret, outfile ); if( len < ret ) break; diff --git a/doc/minilzip.1 b/doc/minilzip.1 index 0c4c06d..3532520 100644 --- a/doc/minilzip.1 +++ b/doc/minilzip.1 @@ -1,24 +1,25 @@ -.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.16. -.TH MINILZIP "1" "January 2022" "minilzip 1.13" "User Commands" +.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.2. +.TH MINILZIP "1" "January 2024" "minilzip 1.14" "User Commands" .SH NAME minilzip \- reduces the size of files .SH SYNOPSIS .B minilzip [\fI\,options\/\fR] [\fI\,files\/\fR] .SH DESCRIPTION -Minilzip is a test program for the compression library lzlib, fully -compatible with lzip 1.4 or newer. +Minilzip is a test program for the compression library lzlib, compatible +with lzip 1.4 or newer. .PP Lzip is a lossless data compressor with a user interface similar to the one of gzip or bzip2. Lzip uses a simplified form of the 'Lempel\-Ziv\-Markov -chain\-Algorithm' (LZMA) stream format and provides a 3 factor integrity -checking to maximize interoperability and optimize safety. Lzip can compress -about as fast as gzip (lzip \fB\-0\fR) or compress most files more than bzip2 -(lzip \fB\-9\fR). Decompression speed is intermediate between gzip and bzip2. -Lzip is better than gzip and bzip2 from a data recovery perspective. Lzip -has been designed, written, and tested with great care to replace gzip and -bzip2 as the standard general\-purpose compressed format for unix\-like -systems. +chain\-Algorithm' (LZMA) stream format to maximize interoperability. The +maximum dictionary size is 512 MiB so that any lzip file can be decompressed +on 32\-bit machines. Lzip provides accurate and robust 3\-factor integrity +checking. Lzip can compress about as fast as gzip (lzip \fB\-0\fR) or compress most +files more than bzip2 (lzip \fB\-9\fR). Decompression speed is intermediate between +gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery +perspective. Lzip has been designed, written, and tested with great care to +replace gzip and bzip2 as the standard general\-purpose compressed format for +Unix\-like systems. .SH OPTIONS .TP \fB\-h\fR, \fB\-\-help\fR @@ -37,7 +38,7 @@ set member size limit in bytes write to standard output, keep input files .TP \fB\-d\fR, \fB\-\-decompress\fR -decompress +decompress, test compressed file integrity .TP \fB\-f\fR, \fB\-\-force\fR overwrite existing output files @@ -88,24 +89,24 @@ If no file names are given, or if a file is '\-', minilzip compresses or decompresses from standard input to standard output. Numbers may be followed by a multiplier: k = kB = 10^3 = 1000, Ki = KiB = 2^10 = 1024, M = 10^6, Mi = 2^20, G = 10^9, Gi = 2^30, etc... -Dictionary sizes 12 to 29 are interpreted as powers of two, meaning 2^12 -to 2^29 bytes. +Dictionary sizes 12 to 29 are interpreted as powers of two, meaning 2^12 to +2^29 bytes. .PP -The bidimensional parameter space of LZMA can't be mapped to a linear -scale optimal for all files. If your files are large, very repetitive, -etc, you may need to use the options \fB\-\-dictionary\-size\fR and \fB\-\-match\-length\fR -directly to achieve optimal performance. +The bidimensional parameter space of LZMA can't be mapped to a linear scale +optimal for all files. If your files are large, very repetitive, etc, you +may need to use the options \fB\-\-dictionary\-size\fR and \fB\-\-match\-length\fR directly +to achieve optimal performance. .PP To extract all the files from archive 'foo.tar.lz', use the commands \&'tar \fB\-xf\fR foo.tar.lz' or 'minilzip \fB\-cd\fR foo.tar.lz | tar \fB\-xf\fR \-'. .PP -Exit status: 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 (e.g., bug) which -caused minilzip to panic. +Exit status: 0 for a normal exit, 1 for environmental problems +(file not found, invalid command\-line options, I/O errors, etc), 2 to +indicate a corrupt or invalid input file, 3 for an internal consistency +error (e.g., bug) which caused minilzip to panic. .PP The ideas embodied in lzlib are due to (at least) the following people: -Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the +Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrei Markov (for the definition of Markov chains), G.N.N. Martin (for the definition of range encoding), Igor Pavlov (for putting all the above together in LZMA), and Julian Seward (for bzip2's CLI). @@ -114,8 +115,9 @@ Report bugs to lzip\-bug@nongnu.org .br Lzlib home page: http://www.nongnu.org/lzip/lzlib.html .SH COPYRIGHT -Copyright \(co 2022 Antonio Diaz Diaz. -Using lzlib 1.13 +Copyright \(co 2024 Antonio Diaz Diaz. +Using lzlib 1.14 +Using LZ_API_VERSION = 1014 License GPLv2+: GNU GPL version 2 or later .br This is free software: you are free to change and redistribute it. diff --git a/encoder.c b/encoder.c index b76dafa..c6190ea 100644 --- a/encoder.c +++ b/encoder.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2022 Antonio Diaz Diaz. + Copyright (C) 2009-2024 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -200,8 +200,6 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, } const int pos_state = Mb_data_position( &e->eb.mb ) & pos_state_mask; - const int match_price = price1( e->eb.bm_match[state][pos_state] ); - const int rep_match_price = match_price + price1( e->eb.bm_rep[state] ); const uint8_t prev_byte = Mb_peek( &e->eb.mb, 1 ); const uint8_t cur_byte = Mb_peek( &e->eb.mb, 0 ); const uint8_t match_byte = Mb_peek( &e->eb.mb, reps[0] + 1 ); @@ -213,6 +211,9 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, e->trials[1].price += LZeb_price_matched( &e->eb, prev_byte, cur_byte, match_byte ); e->trials[1].dis4 = -1; /* literal */ + const int match_price = price1( e->eb.bm_match[state][pos_state] ); + const int rep_match_price = match_price + price1( e->eb.bm_rep[state] ); + if( match_byte == cur_byte ) Tr_update( &e->trials[1], rep_match_price + LZeb_price_shortrep( &e->eb, state, pos_state ), 0, 0 ); diff --git a/encoder.h b/encoder.h index f17bb99..edac815 100644 --- a/encoder.h +++ b/encoder.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2022 Antonio Diaz Diaz. + Copyright (C) 2009-2024 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/encoder_base.c b/encoder_base.c index 4535352..047f372 100644 --- a/encoder_base.c +++ b/encoder_base.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2022 Antonio Diaz Diaz. + Copyright (C) 2009-2024 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -140,9 +140,7 @@ static void LZeb_try_full_flush( struct LZ_encoder_base * const eb ) Lt_set_data_crc( trailer, LZeb_crc( eb ) ); Lt_set_data_size( trailer, Mb_data_position( &eb->mb ) ); Lt_set_member_size( trailer, Re_member_position( &eb->renc ) + Lt_size ); - int i; - for( i = 0; i < Lt_size; ++i ) - Cb_put_byte( &eb->renc.cb, trailer[i] ); + int i; for( i = 0; i < Lt_size; ++i ) Cb_put_byte( &eb->renc.cb, trailer[i] ); } diff --git a/encoder_base.h b/encoder_base.h index 17ffc93..094f679 100644 --- a/encoder_base.h +++ b/encoder_base.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2022 Antonio Diaz Diaz. + Copyright (C) 2009-2024 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -142,7 +142,7 @@ static inline int price1( const Bit_model probability ) { return get_price( bit_model_total - probability ); } static inline int price_bit( const Bit_model bm, const bool bit ) - { return ( bit ? price1( bm ) : price0( bm ) ); } + { return bit ? price1( bm ) : price0( bm ); } static inline int price_symbol3( const Bit_model bm[], int symbol ) @@ -276,8 +276,8 @@ static inline int Mb_free_bytes( const struct Matchfinder_base * const mb ) static inline bool Mb_enough_available_bytes( const struct Matchfinder_base * const mb ) - { return ( mb->pos + mb->after_size <= mb->stream_pos || - ( Mb_flushing_or_end( mb ) && mb->pos < mb->stream_pos ) ); } + { return mb->pos + mb->after_size <= mb->stream_pos || + ( Mb_flushing_or_end( mb ) && mb->pos < mb->stream_pos ); } static inline const uint8_t * Mb_ptr_to_current_pos( const struct Matchfinder_base * const mb ) @@ -340,7 +340,6 @@ static inline void Re_shift_low( struct Range_encoder * const renc ) static inline void Re_reset( struct Range_encoder * const renc, const unsigned dictionary_size ) { - int i; Cb_reset( &renc->cb ); renc->low = 0; renc->partial_member_pos = 0; @@ -348,8 +347,7 @@ static inline void Re_reset( struct Range_encoder * const renc, renc->ff_count = 0; renc->cache = 0; Lh_set_dictionary_size( renc->header, dictionary_size ); - for( i = 0; i < Lh_size; ++i ) - Cb_put_byte( &renc->cb, renc->header[i] ); + int i; for( i = 0; i < Lh_size; ++i ) Cb_put_byte( &renc->cb, renc->header[i] ); } static inline bool Re_init( struct Range_encoder * const renc, @@ -398,8 +396,7 @@ static inline void Re_encode( struct Range_encoder * const renc, { renc->range >>= 1; if( symbol & mask ) renc->low += renc->range; - if( renc->range <= 0x00FFFFFFU ) - { renc->range <<= 8; Re_shift_low( renc ); } + if( renc->range <= 0x00FFFFFFU ) { renc->range <<= 8; Re_shift_low( renc ); } } } @@ -559,7 +556,7 @@ static inline bool LZeb_init( struct LZ_encoder_base * const eb, } static inline bool LZeb_member_finished( const struct LZ_encoder_base * const eb ) - { return ( eb->member_finished && Cb_empty( &eb->renc.cb ) ); } + { return eb->member_finished && Cb_empty( &eb->renc.cb ); } static inline void LZeb_free( struct LZ_encoder_base * const eb ) { Re_free( &eb->renc ); Mb_free( &eb->mb ); } diff --git a/fast_encoder.c b/fast_encoder.c index 618c3d6..bb6363a 100644 --- a/fast_encoder.c +++ b/fast_encoder.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2022 Antonio Diaz Diaz. + Copyright (C) 2009-2024 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/fast_encoder.h b/fast_encoder.h index 54756bd..b9421f4 100644 --- a/fast_encoder.h +++ b/fast_encoder.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2022 Antonio Diaz Diaz. + Copyright (C) 2009-2024 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/ffexample.c b/ffexample.c index 59345ee..826abcd 100644 --- a/ffexample.c +++ b/ffexample.c @@ -1,5 +1,5 @@ /* File to file example - Test program for the library lzlib - Copyright (C) 2010-2022 Antonio Diaz Diaz. + Copyright (C) 2010-2024 Antonio Diaz Diaz. This program is free software: you have unlimited permission to copy, distribute, and modify it. @@ -245,7 +245,7 @@ int ffrsdecompress( struct LZ_Decoder * const decoder, if( LZ_decompress_errno( decoder ) == LZ_header_error || LZ_decompress_errno( decoder ) == LZ_data_error ) { LZ_decompress_sync_to_member( decoder ); continue; } - else break; + break; } len = fwrite( buffer, 1, ret, outfile ); if( len < ret ) break; @@ -277,10 +277,10 @@ int main( const int argc, const char * const argv[] ) { fputs( "ffexample: Not enough memory.\n", stderr ); LZ_compress_close( encoder ); LZ_decompress_close( decoder ); return 1; } if( !infile ) - { fprintf( stderr, "ffexample: Can't open input file '%s': %s\n", + { fprintf( stderr, "ffexample: %s: Can't open input file: %s\n", argv[2], strerror( errno ) ); return 1; } if( !outfile ) - { fprintf( stderr, "ffexample: Can't open output file '%s': %s\n", + { fprintf( stderr, "ffexample: %s: Can't open output file: %s\n", argv[3], strerror( errno ) ); return 1; } switch( argv[1][1] ) @@ -291,7 +291,7 @@ int main( const int argc, const char * const argv[] ) case 'm': retval = ffmmcompress( infile, outfile ); break; case 'l': retval = fflfcompress( encoder, infile, outfile ); break; case 'r': retval = ffrsdecompress( decoder, infile, outfile ); break; - default: show_help(); return ( argv[1][1] != 'h' ); + default: show_help(); return argv[1][1] != 'h'; } if( LZ_decompress_close( decoder ) < 0 || LZ_compress_close( encoder ) < 0 || diff --git a/lzcheck.c b/lzcheck.c index 88dd4c9..4f4bf9f 100644 --- a/lzcheck.c +++ b/lzcheck.c @@ -1,5 +1,5 @@ /* Lzcheck - Test program for the library lzlib - Copyright (C) 2009-2022 Antonio Diaz Diaz. + Copyright (C) 2009-2024 Antonio Diaz Diaz. This program is free software: you have unlimited permission to copy, distribute, and modify it. @@ -26,7 +26,7 @@ const unsigned long long member_size = INT64_MAX; -enum { buffer_size = 32768 }; +enum { buffer_size = 32749 }; /* largest prime < 32768 */ uint8_t in_buffer[buffer_size]; uint8_t mid_buffer[buffer_size]; uint8_t out_buffer[buffer_size]; @@ -62,6 +62,7 @@ static struct LZ_Encoder * xopen_encoder( const int dictionary_size ) return encoder; } + static struct LZ_Decoder * xopen_decoder( void ) { struct LZ_Decoder * const decoder = LZ_decompress_open(); @@ -171,17 +172,49 @@ static int check_sync_flush( FILE * const file, const int dictionary_size ) if( line_size <= 0 ) break; /* end of file */ in_size = LZ_compress_write( encoder, line_buf, line_size ); - if( in_size < line_size ) - fprintf( stderr, "lzcheck: sync: LZ_compress_write only accepted %d of %d bytes\n", - in_size, line_size ); - LZ_compress_sync_flush( encoder ); - if( line_buf[0] & 1 ) /* read all data at once or byte by byte */ - mid_size = LZ_compress_read( encoder, mid_buffer, buffer_size ); - else for( mid_size = 0; mid_size < buffer_size; ) + if( in_size < 0 ) { - const int rd = LZ_compress_read( encoder, mid_buffer + mid_size, 1 ); + fprintf( stderr, "lzcheck: LZ_compress_write error: %s\n", + LZ_strerror( LZ_compress_errno( encoder ) ) ); + retval = 3; break; + } + if( in_size < line_size ) + { + fprintf( stderr, "lzcheck: sync: LZ_compress_write only accepted %d " + "of %d bytes\n", in_size, line_size ); + mid_size = LZ_compress_read( encoder, mid_buffer, buffer_size ); + const int wr = + LZ_compress_write( encoder, line_buf + in_size, line_size - in_size ); + if( wr < 0 ) + { + fprintf( stderr, "lzcheck: LZ_compress_write error: %s\n", + LZ_strerror( LZ_compress_errno( encoder ) ) ); + retval = 3; break; + } + if( wr + in_size != line_size ) + { + fprintf( stderr, "lzcheck: sync: LZ_compress_write only accepted %d " + "of %d remaining bytes\n", wr, line_size - in_size ); + retval = 3; break; + } + in_size += wr; + LZ_compress_sync_flush( encoder ); + const int rd = LZ_compress_read( encoder, mid_buffer + mid_size, + buffer_size - mid_size ); if( rd > 0 ) mid_size += rd; - else { if( rd < 0 ) { mid_size = -1; } break; } + else if( rd < 0 ) mid_size = -1; + } + else + { + LZ_compress_sync_flush( encoder ); + if( line_buf[0] & 1 ) /* read all data at once or byte by byte */ + mid_size = LZ_compress_read( encoder, mid_buffer, buffer_size ); + else for( mid_size = 0; mid_size < buffer_size; ) + { + const int rd = LZ_compress_read( encoder, mid_buffer + mid_size, 1 ); + if( rd > 0 ) mid_size += rd; + else { if( rd < 0 ) { mid_size = -1; } break; } + } } if( mid_size < 0 ) { @@ -344,7 +377,7 @@ int main( const int argc, const char * const argv[] ) FILE * file = fopen( argv[i], "rb" ); if( !file ) { - fprintf( stderr, "lzcheck: Can't open file '%s' for reading.\n", argv[i] ); + fprintf( stderr, "lzcheck: %s: Can't open file for reading.\n", argv[i] ); ++open_failures; continue; } if( verbose ) fprintf( stderr, " Testing file '%s'\n", argv[i] ); diff --git a/lzip.h b/lzip.h index aad7e00..e0bdae9 100644 --- a/lzip.h +++ b/lzip.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2022 Antonio Diaz Diaz. + Copyright (C) 2009-2024 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -35,17 +35,13 @@ static inline State St_set_char( const State st ) static const State next[states] = { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 }; return next[st]; } - static inline State St_set_char_rep() { return 8; } - static inline State St_set_match( const State st ) - { return ( ( st < 7 ) ? 7 : 10 ); } - + { return ( st < 7 ) ? 7 : 10; } static inline State St_set_rep( const State st ) - { return ( ( st < 7 ) ? 8 : 11 ); } - + { return ( st < 7 ) ? 8 : 11; } static inline State St_set_short_rep( const State st ) - { return ( ( st < 7 ) ? 9 : 11 ); } + { return ( st < 7 ) ? 9 : 11; } enum { @@ -182,8 +178,8 @@ static inline void CRC32_update_buf( uint32_t * const crc, static inline bool isvalid_ds( const unsigned dictionary_size ) - { return ( dictionary_size >= min_dictionary_size && - dictionary_size <= max_dictionary_size ); } + { return dictionary_size >= min_dictionary_size && + dictionary_size <= max_dictionary_size; } static inline int real_bits( unsigned value ) @@ -196,43 +192,43 @@ static inline int real_bits( unsigned value ) static const uint8_t lzip_magic[4] = { 0x4C, 0x5A, 0x49, 0x50 }; /* "LZIP" */ -typedef uint8_t Lzip_header[6]; /* 0-3 magic bytes */ +enum { Lh_size = 6 }; +typedef uint8_t Lzip_header[Lh_size]; /* 0-3 magic bytes */ /* 4 version */ /* 5 coded dictionary size */ -enum { Lh_size = 6 }; static inline void Lh_set_magic( Lzip_header data ) { memcpy( data, lzip_magic, 4 ); data[4] = 1; } -static inline bool Lh_verify_magic( const Lzip_header data ) - { return ( memcmp( data, lzip_magic, 4 ) == 0 ); } +static inline bool Lh_check_magic( const Lzip_header data ) + { return memcmp( data, lzip_magic, 4 ) == 0; } /* detect (truncated) header */ -static inline bool Lh_verify_prefix( const Lzip_header data, const int sz ) +static inline bool Lh_check_prefix( const Lzip_header data, const int sz ) { int i; for( i = 0; i < sz && i < 4; ++i ) if( data[i] != lzip_magic[i] ) return false; - return ( sz > 0 ); + return sz > 0; } /* detect corrupt header */ -static inline bool Lh_verify_corrupt( const Lzip_header data ) +static inline bool Lh_check_corrupt( const Lzip_header data ) { int matches = 0; int i; for( i = 0; i < 4; ++i ) if( data[i] == lzip_magic[i] ) ++matches; - return ( matches > 1 && matches < 4 ); + return matches > 1 && matches < 4; } static inline uint8_t Lh_version( const Lzip_header data ) { return data[4]; } -static inline bool Lh_verify_version( const Lzip_header data ) - { return ( data[4] == 1 ); } +static inline bool Lh_check_version( const Lzip_header data ) + { return data[4] == 1; } static inline unsigned Lh_get_dictionary_size( const Lzip_header data ) { - unsigned sz = ( 1 << ( data[5] & 0x1F ) ); + unsigned sz = 1 << ( data[5] & 0x1F ); if( sz > min_dictionary_size ) sz -= ( sz / 16 ) * ( ( data[5] >> 5 ) & 7 ); return sz; @@ -249,23 +245,23 @@ static inline bool Lh_set_dictionary_size( Lzip_header data, const unsigned sz ) unsigned i; for( i = 7; i >= 1; --i ) if( base_size - ( i * fraction ) >= sz ) - { data[5] |= ( i << 5 ); break; } + { data[5] |= i << 5; break; } } return true; } -static inline bool Lh_verify( const Lzip_header data ) +static inline bool Lh_check( const Lzip_header data ) { - return Lh_verify_magic( data ) && Lh_verify_version( data ) && + return Lh_check_magic( data ) && Lh_check_version( data ) && isvalid_ds( Lh_get_dictionary_size( data ) ); } -typedef uint8_t Lzip_trailer[20]; +enum { Lt_size = 20 }; +typedef uint8_t Lzip_trailer[Lt_size]; /* 0-3 CRC32 of the uncompressed data */ /* 4-11 size of the uncompressed data */ /* 12-19 member size including header and trailer */ -enum { Lt_size = 20 }; static inline unsigned Lt_get_data_crc( const Lzip_trailer data ) { diff --git a/lzlib.c b/lzlib.c index 3084fbd..4105205 100644 --- a/lzlib.c +++ b/lzlib.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2022 Antonio Diaz Diaz. + Copyright (C) 2009-2024 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -86,7 +86,7 @@ static void LZ_Decoder_init( struct LZ_Decoder * const d ) } -static bool verify_encoder( struct LZ_Encoder * const e ) +static bool check_encoder( struct LZ_Encoder * const e ) { if( !e ) return false; if( !e->lz_encoder_base || ( !e->lz_encoder && !e->flz_encoder ) || @@ -96,7 +96,7 @@ static bool verify_encoder( struct LZ_Encoder * const e ) } -static bool verify_decoder( struct LZ_Decoder * const d ) +static bool check_decoder( struct LZ_Decoder * const d ) { if( !d ) return false; if( !d->rdec ) @@ -189,7 +189,7 @@ int LZ_compress_close( struct LZ_Encoder * const e ) int LZ_compress_finish( struct LZ_Encoder * const e ) { - if( !verify_encoder( e ) || e->fatal ) return -1; + if( !check_encoder( e ) || e->fatal ) return -1; Mb_finish( &e->lz_encoder_base->mb ); /* if (open --> write --> finish) use same dictionary size as lzip. */ /* this does not save any memory. */ @@ -208,7 +208,7 @@ int LZ_compress_finish( struct LZ_Encoder * const e ) int LZ_compress_restart_member( struct LZ_Encoder * const e, const unsigned long long member_size ) { - if( !verify_encoder( e ) || e->fatal ) return -1; + if( !check_encoder( e ) || e->fatal ) return -1; if( !LZeb_member_finished( e->lz_encoder_base ) ) { e->lz_errno = LZ_sequence_error; return -1; } if( member_size < min_dictionary_size ) @@ -226,7 +226,7 @@ int LZ_compress_restart_member( struct LZ_Encoder * const e, int LZ_compress_sync_flush( struct LZ_Encoder * const e ) { - if( !verify_encoder( e ) || e->fatal ) return -1; + if( !check_encoder( e ) || e->fatal ) return -1; if( !e->lz_encoder_base->mb.at_stream_end ) e->lz_encoder_base->mb.sync_flush_pending = true; return 0; @@ -236,7 +236,7 @@ int LZ_compress_sync_flush( struct LZ_Encoder * const e ) int LZ_compress_read( struct LZ_Encoder * const e, uint8_t * const buffer, const int size ) { - if( !verify_encoder( e ) || e->fatal ) return -1; + if( !check_encoder( e ) || e->fatal ) return -1; if( size < 0 ) return 0; { struct LZ_encoder_base * const eb = e->lz_encoder_base; @@ -258,14 +258,14 @@ int LZ_compress_read( struct LZ_Encoder * const e, int LZ_compress_write( struct LZ_Encoder * const e, const uint8_t * const buffer, const int size ) { - if( !verify_encoder( e ) || e->fatal ) return -1; + if( !check_encoder( e ) || e->fatal ) return -1; return Mb_write_data( &e->lz_encoder_base->mb, buffer, size ); } int LZ_compress_write_size( struct LZ_Encoder * const e ) { - if( !verify_encoder( e ) || e->fatal ) return -1; + if( !check_encoder( e ) || e->fatal ) return -1; return Mb_free_bytes( &e->lz_encoder_base->mb ); } @@ -279,43 +279,43 @@ enum LZ_Errno LZ_compress_errno( struct LZ_Encoder * const e ) int LZ_compress_finished( struct LZ_Encoder * const e ) { - if( !verify_encoder( e ) ) return -1; - return ( Mb_data_finished( &e->lz_encoder_base->mb ) && - LZeb_member_finished( e->lz_encoder_base ) ); + if( !check_encoder( e ) ) return -1; + return Mb_data_finished( &e->lz_encoder_base->mb ) && + LZeb_member_finished( e->lz_encoder_base ); } int LZ_compress_member_finished( struct LZ_Encoder * const e ) { - if( !verify_encoder( e ) ) return -1; + if( !check_encoder( e ) ) return -1; return LZeb_member_finished( e->lz_encoder_base ); } unsigned long long LZ_compress_data_position( struct LZ_Encoder * const e ) { - if( !verify_encoder( e ) ) return 0; + if( !check_encoder( e ) ) return 0; return Mb_data_position( &e->lz_encoder_base->mb ); } unsigned long long LZ_compress_member_position( struct LZ_Encoder * const e ) { - if( !verify_encoder( e ) ) return 0; + if( !check_encoder( e ) ) return 0; return Re_member_position( &e->lz_encoder_base->renc ); } unsigned long long LZ_compress_total_in_size( struct LZ_Encoder * const e ) { - if( !verify_encoder( e ) ) return 0; + if( !check_encoder( e ) ) return 0; return e->partial_in_size + Mb_data_position( &e->lz_encoder_base->mb ); } unsigned long long LZ_compress_total_out_size( struct LZ_Encoder * const e ) { - if( !verify_encoder( e ) ) return 0; + if( !check_encoder( e ) ) return 0; return e->partial_out_size + Re_member_position( &e->lz_encoder_base->renc ); } @@ -352,7 +352,7 @@ int LZ_decompress_close( struct LZ_Decoder * const d ) int LZ_decompress_finish( struct LZ_Decoder * const d ) { - if( !verify_decoder( d ) || d->fatal ) return -1; + if( !check_decoder( d ) || d->fatal ) return -1; if( d->seeking ) { d->seeking = false; d->partial_in_size += Rd_purge( d->rdec ); } else Rd_finish( d->rdec ); @@ -362,7 +362,7 @@ int LZ_decompress_finish( struct LZ_Decoder * const d ) int LZ_decompress_reset( struct LZ_Decoder * const d ) { - if( !verify_decoder( d ) ) return -1; + if( !check_decoder( d ) ) return -1; if( d->lz_decoder ) { LZd_free( d->lz_decoder ); free( d->lz_decoder ); d->lz_decoder = 0; } d->partial_in_size = 0; @@ -379,7 +379,7 @@ int LZ_decompress_reset( struct LZ_Decoder * const d ) int LZ_decompress_sync_to_member( struct LZ_Decoder * const d ) { unsigned skipped = 0; - if( !verify_decoder( d ) ) return -1; + if( !check_decoder( d ) ) return -1; if( d->lz_decoder ) { LZd_free( d->lz_decoder ); free( d->lz_decoder ); d->lz_decoder = 0; } if( Rd_find_header( d->rdec, &skipped ) ) d->seeking = false; @@ -399,7 +399,7 @@ int LZ_decompress_read( struct LZ_Decoder * const d, uint8_t * const buffer, const int size ) { int result; - if( !verify_decoder( d ) ) return -1; + if( !check_decoder( d ) ) return -1; if( size < 0 ) return 0; if( d->fatal ) /* don't return error until pending bytes are read */ { if( d->lz_decoder && !Cb_empty( &d->lz_decoder->cb ) ) goto get_data; @@ -422,20 +422,20 @@ int LZ_decompress_read( struct LZ_Decoder * const d, rd = Rd_read_data( d->rdec, d->member_header, Lh_size ); if( rd < Lh_size || Rd_finished( d->rdec ) ) /* End Of File */ { - if( rd <= 0 || Lh_verify_prefix( d->member_header, rd ) ) + if( rd <= 0 || Lh_check_prefix( d->member_header, rd ) ) d->lz_errno = LZ_unexpected_eof; else d->lz_errno = LZ_header_error; d->fatal = true; return -1; } - if( !Lh_verify_magic( d->member_header ) ) + if( !Lh_check_magic( d->member_header ) ) { /* unreading the header prevents sync_to_member from skipping a member if leading garbage is shorter than a full header; "lgLZIP\x01\x0C" */ if( Rd_unread_data( d->rdec, rd ) ) { - if( d->first_header || !Lh_verify_corrupt( d->member_header ) ) + if( d->first_header || !Lh_check_corrupt( d->member_header ) ) d->lz_errno = LZ_header_error; else d->lz_errno = LZ_data_error; /* corrupt header */ @@ -445,12 +445,12 @@ int LZ_decompress_read( struct LZ_Decoder * const d, d->fatal = true; return -1; } - if( !Lh_verify_version( d->member_header ) || + if( !Lh_check_version( d->member_header ) || !isvalid_ds( Lh_get_dictionary_size( d->member_header ) ) ) { /* Skip a possible "LZIP" leading garbage; "LZIPLZIP\x01\x0C". Leave member_pos pointing to the first error. */ - if( Rd_unread_data( d->rdec, 1 + !Lh_verify_version( d->member_header ) ) ) + if( Rd_unread_data( d->rdec, 1 + !Lh_check_version( d->member_header ) ) ) d->lz_errno = LZ_data_error; /* bad version or bad dict size */ else d->lz_errno = LZ_library_error; @@ -500,7 +500,7 @@ int LZ_decompress_write( struct LZ_Decoder * const d, const uint8_t * const buffer, const int size ) { int result; - if( !verify_decoder( d ) || d->fatal ) return -1; + if( !check_decoder( d ) || d->fatal ) return -1; if( size < 0 ) return 0; result = Rd_write_data( d->rdec, buffer, size ); @@ -521,7 +521,7 @@ int LZ_decompress_write( struct LZ_Decoder * const d, int LZ_decompress_write_size( struct LZ_Decoder * const d ) { - if( !verify_decoder( d ) || d->fatal ) return -1; + if( !check_decoder( d ) || d->fatal ) return -1; return Rd_free_bytes( d->rdec ); } @@ -535,36 +535,36 @@ enum LZ_Errno LZ_decompress_errno( struct LZ_Decoder * const d ) int LZ_decompress_finished( struct LZ_Decoder * const d ) { - if( !verify_decoder( d ) || d->fatal ) return -1; - return ( Rd_finished( d->rdec ) && - ( !d->lz_decoder || LZd_member_finished( d->lz_decoder ) ) ); + if( !check_decoder( d ) || d->fatal ) return -1; + return Rd_finished( d->rdec ) && + ( !d->lz_decoder || LZd_member_finished( d->lz_decoder ) ); } int LZ_decompress_member_finished( struct LZ_Decoder * const d ) { - if( !verify_decoder( d ) || d->fatal ) return -1; - return ( d->lz_decoder && LZd_member_finished( d->lz_decoder ) ); + if( !check_decoder( d ) || d->fatal ) return -1; + return d->lz_decoder && LZd_member_finished( d->lz_decoder ); } int LZ_decompress_member_version( struct LZ_Decoder * const d ) { - if( !verify_decoder( d ) ) return -1; + if( !check_decoder( d ) ) return -1; return Lh_version( d->member_header ); } int LZ_decompress_dictionary_size( struct LZ_Decoder * const d ) { - if( !verify_decoder( d ) ) return -1; + if( !check_decoder( d ) ) return -1; return Lh_get_dictionary_size( d->member_header ); } unsigned LZ_decompress_data_crc( struct LZ_Decoder * const d ) { - if( verify_decoder( d ) && d->lz_decoder ) + if( check_decoder( d ) && d->lz_decoder ) return LZd_crc( d->lz_decoder ); return 0; } @@ -572,7 +572,7 @@ unsigned LZ_decompress_data_crc( struct LZ_Decoder * const d ) unsigned long long LZ_decompress_data_position( struct LZ_Decoder * const d ) { - if( verify_decoder( d ) && d->lz_decoder ) + if( check_decoder( d ) && d->lz_decoder ) return LZd_data_position( d->lz_decoder ); return 0; } @@ -580,21 +580,21 @@ unsigned long long LZ_decompress_data_position( struct LZ_Decoder * const d ) unsigned long long LZ_decompress_member_position( struct LZ_Decoder * const d ) { - if( !verify_decoder( d ) ) return 0; + if( !check_decoder( d ) ) return 0; return d->rdec->member_position; } unsigned long long LZ_decompress_total_in_size( struct LZ_Decoder * const d ) { - if( !verify_decoder( d ) ) return 0; + if( !check_decoder( d ) ) return 0; return d->partial_in_size + d->rdec->member_position; } unsigned long long LZ_decompress_total_out_size( struct LZ_Decoder * const d ) { - if( !verify_decoder( d ) ) return 0; + if( !check_decoder( d ) ) return 0; if( d->lz_decoder ) return d->partial_out_size + LZd_data_position( d->lz_decoder ); return d->partial_out_size; diff --git a/lzlib.h b/lzlib.h index ba29f97..b7357d2 100644 --- a/lzlib.h +++ b/lzlib.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2022 Antonio Diaz Diaz. + Copyright (C) 2009-2024 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -24,9 +24,9 @@ extern "C" { /* LZ_API_VERSION was first defined in lzlib 1.8 to 1. Since lzlib 1.12, LZ_API_VERSION is defined as (major * 1000 + minor). */ -#define LZ_API_VERSION 1013 +#define LZ_API_VERSION 1014 -static const char * const LZ_version_string = "1.13"; +static const char * const LZ_version_string = "1.14"; enum LZ_Errno { LZ_ok = 0, LZ_bad_argument, LZ_mem_error, LZ_sequence_error, LZ_header_error, LZ_unexpected_eof, diff --git a/minilzip.c b/minilzip.c index f9313b2..a0a6721 100644 --- a/minilzip.c +++ b/minilzip.c @@ -1,5 +1,5 @@ /* Minilzip - Test program for the library lzlib - Copyright (C) 2009-2022 Antonio Diaz Diaz. + Copyright (C) 2009-2024 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 @@ -16,9 +16,9 @@ */ /* Exit status: 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 - (e.g., bug) which caused minilzip to panic. + (file not found, invalid command-line options, I/O errors, etc), 2 to + indicate a corrupt or invalid input file, 3 for an internal consistency + error (e.g., bug) which caused minilzip to panic. */ #define _FILE_OFFSET_BITS 64 @@ -26,10 +26,10 @@ #include #include #include -#include +#include /* SSIZE_MAX */ #include #include -#include +#include /* SIZE_MAX */ #include #include #include @@ -91,7 +91,7 @@ static const char * const mem_msg = "Not enough memory."; int verbosity = 0; static const char * const program_name = "minilzip"; -static const char * const program_year = "2022"; +static const char * const program_year = "2024"; static const char * invocation_name = "minilzip"; /* default value */ static const struct { const char * from; const char * to; } known_extensions[] = { @@ -116,18 +116,19 @@ static bool delete_output_on_interrupt = false; static void show_help( void ) { - printf( "Minilzip is a test program for the compression library lzlib, fully\n" - "compatible with lzip 1.4 or newer.\n" + printf( "Minilzip is a test program for the compression library lzlib, compatible\n" + "with lzip 1.4 or newer.\n" "\nLzip is a lossless data compressor with a user interface similar to the one\n" "of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov\n" - "chain-Algorithm' (LZMA) stream format and provides a 3 factor integrity\n" - "checking to maximize interoperability and optimize safety. Lzip can compress\n" - "about as fast as gzip (lzip -0) or compress most files more than bzip2\n" - "(lzip -9). Decompression speed is intermediate between gzip and bzip2.\n" - "Lzip is better than gzip and bzip2 from a data recovery perspective. Lzip\n" - "has been designed, written, and tested with great care to replace gzip and\n" - "bzip2 as the standard general-purpose compressed format for unix-like\n" - "systems.\n" + "chain-Algorithm' (LZMA) stream format to maximize interoperability. The\n" + "maximum dictionary size is 512 MiB so that any lzip file can be decompressed\n" + "on 32-bit machines. Lzip provides accurate and robust 3-factor integrity\n" + "checking. Lzip can compress about as fast as gzip (lzip -0) or compress most\n" + "files more than bzip2 (lzip -9). Decompression speed is intermediate between\n" + "gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery\n" + "perspective. Lzip has been designed, written, and tested with great care to\n" + "replace gzip and bzip2 as the standard general-purpose compressed format for\n" + "Unix-like systems.\n" "\nUsage: %s [options] [files]\n", invocation_name ); printf( "\nOptions:\n" " -h, --help display this help and exit\n" @@ -135,7 +136,7 @@ static void show_help( void ) " -a, --trailing-error exit with error status if trailing data\n" " -b, --member-size= set member size limit in bytes\n" " -c, --stdout write to standard output, keep input files\n" - " -d, --decompress decompress\n" + " -d, --decompress decompress, test compressed file integrity\n" " -f, --force overwrite existing output files\n" " -F, --recompress force re-compression of compressed files\n" " -k, --keep keep (don't delete) input files\n" @@ -155,20 +156,20 @@ static void show_help( void ) "decompresses from standard input to standard output.\n" "Numbers may be followed by a multiplier: k = kB = 10^3 = 1000,\n" "Ki = KiB = 2^10 = 1024, M = 10^6, Mi = 2^20, G = 10^9, Gi = 2^30, etc...\n" - "Dictionary sizes 12 to 29 are interpreted as powers of two, meaning 2^12\n" - "to 2^29 bytes.\n" - "\nThe bidimensional parameter space of LZMA can't be mapped to a linear\n" - "scale optimal for all files. If your files are large, very repetitive,\n" - "etc, you may need to use the options --dictionary-size and --match-length\n" - "directly to achieve optimal performance.\n" + "Dictionary sizes 12 to 29 are interpreted as powers of two, meaning 2^12 to\n" + "2^29 bytes.\n" + "\nThe bidimensional parameter space of LZMA can't be mapped to a linear scale\n" + "optimal for all files. If your files are large, very repetitive, etc, you\n" + "may need to use the options --dictionary-size and --match-length directly\n" + "to achieve optimal performance.\n" "\nTo extract all the files from archive 'foo.tar.lz', use the commands\n" "'tar -xf foo.tar.lz' or 'minilzip -cd foo.tar.lz | tar -xf -'.\n" - "\nExit status: 0 for a normal exit, 1 for environmental problems (file\n" - "not found, invalid flags, I/O errors, etc), 2 to indicate a corrupt or\n" - "invalid input file, 3 for an internal consistency error (e.g., bug) which\n" - "caused minilzip to panic.\n" + "\nExit status: 0 for a normal exit, 1 for environmental problems\n" + "(file not found, invalid command-line options, I/O errors, etc), 2 to\n" + "indicate a corrupt or invalid input file, 3 for an internal consistency\n" + "error (e.g., bug) which caused minilzip to panic.\n" "\nThe ideas embodied in lzlib are due to (at least) the following people:\n" - "Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the\n" + "Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrei Markov (for the\n" "definition of Markov chains), G.N.N. Martin (for the definition of range\n" "encoding), Igor Pavlov (for putting all the above together in LZMA), and\n" "Julian Seward (for bzip2's CLI).\n" @@ -177,11 +178,25 @@ static void show_help( void ) } +static void show_lzlib_version( void ) + { + printf( "Using lzlib %s\n", LZ_version() ); +#if !defined LZ_API_VERSION + fputs( "LZ_API_VERSION is not defined.\n", stdout ); +#elif LZ_API_VERSION >= 1012 + printf( "Using LZ_API_VERSION = %u\n", LZ_api_version() ); +#else + printf( "Compiled with LZ_API_VERSION = %u. " + "Using an unknown LZ_API_VERSION\n", LZ_API_VERSION ); +#endif + } + + static void show_version( void ) { printf( "%s %s\n", program_name, PROGVERSION ); printf( "Copyright (C) %s Antonio Diaz Diaz.\n", program_year ); - printf( "Using lzlib %s\n", LZ_version() ); + show_lzlib_version(); printf( "License GPLv2+: GNU GPL version 2 or later \n" "This is free software: you are free to change and redistribute it.\n" "There is NO WARRANTY, to the extent permitted by law.\n" ); @@ -234,18 +249,7 @@ static int check_lib() printf( "warning: LZ_API_VERSION != LZ_api_version() (%u vs %u)\n", LZ_API_VERSION, LZ_api_version() ); } #endif - if( verbosity >= 1 ) - { - printf( "Using lzlib %s\n", LZ_version() ); -#if !defined LZ_API_VERSION - fputs( "LZ_API_VERSION is not defined.\n", stdout ); -#elif LZ_API_VERSION >= 1012 - printf( "Using LZ_API_VERSION = %u\n", LZ_api_version() ); -#else - printf( "Compiled with LZ_API_VERSION = %u. " - "Using an unknown LZ_API_VERSION\n", LZ_API_VERSION ); -#endif - } + if( verbosity >= 1 ) show_lzlib_version(); return retval; } @@ -327,27 +331,26 @@ static void Pp_show_msg( struct Pretty_print * const pp, const char * const msg static void show_header( const unsigned dictionary_size ) { - enum { factor = 1024 }; - const char * const prefix[8] = - { "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" }; + enum { factor = 1024, n = 3 }; + const char * const prefix[n] = { "Ki", "Mi", "Gi" }; const char * p = ""; const char * np = " "; unsigned num = dictionary_size; bool exact = ( num % factor == 0 ); - int i; for( i = 0; i < 8 && ( num > 9999 || ( exact && num >= factor ) ); ++i ) + int i; for( i = 0; i < n && ( num > 9999 || ( exact && num >= factor ) ); ++i ) { num /= factor; if( num % factor != 0 ) exact = false; p = prefix[i]; np = ""; } fprintf( stderr, "dict %s%4u %sB, ", np, num, p ); } -/* separate large numbers >= 100_000 in groups of 3 digits using '_' */ +/* separate numbers of 5 or more digits in groups of 3 digits using '_' */ static const char * format_num3( unsigned long long num ) { - const char * const si_prefix = "kMGTPEZY"; - const char * const binary_prefix = "KMGTPEZY"; - enum { buffers = 8, bufsize = 4 * sizeof (long long) }; + enum { buffers = 8, bufsize = 4 * sizeof num, n = 10 }; + const char * const si_prefix = "kMGTPEZYRQ"; + const char * const binary_prefix = "KMGTPEZYRQ"; static char buffer[buffers][bufsize]; /* circle of static buffers for printf */ static int current = 0; int i; @@ -357,15 +360,15 @@ static const char * format_num3( unsigned long long num ) if( num > 1024 ) { char prefix = 0; /* try binary first, then si */ - for( i = 0; i < 8 && num >= 1024 && num % 1024 == 0; ++i ) + for( i = 0; i < n && num != 0 && num % 1024 == 0; ++i ) { num /= 1024; prefix = binary_prefix[i]; } if( prefix ) *(--p) = 'i'; else - for( i = 0; i < 8 && num >= 1000 && num % 1000 == 0; ++i ) + for( i = 0; i < n && num != 0 && num % 1000 == 0; ++i ) { num /= 1000; prefix = si_prefix[i]; } if( prefix ) *(--p) = prefix; } - const bool split = num >= 100000; + const bool split = num >= 10000; for( i = 0; ; ) { @@ -376,6 +379,16 @@ static const char * format_num3( unsigned long long num ) } +void show_option_error( const char * const arg, const char * const msg, + const char * const option_name ) + { + if( verbosity >= 0 ) + fprintf( stderr, "%s: '%s': %s option '%s'.\n", + program_name, arg, msg, option_name ); + } + + +/* Recognized formats: k, Ki, [MGTPEZYRQ][i] */ static unsigned long long getnum( const char * const arg, const char * const option_name, const unsigned long long llimit, @@ -385,12 +398,8 @@ static unsigned long long getnum( const char * const arg, errno = 0; unsigned long long result = strtoull( arg, &tail, 0 ); if( tail == arg ) - { - if( verbosity >= 0 ) - fprintf( stderr, "%s: Bad or missing numerical argument in " - "option '%s'.\n", program_name, option_name ); - exit( 1 ); - } + { show_option_error( arg, "Bad or missing numerical argument in", + option_name ); exit( 1 ); } if( !errno && tail[0] ) { @@ -399,6 +408,8 @@ static unsigned long long getnum( const char * const arg, int i; switch( tail[0] ) { + case 'Q': exponent = 10; break; + case 'R': exponent = 9; break; case 'Y': exponent = 8; break; case 'Z': exponent = 7; break; case 'E': exponent = 6; break; @@ -410,12 +421,8 @@ static unsigned long long getnum( const char * const arg, case 'k': if( factor == 1000 ) exponent = 1; break; } if( exponent <= 0 ) - { - if( verbosity >= 0 ) - fprintf( stderr, "%s: Bad multiplier in numerical argument of " - "option '%s'.\n", program_name, option_name ); - exit( 1 ); - } + { show_option_error( arg, "Bad multiplier in numerical argument of", + option_name ); exit( 1 ); } for( i = 0; i < exponent; ++i ) { if( ulimit / factor >= result ) result *= factor; @@ -426,8 +433,8 @@ static unsigned long long getnum( const char * const arg, if( errno ) { if( verbosity >= 0 ) - fprintf( stderr, "%s: Numerical argument out of limits [%s,%s] " - "in option '%s'.\n", program_name, format_num3( llimit ), + fprintf( stderr, "%s: '%s': Value out of limits [%s,%s] in " + "option '%s'.\n", program_name, arg, format_num3( llimit ), format_num3( ulimit ), option_name ); exit( 1 ); } @@ -508,7 +515,7 @@ static void set_d_outname( const char * const name, const int eindex ) strcpy( output_filename, name ); strcat( output_filename, ".out" ); if( verbosity >= 1 ) - fprintf( stderr, "%s: Can't guess original name for '%s' -- using '%s'\n", + fprintf( stderr, "%s: %s: Can't guess original name -- using '%s'\n", program_name, name, output_filename ); } @@ -520,7 +527,7 @@ static int open_instream( const char * const name, struct stat * const in_statsp if( program_mode == m_compress && !recompress && eindex >= 0 ) { if( verbosity >= 0 ) - fprintf( stderr, "%s: Input file '%s' already has '%s' suffix.\n", + fprintf( stderr, "%s: %s: Input file already has '%s' suffix.\n", program_name, name, known_extensions[eindex].from ); return -1; } @@ -537,9 +544,9 @@ static int open_instream( const char * const name, struct stat * const in_statsp if( i != 0 || ( !S_ISREG( mode ) && ( !can_read || one_to_one ) ) ) { if( verbosity >= 0 ) - fprintf( stderr, "%s: Input file '%s' is not a regular file%s.\n", + fprintf( stderr, "%s: %s: Input file is not a regular file%s.\n", program_name, name, ( can_read && one_to_one ) ? - ",\n and neither '-c' nor '-o' were specified" : "" ); + ",\n and neither '-c' nor '-o' were specified" : "" ); close( infd ); infd = -1; } @@ -558,16 +565,12 @@ static bool open_outstream( const bool force, const bool protect ) outfd = open( output_filename, flags, outfd_mode ); if( outfd >= 0 ) delete_output_on_interrupt = true; - else if( verbosity >= 0 ) - { - if( errno == EEXIST ) - fprintf( stderr, "%s: Output file '%s' already exists, skipping.\n", - program_name, output_filename ); - else - fprintf( stderr, "%s: Can't create output file '%s': %s\n", - program_name, output_filename, strerror( errno ) ); - } - return ( outfd >= 0 ); + else if( errno == EEXIST ) + show_file_error( output_filename, + "Output file already exists, skipping.", 0 ); + else + show_file_error( output_filename, "Can't create output file", errno ); + return outfd >= 0; } @@ -585,12 +588,10 @@ static void cleanup_and_fail( const int retval ) if( delete_output_on_interrupt ) { delete_output_on_interrupt = false; - if( verbosity >= 0 ) - fprintf( stderr, "%s: Deleting output file '%s', if it exists.\n", - program_name, output_filename ); + show_file_error( output_filename, "Deleting output file, if it exists.", 0 ); if( outfd >= 0 ) { close( outfd ); outfd = -1; } if( remove( output_filename ) != 0 && errno != ENOENT ) - show_error( "WARNING: deletion of output file (apparently) failed.", 0, false ); + show_error( "warning: deletion of output file failed", errno, false ); } exit( retval ); } @@ -635,7 +636,7 @@ static void close_and_set_permissions( const struct stat * const in_statsp ) if( in_statsp ) { const mode_t mode = in_statsp->st_mode; - /* fchown will in many cases return with EPERM, which can be safely ignored. */ + /* fchown in many cases returns with EPERM, which can be safely ignored. */ if( fchown( outfd, in_statsp->st_uid, in_statsp->st_gid ) == 0 ) { if( fchmod( outfd, mode ) != 0 ) warning = true; } else @@ -644,10 +645,8 @@ static void close_and_set_permissions( const struct stat * const in_statsp ) warning = true; } if( close( outfd ) != 0 ) - { - show_error( "Error closing output file", errno, false ); - cleanup_and_fail( 1 ); - } + { show_file_error( output_filename, "Error closing output file", errno ); + cleanup_and_fail( 1 ); } outfd = -1; delete_output_on_interrupt = false; if( in_statsp ) @@ -658,7 +657,8 @@ static void close_and_set_permissions( const struct stat * const in_statsp ) if( utime( output_filename, &t ) != 0 ) warning = true; } if( warning && verbosity >= 1 ) - show_error( "Can't change output file attributes.", 0, false ); + show_file_error( output_filename, + "warning: can't change output file attributes", errno ); } @@ -1033,8 +1033,8 @@ static void internal_error( const char * const msg ) int main( const int argc, const char * const argv[] ) { - /* Mapping from gzip/bzip2 style 1..9 compression modes - to the corresponding LZMA compression modes. */ + /* Mapping from gzip/bzip2 style 0..9 compression levels to the + corresponding LZMA compression parameters. */ const struct Lzma_options option_mapping[] = { { 65535, 16 }, /* -0 (65535,16 chooses fast encoder) */ @@ -1139,7 +1139,7 @@ int main( const int argc, const char * const argv[] ) case 'V': show_version(); return 0; case opt_chk: return check_lib(); case opt_lt: loose_trailing = true; break; - default : internal_error( "uncaught option." ); + default: internal_error( "uncaught option." ); } } /* end process options */ @@ -1204,11 +1204,11 @@ int main( const int argc, const char * const argv[] ) int retval = 0; const bool one_to_one = !to_stdout && program_mode != m_test && !to_file; bool stdin_used = false; + struct stat in_stats; for( i = 0; i < num_filenames; ++i ) { const char * input_filename = ""; int infd; - struct stat in_stats; Pp_set_name( &pp, filenames[i] ); if( strcmp( filenames[i], "-" ) == 0 ) @@ -1225,7 +1225,7 @@ int main( const int argc, const char * const argv[] ) eindex, one_to_one, recompress ); if( infd < 0 ) { set_retval( &retval, 1 ); continue; } if( !check_tty_in( pp.name, infd, program_mode, &retval ) ) continue; - if( one_to_one ) /* open outfd after verifying infd */ + if( one_to_one ) /* open outfd after checking infd */ { if( program_mode == m_compress ) set_c_outname( input_filename, true, volume_size > 0 ); @@ -1238,7 +1238,7 @@ int main( const int argc, const char * const argv[] ) if( one_to_one && !check_tty_out( program_mode ) ) { set_retval( &retval, 1 ); return retval; } /* don't delete a tty */ - if( to_file && outfd < 0 ) /* open outfd after verifying infd */ + if( to_file && outfd < 0 ) /* open outfd after checking infd */ { if( program_mode == m_compress ) set_c_outname( default_output_filename, false, volume_size > 0 ); @@ -1257,8 +1257,8 @@ int main( const int argc, const char * const argv[] ) tmp = compress( member_size, volume_size, infd, &encoder_options, &pp, in_statsp ); else - tmp = decompress( infd, &pp, ignore_trailing, - loose_trailing, program_mode == m_test ); + tmp = decompress( infd, &pp, ignore_trailing, loose_trailing, + program_mode == m_test ); if( close( infd ) != 0 ) { show_file_error( pp.name, "Error closing input file", errno ); set_retval( &tmp, 1 ); } @@ -1273,7 +1273,9 @@ int main( const int argc, const char * const argv[] ) ( program_mode != m_compress || volume_size == 0 ) ) remove( input_filename ); } - if( delete_output_on_interrupt ) close_and_set_permissions( 0 ); /* -o */ + if( delete_output_on_interrupt ) /* -o */ + close_and_set_permissions( ( retval == 0 && !stdin_used && + filenames_given && num_filenames == 1 ) ? &in_stats : 0 ); else if( outfd >= 0 && close( outfd ) != 0 ) /* -c */ { show_error( "Error closing stdout", errno, false ); diff --git a/testsuite/check.sh b/testsuite/check.sh index e93697e..1c5daf7 100755 --- a/testsuite/check.sh +++ b/testsuite/check.sh @@ -1,6 +1,6 @@ #! /bin/sh # check script for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2022 Antonio Diaz Diaz. +# Copyright (C) 2009-2024 Antonio Diaz Diaz. # # This script is free software: you have unlimited permission # to copy, distribute, and modify it. @@ -41,6 +41,7 @@ test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; } "${LZIP}" --check-lib # just print warning [ $? != 2 ] || { test_failed $LINENO ; exit 2 ; } # unless bad lzlib.h + printf "testing lzlib-%s..." "$2" "${LZIP}" -fkqm4 in @@ -74,8 +75,9 @@ done [ ! -e out.lz ] || test_failed $LINENO "${LZIP}" -qf -S100k -o out in in [ $? = 1 ] || test_failed $LINENO +{ [ ! -e out ] && [ ! -e out.lz ] ; } || test_failed $LINENO # these are for code coverage -"${LZIP}" -cdt "${in_lz}" > out 2> /dev/null +"${LZIP}" -cdt "${in_lz}" 2> /dev/null [ $? = 1 ] || test_failed $LINENO "${LZIP}" -t -- nx_file.lz 2> /dev/null [ $? = 1 ] || test_failed $LINENO @@ -100,35 +102,35 @@ done printf "LZIP\001-.............................." | "${LZIP}" -t 2> /dev/null printf "LZIP\002-.............................." | "${LZIP}" -t 2> /dev/null printf "LZIP\001+.............................." | "${LZIP}" -t 2> /dev/null -rm -f out || framework_failure printf "\ntesting decompression..." for i in "${in_lz}" "${in_em}" "${testdir}"/test_sync.lz ; do "${LZIP}" -t "$i" || test_failed $LINENO "$i" - "${LZIP}" -d "$i" -o copy || test_failed $LINENO "$i" - cmp in copy || test_failed $LINENO "$i" - "${LZIP}" -cd "$i" > copy || test_failed $LINENO "$i" - cmp in copy || test_failed $LINENO "$i" - "${LZIP}" -d "$i" -o - > copy || test_failed $LINENO "$i" - cmp in copy || test_failed $LINENO "$i" - "${LZIP}" -d < "$i" > copy || test_failed $LINENO "$i" - cmp in copy || test_failed $LINENO "$i" - rm -f copy || framework_failure + "${LZIP}" -d "$i" -o out || test_failed $LINENO "$i" + cmp in out || test_failed $LINENO "$i" + "${LZIP}" -cd "$i" > out || test_failed $LINENO "$i" + cmp in out || test_failed $LINENO "$i" + "${LZIP}" -d "$i" -o - > out || test_failed $LINENO "$i" + cmp in out || test_failed $LINENO "$i" + "${LZIP}" -d < "$i" > out || test_failed $LINENO "$i" + cmp in out || test_failed $LINENO "$i" + rm -f out || framework_failure done -lines=$("${LZIP}" -tvv "${in_em}" 2>&1 | wc -l) || test_failed $LINENO +lines=`"${LZIP}" -tvv "${in_em}" 2>&1 | wc -l` || test_failed $LINENO [ "${lines}" -eq 8 ] || test_failed $LINENO "${lines}" -"${LZIP}" -cd "${fox_lz}" > fox || test_failed $LINENO -cat "${in_lz}" > copy.lz || framework_failure -"${LZIP}" -dk copy.lz || test_failed $LINENO -cmp in copy || test_failed $LINENO -cat fox > copy || framework_failure cat "${in_lz}" > out.lz || framework_failure +"${LZIP}" -dk out.lz || test_failed $LINENO +cmp in out || test_failed $LINENO rm -f out || framework_failure +"${LZIP}" -cd "${fox_lz}" > fox || test_failed $LINENO +cat fox > copy || framework_failure +cat "${in_lz}" > copy.lz || framework_failure "${LZIP}" -d copy.lz out.lz 2> /dev/null # skip copy, decompress out [ $? = 1 ] || test_failed $LINENO +[ ! -e out.lz ] || test_failed $LINENO cmp fox copy || test_failed $LINENO cmp in out || test_failed $LINENO "${LZIP}" -df copy.lz || test_failed $LINENO @@ -136,15 +138,15 @@ cmp in out || test_failed $LINENO cmp in copy || test_failed $LINENO rm -f copy out || framework_failure -cat "${in_lz}" > copy.lz || framework_failure -"${LZIP}" -d -S100k copy.lz || test_failed $LINENO # ignore -S -[ ! -e copy.lz ] || test_failed $LINENO -cmp in copy || test_failed $LINENO +cat "${in_lz}" > out.lz || framework_failure +"${LZIP}" -d -S100k out.lz || test_failed $LINENO # ignore -S +[ ! -e out.lz ] || test_failed $LINENO +cmp in out || test_failed $LINENO -printf "to be overwritten" > copy || framework_failure -"${LZIP}" -df -o copy < "${in_lz}" || test_failed $LINENO -cmp in copy || test_failed $LINENO -rm -f out copy || framework_failure +printf "to be overwritten" > out || framework_failure +"${LZIP}" -df -o out < "${in_lz}" || test_failed $LINENO +cmp in out || test_failed $LINENO +rm -f out || framework_failure "${LZIP}" -d -o ./- "${in_lz}" || test_failed $LINENO cmp in ./- || test_failed $LINENO rm -f ./- || framework_failure @@ -153,67 +155,68 @@ cmp in ./- || test_failed $LINENO rm -f ./- || framework_failure cat "${in_lz}" > anyothername || framework_failure -"${LZIP}" -dv - anyothername - < "${in_lz}" > copy 2> /dev/null || +"${LZIP}" -dv - anyothername - < "${in_lz}" > out 2> /dev/null || test_failed $LINENO -cmp in copy || test_failed $LINENO +cmp in out || test_failed $LINENO cmp in anyothername.out || test_failed $LINENO -rm -f copy anyothername.out || framework_failure +rm -f out anyothername.out || framework_failure "${LZIP}" -tq in "${in_lz}" [ $? = 2 ] || test_failed $LINENO "${LZIP}" -tq nx_file.lz "${in_lz}" [ $? = 1 ] || test_failed $LINENO -"${LZIP}" -cdq in "${in_lz}" > copy +"${LZIP}" -cdq in "${in_lz}" > out [ $? = 2 ] || test_failed $LINENO -cat copy in | cmp in - || test_failed $LINENO # copy must be empty -"${LZIP}" -cdq nx_file.lz "${in_lz}" > copy +cat out in | cmp in - || test_failed $LINENO # out must be empty +"${LZIP}" -cdq nx_file.lz "${in_lz}" > out # skip nx_file, decompress in [ $? = 1 ] || test_failed $LINENO -cmp in copy || test_failed $LINENO -rm -f copy || framework_failure -cat "${in_lz}" > copy.lz || framework_failure +cmp in out || test_failed $LINENO +rm -f out || framework_failure +cat "${in_lz}" > out.lz || framework_failure for i in 1 2 3 4 5 6 7 ; do - printf "g" >> copy.lz || framework_failure - "${LZIP}" -atvvvv copy.lz "${in_lz}" 2> /dev/null + printf "g" >> out.lz || framework_failure + "${LZIP}" -atvvvv out.lz "${in_lz}" 2> /dev/null [ $? = 2 ] || test_failed $LINENO $i done -"${LZIP}" -dq in copy.lz +"${LZIP}" -dq in out.lz [ $? = 2 ] || test_failed $LINENO -[ -e copy.lz ] || test_failed $LINENO -[ ! -e copy ] || test_failed $LINENO +[ -e out.lz ] || test_failed $LINENO +[ ! -e out ] || test_failed $LINENO [ ! -e in.out ] || test_failed $LINENO -"${LZIP}" -dq nx_file.lz copy.lz +"${LZIP}" -dq nx_file.lz out.lz [ $? = 1 ] || test_failed $LINENO -[ ! -e copy.lz ] || test_failed $LINENO +[ ! -e out.lz ] || test_failed $LINENO [ ! -e nx_file ] || test_failed $LINENO -cmp in copy || test_failed $LINENO +cmp in out || test_failed $LINENO +rm -f out || framework_failure cat in in > in2 || framework_failure "${LZIP}" -t "${in_lz}" "${in_lz}" || test_failed $LINENO -"${LZIP}" -cd "${in_lz}" "${in_lz}" -o out > copy2 || test_failed $LINENO +"${LZIP}" -cd "${in_lz}" "${in_lz}" -o out > out2 || test_failed $LINENO [ ! -e out ] || test_failed $LINENO # override -o -cmp in2 copy2 || test_failed $LINENO -rm -f copy2 || framework_failure -"${LZIP}" -d "${in_lz}" "${in_lz}" -o copy2 || test_failed $LINENO -cmp in2 copy2 || test_failed $LINENO -rm -f copy2 || framework_failure +cmp in2 out2 || test_failed $LINENO +rm -f out2 || framework_failure +"${LZIP}" -d "${in_lz}" "${in_lz}" -o out2 || test_failed $LINENO +cmp in2 out2 || test_failed $LINENO +rm -f out2 || framework_failure -cat "${in_lz}" "${in_lz}" > copy2.lz || framework_failure -printf "\ngarbage" >> copy2.lz || framework_failure -"${LZIP}" -tvvvv copy2.lz 2> /dev/null || test_failed $LINENO -"${LZIP}" -atq copy2.lz +cat "${in_lz}" "${in_lz}" > out2.lz || framework_failure +printf "\ngarbage" >> out2.lz || framework_failure +"${LZIP}" -tvvvv out2.lz 2> /dev/null || test_failed $LINENO +"${LZIP}" -atq out2.lz [ $? = 2 ] || test_failed $LINENO -"${LZIP}" -atq < copy2.lz +"${LZIP}" -atq < out2.lz [ $? = 2 ] || test_failed $LINENO -"${LZIP}" -adkq copy2.lz +"${LZIP}" -adkq out2.lz [ $? = 2 ] || test_failed $LINENO -[ ! -e copy2 ] || test_failed $LINENO -"${LZIP}" -adkq -o copy2 < copy2.lz +[ ! -e out2 ] || test_failed $LINENO +"${LZIP}" -adkq -o out2 < out2.lz [ $? = 2 ] || test_failed $LINENO -[ ! -e copy2 ] || test_failed $LINENO -printf "to be overwritten" > copy2 || framework_failure -"${LZIP}" -df copy2.lz || test_failed $LINENO -cmp in2 copy2 || test_failed $LINENO -rm -f copy2 || framework_failure +[ ! -e out2 ] || test_failed $LINENO +printf "to be overwritten" > out2 || framework_failure +"${LZIP}" -df out2.lz || test_failed $LINENO +cmp in2 out2 || test_failed $LINENO +rm -f out2 || framework_failure printf "\ntesting compression..." @@ -221,14 +224,16 @@ printf "\ntesting compression..." [ ! -e out3.lz ] || test_failed $LINENO # override -o and -S "${LZIP}" -0f in in --output=copy2.lz || test_failed $LINENO "${LZIP}" -d copy2.lz -o out2 || test_failed $LINENO +[ -e copy2.lz ] || test_failed $LINENO cmp in2 out2 || test_failed $LINENO rm -f out2 copy2.lz || framework_failure -"${LZIP}" -cf "${in_lz}" > out 2> /dev/null # /dev/null is a tty on OS/2 +"${LZIP}" -cf "${in_lz}" > lzlz 2> /dev/null # /dev/null is a tty on OS/2 [ $? = 1 ] || test_failed $LINENO -"${LZIP}" -Fvvm36 -o - -s16 "${in_lz}" > out 2> /dev/null || test_failed $LINENO -"${LZIP}" -cd out | "${LZIP}" -d > copy || test_failed $LINENO -cmp in copy || test_failed $LINENO +"${LZIP}" -Fvvm36 -o - -s16 "${in_lz}" > lzlz 2> /dev/null || test_failed $LINENO +"${LZIP}" -cd lzlz | "${LZIP}" -d > out || test_failed $LINENO +cmp in out || test_failed $LINENO +rm -f lzlz out || framework_failure "${LZIP}" -0 -o ./- in || test_failed $LINENO "${LZIP}" -cd ./- | cmp in - || test_failed $LINENO @@ -240,10 +245,10 @@ rm -f ./- || framework_failure for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do "${LZIP}" -k -$i -s16 in || test_failed $LINENO $i - mv -f in.lz copy.lz || test_failed $LINENO $i - printf "garbage" >> copy.lz || framework_failure - "${LZIP}" -df copy.lz || test_failed $LINENO $i - cmp in copy || test_failed $LINENO $i + mv in.lz out.lz || test_failed $LINENO $i + printf "garbage" >> out.lz || framework_failure + "${LZIP}" -df out.lz || test_failed $LINENO $i + cmp in out || test_failed $LINENO $i "${LZIP}" -$i -s16 in -c > out || test_failed $LINENO $i "${LZIP}" -$i -s16 in -o o_out || test_failed $LINENO $i # don't add .lz @@ -259,13 +264,13 @@ for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do cmp in copy || test_failed $LINENO $i rm -f out.lz || framework_failure - printf "to be overwritten" > out || framework_failure # don't add .lz - "${LZIP}" -f -$i -s16 -o out < in || test_failed $LINENO $i + printf "to be overwritten" > out || framework_failure + "${LZIP}" -f -$i -s16 -o out < in || test_failed $LINENO $i # don't add .lz [ ! -e out.lz ] || test_failed $LINENO "${LZIP}" -df -o copy < out || test_failed $LINENO $i cmp in copy || test_failed $LINENO $i done -rm -f out out.lz || framework_failure +rm -f copy out || framework_failure cat in in in in in in in in > in8 || framework_failure "${LZIP}" -1s12 -S100k in8 || test_failed $LINENO @@ -337,12 +342,12 @@ printf "\ntesting bad input..." headers='LZIp LZiP LZip LzIP LzIp LziP lZIP lZIp lZiP lzIP' body='\001\014\000\203\377\373\377\377\300\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000$\000\000\000\000\000\000\000' -cat "${in_lz}" > int.lz -printf "LZIP${body}" >> int.lz +cat "${in_lz}" > int.lz || framework_failure +printf "LZIP${body}" >> int.lz || framework_failure if "${LZIP}" -tq int.lz ; then for header in ${headers} ; do - printf "${header}${body}" > int.lz # first member - "${LZIP}" -tq int.lz + printf "${header}${body}" > int.lz || framework_failure + "${LZIP}" -tq int.lz # first member [ $? = 2 ] || test_failed $LINENO ${header} "${LZIP}" -tq < int.lz [ $? = 2 ] || test_failed $LINENO ${header} @@ -354,9 +359,9 @@ if "${LZIP}" -tq int.lz ; then [ $? = 2 ] || test_failed $LINENO ${header} "${LZIP}" -cdq --loose-trailing int.lz > /dev/null [ $? = 2 ] || test_failed $LINENO ${header} - cat "${in_lz}" > int.lz - printf "${header}${body}" >> int.lz # trailing data - "${LZIP}" -tq int.lz + cat "${in_lz}" > int.lz || framework_failure + printf "${header}${body}" >> int.lz || framework_failure + "${LZIP}" -tq int.lz # trailing data [ $? = 2 ] || test_failed $LINENO ${header} "${LZIP}" -tq < int.lz [ $? = 2 ] || test_failed $LINENO ${header} @@ -403,15 +408,15 @@ if dd if=in3.lz of=trunc.lz bs=14752 count=1 2> /dev/null && [ $? = 2 ] || test_failed $LINENO $i "${LZIP}" -tq < trunc.lz [ $? = 2 ] || test_failed $LINENO $i - "${LZIP}" -cdq trunc.lz > out + "${LZIP}" -cdq trunc.lz > /dev/null [ $? = 2 ] || test_failed $LINENO $i - "${LZIP}" -dq < trunc.lz > out + "${LZIP}" -dq < trunc.lz > /dev/null [ $? = 2 ] || test_failed $LINENO $i done else printf "\nwarning: skipping truncation test: 'dd' does not work on your system." fi -rm -f in2.lz in3.lz trunc.lz out || framework_failure +rm -f in2.lz in3.lz trunc.lz || framework_failure cat "${in_lz}" > ingin.lz || framework_failure printf "g" >> ingin.lz || framework_failure @@ -420,19 +425,19 @@ cat "${in_lz}" >> ingin.lz || framework_failure [ $? = 2 ] || test_failed $LINENO "${LZIP}" -atq < ingin.lz [ $? = 2 ] || test_failed $LINENO -"${LZIP}" -acdq ingin.lz > out +"${LZIP}" -acdq ingin.lz > /dev/null [ $? = 2 ] || test_failed $LINENO -"${LZIP}" -adq < ingin.lz > out +"${LZIP}" -adq < ingin.lz > /dev/null [ $? = 2 ] || test_failed $LINENO "${LZIP}" -t ingin.lz || test_failed $LINENO "${LZIP}" -t < ingin.lz || test_failed $LINENO -"${LZIP}" -cd ingin.lz > copy || test_failed $LINENO -cmp in copy || test_failed $LINENO -"${LZIP}" -d < ingin.lz > copy || test_failed $LINENO -cmp in copy || test_failed $LINENO +"${LZIP}" -cd ingin.lz > out || test_failed $LINENO +cmp in out || test_failed $LINENO +"${LZIP}" -d < ingin.lz > out || test_failed $LINENO +cmp in out || test_failed $LINENO "${FFEXAMPLE}" -d ingin.lz | cmp in - || test_failed $LINENO "${FFEXAMPLE}" -r ingin.lz | cmp in2 - || test_failed $LINENO -rm -f copy ingin.lz in2 out || framework_failure +rm -f in2 out ingin.lz || framework_failure echo if [ ${fail} = 0 ] ; then From f9a7449f7c5440c0c4215eae59526295492e114e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 20 Feb 2025 21:34:00 +0100 Subject: [PATCH 07/10] Adding upstream version 1.15~pre1. Signed-off-by: Daniel Baumann --- ChangeLog | 14 +++++++++++--- INSTALL | 14 ++++++++++---- Makefile.in | 21 ++++++++++++-------- NEWS | 22 +++++++-------------- README | 2 +- configure | 13 ++++++++++--- decoder.c | 10 +++++----- doc/lzlib.info | 52 ++++++++++++++++++++++++++------------------------ doc/lzlib.texi | 10 ++++++---- doc/minilzip.1 | 8 ++++---- encoder_base.c | 10 ++++------ lzlib.h | 4 ++-- minilzip.c | 10 +++++++--- 13 files changed, 107 insertions(+), 83 deletions(-) diff --git a/ChangeLog b/ChangeLog index f178fe7..a945949 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2024-04-19 Antonio Diaz Diaz + + * Version 1.15-pre1 released. + * Makefile.in: New target 'lib' which builds just the library. + New target 'bin' which builds the library and minilzip. + 'lib' is now the default; minilzip is no longer built by default. + 'install-bin' installs minilzip and its man page again. + * INSTALL: Document use of 'make bin'. + 2024-01-20 Antonio Diaz Diaz * Version 1.14 released. @@ -261,6 +270,5 @@ Copyright (C) 2009-2024 Antonio Diaz Diaz. -This file is a collection of facts, and thus it is not copyrightable, -but just in case, you have unlimited permission to copy, distribute, and -modify it. +This file is a collection of facts, and thus it is not copyrightable, but just +in case, you have unlimited permission to copy, distribute, and modify it. diff --git a/INSTALL b/INSTALL index 275b69b..570247e 100644 --- a/INSTALL +++ b/INSTALL @@ -35,10 +35,16 @@ extracted from the archive. ./configure CFLAGS+='-D __USE_MINGW_ANSI_STDIO' -3. Run make. +3. Run make make +to build the library, or + + make bin + +to build also minilzip. + 4. Optionally, type 'make check' to run the tests that come with lzlib. 5. Type 'make install' to install the library and any data files and @@ -52,9 +58,9 @@ extracted from the archive. You can install only the library or the info manual by typing 'make install-lib' or 'make install-info' respectively. - 'make install-bin install-man' installs the program minilzip and its man - page. 'install-bin' installs a shared minilzip if the shared library has - been configured. Else it installs a static minilzip. + 'make install-bin' installs the program minilzip and its man page. It + installs a shared minilzip if the shared library has been configured. + Else it installs a static minilzip. 'make install-bin-compress' additionally compresses the man page after installation. diff --git a/Makefile.in b/Makefile.in index de54626..cf90c91 100644 --- a/Makefile.in +++ b/Makefile.in @@ -20,7 +20,9 @@ objs = carg_parser.o minilzip.o uninstall uninstall-bin uninstall-lib uninstall-info uninstall-man \ doc info man check dist clean distclean -all : $(progname_static) $(progname_shared) +all : lib + +lib : $(libname_static) $(libname_shared) lib$(libname).a : lzlib.o $(AR) $(ARFLAGS) $@ $< @@ -28,6 +30,8 @@ lib$(libname).a : lzlib.o lib$(libname).so.$(pkgversion) : lzlib_sh.o $(CC) $(CFLAGS) $(LDFLAGS) -fpic -fPIC -shared -Wl,--soname=lib$(libname).so.$(soversion) -o $@ $< +bin : $(progname_static) $(progname_shared) + $(progname) : $(objs) lib$(libname).a $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(objs) lib$(libname).a @@ -54,7 +58,8 @@ lzlib_sh.o : lzlib.c # prevent 'make' from trying to remake source files $(VPATH)/configure $(VPATH)/Makefile.in $(VPATH)/doc/$(pkgname).texi : ; -%.h %.c : ; +MAKEFLAGS += -r +.SUFFIXES : lzdeps = lzlib.h lzip.h cbuffer.c decoder.h decoder.c encoder_base.h \ encoder_base.c encoder.h encoder.c fast_encoder.h fast_encoder.c @@ -93,21 +98,21 @@ install-strip-compress : install-lib-strip install-info-compress install-bin-compress : install-bin install-man-compress install-bin-strip-compress : install-bin-strip install-man-compress -install-bin : all +install-bin : bin install-man if [ ! -d "$(DESTDIR)$(bindir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(bindir)" ; fi $(INSTALL_PROGRAM) ./$(progname_lzip) "$(DESTDIR)$(bindir)/$(progname)" -install-bin-strip : all +install-bin-strip : bin $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-bin -install-lib : all +install-lib : lib if [ ! -d "$(DESTDIR)$(includedir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(includedir)" ; fi if [ ! -d "$(DESTDIR)$(libdir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(libdir)" ; fi $(INSTALL_DATA) $(VPATH)/$(libname)lib.h "$(DESTDIR)$(includedir)/$(libname)lib.h" - if [ -n "$(progname_static)" ] ; then \ + if [ -n "$(libname_static)" ] ; then \ $(INSTALL_DATA) ./lib$(libname).a "$(DESTDIR)$(libdir)/lib$(libname).a" ; \ fi - if [ -n "$(progname_shared)" ] ; then \ + if [ -n "$(libname_shared)" ] ; then \ $(INSTALL_PROGRAM) ./lib$(libname).so.$(pkgversion) "$(DESTDIR)$(libdir)/lib$(libname).so.$(pkgversion)" ; \ if [ -e "$(DESTDIR)$(libdir)/lib$(libname).so.$(soversion)" ] ; then \ run_ldconfig=no ; \ @@ -121,7 +126,7 @@ install-lib : all [ -x "$(LDCONFIG)" ] ; then "$(LDCONFIG)" -n "$(DESTDIR)$(libdir)" || true ; fi ; \ fi -install-lib-strip : all +install-lib-strip : lib $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-lib install-info : diff --git a/NEWS b/NEWS index 101b35a..94f6a9a 100644 --- a/NEWS +++ b/NEWS @@ -1,19 +1,11 @@ -Changes in version 1.14: +Changes in version 1.15: -In minilzip, file diagnostics have been reformatted as 'PROGRAM: FILE: MESSAGE'. +The targets 'lib' and 'bin' have been added to Makefile.in. 'lib' is the new +default and builds just the library. 'bin' builds both the library and +minilzip. -In minilzip, diagnostics caused by invalid arguments to command-line options -now show the argument and the name of the option. +minilzip is no longer built by default. -The option '-o, --output' of minilzip now preserves dates, permissions, and -ownership of the file, when (de)compressing exactly one file. +'install-bin' installs minilzip and its man page again. -It has been documented in the manual that it is the responsibility of the -program using lzlib to include before 'lzlib.h' some header that declares -the type 'uint8_t'. (Reported by Michal Górny). - -The variable MAKEINFO has been added to configure and Makefile.in. - -It has been documented in INSTALL that when choosing a C standard, the POSIX -features need to be enabled explicitly: - ./configure CFLAGS+='--std=c99 -D_XOPEN_SOURCE=500' +The use of the target 'bin' has been documented in INSTALL. diff --git a/README b/README index 7dc2950..2207fb5 100644 --- a/README +++ b/README @@ -83,7 +83,7 @@ Lzlib currently implements two variants of the LZMA algorithm: fast (used by option '-0' of minilzip) and normal (used by all other compression levels). The high compression of LZMA comes from combining two basic, well-proven -compression ideas: sliding dictionaries (LZ77) and markov models (the thing +compression ideas: sliding dictionaries (LZ77) and Markov models (the thing used by every compression algorithm that uses a range encoder or similar order-0 entropy coder as its last stage) with segregation of contexts according to what the bits are used for. diff --git a/configure b/configure index ec5c149..b24d769 100755 --- a/configure +++ b/configure @@ -6,14 +6,16 @@ # to copy, distribute, and modify it. pkgname=lzlib -pkgversion=1.14 +pkgversion=1.15-pre1 soversion=1 +libname=lz +libname_static=lib${libname}.a +libname_shared= progname=minilzip progname_static=${progname} progname_shared= progname_lzip=${progname} disable_ldconfig= -libname=lz srctrigger=doc/${pkgname}.texi # clear some things potentially inherited from environment. @@ -115,10 +117,13 @@ while [ $# != 0 ] ; do --mandir=*) mandir=${optarg} ;; --no-create) no_create=yes ;; --disable-static) + libname_static= + libname_shared=lib${libname}.so.${pkgversion} progname_static= progname_shared=${progname}_shared progname_lzip=${progname}_shared ;; --enable-shared) + libname_shared=lib${libname}.so.${pkgversion} progname_shared=${progname}_shared progname_lzip=${progname}_shared ;; --disable-ldconfig) disable_ldconfig=yes ;; @@ -216,12 +221,14 @@ cat > Makefile << EOF pkgname = ${pkgname} pkgversion = ${pkgversion} soversion = ${soversion} +libname = ${libname} +libname_static = ${libname_static} +libname_shared = ${libname_shared} progname = ${progname} progname_static = ${progname_static} progname_shared = ${progname_shared} progname_lzip = ${progname_lzip} disable_ldconfig = ${disable_ldconfig} -libname = ${libname} VPATH = ${srcdir} prefix = ${prefix} exec_prefix = ${exec_prefix} diff --git a/decoder.c b/decoder.c index 6544ec6..d1fbe54 100644 --- a/decoder.c +++ b/decoder.c @@ -40,7 +40,7 @@ static int LZd_decode_member( struct LZ_decoder * const d ) { struct Range_decoder * const rdec = d->rdec; State * const state = &d->state; - /* unsigned old_mpos = rdec->member_position; */ + unsigned old_mpos = rdec->member_position; if( d->member_finished ) return 0; if( !Rd_try_reload( rdec ) ) @@ -49,9 +49,9 @@ static int LZd_decode_member( struct LZ_decoder * const d ) while( !Rd_finished( rdec ) ) { - /* const unsigned mpos = rdec->member_position; + const unsigned mpos = rdec->member_position; if( mpos - old_mpos > rd_min_available_bytes ) return 5; - old_mpos = mpos; */ + old_mpos = mpos; if( !Rd_enough_available_bytes( rdec ) ) /* check unexpected EOF */ { if( !rdec->at_stream_end ) return 0; if( Cb_empty( &rdec->cb ) ) break; } /* decode until EOF */ @@ -116,9 +116,9 @@ static int LZd_decode_member( struct LZ_decoder * const d ) if( distance == 0xFFFFFFFFU ) /* marker found */ { Rd_normalize( rdec ); - /* const unsigned mpos = rdec->member_position; + const unsigned mpos = rdec->member_position; if( mpos - old_mpos > rd_min_available_bytes ) return 5; - old_mpos = mpos; */ + old_mpos = mpos; if( len == min_match_len ) /* End Of Stream marker */ { d->check_trailer_pending = true; diff --git a/doc/lzlib.info b/doc/lzlib.info index 979c477..314c98a 100644 --- a/doc/lzlib.info +++ b/doc/lzlib.info @@ -11,7 +11,7 @@ File: lzlib.info, Node: Top, Next: Introduction, Up: (dir) Lzlib Manual ************ -This manual is for Lzlib (version 1.14, 20 January 2024). +This manual is for Lzlib (version 1.15-pre1, 19 April 2024). * Menu: @@ -127,7 +127,7 @@ using the LZMA coding scheme. levels). The high compression of LZMA comes from combining two basic, well-proven -compression ideas: sliding dictionaries (LZ77) and markov models (the thing +compression ideas: sliding dictionaries (LZ77) and Markov models (the thing used by every compression algorithm that uses a range encoder or similar order-0 entropy coder as its last stage) with segregation of contexts according to what the bits are used for. @@ -647,7 +647,9 @@ File: lzlib.info, Node: Invoking minilzip, Next: Data format, Prev: Error mes ******************* Minilzip is a test program for the compression library lzlib, compatible -with lzip 1.4 or newer. +(interoperable) with lzip 1.4 or newer. Minilzip is not intended to be +installed because lzip has more features, but minilzip is well tested and +you can use it as your main compressor if so you wish. Lzip is a lossless data compressor with a user interface similar to the one of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov @@ -1305,28 +1307,28 @@ Concept index  Tag Table: Node: Top215 -Node: Introduction1338 -Node: Library version6778 -Node: Buffering9329 -Node: Parameter limits10554 -Node: Compression functions11508 -Ref: member_size13301 -Ref: sync_flush15063 -Node: Decompression functions19751 -Node: Error codes27308 -Node: Error messages29598 -Node: Invoking minilzip30177 -Node: Data format40595 -Ref: coded-dict-size42041 -Node: Examples43446 -Node: Buffer compression44407 -Node: Buffer decompression45927 -Node: File compression47341 -Node: File decompression48324 -Node: File compression mm49328 -Node: Skipping data errors52357 -Node: Problems53662 -Node: Concept index54223 +Node: Introduction1341 +Node: Library version6781 +Node: Buffering9332 +Node: Parameter limits10557 +Node: Compression functions11511 +Ref: member_size13304 +Ref: sync_flush15066 +Node: Decompression functions19754 +Node: Error codes27311 +Node: Error messages29601 +Node: Invoking minilzip30180 +Node: Data format40774 +Ref: coded-dict-size42220 +Node: Examples43625 +Node: Buffer compression44586 +Node: Buffer decompression46106 +Node: File compression47520 +Node: File decompression48503 +Node: File compression mm49507 +Node: Skipping data errors52536 +Node: Problems53841 +Node: Concept index54402  End Tag Table diff --git a/doc/lzlib.texi b/doc/lzlib.texi index 75cb7ba..462c840 100644 --- a/doc/lzlib.texi +++ b/doc/lzlib.texi @@ -6,8 +6,8 @@ @finalout @c %**end of header -@set UPDATED 20 January 2024 -@set VERSION 1.14 +@set UPDATED 19 April 2024 +@set VERSION 1.15-pre1 @dircategory Compression @direntry @@ -158,7 +158,7 @@ Lzlib currently implements two variants of the LZMA algorithm: fast (used by option @option{-0} of minilzip) and normal (used by all other compression levels). The high compression of LZMA comes from combining two basic, well-proven -compression ideas: sliding dictionaries (LZ77) and markov models (the thing +compression ideas: sliding dictionaries (LZ77) and Markov models (the thing used by every compression algorithm that uses a range encoder or similar order-0 entropy coder as its last stage) with segregation of contexts according to what the bits are used for. @@ -735,7 +735,9 @@ The value of @var{lz_errno} normally comes from a call to @cindex options Minilzip is a test program for the compression library lzlib, compatible -with lzip 1.4 or newer. +(interoperable) with lzip 1.4 or newer. Minilzip is not intended to be +installed because lzip has more features, but minilzip is well tested and +you can use it as your main compressor if so you wish. @uref{http://www.nongnu.org/lzip/lzip.html,,Lzip} is a lossless data compressor with a user interface similar to the one diff --git a/doc/minilzip.1 b/doc/minilzip.1 index 3532520..22ad101 100644 --- a/doc/minilzip.1 +++ b/doc/minilzip.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.2. -.TH MINILZIP "1" "January 2024" "minilzip 1.14" "User Commands" +.TH MINILZIP "1" "April 2024" "minilzip 1.15-pre1" "User Commands" .SH NAME minilzip \- reduces the size of files .SH SYNOPSIS @@ -7,7 +7,7 @@ minilzip \- reduces the size of files [\fI\,options\/\fR] [\fI\,files\/\fR] .SH DESCRIPTION Minilzip is a test program for the compression library lzlib, compatible -with lzip 1.4 or newer. +(interoperable) with lzip 1.4 or newer. .PP Lzip is a lossless data compressor with a user interface similar to the one of gzip or bzip2. Lzip uses a simplified form of the 'Lempel\-Ziv\-Markov @@ -116,12 +116,12 @@ Report bugs to lzip\-bug@nongnu.org Lzlib home page: http://www.nongnu.org/lzip/lzlib.html .SH COPYRIGHT Copyright \(co 2024 Antonio Diaz Diaz. -Using lzlib 1.14 -Using LZ_API_VERSION = 1014 License GPLv2+: GNU GPL version 2 or later .br This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. +Using lzlib 1.15\-pre1 +Using LZ_API_VERSION = 1015 .SH "SEE ALSO" The full documentation for .B minilzip diff --git a/encoder_base.c b/encoder_base.c index 047f372..d2ed53c 100644 --- a/encoder_base.c +++ b/encoder_base.c @@ -126,9 +126,8 @@ static void Mb_reset( struct Matchfinder_base * const mb ) /* End Of Stream marker => (dis == 0xFFFFFFFFU, len == min_match_len) */ static void LZeb_try_full_flush( struct LZ_encoder_base * const eb ) { - if( eb->member_finished || - Cb_free_bytes( &eb->renc.cb ) < max_marker_size + eb->renc.ff_count + Lt_size ) - return; + if( eb->member_finished || Cb_free_bytes( &eb->renc.cb ) < + max_marker_size + eb->renc.ff_count + Lt_size ) return; eb->member_finished = true; const int pos_state = Mb_data_position( &eb->mb ) & pos_state_mask; const State state = eb->state; @@ -171,9 +170,8 @@ static void LZeb_reset( struct LZ_encoder_base * const eb, const unsigned long long max_member_size = 0x0008000000000000ULL; /* 2 PiB */ int i; Mb_reset( &eb->mb ); - eb->member_size_limit = - min( max( min_member_size, member_size ), max_member_size ) - - Lt_size - max_marker_size; + eb->member_size_limit = min( max( min_member_size, member_size ), + max_member_size ) - Lt_size - max_marker_size; eb->crc = 0xFFFFFFFFU; Bm_array_init( eb->bm_literal[0], (1 << literal_context_bits) * 0x300 ); Bm_array_init( eb->bm_match[0], states * pos_states ); diff --git a/lzlib.h b/lzlib.h index b7357d2..7a52342 100644 --- a/lzlib.h +++ b/lzlib.h @@ -24,9 +24,9 @@ extern "C" { /* LZ_API_VERSION was first defined in lzlib 1.8 to 1. Since lzlib 1.12, LZ_API_VERSION is defined as (major * 1000 + minor). */ -#define LZ_API_VERSION 1014 +#define LZ_API_VERSION 1015 -static const char * const LZ_version_string = "1.14"; +static const char * const LZ_version_string = "1.15-pre1"; enum LZ_Errno { LZ_ok = 0, LZ_bad_argument, LZ_mem_error, LZ_sequence_error, LZ_header_error, LZ_unexpected_eof, diff --git a/minilzip.c b/minilzip.c index a0a6721..c0e542a 100644 --- a/minilzip.c +++ b/minilzip.c @@ -26,7 +26,7 @@ #include #include #include -#include /* SSIZE_MAX */ +#include /* CHAR_BIT, SSIZE_MAX */ #include #include #include /* SIZE_MAX */ @@ -117,7 +117,7 @@ static bool delete_output_on_interrupt = false; static void show_help( void ) { printf( "Minilzip is a test program for the compression library lzlib, compatible\n" - "with lzip 1.4 or newer.\n" + "(interoperable) with lzip 1.4 or newer.\n" "\nLzip is a lossless data compressor with a user interface similar to the one\n" "of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov\n" "chain-Algorithm' (LZMA) stream format to maximize interoperability. The\n" @@ -196,10 +196,10 @@ static void show_version( void ) { printf( "%s %s\n", program_name, PROGVERSION ); printf( "Copyright (C) %s Antonio Diaz Diaz.\n", program_year ); - show_lzlib_version(); printf( "License GPLv2+: GNU GPL version 2 or later \n" "This is free software: you are free to change and redistribute it.\n" "There is NO WARRANTY, to the extent permitted by law.\n" ); + show_lzlib_version(); } @@ -294,6 +294,9 @@ static void Pp_init( struct Pretty_print * const pp, if( pp->longest_name == 0 ) pp->longest_name = stdin_name_len; } +void Pp_free( struct Pretty_print * const pp ) + { if( pp->padded_name ) { free( pp->padded_name ); pp->padded_name = 0; } } + static void Pp_set_name( struct Pretty_print * const pp, const char * const filename ) { @@ -1286,6 +1289,7 @@ int main( const int argc, const char * const argv[] ) program_name, failed_tests, ( failed_tests == 1 ) ? "file" : "files" ); free( output_filename ); + Pp_free( &pp ); free( filenames ); ap_free( &parser ); return retval; From 57718ee5a917fb876748fc3776d2f361ee2f732f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 20 Feb 2025 21:34:26 +0100 Subject: [PATCH 08/10] Adding upstream version 1.15~pre2. Signed-off-by: Daniel Baumann --- COPYING.GPL | 3 +- ChangeLog | 7 +++ Makefile.in | 17 +++---- NEWS | 8 ++++ README | 2 +- carg_parser.c | 18 +++---- carg_parser.h | 11 +++-- configure | 8 ++-- decoder.c | 15 +++--- decoder.h | 14 +++--- doc/lzlib.info | 92 ++++++++++++++++++----------------- doc/lzlib.texi | 101 ++++++++++++++++++++------------------- doc/minilzip.1 | 8 ++-- encoder_base.c | 3 +- lzlib.c | 2 +- lzlib.h | 2 +- minilzip.c | 43 ++++++++++------- testsuite/check.sh | 77 ++++++++++++++++++++--------- testsuite/fox_nz.lz | Bin 0 -> 80 bytes testsuite/test.txt | 6 +-- testsuite/test.txt.lz | Bin 7376 -> 7341 bytes testsuite/test_em.txt.lz | Bin 14024 -> 0 bytes testsuite/test_sync.lz | Bin 7568 -> 7367 bytes 23 files changed, 249 insertions(+), 188 deletions(-) create mode 100644 testsuite/fox_nz.lz delete mode 100644 testsuite/test_em.txt.lz diff --git a/COPYING.GPL b/COPYING.GPL index 4ad17ae..42fe735 100644 --- a/COPYING.GPL +++ b/COPYING.GPL @@ -1,8 +1,7 @@ GNU GENERAL PUBLIC LICENSE Version 2, June 1991 - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Copyright (C) 1989, 1991 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. diff --git a/ChangeLog b/ChangeLog index a945949..33f023c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2024-10-16 Antonio Diaz Diaz + + * Version 1.15-pre2 released. + * decoder.h (Rd_try_reload): Reject a nonzero first LZMA byte. + * minilzip.c (do_decompress): Reject empty member in multimember. + * configure, Makefile.in: Don't use '--soname'; create 'liblz.so.1'. + 2024-04-19 Antonio Diaz Diaz * Version 1.15-pre1 released. diff --git a/Makefile.in b/Makefile.in index cf90c91..6d9035c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -27,16 +27,16 @@ lib : $(libname_static) $(libname_shared) lib$(libname).a : lzlib.o $(AR) $(ARFLAGS) $@ $< -lib$(libname).so.$(pkgversion) : lzlib_sh.o - $(CC) $(CFLAGS) $(LDFLAGS) -fpic -fPIC -shared -Wl,--soname=lib$(libname).so.$(soversion) -o $@ $< +lib$(libname).so.$(soversion) : lzlib_sh.o + $(CC) $(CFLAGS) $(LDFLAGS) -fpic -fPIC -shared -o $@ $< bin : $(progname_static) $(progname_shared) $(progname) : $(objs) lib$(libname).a $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(objs) lib$(libname).a -$(progname)_shared : $(objs) lib$(libname).so.$(pkgversion) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(objs) lib$(libname).so.$(pkgversion) +$(progname)_shared : $(objs) lib$(libname).so.$(soversion) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(objs) lib$(libname).so.$(soversion) bbexample : bbexample.o lib$(libname).a $(CC) $(CFLAGS) $(LDFLAGS) -o $@ bbexample.o lib$(libname).a @@ -113,15 +113,14 @@ install-lib : lib $(INSTALL_DATA) ./lib$(libname).a "$(DESTDIR)$(libdir)/lib$(libname).a" ; \ fi if [ -n "$(libname_shared)" ] ; then \ - $(INSTALL_PROGRAM) ./lib$(libname).so.$(pkgversion) "$(DESTDIR)$(libdir)/lib$(libname).so.$(pkgversion)" ; \ if [ -e "$(DESTDIR)$(libdir)/lib$(libname).so.$(soversion)" ] ; then \ run_ldconfig=no ; \ else run_ldconfig=yes ; \ fi ; \ rm -f "$(DESTDIR)$(libdir)/lib$(libname).so" ; \ rm -f "$(DESTDIR)$(libdir)/lib$(libname).so.$(soversion)" ; \ - cd "$(DESTDIR)$(libdir)" && ln -s lib$(libname).so.$(pkgversion) lib$(libname).so ; \ - cd "$(DESTDIR)$(libdir)" && ln -s lib$(libname).so.$(pkgversion) lib$(libname).so.$(soversion) ; \ + $(INSTALL_PROGRAM) ./lib$(libname).so.$(soversion) "$(DESTDIR)$(libdir)/lib$(libname).so.$(soversion)" ; \ + cd "$(DESTDIR)$(libdir)" && ln -s lib$(libname).so.$(soversion) lib$(libname).so ; \ if [ "${disable_ldconfig}" != yes ] && [ $${run_ldconfig} = yes ] && \ [ -x "$(LDCONFIG)" ] ; then "$(LDCONFIG)" -n "$(DESTDIR)$(libdir)" || true ; fi ; \ fi @@ -162,7 +161,6 @@ uninstall-lib : -rm -f "$(DESTDIR)$(libdir)/lib$(libname).a" -rm -f "$(DESTDIR)$(libdir)/lib$(libname).so" -rm -f "$(DESTDIR)$(libdir)/lib$(libname).so.$(soversion)" - -rm -f "$(DESTDIR)$(libdir)/lib$(libname).so.$(pkgversion)" uninstall-info : -if $(CAN_RUN_INSTALLINFO) ; then \ @@ -196,8 +194,7 @@ dist : doc $(DISTNAME)/testsuite/fox.lz \ $(DISTNAME)/testsuite/fox_*.lz \ $(DISTNAME)/testsuite/test_sync.lz \ - $(DISTNAME)/testsuite/test.txt.lz \ - $(DISTNAME)/testsuite/test_em.txt.lz + $(DISTNAME)/testsuite/test.txt.lz rm -f $(DISTNAME) lzip -v -9 $(DISTNAME).tar diff --git a/NEWS b/NEWS index 94f6a9a..d7da1c1 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,10 @@ Changes in version 1.15: +Lzlib now reports a nonzero first LZMA byte as a LZ_data_error. + +minilzip now exits with error status 2 if any empty member is found in a +multimember file. + The targets 'lib' and 'bin' have been added to Makefile.in. 'lib' is the new default and builds just the library. 'bin' builds both the library and minilzip. @@ -9,3 +14,6 @@ minilzip is no longer built by default. 'install-bin' installs minilzip and its man page again. The use of the target 'bin' has been documented in INSTALL. + +To improve portability, the linker option '--soname' is no longer used. +Instead the shared library is written to 'liblz.so.1'. diff --git a/README b/README index 2207fb5..ec3a5a0 100644 --- a/README +++ b/README @@ -3,7 +3,7 @@ Description Lzlib is a data compression library providing in-memory LZMA compression and decompression functions, including integrity checking of the decompressed data. The compressed data format used by the library is the lzip format. -Lzlib is written in C. +Lzlib is written in C and is distributed under a 2-clause BSD license. The lzip file format is designed for data sharing and long-term archiving, taking into account both data integrity and decoder availability: diff --git a/carg_parser.c b/carg_parser.c index edb4eb9..e16fa73 100644 --- a/carg_parser.c +++ b/carg_parser.c @@ -148,21 +148,21 @@ static char parse_long_option( struct Arg_parser * const ap, add_error( ap, "' requires an argument" ); return 1; } - return push_back_record( ap, options[index].code, - options[index].long_name, &opt[len+3] ); + return push_back_record( ap, options[index].code, options[index].long_name, + &opt[len+3] ); /* argument may be empty */ } - if( options[index].has_arg == ap_yes ) + if( options[index].has_arg == ap_yes || options[index].has_arg == ap_yme ) { - if( !arg || !arg[0] ) + if( !arg || ( options[index].has_arg == ap_yes && !arg[0] ) ) { add_error( ap, "option '--" ); add_error( ap, options[index].long_name ); add_error( ap, "' requires an argument" ); return 1; } ++*argindp; - return push_back_record( ap, options[index].code, - options[index].long_name, arg ); + return push_back_record( ap, options[index].code, options[index].long_name, + arg ); /* argument may be empty */ } return push_back_record( ap, options[index].code, @@ -204,15 +204,15 @@ static char parse_short_option( struct Arg_parser * const ap, if( !push_back_record( ap, c, 0, &opt[cind] ) ) return 0; ++*argindp; cind = 0; } - else if( options[index].has_arg == ap_yes ) + else if( options[index].has_arg == ap_yes || options[index].has_arg == ap_yme ) { - if( !arg || !arg[0] ) + if( !arg || ( options[index].has_arg == ap_yes && !arg[0] ) ) { add_error( ap, "option requires an argument -- '" ); add_error( ap, code_str ); add_error( ap, "'" ); return 1; } - ++*argindp; cind = 0; + ++*argindp; cind = 0; /* argument may be empty */ if( !push_back_record( ap, c, 0, arg ) ) return 0; } else if( !push_back_record( ap, c, 0, 0 ) ) return 0; diff --git a/carg_parser.h b/carg_parser.h index 69ce271..65a6d7d 100644 --- a/carg_parser.h +++ b/carg_parser.h @@ -37,15 +37,20 @@ 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 of options with an optional argument is + '-' (without whitespace), or + '--='. + + The syntax of options with an empty argument is '- ""', + '-- ""', or '--=""'. */ #ifdef __cplusplus extern "C" { #endif -enum ap_Has_arg { ap_no, ap_yes, ap_maybe }; +/* ap_yme = yes but maybe empty */ +enum ap_Has_arg { ap_no, ap_yes, ap_maybe, ap_yme }; struct ap_Option { diff --git a/configure b/configure index b24d769..7fa49d2 100755 --- a/configure +++ b/configure @@ -6,7 +6,7 @@ # to copy, distribute, and modify it. pkgname=lzlib -pkgversion=1.15-pre1 +pkgversion=1.15-pre2 soversion=1 libname=lz libname_static=lib${libname}.a @@ -118,12 +118,12 @@ while [ $# != 0 ] ; do --no-create) no_create=yes ;; --disable-static) libname_static= - libname_shared=lib${libname}.so.${pkgversion} progname_static= + libname_shared=lib${libname}.so.${soversion} progname_shared=${progname}_shared progname_lzip=${progname}_shared ;; --enable-shared) - libname_shared=lib${libname}.so.${pkgversion} + libname_shared=lib${libname}.so.${soversion} progname_shared=${progname}_shared progname_lzip=${progname}_shared ;; --disable-ldconfig) disable_ldconfig=yes ;; @@ -146,7 +146,7 @@ while [ $# != 0 ] ; do exit 1 ;; esac - # Check if the option took a separate argument + # Check whether the option took a separate argument if [ "${arg2}" = yes ] ; then if [ $# != 0 ] ; then args="${args} \"$1\"" ; shift else echo "configure: Missing argument to '${option}'" 1>&2 diff --git a/decoder.c b/decoder.c index d1fbe54..7b90d6e 100644 --- a/decoder.c +++ b/decoder.c @@ -35,7 +35,7 @@ static int LZd_try_check_trailer( struct LZ_decoder * const d ) /* Return value: 0 = OK, 1 = decoder error, 2 = unexpected EOF, 3 = trailer error, 4 = unknown marker found, - 5 = library error. */ + 5 = nonzero first LZMA byte found, 6 = library error. */ static int LZd_decode_member( struct LZ_decoder * const d ) { struct Range_decoder * const rdec = d->rdec; @@ -43,14 +43,15 @@ static int LZd_decode_member( struct LZ_decoder * const d ) unsigned old_mpos = rdec->member_position; if( d->member_finished ) return 0; - if( !Rd_try_reload( rdec ) ) - { if( !rdec->at_stream_end ) return 0; else return 2; } + const int tmp = Rd_try_reload( rdec ); + if( tmp > 1 ) return 5; + if( !tmp ) { if( !rdec->at_stream_end ) return 0; else return 2; } if( d->check_trailer_pending ) return LZd_try_check_trailer( d ); while( !Rd_finished( rdec ) ) { const unsigned mpos = rdec->member_position; - if( mpos - old_mpos > rd_min_available_bytes ) return 5; + if( mpos - old_mpos > rd_min_available_bytes ) return 6; old_mpos = mpos; if( !Rd_enough_available_bytes( rdec ) ) /* check unexpected EOF */ { if( !rdec->at_stream_end ) return 0; @@ -117,7 +118,7 @@ static int LZd_decode_member( struct LZ_decoder * const d ) { Rd_normalize( rdec ); const unsigned mpos = rdec->member_position; - if( mpos - old_mpos > rd_min_available_bytes ) return 5; + if( mpos - old_mpos > rd_min_available_bytes ) return 6; old_mpos = mpos; if( len == min_match_len ) /* End Of Stream marker */ { @@ -127,7 +128,9 @@ static int LZd_decode_member( struct LZ_decoder * const d ) if( len == min_match_len + 1 ) /* Sync Flush marker */ { rdec->reload_pending = true; - if( Rd_try_reload( rdec ) ) continue; + const int tmp = Rd_try_reload( rdec ); + if( tmp > 1 ) return 5; + if( tmp ) continue; if( !rdec->at_stream_end ) return 0; else break; } return 4; diff --git a/decoder.h b/decoder.h index 4b91fec..57e47cb 100644 --- a/decoder.h +++ b/decoder.h @@ -133,13 +133,15 @@ static inline bool Rd_unread_data( struct Range_decoder * const rdec, return true; } -static bool Rd_try_reload( struct Range_decoder * const rdec ) +static int Rd_try_reload( struct Range_decoder * const rdec ) { if( rdec->reload_pending && Rd_available_bytes( rdec ) >= 5 ) { rdec->reload_pending = false; rdec->code = 0; rdec->range = 0xFFFFFFFFU; + /* check first byte of the LZMA stream without reading it */ + if( rdec->cb.buffer[rdec->cb.get] != 0 ) return 2; Rd_get_byte( rdec ); /* discard first byte of the LZMA stream */ int i; for( i = 0; i < 4; ++i ) rdec->code = (rdec->code << 8) | Rd_get_byte( rdec ); @@ -164,7 +166,7 @@ static inline unsigned Rd_decode( struct Range_decoder * const rdec, rdec->range >>= 1; /* symbol <<= 1; */ /* if( rdec->code >= rdec->range ) { rdec->code -= rdec->range; symbol |= 1; } */ - const bool bit = ( rdec->code >= rdec->range ); + const bool bit = rdec->code >= rdec->range; symbol <<= 1; symbol += bit; rdec->code -= rdec->range & ( 0U - bit ); } @@ -387,14 +389,14 @@ static inline void LZd_copy_block( struct LZ_decoder * const d, bool fast, fast2; if( lpos > distance ) { - fast = ( len < d->cb.buffer_size - lpos ); - fast2 = ( fast && len <= lpos - i ); + fast = len < d->cb.buffer_size - lpos; + fast2 = fast && len <= lpos - i; } else { i += d->cb.buffer_size; - fast = ( len < d->cb.buffer_size - i ); /* (i == pos) may happen */ - fast2 = ( fast && len <= i - lpos ); + fast = len < d->cb.buffer_size - i; /* (i == pos) may happen */ + fast2 = fast && len <= i - lpos; } if( fast ) /* no wrap */ { diff --git a/doc/lzlib.info b/doc/lzlib.info index 314c98a..44bf3ce 100644 --- a/doc/lzlib.info +++ b/doc/lzlib.info @@ -11,7 +11,7 @@ File: lzlib.info, Node: Top, Next: Introduction, Up: (dir) Lzlib Manual ************ -This manual is for Lzlib (version 1.15-pre1, 19 April 2024). +This manual is for Lzlib (version 1.15-pre2, 16 October 2024). * Menu: @@ -24,7 +24,7 @@ This manual is for Lzlib (version 1.15-pre1, 19 April 2024). * Error codes:: Meaning of codes returned by functions * Error messages:: Error messages corresponding to error codes * Invoking minilzip:: Command-line interface of the test program -* Data format:: Detailed format of the compressed data +* File format:: Detailed format of the compressed file * Examples:: A small tutorial with examples * Problems:: Reporting bugs * Concept index:: Index of concepts @@ -44,7 +44,7 @@ File: lzlib.info, Node: Introduction, Next: Library version, Prev: Top, Up: Lzlib is a data compression library providing in-memory LZMA compression and decompression functions, including integrity checking of the decompressed data. The compressed data format used by the library is the lzip format. -Lzlib is written in C. +Lzlib is written in C and is distributed under a 2-clause BSD license. The lzip file format is designed for data sharing and long-term archiving, taking into account both data integrity and decoder availability: @@ -339,7 +339,7 @@ except 'LZ_compress_open' whose return value must be checked by calling between applications using lzlib, but is useless and wasteful in a file, and is excluded from the media type 'application/lzip'. The LZMA marker '2' ("End Of Stream" marker) is the only marker allowed in lzip - files. *Note Data format::. + files. *Note File format::. Repeated use of 'LZ_compress_sync_flush' may degrade compression ratio, so use it only when needed. If the interval between calls to @@ -459,7 +459,7 @@ except 'LZ_decompress_open' whose return value must be checked by calling -- Function: int LZ_decompress_reset ( struct LZ_Decoder * const DECODER ) Resets the internal state of DECODER as it was just after opening it with the function 'LZ_decompress_open'. Data stored in the internal - buffers is discarded. Position counters are set to 0. + buffers are discarded. Position counters are set to 0. -- Function: int LZ_decompress_sync_to_member ( struct LZ_Decoder * const DECODER ) @@ -618,9 +618,10 @@ failed. If the call failed, then you can examine 'LZ_(de)compress_errno'. -- Constant: enum LZ_Errno LZ_data_error The data stream is corrupt. If 'LZ_decompress_member_position' is 6 or less, it indicates either a format version not supported, an invalid - dictionary size, a corrupt header in a multimember data stream, or - trailing data too similar to a valid lzip header. Lziprecover can be - used to remove conflicting trailing data from a file. + dictionary size, a nonzero first LZMA byte, a corrupt header in a + multimember data stream, or trailing data too similar to a valid lzip + header. Lziprecover can be used to repair some of these errors and to + remove conflicting trailing data from a file. -- Constant: enum LZ_Errno LZ_library_error A bug was detected in the library. Please, report it. *Note Problems::. @@ -641,7 +642,7 @@ File: lzlib.info, Node: Error messages, Next: Invoking minilzip, Prev: Error 'LZ_(de)compress_errno'.  -File: lzlib.info, Node: Invoking minilzip, Next: Data format, Prev: Error messages, Up: Top +File: lzlib.info, Node: Invoking minilzip, Next: File format, Prev: Error messages, Up: Top 9 Invoking minilzip ******************* @@ -658,8 +659,8 @@ maximum dictionary size is 512 MiB so that any lzip file can be decompressed on 32-bit machines. Lzip provides accurate and robust 3-factor integrity checking. Lzip can compress about as fast as gzip (lzip -0) or compress most files more than bzip2 (lzip -9). Decompression speed is intermediate between -gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery -perspective. Lzip has been designed, written, and tested with great care to +gzip and bzip2. Lzip provides better data recovery capabilities than gzip +and bzip2. Lzip has been designed, written, and tested with great care to replace gzip and bzip2 as the standard general-purpose compressed format for Unix-like systems. @@ -673,7 +674,7 @@ means standard input. It can be mixed with other FILES and is read just once, the first time it appears in the command line. Remember to prepend './' to any file name beginning with a hyphen, or use '--'. - minilzip supports the following options: *Note Argument syntax: +minilzip supports the following options: *Note Argument syntax: (arg_parser)Argument syntax. '-h' @@ -818,6 +819,7 @@ once, the first time it appears in the command line. Remember to prepend '-s64MiB -m273' Level Dictionary size (-s) Match length limit (-m) + ------------------------------------------------------ -0 64 KiB 16 bytes -1 1 MiB 5 bytes -2 1.5 MiB 6 bytes @@ -858,6 +860,7 @@ and may be followed by a multiplier and an optional 'B' for "byte". Table of SI and binary prefixes (unit multipliers): Prefix Value | Prefix Value +---------------------------------------------------------------------- k kilobyte (10^3 = 1000) | Ki kibibyte (2^10 = 1024) M megabyte (10^6) | Mi mebibyte (2^20) G gigabyte (10^9) | Gi gibibyte (2^30) @@ -876,16 +879,15 @@ corrupt or invalid input file, 3 for an internal consistency error (e.g., bug) which caused minilzip to panic.  -File: lzlib.info, Node: Data format, Next: Examples, Prev: Invoking minilzip, Up: Top +File: lzlib.info, Node: File format, Next: Examples, Prev: Invoking minilzip, Up: Top -10 Data format +10 File format ************** Perfection is reached, not when there is no longer anything to add, but when there is no longer anything to take away. -- Antoine de Saint-Exupery - In the diagram below, a box like this: +---+ @@ -900,12 +902,12 @@ when there is no longer anything to take away. represents a variable number of bytes. - - Lzip data consist of one or more independent "members" (compressed data -sets). The members simply appear one after another in the data stream, with -no additional information before, between, or after them. Each member can +A lzip file consists of one or more independent "members" (compressed data +sets). The members simply appear one after another in the file, with no +additional information before, between, or after them. Each member can encode in compressed form up to 16 EiB - 1 byte of uncompressed data. The -size of a multimember data stream is unlimited. +size of a multimember file is unlimited. Empty members (data size = 0) are +not allowed in multimember files. Each member has the following structure: @@ -933,7 +935,7 @@ size of a multimember data stream is unlimited. Valid values for dictionary size range from 4 KiB to 512 MiB. 'LZMA stream' - The LZMA stream, finished by an "End Of Stream" marker. Uses default + The LZMA stream, terminated by an "End Of Stream" marker. Uses default values for encoder properties. *Note Stream format: (lzip)Stream format, for a complete description. Lzip only uses the LZMA marker '2' ("End Of Stream" marker). Lzlib @@ -955,7 +957,7 @@ size of a multimember data stream is unlimited.  -File: lzlib.info, Node: Examples, Next: Problems, Prev: Data format, Up: Top +File: lzlib.info, Node: Examples, Next: Problems, Prev: File format, Up: Top 11 A small tutorial with examples ********************************* @@ -1287,13 +1289,13 @@ Concept index * buffering: Buffering. (line 6) * bugs: Problems. (line 6) * compression functions: Compression functions. (line 6) -* data format: Data format. (line 6) * decompression functions: Decompression functions. (line 6) * error codes: Error codes. (line 6) * error messages: Error messages. (line 6) * examples: Examples. (line 6) * file compression: File compression. (line 6) * file decompression: File decompression. (line 6) +* file format: File format. (line 6) * getting help: Problems. (line 6) * introduction: Introduction. (line 6) * invoking: Invoking minilzip. (line 6) @@ -1307,28 +1309,28 @@ Concept index  Tag Table: Node: Top215 -Node: Introduction1341 -Node: Library version6781 -Node: Buffering9332 -Node: Parameter limits10557 -Node: Compression functions11511 -Ref: member_size13304 -Ref: sync_flush15066 -Node: Decompression functions19754 -Node: Error codes27311 -Node: Error messages29601 -Node: Invoking minilzip30180 -Node: Data format40774 -Ref: coded-dict-size42220 -Node: Examples43625 -Node: Buffer compression44586 -Node: Buffer decompression46106 -Node: File compression47520 -Node: File decompression48503 -Node: File compression mm49507 -Node: Skipping data errors52536 -Node: Problems53841 -Node: Concept index54402 +Node: Introduction1343 +Node: Library version6831 +Node: Buffering9382 +Node: Parameter limits10607 +Node: Compression functions11561 +Ref: member_size13354 +Ref: sync_flush15116 +Node: Decompression functions19804 +Node: Error codes27362 +Node: Error messages29719 +Node: Invoking minilzip30298 +Node: File format41020 +Ref: coded-dict-size42518 +Node: Examples43925 +Node: Buffer compression44886 +Node: Buffer decompression46406 +Node: File compression47820 +Node: File decompression48803 +Node: File compression mm49807 +Node: Skipping data errors52836 +Node: Problems54141 +Node: Concept index54702  End Tag Table diff --git a/doc/lzlib.texi b/doc/lzlib.texi index 462c840..23bbbfb 100644 --- a/doc/lzlib.texi +++ b/doc/lzlib.texi @@ -6,8 +6,8 @@ @finalout @c %**end of header -@set UPDATED 19 April 2024 -@set VERSION 1.15-pre1 +@set UPDATED 16 October 2024 +@set VERSION 1.15-pre2 @dircategory Compression @direntry @@ -45,7 +45,7 @@ This manual is for Lzlib (version @value{VERSION}, @value{UPDATED}). * Error codes:: Meaning of codes returned by functions * Error messages:: Error messages corresponding to error codes * Invoking minilzip:: Command-line interface of the test program -* Data format:: Detailed format of the compressed data +* File format:: Detailed format of the compressed file * Examples:: A small tutorial with examples * Problems:: Reporting bugs * Concept index:: Index of concepts @@ -67,7 +67,7 @@ distribute, and modify it. is a data compression library providing in-memory LZMA compression and decompression functions, including integrity checking of the decompressed data. The compressed data format used by the library is the lzip format. -Lzlib is written in C. +Lzlib is written in C and is distributed under a 2-clause BSD license. The lzip file format is designed for data sharing and long-term archiving, taking into account both data integrity and decoder availability: @@ -103,16 +103,16 @@ lziprecover, losing an entire archive just because of a corrupt byte near the beginning is a thing of the past. The functions and variables forming the interface of the compression library -are declared in the file @samp{lzlib.h}. Usage examples of the library are -given in the files @samp{bbexample.c}, @samp{ffexample.c}, and -@samp{minilzip.c} from the source distribution. +are declared in the file @file{lzlib.h}. Usage examples of the library are +given in the files @file{bbexample.c}, @file{ffexample.c}, and +@file{minilzip.c} from the source distribution. -As @samp{lzlib.h} can be used by C and C++ programs, it must not impose a +As @file{lzlib.h} can be used by C and C++ programs, it must not impose a choice of system headers on the program by including one of them. Therefore it is the responsibility of the program using lzlib to include before -@samp{lzlib.h} some header that declares the type @samp{uint8_t}. There are -at least four such headers in C and C++: @samp{stdint.h}, @samp{cstdint}, -@samp{inttypes.h}, and @samp{cinttypes}. +@file{lzlib.h} some header that declares the type @samp{uint8_t}. There are +at least four such headers in C and C++: @file{stdint.h}, @file{cstdint}, +@file{inttypes.h}, and @file{cinttypes}. All the library functions are thread safe. The library does not install any signal handler. The decoder checks the consistency of the compressed data, @@ -183,10 +183,10 @@ versions of itself down to 1.0. Any application working with an older lzlib should work with a newer lzlib. Installing a newer lzlib should not break anything. This chapter describes the constants and functions that the application can use to discover the version of the library being used. All -of them are declared in @samp{lzlib.h}. +of them are declared in @file{lzlib.h}. @defvr Constant LZ_API_VERSION -This constant is defined in @samp{lzlib.h} and works as a version test +This constant is defined in @file{lzlib.h} and works as a version test macro. The application should check at compile time that LZ_API_VERSION is greater than or equal to the version required by the application: @@ -207,7 +207,7 @@ which allow the application to announce to the library its desire to have certain symbols and prototypes exposed. @deftypefun int LZ_api_version ( void ) -If LZ_API_VERSION >= 1012, this function is declared in @samp{lzlib.h} (else +If LZ_API_VERSION >= 1012, this function is declared in @file{lzlib.h} (else it doesn't exist). It returns the LZ_API_VERSION of the library object code being used. The application should check at run time that the value returned by @code{LZ_api_version} is greater than or equal to the version @@ -225,7 +225,7 @@ the functionality required by the application. @end deftypefun @deftypevr Constant {const char *} LZ_version_string -This string constant is defined in the header file @samp{lzlib.h} and +This string constant is defined in the header file @file{lzlib.h} and represents the version of the library being used at compile time. @end deftypevr @@ -385,7 +385,7 @@ lzip files; it is a device for interactive communication between applications using lzlib, but is useless and wasteful in a file, and is excluded from the media type @samp{application/lzip}. The LZMA marker @samp{2} ("End Of Stream" marker) is the only marker allowed in lzip files. -@xref{Data format}. +@xref{File format}. Repeated use of @samp{LZ_compress_sync_flush} may degrade compression ratio, so use it only when needed. If the interval between calls to @@ -524,7 +524,7 @@ detecting a truncated member. @deftypefun int LZ_decompress_reset ( struct LZ_Decoder * const @var{decoder} ) Resets the internal state of @var{decoder} as it was just after opening it with the function @samp{LZ_decompress_open}. Data stored in the -internal buffers is discarded. Position counters are set to 0. +internal buffers are discarded. Position counters are set to 0. @end deftypefun @@ -670,7 +670,7 @@ necessarily LZ_ok, and you should not use @samp{LZ_(de)compress_errno} to determine whether a call failed. If the call failed, then you can examine @samp{LZ_(de)compress_errno}. -The error codes are defined in the header file @samp{lzlib.h}. +The error codes are defined in the header file @file{lzlib.h}. @deftypevr Constant {enum LZ_Errno} LZ_ok The value of this constant is 0 and is used to indicate that there is no error. @@ -693,8 +693,8 @@ finished. @end deftypevr @deftypevr Constant {enum LZ_Errno} LZ_header_error -An invalid member header (one with the wrong magic bytes) was read. If -this happens at the end of the data stream it may indicate trailing data. +An invalid member header (one with the wrong magic bytes) was read. If this +happens at the end of the data stream it may indicate trailing data. @end deftypevr @deftypevr Constant {enum LZ_Errno} LZ_unexpected_eof @@ -702,11 +702,12 @@ The end of the data stream was reached in the middle of a member. @end deftypevr @deftypevr Constant {enum LZ_Errno} LZ_data_error -The data stream is corrupt. If @samp{LZ_decompress_member_position} is 6 -or less, it indicates either a format version not supported, an invalid -dictionary size, a corrupt header in a multimember data stream, or -trailing data too similar to a valid lzip header. Lziprecover can be -used to remove conflicting trailing data from a file. +The data stream is corrupt. If @samp{LZ_decompress_member_position} is 6 or +less, it indicates either a format version not supported, an invalid +dictionary size, a nonzero first LZMA byte, a corrupt header in a multimember +data stream, or trailing data too similar to a valid lzip header. +Lziprecover can be used to repair some of these errors and to remove +conflicting trailing data from a file. @end deftypevr @deftypevr Constant {enum LZ_Errno} LZ_library_error @@ -747,8 +748,8 @@ maximum dictionary size is 512 MiB so that any lzip file can be decompressed on 32-bit machines. Lzip provides accurate and robust 3-factor integrity checking. Lzip can compress about as fast as gzip @w{(lzip -0)} or compress most files more than bzip2 @w{(lzip -9)}. Decompression speed is intermediate between -gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery -perspective. Lzip has been designed, written, and tested with great care to +gzip and bzip2. Lzip provides better data recovery capabilities than gzip +and bzip2. Lzip has been designed, written, and tested with great care to replace gzip and bzip2 as the standard general-purpose compressed format for Unix-like systems. @@ -766,6 +767,7 @@ argument means standard input. It can be mixed with other @var{files} and is read just once, the first time it appears in the command line. Remember to prepend @file{./} to any file name beginning with a hyphen, or use @samp{--}. +@noindent minilzip supports the following @uref{http://www.nongnu.org/arg-parser/manual/arg_parser_manual.html#Argument-syntax,,options}: @ifnothtml @@ -823,7 +825,7 @@ Force overwrite of output files. @item -F @itemx --recompress When compressing, force re-compression of files whose name already has -the @samp{.lz} or @samp{.tlz} suffix. +the @file{.lz} or @file{.tlz} suffix. @item -k @itemx --keep @@ -846,8 +848,8 @@ when reading from a named pipe (fifo) or from a device. @w{@option{-o -}} is equivalent to @option{-c}. @option{-o} has no effect when testing. When compressing and splitting the output in volumes, @var{file} is used as -a prefix, and several files named @samp{@var{file}00001.lz}, -@samp{@var{file}00002.lz}, etc, are created. In this case, only one input +a prefix, and several files named @file{@var{file}00001.lz}, +@file{@var{file}00002.lz}, etc, are created. In this case, only one input file is allowed. @item -q @@ -873,7 +875,7 @@ is affected at compression time by the choice of dictionary size limit. @itemx --volume-size=@var{bytes} When compressing, and @option{-c} has not been also specified, split the compressed output into several volume files with names -@samp{original_name00001.lz}, @samp{original_name00002.lz}, etc, and set the +@file{original_name00001.lz}, @file{original_name00002.lz}, etc, and set the volume size limit to @var{bytes}. Input files are kept unchanged. Each volume is a complete, maybe multimember, lzip file. A small volume size may degrade compression ratio, so use it only when needed. Valid values range @@ -892,11 +894,10 @@ files. @item -v @itemx --verbose Verbose mode.@* -When compressing, show the compression ratio and size for each file -processed.@* -When decompressing or testing, further -v's (up to 4) increase the -verbosity level, showing status, compression ratio, dictionary size, -and trailer contents (CRC, data size, member size). +When compressing, show the compression ratio and size for each file processed.@* +When decompressing or testing, further -v's (up to 4) increase the verbosity +level, showing status, compression ratio, dictionary size, and trailer +contents (CRC, data size, member size). @item -0 .. -9 Compression level. Set the compression parameters (dictionary size and @@ -915,7 +916,7 @@ given, the last setting is used. For example @w{@option{-9 -s64MiB}} is equivalent to @w{@option{-s64MiB -m273}} @multitable {Level} {Dictionary size (-s)} {Match length limit (-m)} -@item Level @tab Dictionary size (-s) @tab Match length limit (-m) +@headitem Level @tab Dictionary size (-s) @tab Match length limit (-m) @item -0 @tab 64 KiB @tab 16 bytes @item -1 @tab 1 MiB @tab 5 bytes @item -2 @tab 1.5 MiB @tab 6 bytes @@ -960,7 +961,7 @@ and may be followed by a multiplier and an optional @samp{B} for "byte". Table of SI and binary prefixes (unit multipliers): @multitable {Prefix} {kilobyte (10^3 = 1000)} {|} {Prefix} {kibibyte (2^10 = 1024)} -@item Prefix @tab Value @tab | @tab Prefix @tab Value +@headitem Prefix @tab Value @tab | @tab Prefix @tab Value @item k @tab kilobyte (10^3 = 1000) @tab | @tab Ki @tab kibibyte (2^10 = 1024) @item M @tab megabyte (10^6) @tab | @tab Mi @tab mebibyte (2^20) @item G @tab gigabyte (10^9) @tab | @tab Gi @tab gibibyte (2^30) @@ -980,15 +981,14 @@ indicate a corrupt or invalid input file, 3 for an internal consistency error (e.g., bug) which caused minilzip to panic. -@node Data format -@chapter Data format -@cindex data format +@node File format +@chapter File format +@cindex file format Perfection is reached, not when there is no longer anything to add, but when there is no longer anything to take away.@* --- Antoine de Saint-Exupery -@sp 1 In the diagram below, a box like this: @verbatim @@ -1007,12 +1007,13 @@ represents one byte; a box like this: represents a variable number of bytes. -@sp 1 -Lzip data consist of one or more independent "members" (compressed data -sets). The members simply appear one after another in the data stream, with -no additional information before, between, or after them. Each member can +@noindent +A lzip file consists of one or more independent "members" (compressed data +sets). The members simply appear one after another in the file, with no +additional information before, between, or after them. Each member can encode in compressed form up to @w{16 EiB - 1 byte} of uncompressed data. -The size of a multimember data stream is unlimited. +The size of a multimember file is unlimited. Empty members (data size = 0) +are not allowed in multimember files. Each member has the following structure: @@ -1043,7 +1044,7 @@ Example: 0xD3 = 2^19 - 6 * 2^15 = 512 KiB - 6 * 32 KiB = 320 KiB@* Valid values for dictionary size range from 4 KiB to 512 MiB. @item LZMA stream -The LZMA stream, finished by an "End Of Stream" marker. Uses default values +The LZMA stream, terminated by an "End Of Stream" marker. Uses default values for encoder properties. @ifnothtml @xref{Stream format,,,lzip}, @@ -1077,8 +1078,8 @@ overflowing. @cindex examples This chapter provides real code examples for the most common uses of the -library. See these examples in context in the files @samp{bbexample.c} and -@samp{ffexample.c} from the source distribution of lzlib. +library. See these examples in context in the files @file{bbexample.c} and +@file{ffexample.c} from the source distribution of lzlib. Note that the interface of lzlib is symmetrical. That is, the code for normal compression and decompression is identical except because one calls diff --git a/doc/minilzip.1 b/doc/minilzip.1 index 22ad101..c60e528 100644 --- a/doc/minilzip.1 +++ b/doc/minilzip.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.2. -.TH MINILZIP "1" "April 2024" "minilzip 1.15-pre1" "User Commands" +.TH MINILZIP "1" "October 2024" "minilzip 1.15-pre2" "User Commands" .SH NAME minilzip \- reduces the size of files .SH SYNOPSIS @@ -16,8 +16,8 @@ maximum dictionary size is 512 MiB so that any lzip file can be decompressed on 32\-bit machines. Lzip provides accurate and robust 3\-factor integrity checking. Lzip can compress about as fast as gzip (lzip \fB\-0\fR) or compress most files more than bzip2 (lzip \fB\-9\fR). Decompression speed is intermediate between -gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery -perspective. Lzip has been designed, written, and tested with great care to +gzip and bzip2. Lzip provides better data recovery capabilities than gzip +and bzip2. Lzip has been designed, written, and tested with great care to replace gzip and bzip2 as the standard general\-purpose compressed format for Unix\-like systems. .SH OPTIONS @@ -120,7 +120,7 @@ License GPLv2+: GNU GPL version 2 or later .br This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. -Using lzlib 1.15\-pre1 +Using lzlib 1.15\-pre2 Using LZ_API_VERSION = 1015 .SH "SEE ALSO" The full documentation for diff --git a/encoder_base.c b/encoder_base.c index d2ed53c..cd790fb 100644 --- a/encoder_base.c +++ b/encoder_base.c @@ -168,7 +168,6 @@ static void LZeb_reset( struct LZ_encoder_base * const eb, { const unsigned long long min_member_size = min_dictionary_size; const unsigned long long max_member_size = 0x0008000000000000ULL; /* 2 PiB */ - int i; Mb_reset( &eb->mb ); eb->member_size_limit = min( max( min_member_size, member_size ), max_member_size ) - Lt_size - max_marker_size; @@ -186,7 +185,7 @@ static void LZeb_reset( struct LZ_encoder_base * const eb, Lm_init( &eb->match_len_model ); Lm_init( &eb->rep_len_model ); Re_reset( &eb->renc, eb->mb.dictionary_size ); - for( i = 0; i < num_rep_distances; ++i ) eb->reps[i] = 0; + int i; for( i = 0; i < num_rep_distances; ++i ) eb->reps[i] = 0; eb->state = 0; eb->member_finished = false; } diff --git a/lzlib.c b/lzlib.c index 4105205..23dd0ac 100644 --- a/lzlib.c +++ b/lzlib.c @@ -486,7 +486,7 @@ int LZ_decompress_read( struct LZ_Decoder * const d, { d->rdec->member_position += Cb_used_bytes( &d->rdec->cb ); Cb_reset( &d->rdec->cb ); d->lz_errno = LZ_unexpected_eof; } - else if( result == 5 ) d->lz_errno = LZ_library_error; + else if( result == 6 ) d->lz_errno = LZ_library_error; else d->lz_errno = LZ_data_error; d->fatal = true; if( Cb_empty( &d->lz_decoder->cb ) ) return -1; diff --git a/lzlib.h b/lzlib.h index 7a52342..431a736 100644 --- a/lzlib.h +++ b/lzlib.h @@ -26,7 +26,7 @@ extern "C" { #define LZ_API_VERSION 1015 -static const char * const LZ_version_string = "1.15-pre1"; +static const char * const LZ_version_string = "1.15-pre2"; enum LZ_Errno { LZ_ok = 0, LZ_bad_argument, LZ_mem_error, LZ_sequence_error, LZ_header_error, LZ_unexpected_eof, diff --git a/minilzip.c b/minilzip.c index c0e542a..db6a4d0 100644 --- a/minilzip.c +++ b/minilzip.c @@ -125,8 +125,8 @@ static void show_help( void ) "on 32-bit machines. Lzip provides accurate and robust 3-factor integrity\n" "checking. Lzip can compress about as fast as gzip (lzip -0) or compress most\n" "files more than bzip2 (lzip -9). Decompression speed is intermediate between\n" - "gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery\n" - "perspective. Lzip has been designed, written, and tested with great care to\n" + "gzip and bzip2. Lzip provides better data recovery capabilities than gzip\n" + "and bzip2. Lzip has been designed, written, and tested with great care to\n" "replace gzip and bzip2 as the standard general-purpose compressed format for\n" "Unix-like systems.\n" "\nUsage: %s [options] [files]\n", invocation_name ); @@ -348,7 +348,7 @@ static void show_header( const unsigned dictionary_size ) } -/* separate numbers of 5 or more digits in groups of 3 digits using '_' */ +/* separate numbers of 6 or more digits in groups of 3 digits using '_' */ static const char * format_num3( unsigned long long num ) { enum { buffers = 8, bufsize = 4 * sizeof num, n = 10 }; @@ -360,7 +360,7 @@ static const char * format_num3( unsigned long long num ) char * const buf = buffer[current++]; current %= buffers; char * p = buf + bufsize - 1; /* fill the buffer backwards */ *p = 0; /* terminator */ - if( num > 1024 ) + if( num > 9999 ) { char prefix = 0; /* try binary first, then si */ for( i = 0; i < n && num != 0 && num % 1024 == 0; ++i ) @@ -371,7 +371,7 @@ static const char * format_num3( unsigned long long num ) { num /= 1000; prefix = si_prefix[i]; } if( prefix ) *(--p) = prefix; } - const bool split = num >= 10000; + const bool split = num >= 100000; for( i = 0; ; ) { @@ -530,7 +530,7 @@ static int open_instream( const char * const name, struct stat * const in_statsp if( program_mode == m_compress && !recompress && eindex >= 0 ) { if( verbosity >= 0 ) - fprintf( stderr, "%s: %s: Input file already has '%s' suffix.\n", + fprintf( stderr, "%s: %s: Input file already has '%s' suffix, ignored.\n", program_name, name, known_extensions[eindex].from ); return -1; } @@ -845,13 +845,15 @@ static int compress( const unsigned long long member_size, static int do_decompress( struct LZ_Decoder * const decoder, const int infd, - struct Pretty_print * const pp, const bool ignore_trailing, - const bool loose_trailing, const bool testing ) + struct Pretty_print * const pp, const bool from_stdin, + const bool ignore_trailing, const bool loose_trailing, + const bool testing ) { enum { buffer_size = 65536 }; uint8_t buffer[buffer_size]; /* read/write buffer */ unsigned long long total_in = 0; /* to detect library stall */ bool first_member; + bool empty = false, nonempty = false; for( first_member = true; ; ) { @@ -890,9 +892,11 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd, else if( rd < 0 ) { out_size = rd; break; } if( LZ_decompress_member_finished( decoder ) == 1 ) { + const unsigned long long data_size = LZ_decompress_data_position( decoder ); + if( !from_stdin ) + { if( data_size == 0 ) empty = true; else nonempty = true; } if( verbosity >= 1 ) { - const unsigned long long data_size = LZ_decompress_data_position( decoder ); const unsigned long long member_size = LZ_decompress_member_position( decoder ); if( verbosity >= 2 || ( verbosity == 1 && first_member ) ) Pp_show_msg( pp, 0 ); @@ -943,6 +947,8 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd, LZ_decompress_member_version( decoder ) ); } } else if( member_pos == 5 ) Pp_show_msg( pp, "Invalid dictionary size in member header." ); + else if( member_pos == 6 ) + Pp_show_msg( pp, "Nonzero first LZMA byte." ); else if( first_member ) /* for lzlib older than 1.10 */ Pp_show_msg( pp, "Bad version or dictionary size in member header." ); else if( !loose_trailing ) @@ -982,12 +988,14 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd, } } if( verbosity == 1 ) fputs( testing ? "ok\n" : "done\n", stderr ); + if( empty && nonempty ) + { show_file_error( pp->name, "Empty member not allowed.", 0 ); return 2; } return 0; } static int decompress( const int infd, struct Pretty_print * const pp, - const bool ignore_trailing, + const bool from_stdin, const bool ignore_trailing, const bool loose_trailing, const bool testing ) { struct LZ_Decoder * const decoder = LZ_decompress_open(); @@ -995,7 +1003,7 @@ static int decompress( const int infd, struct Pretty_print * const pp, if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok ) { Pp_show_msg( pp, mem_msg ); retval = 1; } - else retval = do_decompress( decoder, infd, pp, ignore_trailing, + else retval = do_decompress( decoder, infd, pp, from_stdin, ignore_trailing, loose_trailing, testing ); LZ_decompress_close( decoder ); return retval; @@ -1098,7 +1106,7 @@ int main( const int argc, const char * const argv[] ) { 'V', "version", ap_no }, { opt_chk, "check-lib", ap_no }, { opt_lt, "loose-trailing", ap_no }, - { 0, 0, ap_no } }; + { 0, 0, ap_no } }; /* static because valgrind complains and memory management in C sucks */ static struct Arg_parser parser; @@ -1116,8 +1124,8 @@ int main( const int argc, const char * const argv[] ) const char * const arg = ap_argument( &parser, argind ); switch( code ) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': + case '0': case '1': case '2': case '3': case '4': case '5': + case '6': case '7': case '8': case '9': encoder_options = option_mapping[code-'0']; break; case 'a': ignore_trailing = false; break; case 'b': member_size = getnum( arg, pn, 100000, max_member_size ); break; @@ -1130,7 +1138,7 @@ int main( const int argc, const char * const argv[] ) case 'm': encoder_options.match_len_limit = getnum( arg, pn, LZ_min_match_len_limit(), LZ_max_match_len_limit() ); break; - case 'n': break; + case 'n': break; /* ignored */ case 'o': if( strcmp( arg, "-" ) == 0 ) to_stdout = true; else { default_output_filename = arg; } break; case 'q': verbosity = -1; break; @@ -1212,9 +1220,10 @@ int main( const int argc, const char * const argv[] ) { const char * input_filename = ""; int infd; + const bool from_stdin = strcmp( filenames[i], "-" ) == 0; Pp_set_name( &pp, filenames[i] ); - if( strcmp( filenames[i], "-" ) == 0 ) + if( from_stdin ) { if( stdin_used ) continue; else stdin_used = true; infd = STDIN_FILENO; @@ -1260,7 +1269,7 @@ int main( const int argc, const char * const argv[] ) tmp = compress( member_size, volume_size, infd, &encoder_options, &pp, in_statsp ); else - tmp = decompress( infd, &pp, ignore_trailing, loose_trailing, + tmp = decompress( infd, &pp, from_stdin, ignore_trailing, loose_trailing, program_mode == m_test ); if( close( infd ) != 0 ) { show_file_error( pp.name, "Error closing input file", errno ); diff --git a/testsuite/check.sh b/testsuite/check.sh index 1c5daf7..21f6def 100755 --- a/testsuite/check.sh +++ b/testsuite/check.sh @@ -31,11 +31,11 @@ if [ -d tmp ] ; then rm -rf tmp ; fi mkdir tmp cd "${objdir}"/tmp || framework_failure -cat "${testdir}"/test.txt > in || framework_failure +cp "${testdir}"/test.txt in || framework_failure in_lz="${testdir}"/test.txt.lz -in_em="${testdir}"/test_em.txt.lz fox_lf="${testdir}"/fox_lf fox_lz="${testdir}"/fox.lz +fnz_lz="${testdir}"/fox_nz.lz fail=0 test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; } @@ -105,7 +105,7 @@ printf "LZIP\001+.............................." | "${LZIP}" -t 2> /dev/null printf "\ntesting decompression..." -for i in "${in_lz}" "${in_em}" "${testdir}"/test_sync.lz ; do +for i in "${in_lz}" "${testdir}"/test_sync.lz ; do "${LZIP}" -t "$i" || test_failed $LINENO "$i" "${LZIP}" -d "$i" -o out || test_failed $LINENO "$i" cmp in out || test_failed $LINENO "$i" @@ -118,16 +118,13 @@ for i in "${in_lz}" "${in_em}" "${testdir}"/test_sync.lz ; do rm -f out || framework_failure done -lines=`"${LZIP}" -tvv "${in_em}" 2>&1 | wc -l` || test_failed $LINENO -[ "${lines}" -eq 8 ] || test_failed $LINENO "${lines}" - -cat "${in_lz}" > out.lz || framework_failure +cp "${in_lz}" out.lz || framework_failure "${LZIP}" -dk out.lz || test_failed $LINENO cmp in out || test_failed $LINENO rm -f out || framework_failure "${LZIP}" -cd "${fox_lz}" > fox || test_failed $LINENO -cat fox > copy || framework_failure -cat "${in_lz}" > copy.lz || framework_failure +cp fox copy || framework_failure +cp "${in_lz}" copy.lz || framework_failure "${LZIP}" -d copy.lz out.lz 2> /dev/null # skip copy, decompress out [ $? = 1 ] || test_failed $LINENO [ ! -e out.lz ] || test_failed $LINENO @@ -138,7 +135,7 @@ cmp in out || test_failed $LINENO cmp in copy || test_failed $LINENO rm -f copy out || framework_failure -cat "${in_lz}" > out.lz || framework_failure +cp "${in_lz}" out.lz || framework_failure "${LZIP}" -d -S100k out.lz || test_failed $LINENO # ignore -S [ ! -e out.lz ] || test_failed $LINENO cmp in out || test_failed $LINENO @@ -154,7 +151,7 @@ rm -f ./- || framework_failure cmp in ./- || test_failed $LINENO rm -f ./- || framework_failure -cat "${in_lz}" > anyothername || framework_failure +cp "${in_lz}" anyothername || framework_failure "${LZIP}" -dv - anyothername - < "${in_lz}" > out 2> /dev/null || test_failed $LINENO cmp in out || test_failed $LINENO @@ -172,7 +169,7 @@ cat out in | cmp in - || test_failed $LINENO # out must be empty [ $? = 1 ] || test_failed $LINENO cmp in out || test_failed $LINENO rm -f out || framework_failure -cat "${in_lz}" > out.lz || framework_failure +cp "${in_lz}" out.lz || framework_failure for i in 1 2 3 4 5 6 7 ; do printf "g" >> out.lz || framework_failure "${LZIP}" -atvvvv out.lz "${in_lz}" 2> /dev/null @@ -201,6 +198,9 @@ cmp in2 out2 || test_failed $LINENO rm -f out2 || framework_failure cat "${in_lz}" "${in_lz}" > out2.lz || framework_failure +lines=`"${LZIP}" -tvv out2.lz 2>&1 | wc -l` || test_failed $LINENO +[ "${lines}" -eq 2 ] || test_failed $LINENO "${lines}" + printf "\ngarbage" >> out2.lz || framework_failure "${LZIP}" -tvvvv out2.lz 2> /dev/null || test_failed $LINENO "${LZIP}" -atq out2.lz @@ -218,6 +218,18 @@ printf "to be overwritten" > out2 || framework_failure cmp in2 out2 || test_failed $LINENO rm -f out2 || framework_failure +touch empty em || framework_failure +"${LZIP}" -0 em || test_failed $LINENO +"${LZIP}" -dk em.lz || test_failed $LINENO +cmp empty em || test_failed $LINENO +rm -f empty em || framework_failure +cat em.lz "${in_lz}" | "${LZIP}" -t || test_failed $LINENO +cat em.lz "${in_lz}" | "${LZIP}" -d > out || test_failed $LINENO +cmp in out || test_failed $LINENO +cat "${in_lz}" em.lz | "${LZIP}" -t || test_failed $LINENO +cat "${in_lz}" em.lz | "${LZIP}" -d > out || test_failed $LINENO +cmp in out || test_failed $LINENO + printf "\ntesting compression..." "${LZIP}" -c -0 in in in -S100k -o out3.lz > copy2.lz || test_failed $LINENO @@ -226,7 +238,7 @@ printf "\ntesting compression..." "${LZIP}" -d copy2.lz -o out2 || test_failed $LINENO [ -e copy2.lz ] || test_failed $LINENO cmp in2 out2 || test_failed $LINENO -rm -f out2 copy2.lz || framework_failure +rm -f copy2.lz || framework_failure "${LZIP}" -cf "${in_lz}" > lzlz 2> /dev/null # /dev/null is a tty on OS/2 [ $? = 1 ] || test_failed $LINENO @@ -293,7 +305,7 @@ rm -f out out.lz00001.lz out.lz00002.lz || framework_failure "${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO "${LZIP}" -cd out00001.lz out00002.lz | cmp in8.lz - || test_failed $LINENO [ ! -e out00003.lz ] || test_failed $LINENO -rm -f out00001.lz || framework_failure +rm -f out00001.lz out00002.lz || framework_failure "${LZIP}" -1 -S100k -o out < in8.lz || test_failed $LINENO "${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO "${LZIP}" -cd out00001.lz out00002.lz | cmp in8.lz - || test_failed $LINENO @@ -314,7 +326,8 @@ rm -f in8.lz in8.lz.lz || framework_failure "${BBEXAMPLE}" "${fox_lf}" || test_failed $LINENO "${FFEXAMPLE}" -h > /dev/null || test_failed $LINENO -"${FFEXAMPLE}" > /dev/null && test_failed $LINENO +"${FFEXAMPLE}" > /dev/null +[ $? = 1 ] || test_failed $LINENO rm -f out || framework_failure "${FFEXAMPLE}" -b in out || test_failed $LINENO cmp in out || test_failed $LINENO @@ -322,7 +335,6 @@ cmp in out || test_failed $LINENO "${FFEXAMPLE}" -b in8 | cmp in8 - || test_failed $LINENO "${FFEXAMPLE}" -b "${fox_lf}" | cmp "${fox_lf}" - || test_failed $LINENO "${FFEXAMPLE}" -d "${in_lz}" - | cmp in - || test_failed $LINENO -"${FFEXAMPLE}" -d "${in_em}" - | cmp in - || test_failed $LINENO "${FFEXAMPLE}" -c in | "${FFEXAMPLE}" -d | cmp in - || test_failed $LINENO "${FFEXAMPLE}" -m in | "${FFEXAMPLE}" -d | cmp in - || test_failed $LINENO "${FFEXAMPLE}" -l in | "${FFEXAMPLE}" -d | cmp in - || test_failed $LINENO @@ -340,9 +352,23 @@ rm -f in8 || framework_failure printf "\ntesting bad input..." +cat "${in_lz}" em.lz "${in_lz}" > inein.lz || framework_failure +"${LZIP}" -t < inein.lz || test_failed $LINENO +"${LZIP}" -d < inein.lz > out2 || test_failed $LINENO +cmp in2 out2 || test_failed $LINENO +"${LZIP}" -tq inein.lz +[ $? = 2 ] || test_failed $LINENO +"${LZIP}" -dq inein.lz +[ $? = 2 ] || test_failed $LINENO +[ ! -e inein ] || test_failed $LINENO +"${LZIP}" -cdq inein.lz > out2 +[ $? = 2 ] || test_failed $LINENO +cmp in2 out2 || test_failed $LINENO +rm -f out2 inein.lz || framework_failure + headers='LZIp LZiP LZip LzIP LzIp LziP lZIP lZIp lZiP lzIP' -body='\001\014\000\203\377\373\377\377\300\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000$\000\000\000\000\000\000\000' -cat "${in_lz}" > int.lz || framework_failure +body='\001\014\000\000\101\376\367\377\377\340\000\200\000\215\357\002\322\001\000\000\000\000\000\000\000\045\000\000\000\000\000\000\000' +cp "${in_lz}" int.lz || framework_failure printf "LZIP${body}" >> int.lz || framework_failure if "${LZIP}" -tq int.lz ; then for header in ${headers} ; do @@ -359,7 +385,7 @@ if "${LZIP}" -tq int.lz ; then [ $? = 2 ] || test_failed $LINENO ${header} "${LZIP}" -cdq --loose-trailing int.lz > /dev/null [ $? = 2 ] || test_failed $LINENO ${header} - cat "${in_lz}" > int.lz || framework_failure + cp "${in_lz}" int.lz || framework_failure printf "${header}${body}" >> int.lz || framework_failure "${LZIP}" -tq int.lz # trailing data [ $? = 2 ] || test_failed $LINENO ${header} @@ -385,6 +411,9 @@ else fi rm -f int.lz || framework_failure +"${LZIP}" -tq "${fnz_lz}" +[ $? = 2 ] || test_failed $LINENO + for i in fox_v2.lz fox_s11.lz fox_de20.lz \ fox_bcrc.lz fox_crc0.lz fox_das46.lz fox_mes81.lz ; do "${LZIP}" -tq "${testdir}"/$i @@ -400,9 +429,9 @@ rm -f fox out || framework_failure cat "${in_lz}" "${in_lz}" > in2.lz || framework_failure cat "${in_lz}" "${in_lz}" "${in_lz}" > in3.lz || framework_failure -if dd if=in3.lz of=trunc.lz bs=14752 count=1 2> /dev/null && +if dd if=in3.lz of=trunc.lz bs=14682 count=1 2> /dev/null && [ -e trunc.lz ] && cmp in2.lz trunc.lz > /dev/null 2>&1 ; then - for i in 6 20 14734 14753 14754 14755 14756 14757 14758 ; do + for i in 6 20 14664 14683 14684 14685 14686 14687 14688 ; do dd if=in3.lz of=trunc.lz bs=$i count=1 2> /dev/null "${LZIP}" -tq trunc.lz [ $? = 2 ] || test_failed $LINENO $i @@ -418,7 +447,7 @@ else fi rm -f in2.lz in3.lz trunc.lz || framework_failure -cat "${in_lz}" > ingin.lz || framework_failure +cp "${in_lz}" ingin.lz || framework_failure printf "g" >> ingin.lz || framework_failure cat "${in_lz}" >> ingin.lz || framework_failure "${LZIP}" -atq ingin.lz @@ -431,13 +460,15 @@ cat "${in_lz}" >> ingin.lz || framework_failure [ $? = 2 ] || test_failed $LINENO "${LZIP}" -t ingin.lz || test_failed $LINENO "${LZIP}" -t < ingin.lz || test_failed $LINENO +"${LZIP}" -dk ingin.lz || test_failed $LINENO +cmp in ingin || test_failed $LINENO "${LZIP}" -cd ingin.lz > out || test_failed $LINENO cmp in out || test_failed $LINENO "${LZIP}" -d < ingin.lz > out || test_failed $LINENO cmp in out || test_failed $LINENO "${FFEXAMPLE}" -d ingin.lz | cmp in - || test_failed $LINENO "${FFEXAMPLE}" -r ingin.lz | cmp in2 - || test_failed $LINENO -rm -f in2 out ingin.lz || framework_failure +rm -f in2 out ingin ingin.lz || framework_failure echo if [ ${fail} = 0 ] ; then diff --git a/testsuite/fox_nz.lz b/testsuite/fox_nz.lz new file mode 100644 index 0000000000000000000000000000000000000000..44a4b58b881d207627f6081d8ad04708c25400dc GIT binary patch literal 80 zcmeZ?@(f_)Nz{_!Sj4QF_R+iI=pxqtde3fNQjl6}^5c>03rDkGci1v_+dL64QRjTU cIqmVA>95u)|NqywfFbKlz-wIw2nc}E0AJQ0O8@`> literal 0 HcmV?d00001 diff --git a/testsuite/test.txt b/testsuite/test.txt index 9196a3a..423f0c0 100644 --- a/testsuite/test.txt +++ b/testsuite/test.txt @@ -1,8 +1,7 @@ GNU GENERAL PUBLIC LICENSE Version 2, June 1991 - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Copyright (C) 1989, 1991 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -339,8 +338,7 @@ Public License instead of this License. GNU GENERAL PUBLIC LICENSE Version 2, June 1991 - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Copyright (C) 1989, 1991 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. diff --git a/testsuite/test.txt.lz b/testsuite/test.txt.lz index 22cea6e4d2a58b4dcb006541dcdb8defabba0cbb..5dc169f7fb6e952f17e7a21ce3691eeaac2fb3aa 100644 GIT binary patch delta 7294 zcmV-^9D(D|IjuR6Zhys3yJ(c8peBW%f-elXuLG8+YcW?HC;m#{D%pU^WiRDBah9%H zoNKDm$X*ivN}frZPJV^dtsX$0%Z^SSxrOZEO@c$q7owY! z`W;W~c7VLKKJvfUJ)mGF=tySp{PxY$8`#(o1p?=vxoYM*hkx#@T($B}rE}wqiNbai zPkS|>8W_N@+GNU=i-?`g4gP^bKc=(O|BTS>tf}Y}sWaDOa9)@f3Z>pC@4M?MqsMyf z$l9a4FCJZ;`)tQ5Wbrs^K<$Gkx9@N*`^#x7IXK%ex=T%-ID=$T@CGUn*XOjK7%aI^ z{P$K|lLRk7DSwY<;3s2ge)hV`mKFEf_=bs$Oa|MsKB4EOEq5 zbi#35GkG6xskoc^ai7hojVayH{;Ap%0D7qkn{2{=+J9YtzU8rM;x_SA8&KAYW1k_h z6jNt-h{86HEF`a<$-VVCu3pxcF)8&GZMPBYv-yMf+{>=Jz?Pv_a#2CFp_qxNnqgCT zm|4IEz>g~)XQacM{Y1yRp0rfS;ey&SmGU6PN1DKxz1fy~zY?HobYOqcMfyA0F^|_9 zb;}1R3V%0WyI53v!P#y+mVW+6`~DBtJ%g}CgV%huoPofSS#k~0)-1G16pg9e$v$?e zi%VFSkvBCM(ol`Qj#NT%bkrS8>~O-o87|jL7238#ja}K2cP!9oEb`4w#xyGr${tR& z=JU|+!?kOF!J6T$CDdJI=|K&qAhmRB}3|`?uO1mRHW>Z7RQRm434$dZv zrmWjFv}gIOgUQbOpzq>y-KJbRR?H@nk#57pYae+VpD{y?DTb$_8GtX26OM*PHr z-vSJ&PF#L`&N2GdO4I5ccDj%*sg@Ykzh5 zu}lXwTSTW%cVaD{4pnda!^Wab!$83FuH!If>se|-CZsXSjQWokCCzc4FeblB1S2bK z0Zmuw*@YNE5m_2?(29CdM_Lcoe%7s^wpU*wFgXx>P8lX$>>Tl}ey^N>HOhW40Gy9~fV$j(A)~rq+3T=amsjsAF7Du$t z4Q?7<0Q9{oIV+Pw$Ugm|6Yi%5+FnEtJ9~AAv_9I+@7OodrV=4hjNqNe2!Cb~w?bgV z?9fRhB)(5`11n||?A<~JfOrn9=-$~WseS7KhEBx^@&;wspROAq?w>*lW@f;o8jFLw zU}<9}64~9g(2p(Jo<*^`YIXc_oT4HZ4Z|I zlK^tdJCeo>CI7bvf+ZmHynmhS3D21!hCmdL3GyTHV@xZHWL-EcQW9ITRspQB3vTg; zugE;m!LZrQj0373lJBIu6GdRRk{kKcmMJ;Yi_UKT*{GsNmnAxwFewgOYOS$ zkr~5b{aw|GMAVB~?JYQz5)~!wF{(=1{CuB79NnjY#sH?NcF;Q>QE{^W6csXXS}s&X9M|4*3z=-?u^bfxVz5UZ3(@xJ-xTkdhQYc@z!xsZ zjF``$q;^R=pO-|7{$~~7Uyw^(s~!x8EgYVV5sx!Lg=>G~ip%ftOc^jy-K3KG62QDX ze<#r_hf?aY**ndtM}JBn<{u?xJtkVGJ}-7`D)`ODny|{A>`LVwd$n4^4L_9(+)czfDW(9$ zU(y#v^gGRj;D4u6kkYU{SkAfJ0E)sx$5+OISMEB0rFUrlNFeP_s9=PV#7-{pw${uf zl@rWvRsXKaUtzPU4x{25Ym%6Jq1Fd|;~zgMzh@2#A+J56K%(Ve>H^YnNq-?mrMsg9l|?$p@O}A-K~+*h zz9ic&z$nYEb;#31K+=4LBD9DCRacGO+cAdL=dF9^JGkG$t3u4L70?ASd*~Q^%IT7? zE$eeem+mSiUN4nofp*Bm7H(TVLLvx*buftO%90*Lkw9(8 z>f%F)-@tp5mx!gt*u)g3S2b<0j<>53rIYkWY}yxwZ7kD~DxE6TS%2DtD2u=&j9A`xDTeg%yU-g@CFY3| zAHwD?yRH?_DCp$7zu<_?7y_c6PM0gVR{bnJG9pOw9BfW6%i0s#Y@(wyajBS5T~Qv& z>wU}hoF9%=ncs=h-}hvF)xF+J)^>b6sPCZv687X{ z0e>4ZyFy+lPY!KgZ<>gT8jD4j_rOS~qqOrj){KFEkhKB(sn{|&Q%@W$3XXcUxa{`t zyZopshf&Z`*HnS4lj;lZmD4lH&w9=O%nKTJ94rujTn?qd-9B%@$Ev*Z&}_*r&m}79 zD9Le#Fz!D|<`wgo_dvA6Yt%y-vs65NB7Yky@LsJLp@#ftKxt2UOFJ{TnbT+TpJ6;+ z5DJC5bsuD95bxsGxh|gup^erNBQ9?k0K-h-G(HzaW{U%`dbxUJuvcim_sIT{!y({- zE2}&UE%+LPW*;n5_QAdp5^9C?|gd?n}2#+ zIj~g%4Vb@_!42VMf`RsgJG-zYrR>zqf$jES13SX>xGJ)LxG+x9S&R8VqKxE4m}Ydj zJXCR8E9mADQBPZ1|xR-yfS+gI#sT<%J`72dIa zB7l25^ID|BM9de%aJaAvYx0wSs(<4fGc6jWJxa#3D+?Dj;uGUy_^?OwC?SXZ7x1T; zX0B2rN-Va zE^7v1>jIxR8oUT_@57byDGWr?+PT}rVn>d^NIwCo#T<@Cv(}g$N}`wa8h=Yp8cVYe`3^jWI;PgCHu~3uc<0M3FqB4;n zlzj!`oAQAynln1!z;l2>sDK~Zve$m5r#eJ;W>svYrElhpxAxCh{(mw<|Cie2-AKA` z@?g;4=@7SLOeg-A?xx=-fKd&pv_+oQ9)PoSp4|sfvLLX*062Bws2yWur&SxuAp5@o z&yO<(3wi9)&pRG{A~4u41{ay4MhA6^x@O1sE| zu`X+`>ZS8gX7Nm$s0E5=DT){YhztjTk zWKMxiMAayBF@NL9qoMqXwC|~j1VT}u=N$Hg80Jp%~Q6{}yqR0U-L>|f z#TqR8Mt-jlYpe zoiPS_GKa_WCurqibvUx;J~&+XiFwaRRIJMol^>srTyhHdjY><}7ZVqH82MNT>8Fe3 ztBrYTtA83T>(LCgek7p0>WO;nrNyz3>q8zJBqYgh$!`^6`5_sRZ2{G8o`>%&(kCeb0UO#W|w>1Te#~=iv@LbzG#7+J5~$Q z09he3Z~!Q_^iTTL1{4oj4x4}KnbM#NkgxjU5r5OxroABjVfajk1MLxm&scbMBZjs= z0?5t-38S@L5*=bHMRwG)EQH`oxDGS_A2N{5LY)ZtWK<~ewb3r#nX%jR80MbbRPpzTV##KHmllydl}1E%*J-*ecNNqBnlEXqlH-M~EhRHM7 zz&>jRa_;N1kz$4m<(9X>8s-?6NaLlGWO$x%87WN=>52BP>re;?S=TRMhiT|}e-Y&hx$e|xEPo45 zc3y-Q#-saOxfriBRvdO3k(!K9ez}Z9;R3rXw2JI!)eaw1+0T%JGZAD55oj6l?&wmI zI_{wo>DSanr9v}%x<)qaeF{T9igHC zAb9Yl2x!-lK4jh=_g)I%*{I3AA4ODt|%SKNbAYAB8Q|NA1W7R%<+JxCL92 zK+|y*53roknp%>2rTnsBlobT7(i7-)992|&kPr_gd-D$UoRR@Ex5+--V}H}|<~hi;uX{Y?pBd_di*@6Cw5&P||; zDaAD8DlmOEWuAz_*Cf8>W{9M9JMy=mJX{idvUcLGbx_I31>KKgjB1&HaKt#H!~YaP zWm4F-4~%%Vj4uhEWguVPrhn9bIw*R5kxO(}O>i#wthYMs-jAnfF;ryr{spm(b4!x{ z-V$5U@=OyzCMg#OTyds}9kciJW@M2LScy~X7?Z9Q(;cj=8K0oH%VyI_-P+7YNm`e= zoq-1&lc&(Ad*zJ+$b?^R?xbHe5D6mu#_X28dzxu5oJ3dyvMr|<%YU5fqM`!Xy2sK* z*4>W|Mt`<c%|1C83A=eq4;T$#jh z+fr3;M5*#R%pHITfqzz46nRhdb_#_V4bA6S((Z`XM`wzc*0Dd!OS{?{0AH&3ww$d6 zE;38sEEjPHi$C7NfWR)#4;8&;<#_goE9W+RdriK$nBnHp<6uqMl+30I@)-$6gK9W~ zkk6&zc-76tuGT-}6_JCgDf_O>Ta+s!zdaZOZp}~6Ihw_)1U{)}Z-}1H>-_JF7CGe0 zs|vHyh=R~z!)>ON8EZn=jPW`vv1_J^;mC9k6GVWwlD1@@DD~WSj1RxDVDiR&+cg>) z{e<2_$OghXXn#{^_VGFl^9y%-jpmBLAFF*<)xXhNJ}cIH7&{b?a;=15}%44oCcZ;WS8;C zdt6&JQG)~gcPEIhZW?yWu#4%2OXMr^jrfUJNN4wCe8No;0y3eEZ2ZblSMHk zY5IC5konlK}PGVob(9ZFF&2| zZjJ$@g$a`(O>HA&*J(bg;Q*!j&Oe!kiX`J;!}45*DdMi^Jv)k_6SDiM%%}zU8%_&? zk@b7og4~X$3A{mqZpHX|&;$(rOh6XUm6gK|o#)!ynMT2=oi($yvFjQvwX>)g{i}=8 z>wm=^h>P3Zs}QRxwnTp|txqi4doFq_Lo-Nn10ys3niD-~j#(^!ybok95@g95w)+(( z!TI=3EzpK##3oe>nGOZ?Zh6UyDIh3X|8uEOI+r1Q1D~Hpe~8n025}&kerjtHv!Fcq zTSXPul=NWjXIzUx3ksE$LZ_vu@w&xKB^o=42v;S+HdrfBF$TSg&_F% z$H`5Cc{_H@v{=@)<-aT#x5e{cuwH}VY9RD@=mS048knDSKQF^9hqC0)65PN=AAhKY zT)WRrlb(@^ z|AxEB$I*SKSbuWTnbKehi$%H#uu#0j&;%+v$NUfGJN(BaOBR?yM$y2wKP~rMjndF| zE++eG9>yESVLREg6j*qxl7U!$|5i{BTI_JYJkq+h1<(M&AqI1!x9E;Ez<-$^l#{C< zG!W!|-CvEVBZjqD27eVnK}NN+>O#q3tlCYWj>?-d!(4-Axhi7`*bbMs{8$C>U9sYnH)_4KmR{@_|F34G9djcQb{0+8gd(oAIyEwl;T+dU-kWJlutAAf$`#fl5_PmtYi zWvQ(dfTE6%yg2WAWpy%I7Egew(ds!!x`hce+-!ylWiM4tVVr(KNdb5vXGdGz|4fbS z=&LX*y%Oti19s#T%YkS0D4x_K=35j?gi_)~X0xuFm*#VmNar0bi}&=CPv>f-&J%6Z z)=G;hw|7|yWl6TPX@A@x>k`U2zsE8R%{av+Wwog^P99K<2S12)kp~x)#aeYDB^?A* z_E1~3JeUs0WYNU`FaU{aIQei3kEC)i@m1-{65l6mX3SZSb_`(E>GR}})OjJit%+WsvoTYrf!->LA}4xQP%^YSpe z@pZ3iGvdCU`Ucd7>W4Ny%CEvw!kivub+>#?NuD^2m&nauO34Ll(YmwVP>-4E1i|*S zrRDDk$n7BdyHMt)4~l}LBnaU|cqOzKp(PS5N(BAxYd4bM!XWD`$)`q@*6|msfIA$K zmN^0N(nE-ut$##6BiEnoY1qW)f&akL01B(I0C*o5_hfoHt3V!4D1OQIB} za$;E(H)v$6rXGS+p?_B2rce+Tm6Cr3M7rN}x9>j;$o^XA;-^g-dMtraeta$tmt?Sk%S@eSN?{vm}$^W zMbL(DU0>qTT{N9MRUqFL@cyXOY`&LiMfMk6vadg!$ms_&3V$4Qmyxh~T)AY)%5WR8 z%4hQg2qeX}R&#>#1w6h;m#rkBaT5GS@jnk`UeeI1Fnby8N0jyzkl*GbRXYbCDkn*DqdPj>CLcELtk7jDTzJL|THsWyP6y zDCHxOx)a#lNg6!etAXU4%K-ud64r6?KMZMBBCmINL!>)ToPT$xJr212Xi67=4{*Z2 zWhr#JKXJu1DSd>c`kzDCkl4$a9JiV@Zuv5YzgU$__z+ShaUGQ>Humevjwu0k!m8eO zFU-@jehf^Jn1!y6Wtnc63rjrulkOfXLc^^ZjN*N;A_4ziSJDpg4-R3 zoATyYt<(A=9a+Y=ki&{&8GtWS*BVaB{Hma`tcU{uKY7cR@HxBX>sWPp@zbK>Lmgs0 zg*p54RI74cK08y(gM+%T*Wo^+wn|eqAm(7=me;ZU`+xkv@>|H}hW>c(eb$6Z9)fmm zh`Rb%^8W4kYGT1RA}=L_STIvMF+=?hatiL;crO01#z!TI5d8gjmW7S=r-E=Q9P4g) zOI0Bo#jywaJ=0&{L+PzBj0h_H)Fm1@+>c6S+o_LxHIuFhPkvo%-S=|9O@=6bH57{Wc?@F!Z+)AYO&NMoqvZ{OG==iIy5MnGa&iJ{Pvm(Up(OW zv0MzhWmuzgc7)0Ah}Y_O>sdbBHv}wowYw-^MrkF`j#0~UOpg6u92UGD!pSjKQT%k} z-F`8YEZSN@zT=^7kyBR#5PGKpwtQ(#mbqm~;ZHTk1rG#bBwL8%{K2UPq|dv$LXQtT}CTt zn@4G?9MQ;;#K7-8$;Eqe-)b0L)8N${>2OOxdxw@mr#i#?fec@O|5Q^WC&DuJniR6i#^HVkBY^cRL|BOVJa!ExBe4C4w|8lAJ`I-1CwG80Wh2)1 zIinJdga$=pT{(l0h$$X1*tl8II%R65_kk`d%DJ$19_U6#;soG2;4fqXrg)fT_%shc z8LTmnPz^n^iv2W*o4qrEiP6SxY=21##{)n|dTAMa4aozt5Mn2Y#9;qk$`G}477r}?ih3!|Bay^%M*$cKgc|6;iv$2WZ2ScLu2;Lu?(u)owSSR3VYq0$ zWmJ`NBrz}Hp;p)09`deol4}es)5O<8t;YuPz^PbQZIXqF$p_)MKitcWaXdUzfhXvV z&fi{uIW^2CD}9a`wyH8ykAcp8-1v%VHk6~v4x-VEy?jl}J_3o91W~a5w1PV%?6HD0 zN~{Rmd8e>;6%uQ&w?WILOnLRM_ z+nz>G6UZraNY>`~BT&sQy(XM24|Ab2zim1L*^s#?F_a;ejr!twsef-HaCS%x*}!dD zR10>x*T=$o@2pRR=5=was#Vuo>`9}6wtT6%z@fBf=P=|WRtRg;1ehAzO(*ayIrW=b z$rkt|i|_BEhIr|ED#Q;qkiN2tEV%GO#J`|!81`LLMk!km5kkcprx3a;(V?H<@gZ^s zMovaWKnPCyy}268?SEmy!*M6!UUg)HwNgKdT&R5Rj)PF2AhMlMB3lqiCuI<<9)Ls# z&NbMAx0Y+C<+sAOtJuJ*-e-Af1>w&P0&h&WnDM>1@^X>xedIoy?dSf??U~Twv`?K- z%W<$J24=`%YEyFxkTyj#L}$VYwOjUByy_4CkHN%@co$8SsDGD<6_wVxnv$wgKsPG`vx@xayiblq--XJZHrUJX4=kfY`$%*43FKL`X6qQ-W2Ry z(uU^-jttYQX@4M-SoaAz7`Z~1-FtyiNhih>6>-?1^zGK}4Qhi(3iBE25!gfW5?Gqp z)%eSIF36?fvvi@JL-AVS$Gz>=ZR?iRC6cEumg3i@kPZkCGFa8kBMy7+?2V7rWdPs` z;-tYI_lr*My=)a3l82dluq#<*KPe|&9NRH95Qak)eA6Cyewtct$ z_0C{9$x;!+I?uKI@O$`y{G(gMS<4Xn za8w+(7JtY!UGu1`J^Seh$j%43nUCb~fvtQZaf*AL!8up%tKGDxd-|(MhzfinE&5%K z!if$n(L3^1ld_#?5%Bh)8D$77gZQ<8{58)X{ZsKEYoycCTnY!%VmlHekvYL%oku2w zY`>vdMX5}x#k)5mfUQ-)6X!+K7{Dvovi8h*=zqFnGLm=bxdBYO1)9}p)VEf>u({q1 zZl=+)?bHA!P<6~WqUU@n^l0h=LE>cR0jNINb3~xA7yain=taC^D#a*S zznmaNWK_seF-V93Kf2?hagtR~YI(5*6Mvff3qmLXH-ls+62`C)gcs!zhO=W*L8hou z8m|BZtR0GsNVW7(llMYk?g+2(pgs|uX*smaGNh6fw|&aT6w`IqIkgRh4PREW6*C$6 zX@X1ouU`14HwpWyWb(=N@dr~gdb#GT8m-SkWi|jQO4R&!qFDuX;~`S=IopTmSIVGF^t_)7SnL@mr$FAH@mWY)y zN}*+;`K!&F>)J3TrxrFZdb^aIB?e7ejpPx6qfFIwkk(J*I*KkI6-U1d0Mm8WX|0eQ z?xj(SXkR%^-YcZ89KfQq&SlW1khqXijEpB^F?NB7A$n(Z@y}b7+&}zjbAO&8HlA5_ zADTSScG)hZBL^(n#otWaLHh3)Od-y=^m8MYD|oqIBk-tgwz~RSQ>yA++}Nc69f~r&Etd z`eM^Z!{b08vkq=wr zMw6XsVK~dB9~kh9U|LO*rc1=#Jpo(Dj6G>~?FXzphWoGY5fj<1V}C3gvX8v5mzU(Y z$MXeR(ZFcsI{rU+<*mwH5WgCWf=UpKO7Qbe+do4MHDDPz@ta;{_57F4c|z`2%fTy2 zLhgP5@w2)v)BMmT6x?xt8Y~b@?~%suePGxx78x`xc!*-X!7w5G9S{+XM_N&XQu|gW zSNOO4n8=TL`0vivhJRYXwr-6HxE*v7k&B|@>fkZt=KRH9xVYLus#zDa%4a~Qd@J1U zAU-+_VwO^dabzsLo@B1%tG?QAfsecfH2sS>^4 zR%zu`#9wBz(0||uJNq!~z`9x@dO^=qZ5}Tcf7lxIRVTAz-{RTG>CoD5&WAtw^?92c z3DA@_f$OXu>Vz_H&kDv+RRX()`OY-tMrWZ^WV}G4SJX{;223)y=kuEGMvACms2jqhN4!^5&VBQGiV4i|6N$v0NI{u zv(aVjxqp2fS2p@F6?a3grETR15IqgqJ?McvRMpfAw?XOvRxYu0suYvc#3|W&>a`Vj z+rt-RL_${OIknrqX}4OOv+HCTrZh-@1!GV8;jtH;VeLxi@C7EQSu5$~N;A@rh&Q@B zSPC5oDFYY%gWFX`#Fb_f5wraJWcwI>YBXNAb(wo5m&?cz1Wpq2s%*v&D9I zPF{zA>dHtZ1Nak+ypqYM%b*NbFoHeO@Sz_QsNSSzTh?}}Q3Q0{e2cE0GG?UbgS9Rf zAAk86X+O;b6=*QP5A?CUrEJ*gEy=&kDfA=WO~4E~k0G=vi3H@C_26;Gg?5C{;_r=C zb8KE~Nmuud;bCl1+!4jQ=Em(+7nRqu+vX>*7E7ojTz)}h*{bO&-sDL&m*1AS-GgO= z)6JX|-|@A6PHFzo`b!mrs|lhV>Zq#E;C~@=x0{JY8B zY~LIo86^c@`hkV?e;ivJ<-Wz6vx~JlA-Km_dqh^q!SJo`I(J7)RYSS_nhnK_?~i`x zwO2(1b$fm;*b|}cWUPS?rjx zr?v z*~ac&SAU+iR~KrI5^xd76Mr2&SdxJw29_)8lU4tc$v@>Dzbh~y^GI?JsQe~TbIC_z z7EKiiQ1(mR<&6(0GU$t<#21d|219D@@%YdWql@Ynn&@q_et%ggy^&<8emOPzRrA+u zO?j!VnVXOIVEV<8x^fVYz-2jUR2P6ZkTI*RPq+d9;e-bIy6G%_g#(nYBU0wwgN1L%IPj9}%Ewv`$7 zw=O?O4&j(%LE5fvE}aNmr0dKG!XUME13FcI8=Be(FTZf`flFO7-wSB%&dsaEa{{}Y zkCFV0Dv-G+3{Jwo$A2`ZnG%Z-rgtkoVK??8vj;no7_@0f;24zwA3xek*1~Mzw%AB_ zKR0)c@2{W^Mbg6Kj1>8wxPUTu=Kd^PQ(o_oV65E0MZ^_rz2r=f^<#O7dq;YemK+8W z$Wn$$x*T>J(^vl%RWuBwkV~%XImGP8R*PzV&^qJu(|6Cpxql+>qFx*$y*dd+~&Z_(!;BsW*_)zMb$;z`*R1V9@5e&v&peFx@`?Qm> zyS>8O(f9IzZMzyb=PbgE%#PN5U#Hv~=0j5oB}nig|9@FWIkUJ)mryb>-nVG^U*icb zwm%G^O-NJRdHPyBjvfu`oe30L=kS?C_FU(e&+1i`W}oeM*0IVZ-zi%Nx}x;ryabeS z`EJ+Rg6`=uv4@zaO0~xOPG@jz2f#=2HzI&Y+{szBWX;A@Tx=&IO!c~MxXk|}P$~jx z6}gw4kAJ(j%qqfCoOjcB!2eFztJ(3o|4LscI09p^@tZQKoee*ZVP>^W#Jp*_8LmRl2w zFOy|t>S{dvYh(k(FM(VrM0B&oCoNWAdZ-iX%oZVlF``c#l1&`;){-Eh3f_>6;`HPY z!6udu1;&>DwIBC{g4cygciqn7xa@C~vik%TG`5HY?!R8avcj~nM{@WS9s~Ar~#IQwU#zmHdJ*bD{7@HVL;t`A_hn8%+V+q zS`Ck{OEqILN0X+sYj`2^?S2RC3_cSqcbnD34)Fe1(yit*m`t(_${IC3x<8Qey3&!= z_X$S#Rt3Lqid~3(?K@4m>(5i_=4?bEa(|XZakaJ!CMpeN&#Sx#?VIxFz;3oNk4fx( za||jYU>OHR=Z81_E!IgF56|d0Doa_R*9V89>1F;P?@|%hd%KcMs1&Gh)f0*|SY!+L zA=#+cF8wbe2ar!I$HiRz5t^4P0{_Vn^IJNJIt&v<|9b>k%fBK7azn)FVp6<1i+@CU z_HV*$@RqOyvjQQ2*2niF-Wqe7?Eiks3u>*kH5N?VE440wO9dNFx#K6r7dPwMKHe=g z*E{KmPa)=w`mz7`V$iPYUx0a_8lbeJ)2^8rFMC4ha#&z7Tzu?F6|{gk3w@XhMXZS#B<&v+3Q zAoH|%WVYJg{8-IlvaHw61A}iw!FZ7&4gzSXpHy?DA7NYbG0Zv+Qiejj0)Khkn9T4v zGWaSoJcT-;!m77^G32rL3c-vGA0IFLsaCrGPF(M`;7U5zV(gK-Nsvq%G2ug0B^_9( zb74h;dIVpx;O@lN35o!MuWU0{*`cdZ3j0Iws7&dV?49;?9&f#Q+`{WmMZIx^s`Z~1 zhD%E<3Ktq>(!vQxNG*1Mi+_n47)cvBtRaJu>9`jJmAmHeQ-h+Yt(`)8f8ZSl43ZE_ zMuh}Ovw~%FUQUe_EqaoQQ-dOBAZx9)bNN^g`Zn98i73zQOm*-0)!D(~aNucUL7ZR1O=417AbSGU>F`Q0L4}z5jH`T_ zC){OaNR`|Sm{3)>?A2&y)oweSnE?O*q6YGRO&Sh zDqvFo`?mO<mK0XU3GqvYCg?)6Gzve}e_^e&1cC1-m8Eef=CcV2A!kMTy=yc*ARHr}| zbW710YcfXCB%GE|^Te^WKzaOB7BwM0Fxq;TKczZjv3zxLb=qXFCMc(&bjB zQ`?vrFjn`de*fEvQC!%>Poj|kvui6=KoBvW@x$<5^YFwY>!p({O~Sk$ljIL_Mrz5o zWTMX$#v7?yb>33D%%$~kmAKc#PYJM|JbO_jS>8!Cuzv+*Bddb0V;^K8K^}5-ER?Ah zB-WZ5H_Cv6JT=YWQHw6H@$%R1V6`}4Y1SjL0D31AKJ5M@hvU-1yn!#~CNIMRrg<1; zbZaZDsy^qCKrs@G+2>+$f`LLRSv*cahZYQrdg6K1^#cgSrb`W}A=w$I3snNYhVI|6 z=C^AVd4F)m=+nn8tvbLg(L!kOC5RjDS^0`r)^bkkba2wa`CMSs1 z6pJ4{29|(EyCk&emj~UpEqWe;w^-tz3G@;yuQM8Mhxa`6tvD#wmAklWHISI|OQ$wj z!K_O4X`3NK;oh-Tm?Z^Mk#EAp#QXv2do!dCKN~jC4*h_EAyf{Nq9l$0000000MHx& I000000MqzJBme*a diff --git a/testsuite/test_em.txt.lz b/testsuite/test_em.txt.lz deleted file mode 100644 index 7e96250d9ec70bc7d8cb173f438c76be447e6b6f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 14024 zcmb7~Ly#~4lVsbrZQHhO+qP}nwr$(CZQJht_TQb^!`^1=Qc)3g%8I(YOc^an1wa^p z;D6u${tW>9zeV!jqs;%_i332e{Szlg{U9R$^emnpP=->;y-J2_NFLo;6abfiRy$%i z;1u`u$LCGROi}}VAX@hA><%1+po5w@DJyf3l$=$r?jKb!fSy)n`3%Yd=-O|aMmvx} z(_25sQF~*#S!d^N#(dfqI#&Mt6bCWEkcPQ-^@r`OYq8}?DB(W0u339!Bw(F*D} z9nEy7I3-T(Lf+Vw#Nyel4m`=31_S~|T628lhp|*6s(1GgF5#BXaWChE>-e>hLJxp< z80t5rbm`)E9A%~S4JrM~7v4zNn9js$&tkFrWD4)sNR|0OP$G52O(kc0yPk@p1auv$ z+H<3yS#I)!kx9%5t&20ww99~&=J`s#!=n}&t`76!suXV@dcSAT1R9~BE&Ueu8+txY zMFruAwF*@)jr4@CLGJaJ;R`JkS*9eQFP6^>X72c#itJq%0>1{PFFvsDV~V_&MGxA> z4bOf$Q?FhABF5DmYfl)CGR6#`S6;`GoBF9LXsU?-2H^LcPJ7_&KE2j(^?Y0|Iugb; z;tl2eepab=(&OV+o(>M~YFIzyD{hlgW+gZ?I7(Y@{QdqJc+#FY3;Xl9_gxE-!V7Y< zi|G2&c>25jureBCC!!|})?iTPVif*`bAr0t@u2%_7!xOrMELo2PYaEGEe~>_!nwBd zkX9wc9&H5w;$7B15WcKsh=HK`Ss}&Z+=-Vm-L5#w_CP0BT%HB~z(wqxr9-OfaH*hC zNP+mf^Qa%{V18r_>ulkj*w@VLhLh+kf#Ma6Emf1#*`KHu2Oq`YFWYBK5fNNJ!X*taZe9 zo;bClvb)Cw+o1sXDM3AGAy_pTV!!sZYFr`B4Of?zDk$J$p~zw;_#FLt%YxG9IrwPQ zf$28YD0X%WnY@o!zjD9Ub{PrqCC&BwdJ8oOY6l`_;!m>%kkEWK>i9aXH=f zV@#ph(h}@DF0@TlRtHA#DhF)yv6M~gG?hG*XB`KH2QebijyOJv!k=ynFBQQ65DU=d zB!4{2+12=HD0v;Fl!b}tcair%?D)GU448a=N9h7AP83zbyVVn1`s21MY%a6zTW8fbf)CKGj}??lh~_=SdZN`pW0hq z->*Oh!&#h292vOhogDRc+PA{cT|QXFxpa^g@D5KCEaw{j4ia8;!I8kgO0l17-%Hx^ zGO=Ui!|Mml@`gbjCasD<-eQG~lLkgk&1A ziPB^y4tS+G$@)=j{hJ2~NJe!R(TMouaf2lzZukvvceixpgH4+xcMo7QC0={uEJlhA z0TVUWTGbsyATsU0y*G1pf>?3^T;s$V1ehytYM5- zfaPtD`elj8?qv>)TpY8rk%Srt77+Kc#Pork1a3kwB99m`1T*T)oYqt+CJ{M59bXTn z3KVqMRd69B~o{#DEOJx)_KC0pPaz0r{y@@1DMU^j~aEjJwa{pFLDL5K}RqSA6 z95?jB=W(@}Eqgq;&6j9GqqEz5Ol4jl9;Nvt5&*;82s=JfE#Ffqxgx5%+0GM_N1mW` zkytzXAXb>A>m|#ffp;!s?ziOv-c0DEU`!!Qi~TzCth6U~aFc-99I(|=fp+U!A0P6% zuaOTqb9Jn)QeD@&kt_~u^Qr6{C~Pr5XE-5NgRou($-vr{C4Zpde9hLHMEf9#zP~RD z^SJb)8i8j^=xd6i>39$t=`XOuc+*uDqtr$~6dJ`UN9dwnEX+T6By<83lM@pafROv@ z?ZleCH5?jtBtO)1H3@E2;*Zj)@VSc%R>&u4%2goJMvx>oMX13G5CNZK-3V$=vo1ev zA8N1O7^vDa_p}5(oQDOnmub&X&V3 zYRJ-~*xGTG#gjsvK*nP}3dN(GZ*Qeal4a9pTLTlnoBf4vm$-*=qq7ut4i*QqTy05^ ztnm)XiP0&PzUv*RC`mqsg6g;CrIgRk`pn}tmHo>aqF!i<()goseV_z+fwfRRV^6-I*}N1-@*=jYOQtIjEm2P8MR*U#KZsDN{At%}x|h zt2%&uF1m~{K)uoQHsg8GWz3Z1e$fdi(+!%nYO&I;*4xmz2WwZh*mS!BK&Ie2!*TL2 zH^Masy8A`XFJQeMNcw2BrDg@D-{exY2W$I1Ro9aCDzhD?N49Yo>^VT}urLhj~i zSWOdAfvGa1A&|~}eSyhFO_KnSQXiBb1v+s1oA_l79B@cZ21V z4y@Yd#QjNYQC)~r1RhT6RM=pX>{6#fh&6w^&^{=CL1&&H~Axj1( zb#_8mz3AMB>c!#;Nbtzy9I%3K(^;gT5&id^}jom5aW14S$S|Z zdInxAbH2F?_5Ca9pqn!Pg8n=p7tsxOPu|f+)>taOO=X(BQbI?4szBzYCm&kl29vy8 zU@!ksQx#_~9zHx>O=h!m6`pFv<#`CJsYJt~Lad4?h*gO#TkDj19Z!yma;S53Gsv=& zqT`PR2I@ToOrg7=Hs9A7dMWzQWh{H(@d>koUqJJal2)qFwD7ZfHv4*ufvg;jjozy} zC5IGDRx9=dF{oH()g@s~{+KI@4j)y#9~$64N?6t=;NF!gMqB7}%I;B@)Zq*iwal3= zlqGZ|D8F1@VU5JnU4$ z3M>>(O zJYZDKK6S=3#4WxR)L0gnH|r)uB;1&}xx9~+E60m}XPlu-6k@X-Y4mjHhF8Dypc!{= zBden2MLZYN>j3Md!!{il<~j%aN=FL*8nhE9!fPLkCFfcia!i-vV?0C~Xvrp(NssLE z0%}jh@LIavg4ghbeb?V3B5&3j(_lBn_cWxZpLC2rgK8}fSe$bG@q3)sPU#}_V?_r^ zA;d^MJj-qK3&XM+U~)cY>zTg(q|bQ@-KkFxQcDWm`2jpOchN2XERdn>IQnDJAjsS& zj@|njY|x`&ve0@&81)V^5dPpIAjXPoDF!QjtC6XHw0~zz#Cv|+&#i@N4Yb+CLU!P~ zASFf@9bFwTo}B%R>UVT(307&MH&2-hl>1Qc+!63`U0^LC(2et6+yjFuuY-O#k-rqE zOt{K-F^Q-^W-|md61^3dh92o3vBNSMpJix4lgo|0!+H3^1UZGDJI8&dI#Zbw#?!4X z)k2ml5#%!#KI2UVexVR1_0)2#3>?WEZu0FZ)(_n>po;$}+Vn!W&=R53`mDH?U-I)G z_%}n=Jx*fN)OsFNI2<+bZHTJ3C=6q z;?bk|Z(zNsk~bUeA8k%tE^OJ)h4X*DdS+uoE~KypUf1AVg)rIALrvShUqeRc>C_~} zPLyu?@J}Uj9AwMHw!@N-o!tsTdZ)k#?_H}SekJBulY;v5!8T6sZAewbOtBRU5xWm)nQ`44OOBnlX&l)fqN5&b$=i$Wi;;_);bo@ z(-}Uoa}FL(#2ycAv$QMgI2nj}U6v=RxjgsPI20S66jgfyG#!g27MGv}7EG&pJ-%j7 z!iuCT(~X7|sm&q&__H%xKrsK))z|>o%(H4Lp zPP0#KuCbg4o~ULK*`^tx(Ab>ALFHxUt1JLPQM?z3#y%4xnf!7O8u@CP-P z|2k|$&o#W2I)4BqtI(vrJe6WzijQFL;?{t|g`fmR{|(+&6*~@6VH2z+2cKy@Dn10J z?#3G%90^*yCkiD^>g9f~UWA8xU5)FBU}k<>SH?ZvW$SjBNuZ^Il67LIdzT%jaOjY5 z<{Ccd7Jr=H&mJSg^l*2dEV=^l_4{oJH$N$8zUV6aTu0f%AA~ztq&`0t8Vj=yZ0A9UI z%L7p6&&G#i2>NcCGMCv5GSvWwA?A^MHj~1(gaSB*Dzy5@E$6;+G@;gVVBx`u^&k@s zNFN|CyI(OGwnoC06cuI8B7GEM;{ri&p}STKaDT3sV)*#bXGc6qEprsRcWl68H>wt^ z-8l_4i{^-aqQ#(kdQ^V{4KE9qRt8i`iI0gNdj{+H>{&+ZEei~Bs&Bakm!J?Ul6@4> z&>p!>&n7XYjc4~@=ty5kLBraMN*Q03mV&g?9EZ>Bc#+CwF+SXJnnQcOf3}Gh8bGbOffMN zJivC}Q}r{!_mq;QOiqWoG9F!Eu7oI0_|J=oj?_)8az-doVN=iKh`TSU!nc5;5N+OX zv>C}5rp?$fra@wj`|GHUD9Rp5%19DnWT-sIubUcHX&(n0Ifr0pw9c+DWP(R!g6GUF zb*oG$&BpBm@bQ6I=L8og7HgLHv0)G__(+8Vs4n-RXj|k`EKH94;X16o7WzVAVBy?_ z?G2eZqS>S_aVdTTikuWe$F+>7-LSE9f|oHWp1noYcSus-E_({Xl9oQPjW&K9$IwW@ zmbC%8Q^5WM7)Hyszw#AzvG+cy@&o?7#p+R!l<*5??{OPGTMEB-HKpw;4f|CXcAgzA zI1bfN`~vi()r0i2PE-N-ewrqjbjuLtf_&=Ljds*+?hou+g%QXjM`)rl4cCLbd7L4!ZRgc{h3dDQ7lmZgp#89LYFLyetH|*| z7-^0ry#>ZhZfHnL#ld9VJUsM{FyZq3SjV?Zr=i@8-RtKncEB)juPBqn3-m0~df^Oskf}zGD-?_<#Td^3 z9uAyESClMo;u2;{IZg&d_;vaeas|M&auoC==UPu^p4P5Xwzi;a%jq!#?U7VV1yVC0 z$n7*X1z`adpAj2|b{kaNsrvM8q^q6sVRbU#XPd&k`ylAGQUC0Eub5t+8ECDjCg+F5ij*KyOJDP|SI7CFl>CxjVq8zbXi1g}k1{hJdE zJN_oW1}ttOI6MOX#^ch`XRY~JuFDL|CkXJUgr<~nJF+=RNLd^Ww2u4Zi#tH%7?32R zU;1{L^N^!12dIKh^79;Q^y_C4HA}|KOZ%;rnK7-axM~i(HEHw!eGCI;lJk$}RylEr z4uT>(3_^EQvdhBj^m=r8ix>v3ad+w9I!<4Ji{~n4_#+^%2Fw@6G(Ieh1Aec)r@_Tz zA9>NrrD;`kx_Zd&SR$p+XrCgK{#^p@E?SA9HB2jIH{#DyECZ4EXZa)t*Ceh5`aIbF z7$FxHug_gd^aVS$QO*NImqr|&gE$IHdp^ztm=FRNDAVuZfdO)h$>jw=0gyZsBlmmk z<$c46V&LduOhY$qRB4U zHW{dzYB|}$40%0-<&2ng!hU1QK~-T-gv#$YmK#Af9}c)oHsG^IB+Jhm*eS=JxeDzf zqn%c$V`BWwjE53j{MKQtZWvbs8&R5TSo^Tmb32Au2pUy$viaZx==J2AWj_t>SniI| zh%;tk@)k6vHK|s95E>0tB`Tn#q0;=rD}PB=W7M^2(RnD2NHA+&&r= zUj%3ZS@d{%-}_}$a3l%z3B(85D6{DBQZeff*21L5(79!|VPbcGg=Yfa+AMfVXV8c^ z$`&no#z8W4#}C8(S`VC+6amRrEgZ@+_N|80ePm^*sbULIQr5@g23hJ%5ZTq!(ZqB4 zeN0cd=VhEeG$t;X=@j`0Ww`KoUK~2rri$Z-H?9vPbUWx%o#7+opk_RAHoJM8%h*5n zZA{N)59Ac|&&ST7AX@?+`;rqYC$bR@SG~l~c@yZ`6^Qnof6x;R*0|2)U0z z?M7X%{~VHy>l-|zsLD5z38*lu>9(;8yTSOvYS1SH`3|^D*RJII5~bvT#hrD*Y(}cu z8+yZxP=trqZy}`M=Y{djFT}~#lrxbbNyrDmO?eu!7b?REco60YVkz$s+zk^eU?wml zEJ=hVBY83kfrJF7pQKxyJ_cK6uPe$AbRdV>Xum2t@ecxHVa2Fc{ySRU5*wZmNtLMu zV1aET?_RGVLb_n&m3^!I)Adig@1%6?I;VqF~FRDiYBRHquSG_(lb>k-hhHS#f_Mw8Ce z>%3XwUV<`_ehYAsL*=wktg<;ZuQ0d1D#jM|SJTk(k>@7#VVCWL$b>q1QZ7q^HH+c} zUdKL#ux2v)3+wJ0p>v-&EnV}4_Cc!Y!oIe%pSxYv)qNno?7t&uy0|ZqHjqursL$_+ zeHv3hN|I%ZamVbKe|C}@njK#g)InlnG`~$8Em7jgnU8z{nLjqn>VxF2x-{Xl(9l9E zqdE$JDS%ez}?8ot+=)RV$dp@fII`b*JU24j@N8}suibTZFkoDk+TncAE{9U z8Bu{2kkTEp+*lOHa-@0A)_$?GY&Iu#xm!^ltIx8pC(Z){H?USWq%y#E@O&KY8_P_B z`LT;Astpd11SU&4lEQHEMey@^CjyEin{>>rkDhhfvBK4lbPbY?O`qy0C#bP(Q85%0)U`K6;P3L63N=)cID_=Q{~f!Rx74P%Wv zbC4QzbP9ozCN{J;7Q?4xSb15y5@P?d8DY!PkChD*cWOPMlMl&8!Z@bjb+oU}X?4m~oG&lUF>FdqwH*Au1$M{M%rG)rF?S zJXz0kX@M!Ke(LVdFo@rK^^L#jI}VL}Q37#WL>WhBJUy&MqoR+C7k_QK`0G%%D>dWBHJ1(FYU#R0%vtM1w=3DIEi}u(S_J-cQIAwy&MvAr9HBC z$T^Kp(&S7*QGWBxp@E)JUXwzU#Pb{Dz%k!-k2zqA8qXq<_Sm+uZeyPt4v`#RDk){w^859`&-T^e_S zSj(Z9qXwPStb0&{Z%wWOw&RfJF8Iu?{JjekfXSJoAx|&tr*8^viiKvJgN+NZ#AKW* zOJ(L&SRGMlI3NLU_fm%~Q=j$0Yaw-pK$I}-Kf*fp9^}T|)LD%?37X~|LM@??4o_S4 z$3rgPTSOXOW^kK`iqy>A;;HF#=pURe?ESYI1B*_ZZm{zNbHcK!l~e`R(MnVmAduU^ zA+w`0vhk{JiTAe<$01nW86=U*ID{iCD0NZO9g|D7c+b{>5LOnWNkk&!4qaX0%vg*|8oR+KR3s!Wp(9v8_g!0u<5!wjtx;PdrYCszEk zNupQ0o!jq)f=sG2LIB!F&e6{}siZzxrHE@}g7N7^`bDDjHKBsuXK)ceha5D=&S5-z=G1R60IfNY8jDE~{;88n%MOcwQ z`O_oA%HYYT5DD-x@bS1h)XWybv2cH*9}qhn^YwM4 zF&c_6UKyoiXa>cZ-(iWO&cE`#>KYhhx|a`^e9lGqm;-SRF<3+5D7f`_CeA9J^S%NmM^7 z4hjy*EWX}uN&LD3(q9Y~vD^2#K4kRi$Qt%$%%FapqLZ*e7_M2=vWKWYB^%s%ogzhAJVL4x-qyq*;DFBzh8;_DH^sn9! z0qW6Zp4&a>jT)aDDCVkZp4nQM>Bc?!KO7Gju=d2J3g0v)2vmkot82#8P}XH?JY^{I zf*wPSbAkv2(|_pHR#w!T?P|^$wF&^-);_SYUN5sKvRfyjF<|OQEGGj_epRFU z>mcsM=LhuF@$2V~LC}W)Thm~xkLb^v{_R-Ve-&HHuG zD0_8T78R@&tyI0C(h+NhOJqNh{M!@&Y#b=02_I!&IUqj}g{3&|DJaLwolwuQbGr|$ zp{JSf7=PJ(qiS8%dA-DDBNntzh>rjMux)WfQ>BIY%@V$PzC{5<6$jx#@~bp6 zgFe)NWO1X;GR3QCbk(Jnk}a)+L#uU)5SG_!3D|rv|7Zb;5_K0=VUc%`uyysv-Lq-m zBm1+9Iwk%omoo2XRkz9x%dP99*G}9%KyYG$`ShTyJmESO)k=44@N1$*zWLTTq zRk8b9bEytkJW?CjkmX9#u_yiPbwV1l(`(QjXqA7yUhk^s&k$F%l4rsIse34INo<{Y zz>v{`DOFTpxC6VQiIY~$)^o0Zsmgy=|C-TnTIt!*G<>oK0EfUKug3G&?tC$7do%eU z!*u2SLam6x)(C008ac4`wvjm)6dn>U(wCo|#`5YMF1g;=ntS@R!K+*ocelMdhO9}= zv2xtNNZK@mpji?zs^j7OB858uDRsX@$YVqH#=82rf6eEJ9hi_ZC2E4YyMImYC^GKa zzSUDdZ0Q>FAz^Rs``72jO<^7MeA{2JBn|eSKN|6>oKcp0c!iqnenQ!S_!at6*Qxzd z5Py5RJa}&e-CXLb)#Gc`B$%f>=%EGmQYZ%5$2xMBh=}{BmkfmM$Ns@s`Cfe=x1f4)T6)wh;D8$B3BRb$$I9&0Jo@xr^( z+${%0z6=J7|1)zeepQ4gq2cK_E^PsSmVJ>lTVwbg$h1)}q&Jm;xUcb-5#Hg-8HJeh z*p!WfH~hQ-8A4|3hrUxe#xO~bj9$6k!`di+f7sa77V&gqaRI}h zGr;#%ZR=`zUBv(g1GwT!G0tD@T?e|BqZ^I*{=om} zeq+7K^0k;qNc0g?;}SvNpbsZGmWp>crl5nYnCUtUf==G&xs7FQ%)4ihgj~y|RTTpg3#*sEzh%dWi zh;MxCpZuzl+_|BOO487fb|a`Uj*iQeN2j`%!ZMW?XQa|Gq0bpL!W?{q=uI12-^z&kf;A_2|S~OiC_{F2?WMam> znt~~Pa?}l{)DO^?@wZESx|ag@TDo$p#~OrNLiGdtU(x7V;+yAj$&t=r6cDi%mIQw; z)yV~UMKf?Adl0c1DK#3)ix?6OT11(3Yl#{l!c~BX@x0yjaDc zo1PX|@+pe>7;dlDruFz(K${;_P6-K1vP5r;aIPI0(>4GQ_mp_bw9U9E0eX7wWIr)Y>73nfY}hA$lLjX@XiN zQJ`fl>h98SYRnjtJ?eXZM2tu?)O5U^LM}hHkiT^6>dKW1n*!5oZfF7++XaEL*VzT` z`%4Qp3VNrmTX1vUC!joY^t3vs9!Z@>QjJB~JGXKTyUOt0JkV5uL}GU`vwe@1DEC%t zxJGB8H%92zjG+iQI$PpO(SF*QQ0)Q|`D}XO`kLn5b(7H5=?7KSr>>^qdDC^ij$1iegb>qL6kV7d6y+Cw);2Hm#!Tn=h;_sdM zO%3Ggg_CW;<h zvu>j@d659Yd|?fRVbkxDA+~khtTEC57LW~FDn*QV0^d?2K=lvxKp_+$A%7Y0Rx%5f zg&u`-_z>ytx!pedsRv%q=Rgv7t*={t839=*rt-8Qxto(*z$4)&TR3rm83YteI~8XW zj*_2Lg^a`%lJHj5)w_@?dyAS!qo^!4A{U0IuKeqFq|H|^hkSHJP2Cl=pgS$vCZ}Hw zhc)aV&IU}vm47M%!D9c3K_%|Whw*H4?Yy&z8{MHeK_?zo;dI2HM>6!&ZDUob)K`;M z&C8_o1aSc8k{BpdJvB5sS%~%eq%ui?*jwPT0qGutuxR9>bqhOIG4#cuxR4j*#OMn+ z^&|eqdZs*rnkjcRLw2*A{n~07x}1FN4Bz>r;phZJ z#c71zSPV}d4j3lt?H+wF?UPMZIqUXWt&^k_eAwGK-fSB5BfczdsS^ zCpq*>Cv$fF^}d;a7Zv>SADpLH!du^?J6}N&X^@PXlpe`RasEl#87(J~Y=07tq%a-l zg7!cCyZR6VdM3PCxGxc6oZ#DhctlLI)nLFX&t(uAP4USpQfT1e zv^FK`-qg?O{#7vOqY5KZJibD2Q_0!8?!Iww)+rqp7L#*VuVohn!sQbV%{g>l^`}Ug zF*^Hu##kXIGglv3B_SqspE^3NX=%IK}ri!P1c! z@amIW0!WTy%3Q4#+1PR`CJ?sy%Z(`K#y=>3AoZvnZUC4kDI<#FXp`bfjx*@<{Pk!f%Edl9u}g&Z0M2;t+xt-Rk*3V%`_y3W^E=Po+Yt&u4no3i8p|q>DpblDpLW4 zBRVZljPXg&IP|&VutC=P+t0IPj!NdZJq?B1>cnZ6vKpZJspn zL4O(P_U^iCQ>mb<%Ifa8HRryIOmEhn)4cB?zX_O@3puXW!Rb?&9qkgJviGj`Az;0` zgIv~PzbO~-ghRaHg{9GhGuBQ-r0Ax>#a>WicZ|xS4=k?{4 zZR(~xR9ori>wdMvUN5absJ1!?<%U-kLPf3FD-*1x`Nzn8g$T*JDl#p*RWy|PcQ=#- zTLW&2Fex?v{!V+fKZv%#js81LW&i(y Gt^OBPlQ$#) diff --git a/testsuite/test_sync.lz b/testsuite/test_sync.lz index db680c3791f8739a100267383905301d0b0f5d13..2a6218bc7804f7c0e5ad14535c26a93acfb1f77b 100644 GIT binary patch delta 7329 zcmV;S9A4v)JI6T&Oj=1$0q>CpXn(~|yJ(c8peBW%f-elXuLG8+YcW?HC;m#{D%pU^ zWiRDBah9%HoNKDm$X*ivN}frZPJV^dtsX$0%Z^SSxrOZEO@c$q7owY!`W;W~c7VLKKJvfUJ)mGF=tySp{PxY$8`#(o1p?=vxoYM*hkx#@T($B} zrE}wqiNbaiPkS|>8W_N@+GNU=i-?`g4gP^bKc=(O|BTS>tf}Y}sWaDOa9)@f3Z>pC z@4M?MqsMyf$l9a4FCJZ;`)tQ5Wbrs^K<$Gkx9@N*`^#x7IXK%ex=T%-ID=$T@CGUn z*XOjK7%aI^{P$K|lLRk7DSwY<;3s2ge)hV`mKFEf_=bs$Oa| zMsKB4EOEq5bi#35GkG6xskoc^ai7hojVayH{;Ap%0D7qkn{2{=+J9YtzU8rM;x_SA z8&KAYW1k_h6jNt-h{86HEF`a<$-VVCu3pxcF)8&GZMPBYv-yMf+{>=Jz?Pv_a#2CF zp_qxNnqgCTm|4IEz>g~)XQacM{Y1yRp0rfS;ey&SmGU6PN1DKxz1fy~zY?HobYOqc zMfyA0F^|_9b;}1R3V%0WyI53v!P#y+mVW+6`~DBtJ%g}CgV%huoPofSS#k~0)-1G1 z6pg9e$v$?ei%VFSkvBCM(ol`Qj#NT%bkrS8>~O-o87|jL7238#ja}K2cP!9oEb`4w z#xyGr${tR&=JU|+!?kOF!J6T$CDdJI=|K&qAhmRB}3|`?uO1mRHW>Z7R zQRm434$dZvrmWjFv}gIOgUQbOpzq>y-KJbRR?H@nk#57pYae+VpD{y?DTb$_8G ztX26OM*PHr-vSJ&PF#L`&N2GdO4I5ccDj z%*sg@Ykzh5u}lXwTSTW%cVaD{4pnda!^Wab!$83FuH!If>se|-CZsXSjQWokCCzc4 zFeblB1S2bK0Zmuw*@YNE5m_2?(29CdM_Lcoe%7s^wpU*wFgXx>P8lX$>>Tl}ey^N>HOhW40Gy9~fV$j(A)~rq+3T=am zsjsAF7Du$t4Q?7<0Q9{oIV+Pw$Ugm|6Yi%5+FnEtJ9~AAv_9I+@7OodrV=4hjNqNe z2!Cb~w?bgV?9fRhB)(5`11n||?A<~JfOrn9=-$~WseS7KhEBx^@&;wspROAq?w>*l zW@f;o8jFLwU}<9}64~9g(2p(Jo<*^`YIXc z_oT4HZ4Z|IlK^tdJCeo>CI7bvf+ZmHynmhS3D21!hCmdL3GyTHV@xZHWL-EcQW9IT zRspQB3vTg;ugE;m!LZrQj0373lJBIu6GdRRk{kKcmMJ;Yi_UKT*{GsNmnAx zwFewgOYOS$kr~5b{aw|GMAVB~?JYQz5)~!wF{(=1{CuB79NnjY#sH?NcF;Q>QE{^W6csXXS}s&X9M|4*3z=-?u^bfxVz5UZ3(@xJ-xTkd zhQYc@z!xsZjF``$q;^R=pO-|7{$~~7Uyw^(s~!x8EgYVV5sx!Lg=>G~ip%ftOc^jy z-K3KG62QDXe<#r_hf?aY**ndtM}JBn<{u?xJtkVGJ}-7`D)`ODny|{A>`LVwd$n4^ z4L_9( z+)czfDW(9$U(y#v^gGRj;D4u6kkYU{SkAfJ0E)sx$5+OISMEB0rFUrlNFeP_s9=PV z#7-{pw${ufl@rWvRsXKaUtzPU4x{25Ym%6Jq1Fd|;~zgMzh@2#A+J56K%(Ve>H^YnNq-?mrMsg9l|?$p z@O}A-K~+*hz9ic&z$nYEb;#31K+=4LBD9DCRacGO+cAdL=dF9^JGkG$t3u4L70?AS zd*~Q^%IT7?E$eeem+mSiUN4nofp*Bm7H(TVLLvx*buftO z%90*Lkw9(8>f%F)-@tp5mx!gt*u)g3S2b<0j<>53rIYkWY}yxwZ7kD~DxE6TS%2DtD2u=&j9A`xDTeg% zyU-g@CFY3|AHwD?yRH?_DCp$7zu<_?7y_c6PM0gVR{bnJG9pOw9BfW6%i0s#Y@(wy zajBS5T~Qv&>wU}hoF9%=ncs=h-}hvF)xF+J)^>b6 zsPCZv687X{0e>4ZyFy+lPY!KgZ<>gT8jD4j_rOS~qqOrj){KFEkhKB(sn{|&Q%@W$ z3XXcUxa{`tyZopshf&Z`*HnS4lj;lZmD4lH&w9=O%nKTJ94rujTn?qd-9B%@$Ev*Z z&}_*r&m}79D9Le#Fz!D|<`wgo_dvA6Yt%y-vs65NB7Yky@LsJLp@#ftKxt2UOFJ{T znbT+TpJ6;+5DJC5bsuD95bxsGxh|gup^erNBQ9?k0K-h-G(HzaW{U%`dbxUJuvcim z_sIT{!y({-E2}&UE%+LPW*;n5_QAdp5^9C z?|gd?n}2#+Ij~g%4Vb@_!42VMf`RsgJG-zYrR>zqf$jES13SX>xGJ)LxG+x9S&R8V zqKxE4m}YdjJXCR8E9mADQBPZ1|xR-yfS+gI#s zT<%J`72dIaB7l25^ID|BM9de%aJaAvYx0wSs(<4fGc6jWJxa#3D+?Dj;uGUy_^?Ow zC?SXZ7x1T;X0B2rN-VaE^7v1>jIxR8oUT_@57byDGWr?+PT}rVn>d^NIwCo#T<@Cv(}g$N}`wa z8h=Yp8cVYe`3^jWI;PgCHu~3uc z<0M3FqB4;nlzj!`oAQAynln1!z;l2>sDK~Zve$m5r#eJ;W>svYrElhpxAxCh{(mw< z|Cie2-AKA`@?g;4=@7SLOeg-A?xx=-fKd&pv_+oQ9)PoSp4|sfvLLX*062Bws2yWu zr&SxuAp5@o&yO<(3wi9)&pRG{A~4u41{ay4Mh zA6^x@O1sE|u`X+`>ZS8gX7Nm$s0E5=D zT){YhztjTkWKMxiMAayBF@NL9qoMqXwC|~j1VT}u=N$Hg80Jp%~Q6{} zyqR0U-L>|f#Tq zR8Mt-jlYpeoiPS_GKa_WCurqibvUx;J~&+XiFwaRRIJMol^>srTyhHdjY><}7ZVqH z82MNT>8Fe3tBrYTtA83T>(LCgek7p0>WO;nrNyz3>q8zJBqYgh$!`^6`5_sRZ2{G8o`>%&(kCeb0UO#W|w>1Te#~=iv@Lb zzG#7+J5~$Q09he3Z~!Q_^iTTL1{4oj4x4}KnbM#NkgxjU5r5OxroABjVfajk1MLxm z&scbMBZjs=0?5t-38S@L5*=bHMRwG)EQH`oxDGS_A2N{5LY)ZtWK<~ewb3r#nX%jR z80MbbRPpzTV##KHmllydl}1E%*J-*ecNNqBnlEXql zH-M~EhRHM7z&>jRa_;N1kz$4m<(9X>8s-?6NaLlGWO$x%87WN=>52BP>re;?S=TRMhiT|}e-Y&h zx$e|xEPo45c3y-Q#-saOxfriBRvdO3k(!K9ez}Z9;R3rXw2JI!)eaw1+0T%JGZAD5 z5oj6l?&wmII_{wo>DSanr9v}%x<)q zaeF{T9igHCAb9Yl2x!-lK4jh=_g)I%*{I3AA4ODt|%SKNbAYAB8Q|NA1W7 zR%<+JxCL92K+|y*53roknp%>2rTnsBlobT7(i7-)992|&kPr_gd-D$UoRR@Ex5+-- zV}H}|<~hi;uX{Y?pBd_di* z@6Cw5&P||;DaAD8DlmOEWuAz_*Cf8>W{9M9JMy=mJX{idvUcLGbx_I31>KKgjB1&H zaKt#H!~YaPWm4F-4~%%Vj4uhEWguVPrhn9bIw*R5kxO(}O>i#wthYMs-jAnfF;ryr z{spm(b4!x{-V$5U@=OyzCMg#OTyds}9kciJW@M2LScy~X7?Z9Q(;cj=8K0oH%VyI_ z-P+7YNm`e=oq-1&lc&(Ad*zJ+$b?^R?xbHe5D6mu#_X28dzxu5oJ3dyvMr|<%YU5f zqM`!Xy2sK**4>W|Mt`<c%|1C83A z=eq4;T$#jh+fr3;M5*#R%pHITfqzz46nRhdb_#_V4bA6S((Z`XM`wzc*0Dd!OS{?{ z0AH&3ww$d6E;38sEEjPHi$C7NfWR)#4;8&;<#_goE9W+RdriK$nBnHp<6uqMl+30I z@)-$6gK9W~kk6&zc-76tuGT-}6_JCgDf_O>Ta+s!zdaZOZp}~6Ihw_)1U{)}Z-}1H z>-_JF7CGe0s|vHyh=R~z!)>ON8EZn=jPW`vv1_J^;mC9k6GVWwlD1@@DD~WSj1RxD zVDiR&+cg>){e<2_$OghXXn#{^_VGFl^9y%-jpmBLAFF*<)xXhNJ}cIH7&{b?a;=15}%44 zoCcZ;WS8;Cdt6&JQG)~gcPEIhZW?yWu#4%2OXMr^jrfUJNN4wCe8No;0y3eEZ2Zbl zSMHkY5IC5konlK}PGV zob(9ZFF&2|ZjJ$@g$a`(O>HA&*J(bg;Q*!j&Oe!kiX`J;!}45*DdMi^Jv)k_6SDiM z%%}zU8%_&?k@b7og4~X$3A{mqZpHX|&;$(rOh6XUm6gK|o#)!ynMT2=oi($yvFjQv zwX>)g{i}=8>wm=^h>P3Zs}QRxwnTp|txqi4doFq_Lo-Nn10ys3niD-~j#(^!ybok9 z5@g95w)+((!TI=3EzpK##3oe>nGOZ?Zh6UyDIh3X|8uEOI+r1Q1D~Hpe~8n025}&k zerjtHv!FcqTSXPul=NWjXIzUx3ksE$LZ_vu@w&xKB^o=42v;S+Hdrf zBF$TSg&_F%$H`5Cc{_H@v{=@)<-aT#x5e{cuwH}VY9RD@=mS048knDSKQF^9hqC0) z65PN=AAhKYT)WRrlb(@^|AxEB$I*SKSbuWTnbKehi$%H#uu#0j&;%+v$NUfGJN(BaOBR?yM$y2w zKP~rMjndF|E++eG9>yESVLREg6j*qxl7U!$|5i{BTI_JYJkq+h1<(M&AqI1!x9E;E zz<-$^l#{CO#q3tlCYWj>?-d!(4-Axhi7`*bbMs{8$C>U9sYnH)_4KmR{@_|F34G9djcQb{0+8gd(oAIyEwl;T+dU-kWJlutAAf$` z#fl5_PmtYiWvQ(dfTE6%yg2WAWpy%I7Egew(ds!!x`hce+-!ylWiM4tVVr(KNdb5v zXGdGz|4fbS=&LX*y%Oti19s#T%YkS0D4x_K=35j?gi_)~X0xuFm*#VmNar0bi}&=C zPv>f-&J%6Z)=G;hw|7|yWl6TPX@A@x>k`U2zsE8R%{av+Wwog^P99K<2S12)kp~x) z#aeYDB^?A*_E1~3JeUs0WYNU`FaU{aIQei3kEC)i@m1-{65l6mX3SZSb_`(E>GR}})OjJit%+WsvoTYrf!->LA} z4xQP%^YSpe@pZ3iGvdCU`Ucd7>W4Ny%CEvw!kivub+>#?NuD^2m&nauO34Ll(YmwV zP>-4E1i|*SrRDDk$n7BdyHMt)4~l}LBnaU|cqOzKp(PS5N(BAxYd4bM!XWD`$)`q@ z*6|msfIA$KmN^0N(nE-ut$##6BiEnoY1qW)f&akL01B(I0C*o5_hfoHt3 zV!4D1OQIB}a$;E(H)v$6rXGS+p?_B2rce+Tm6Cr3M7rN}x9>j;$o^XA;-^g-dMtraeta$tmt?Sk%S@e zSN?{vm}$^WMbL(DU0>qTT{N9MRUqFL@cyXOY`&LiMfMk6vadg!$ms_&3V$4Qmyxh~ zT)AY)A5rz#Lt?A{|Igh5oB-Nsld%8)fe-7g0RN*M0Kj$?j0cRH{`zSlJjPX+Dy!#$ z{=?0h%H7&Y&D6~raevw4HmWQ->5=70aGpB+-ct5>-((xGI{JW(hG50IH>>ZLeetS} z3e?mim!B7?=$8J#jQng(2d{2b4(RIcwRl#@yRR?$i}~{NHp*zZqlf*S=5^H2-?7jV z%-ar96CUvr9;=^sEy>k9?P0q|3cJn$G1@wmhTs432p_8#qY}1$&5Zy600000#~c6v H00000T2*2% delta 7531 zcmV-x9hBn7IgmRBOj=1$0q~IqXn(>$XZC#)1}Y83pyXuL6paL$h?$VlmBDAqwACzkl*GbRXYbCDkn*DqdPj>CLcELtk7jDTzJ zL|THsWyP6yDCHxOx)a#lNg6!etAXU4%K-ud64r6?KMZMBBCmINL!>)ToPT$xJr212 zXi67=4{*Z2Whr#JKXJu1DSd>c`kzDCkl4$a9JiV@Zuv5YzgU$__z+ShaUGQ>Humev zjwu0k!m8eOFU-@jehf^Jn1!y6Wtnc63rjrulkOfXLc^^ZjN*N;A_4z ziSJDpg4-R3oATyYt<(A=9a+Y=ki&{&8GtWS*BVaB{Hma`tcU{uKY7cR@HxBX>sWPp z@zbK>Lmgs0g*p54RI74cK08y(gM+%T*Wo^+wn|eqAm(7=me;ZU`+xkv@>|H}hW>c( zeb$6Z9)fmmh`Rb%^8W4kYGT1RA}=L_STIvMF+=?hatiL;crO01#z!TI5d8gjmW7S= zr-E=Q9P4g)OI0Bo#jywaJ=0&{L+PzBj0h_H)Fm1@+>bdKLA5|#_;Z^2)M-rrw{0td zG`xPkKOZ#ykDmME>wnfA%>+W-(6`iP`fA9YvN;bEvokf_W@8GxMZj%^G2a#&85Icf>2N#*+t%UrsM4PrAw4HQS4E*AAfCL7}5=coV=@7HxOty zyQ};`LRm7NVTH`+%loU2Lv|avCt8?lpjHkyhJ8pA<3p$%a+diNTs6nNAo69BBa@2N zkolF+4)ljUVWbW*mN$NXlW0vmHgvw#4sg>xSY*`b@;PucveqcH^rs#ANR@chvEY~Z z^g}8Z!b;%6-G7ZO%ousF_+P?oboQ(Xe!P$QPY#+s`cH|rRYcuVlD2r%h9%-e?N#Fb zzzwt0r$BUGE!g3b7EC@JQqOj188u=ZE!qWq?4ax`sowbkTIK1OO=!Jnyx!jiI)=mj{Vv&(RxZt!MPp9hV;Rb@FM02Y;tL0fGKLqWQ^NY)*;KdS3yB zp31RXyJ+p$=RSdq+NcJQvIFQ093McTYDdmaKp-V1Y8!(&Q^t8t47C2G8sb7U6B@r+ z<2SL?-A|;JBNZtxEnNWU^<6m)IBZ5Y>Zj@C9<&2XBF*oOne?#vyeh7{M{Fz$rZ7cW zR1+P!ZGWS(zcw>MAB9z5DUj8F=ufCQJiE89^XZaYqB_!J>tO`z*2(#5m>dOTZtW5z zF|8y%5F1+}oSBBlZy21%&~Y0(L&iBjLWmGHnJ0Fc+kR(FS+3jd7?oFBbuAcJ^4I!b zKD|-zQXNFt z-RFlxl_jDh29BBInQ7yQx|~2w#n`3(9#eMPx0@OjiGk%`8Wpf?tJwbrIcy{#4_=N z7Jqk7bgL+2ymaQ0<0<^fQgP;YP3PB>Obks2;yjSA{mr}{^j&QZsE+3)QJ zOvDx=fACLw5GI`wG{@m}lYGlp>IG0h+}B@bH#V^UHQS$Mwz7q2pCJ`TsFvtRcoVJ90Dhw}b(rq`Dm>3_;1 zLr|uFB?F7!DSuF_d#NU(DOtt<6)19pqInkxBDo)M40N7gZppsp@on}cmXwGKUK{lF z|2d=4Qj{{6nBI%UJlh7DvY5^@WVkVXNl0cSENzZZn&qs;c$?X>-i{YEA~zy$jL-Cz zuj|Db9~b3H_`idJ4`)hwTZCu7DS!X2U%8pJ0VZm`In(W?F5GO|UU@4Y97s9kN%+#x z>26}xCyD>@L6unmp7{-o|IMDH%m8wCi@;~C9rCmd_A+dr{o-L5s$yk41(N<|*&*ih zDu-DvyfV2;!&y_0?_GcHnb*)Ko07Brsd#rDkA+Io>Kes$?CUMM4)t;qc?m!*$k%cu4<9UsnFc-yM#D;^*L=_kE9{LPuc3fJgA6xw|CF zXW|US$$wjr9Iuz&e_*Au?lL6LY74|V@|pG+O6m6k2JAog{I7w;#s{2K8gkpS5W)z@ zt{w#t1lWRRctKaQUKEn(UVrhoN6Ppy;h#C91!bK)IL*jG=$W{lY!~3uE0{**(K!ev z+!iheUQEW$WuvrX0!*9&`?Xj()&n;UAB zh+aBeBum*Ir{jy*WsXaxi(T#bZbZX-#x-a!f1y75Hz)u(?wepMC0J)L@_`N;cx83nav0kY|C0yHmrJQK37%{NhgaXK zSF>BT69cn<55x>=-kugs(X4(?4+t3OiS5Nwdw+_JE;F_P!qHRvzjYDk@cy5rDv;e!Ne)9bn;6 zq-w1(SG^N2M@t5*00iVkV<*5vx7gBv;M* z|Arx8&wju^vSO>PauK*3!EVtFxD|Q^4I(UaL~5yUlYP%2v(E@2mhfIh%7&!2fD4j< zI_#UwntwJ2kljoy=Hi8emL2>vOr)4CQ3e}kz#SYylZ}Z1QCs}~u-gJfV`bH`l=-A- zV=22tqj3sSos0ll;y!?cKR>PWFXgbTxIme=h z#D8w&Wraj2GFAgMwzW#>DoT9x!m|+8jGb>Ze$iu!@n7mq6zpQwhdATV8{9$4QBeLtI{1B)qH4?^{^opF&j7Bd)&u|1<4b(EeNkecK_-aC7$HJG7 z#F5}76wZd~_-ep7G-OWFl{#z=Xi?VJuQY553Y!fY+3;n-lz$QiaSyqPov@iy>xRU9<^`*!@S{<(F~w^01HPd$y?@F6B|=r7 z0=t^p2k@;26%=^>Ct4_KL~jre7yu#Dy`gQ^6G^}=R%b@fbOE#xeC4m> zy#kLx*bnR(k#%RxIftKb27eeVX=f@yxyOSvK7$@3!&DSsJa?HDjyQem#wnVU@>Jp{ zE%<;G;m9FTaPv~E@W;+mdt7RwsjTw#sm}kAYJEVEIkxx8Re!*Io6vG--Q}F2FWK8t zU6&N9xaPU2UIO^65kzswr-eht7sSg#wTq9wX@yv=OA>EK4l#H5aepl4Xs8XwOT&77 zJXVS*_}&N4fWz7wiVYT*tUxw&| z7COIycA!^(HbpF3GfpM2^x~OWLbPO};v4BcBmc%?~>_m2jYEj7uJs*!YZ z1|T+YzU)m0oI14K+J7nQC^<(ykDE3NXoHiXFmh@)IVofXIN;3&@4p@>(xe1>9WuN| zG1+)j-gzfE;nRj)}#s??O3i~$7AAde5@cA(6!+X-&uu&-MgXsfD z<|lEqQvG~c6~8#W_(zereJQqSUZQ}E!}GXMxw5k^zPK$WXwDPiS|+_!`3yVMZ6Pzp(B`w-V;fT z&xOH_Z5Gq0Wc+Fx^4Hmii(S;59kRY(=ZwL|?SIcXMtSY=)#3G0lvJcRgE?N|B+nd{ z>s7D*9oF6oSOGrB5|sl5Ip>tAo{&mO^D*K>(=23%!JXz0!;(Pn+5zU(0$xVP+{f!g z%H@kdBWEoIpt<^LH(JTa;OG)p=;93hE=2e{^Nct`d@B6y`${6y%9SdxqBUq`C?KCU zWPg}Yvk2>s9TPD#2|9)OfRoUmE)c%e4=lzj+7=}UFa?Zdj8vZ@BN3t9o0Nl&ZC=PX zh1?-YCU%WMIzTbXAKNPjdGxs>4`uVxNbD*SiNoVXb_}kAF1s&oDkWN0(2v~E*TTHs z21GFDkSjJ8(|=E0!yG9>6i$U4Y4aSwnSVY8Me4%n<&&4-DyLeDaga>NxURY;^>8y+4 z7PYfuV__?F`9JtbRpEkPX$bO`v9E zww->S4+J$>^RiU*(+R3h&J#Ewuty@=KH9&h@zptcA75nGc|C35_bM;I94sxHc(=nQ ztH7@ORTujMtM+J-*jx~>{i{Z{m&~~c*Zos3omeNHNsdLuJ6FdVr3BrjdiGN?VZ_Eo;ZgfECcH=MB-KZsV>kJPQ@&E540rK={pO!aQ z0Lu=$!w=VGaHf_R+;*@Qorql=#<#C7nd6~mAbaFRU`0$RWHqiRqW^}Bj*o76B6lc42P8sba^ zK9*UsC3Tb<1E9-m=cY_XmqI@rj7yBOohN~Y(n2JY&eJ>@stnnf$eD2JRnxQq6LQbS zX%J%2$vNp4oO|$aUw;7|&EApx1N&OMD#+300h`(JCT2Z>3>-HL)nj(JG<-mgpnmb)aT-Rb(- z*1rp%>pFvE1U}S#_LpR@?Lb;$#%pdV*HY0o#3y#=OoJP_?3}jsyFQ3C1pum*an-rj zn|HVPa4YAZxqna2FTkhhhKkutw{RE?Xnrled}}z;WgGVUF`H92U#dcc+e`smJlb~be5 z#u?o#8GnrE>O_2cUxq8;$)%?esEb!P5k&R97oHe#nQc*%%7qoTCns`5bmBR7AQu&m zLKWc!34gAXpMkmrle1c%_NPe_p$ncl3=WePe>N2Co!&xW>zBXK=k)Tyw`Pq zsDEjN`@QU*Ej8zgB52ZZ;q0o5BBSE{j9esa(u;bXzF}WafGi>#p>SbsbD06QyY!y=F!%}koG5jR*`*6Q)}yJh0B ziR*uWA^dbRWT@84`>C}~oaKy{FG+Q7C;O0c$OF-J#nvkSx)3H!HX4Jgiqg9WX`#D&tej$!K_yX3i z9AJ=_h?x5JG|}UM{UYY=Qus{M#^K*d_y8FbnyodOE4>l-pNgZ&DdOq(jt&=ZaVHRX0D!`w4*s#o`?3K3 z*wr`Rj;6aFe_RxEyvUPJA3bGFsQ7z!0Z>EO72)k^#Y4~f^YKX*cbqZiGgP86z$qy0 zM|ndbm0}oUyQrM=0Ug@8Q8eULC^?>$8TI9(N11*YqMZ!>nfCTv+H#1V<$p~wN;=?C z1CPUl{l|2cNu53#O@o&bdj5*P%Fx`uYN*iauJ>i_K=f0sb$wY6TVDbJe(x#l7 z9p$~Rlyf4EX74|D%?~UDy!Rjrlq@$;fHe*1mks{qMk?Me#y;f!NaRtxjQ#)SD_Gb7 zmjMH){+JRK`~dyrRs#02pMPW4lj46q434}@Z!}wpP!9$Tw7A!T*nQr@7J;4`|1*C#ZBS>%OZBwdrd`$QE*{LU^_%fPQi7Yl zwznL=~FdLIrJ$>Q5e$YGy&qi&hCBTT_D6raT*T8eE-LYF7uP9 zooO9J7f7TMOXw)+W`E-1`w)x$U`e5mXc`Kl3IzK65BC zMb0>qhuKliNpFk;qkOkFAvGvfeEEKO5Otg@P^_g2MW8HSpUvS&&p?K3PQ3^( zhd^(Q!W+jvs$4FY-y~Ns%efU8i@Ac_N Date: Thu, 20 Feb 2025 21:34:51 +0100 Subject: [PATCH 09/10] Adding upstream version 1.15~rc1. Signed-off-by: Daniel Baumann --- ChangeLog | 37 +++--- Makefile.in | 11 +- NEWS | 4 +- README | 32 +---- bbexample.c | 22 ++-- carg_parser.c | 42 +++---- carg_parser.h | 34 +++--- cbuffer.c | 28 ++--- configure | 2 +- decoder.c | 6 +- decoder.h | 96 ++++++++------- doc/lzlib.info | 291 ++++++++++++++++++++------------------------- doc/lzlib.texi | 225 ++++++++++++++++------------------- doc/minilzip.1 | 31 ++--- encoder.c | 30 ++--- encoder.h | 80 ++++++------- encoder_base.c | 16 +-- encoder_base.h | 112 ++++++++--------- fast_encoder.c | 4 +- fast_encoder.h | 16 +-- ffexample.c | 22 ++-- lzcheck.c | 24 ++-- lzip.h | 6 +- lzlib.c | 110 +++++++++-------- lzlib.h | 85 ++++++------- minilzip.c | 109 ++++++++--------- testsuite/check.sh | 40 +++++-- 27 files changed, 724 insertions(+), 791 deletions(-) diff --git a/ChangeLog b/ChangeLog index 33f023c..3125f0e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,18 @@ +2024-11-19 Antonio Diaz Diaz + + * Version 1.15-rc1 released. + * lzlib.h: Declare LZ_Errno, LZ_Encoder, and LZ_Decoder as typedef. + * configure, Makefile.in: Use '--soname' conditionally. + * check.sh: Use 'cp' instead of 'cat'. + 2024-10-16 Antonio Diaz Diaz * Version 1.15-pre2 released. * decoder.h (Rd_try_reload): Reject a nonzero first LZMA byte. * minilzip.c (do_decompress): Reject empty member in multimember. + (Pp_free): New function. * configure, Makefile.in: Don't use '--soname'; create 'liblz.so.1'. + (Reported by Michael Sullivan). 2024-04-19 Antonio Diaz Diaz @@ -49,8 +58,8 @@ * encoder_base.c (LZeb_try_sync_flush): Compensate for the increase in 'rd_min_available_bytes'. * main.c (do_decompress): Fix false report about library stall. - * main.c: New option '--check-lib'. - * main.c (main): Report an error if a file name is empty. + New option '--check-lib'. + (main): Report an error if a file name is empty. Make '-o' behave like '-c', but writing to file instead of stdout. Make '-c' and '-o' check whether the output is a terminal only once. Do not open output if input is a terminal. @@ -99,11 +108,11 @@ (Older versions can adjust dictionary size only once). * lzlib.c (LZ_decompress_read): Detect corrupt header with HD=3. * main.c: New option '--loose-trailing'. - * main.c (main): Option '-S, --volume-size' now keeps input files. - * main.c: Replace 'bits/byte' with inverse compression ratio. - * main.c: Show final diagnostic when testing multiple files. - * main.c: Do not add a second .lz extension to the arg of -o. - * main.c: Show dictionary size at verbosity level 4 (-vvvv). + (main): Make option '-S, --volume-size' keep input files. + Replace 'bits/byte' with inverse compression ratio in output. + (main): Show final diagnostic when testing multiple files. + (set_c_outname): Do not add a second '.lz' to the arg of '-o'. + (do_decompress): Show dictionary size at verbosity level 4 (-vvvv). * lzlib.texi: New chapter 'Invoking minilzip'. 2017-04-11 Antonio Diaz Diaz @@ -122,12 +131,11 @@ * lzlib.c (LZ_decompress_sync_to_member): Add skipped size to in_size. * decoder.c (LZd_verify_trailer): Remove test of final code. * main.c: New option '-a, --trailing-error'. - * main.c (main): Delete '--output' file if infd is a terminal. - * main.c (main): Don't use stdin more than once. + (main): Delete '--output' file if infd is a terminal. + (main): Don't use stdin more than once. * configure: Avoid warning on some shells when testing for gcc. * Makefile.in: Detect the existence of install-info. - * check.sh: A POSIX shell is required to run the tests. - * check.sh: Don't check error messages. + * check.sh: Require a POSIX shell. Don't check error messages. 2015-07-08 Antonio Diaz Diaz @@ -166,8 +174,8 @@ * lzlib.c (LZ_decompress_read): Tell LZ_header_error from LZ_unexpected_eof the same way as lzip does. * Makefile.in: New targets 'install-as-lzip' and 'install-bin'. - * main.c: Use 'setmode' instead of '_setmode' on Windows and OS/2. * main.c: Define 'strtoull' to 'strtoul' on Windows. + (main): Use 'setmode' instead of '_setmode' on Windows and OS/2. 2012-02-29 Antonio Diaz Diaz @@ -195,9 +203,8 @@ * All declarations not belonging to the API have been encapsulated in the namespace 'Lzlib'. * testsuite: Rename 'test1' to 'test.txt'. New tests. - * Match length limits set by options -1 to -9 of minilzip have - been changed to match those of lzip 1.11. - * main.cc: Set stdin/stdout in binary mode on OS2. + * main.cc (main): Set match length limits to same values as lzip 1.11. + (main): Set stdin/stdout in binary mode on OS2. * bbexample.cc: New file containing example functions for buffer-to-buffer compression/decompression. diff --git a/Makefile.in b/Makefile.in index 6d9035c..4f99874 100644 --- a/Makefile.in +++ b/Makefile.in @@ -2,8 +2,9 @@ DISTNAME = $(pkgname)-$(pkgversion) INSTALL = install INSTALL_PROGRAM = $(INSTALL) -m 755 -INSTALL_DATA = $(INSTALL) -m 644 INSTALL_DIR = $(INSTALL) -d -m 755 +INSTALL_DATA = $(INSTALL) -m 644 +INSTALL_SO = $(INSTALL) -m 644 LDCONFIG = /sbin/ldconfig SHELL = /bin/sh CAN_RUN_INSTALLINFO = $(SHELL) -c "install-info --version" > /dev/null 2>&1 @@ -28,6 +29,7 @@ lib$(libname).a : lzlib.o $(AR) $(ARFLAGS) $@ $< lib$(libname).so.$(soversion) : lzlib_sh.o + $(CC) $(CFLAGS) $(LDFLAGS) -fpic -fPIC -shared -Wl,--soname=$@ -o $@ $< || \ $(CC) $(CFLAGS) $(LDFLAGS) -fpic -fPIC -shared -o $@ $< bin : $(progname_static) $(progname_shared) @@ -119,14 +121,15 @@ install-lib : lib fi ; \ rm -f "$(DESTDIR)$(libdir)/lib$(libname).so" ; \ rm -f "$(DESTDIR)$(libdir)/lib$(libname).so.$(soversion)" ; \ - $(INSTALL_PROGRAM) ./lib$(libname).so.$(soversion) "$(DESTDIR)$(libdir)/lib$(libname).so.$(soversion)" ; \ - cd "$(DESTDIR)$(libdir)" && ln -s lib$(libname).so.$(soversion) lib$(libname).so ; \ + $(INSTALL_SO) ./lib$(libname).so.$(soversion) "$(DESTDIR)$(libdir)/lib$(libname).so.$(pkgversion)" ; \ + cd "$(DESTDIR)$(libdir)" && ln -s lib$(libname).so.$(pkgversion) lib$(libname).so ; \ + cd "$(DESTDIR)$(libdir)" && ln -s lib$(libname).so.$(pkgversion) lib$(libname).so.$(soversion) ; \ if [ "${disable_ldconfig}" != yes ] && [ $${run_ldconfig} = yes ] && \ [ -x "$(LDCONFIG)" ] ; then "$(LDCONFIG)" -n "$(DESTDIR)$(libdir)" || true ; fi ; \ fi install-lib-strip : lib - $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-lib + $(MAKE) INSTALL_SO='$(INSTALL_SO) -s' install-lib install-info : if [ ! -d "$(DESTDIR)$(infodir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(infodir)" ; fi diff --git a/NEWS b/NEWS index d7da1c1..4651f38 100644 --- a/NEWS +++ b/NEWS @@ -15,5 +15,5 @@ minilzip is no longer built by default. The use of the target 'bin' has been documented in INSTALL. -To improve portability, the linker option '--soname' is no longer used. -Instead the shared library is written to 'liblz.so.1'. +To improve portability, the linker option '--soname' is now used conditionally. +(Reported by Michael Sullivan). diff --git a/README b/README index ec3a5a0..4f94c31 100644 --- a/README +++ b/README @@ -5,30 +5,6 @@ decompression functions, including integrity checking of the decompressed data. The compressed data format used by the library is the lzip format. Lzlib is written in C and is distributed under a 2-clause BSD license. -The lzip file format is designed for data sharing and long-term archiving, -taking into account both data integrity and decoder availability: - - * The lzip format provides very safe integrity checking and some data - recovery means. The program lziprecover can repair bit flip errors - (one of the most common forms of data corruption) in lzip files, and - provides data recovery capabilities, including error-checked merging - of damaged copies of a file. - - * The lzip format is as simple as possible (but not simpler). The lzip - manual provides the source code of a simple decompressor along with a - detailed explanation of how it works, so that with the only help of the - lzip manual it would be possible for a digital archaeologist to extract - the data from a lzip file long after quantum computers eventually - render LZMA obsolete. - - * Additionally the lzip reference implementation is copylefted, which - guarantees that it will remain free forever. - -A nice feature of the lzip format is that a corrupt byte is easier to repair -the nearer it is from the beginning of the file. Therefore, with the help of -lziprecover, losing an entire archive just because of a corrupt byte near -the beginning is a thing of the past. - The functions and variables forming the interface of the compression library are declared in the file 'lzlib.h'. Usage examples of the library are given in the files 'bbexample.c', 'ffexample.c', and 'minilzip.c' from the source @@ -74,10 +50,10 @@ In spite of its name (Lempel-Ziv-Markov chain-Algorithm), LZMA is not a concrete algorithm; it is more like "any algorithm using the LZMA coding scheme". For example, the option '-0' of lzip uses the scheme in almost the simplest way possible; issuing the longest match it can find, or a literal -byte if it can't find a match. Inversely, a much more elaborated way of -finding coding sequences of minimum size than the one currently used by lzip -could be developed, and the resulting sequence could also be coded using the -LZMA coding scheme. +byte if it can't find a match. Inversely, a more elaborate way of finding +coding sequences of minimum size than the one currently used by lzip could +be developed, and the resulting sequence could also be coded using the LZMA +coding scheme. Lzlib currently implements two variants of the LZMA algorithm: fast (used by option '-0' of minilzip) and normal (used by all other compression levels). diff --git a/bbexample.c b/bbexample.c index 50ccf33..d7c324b 100644 --- a/bbexample.c +++ b/bbexample.c @@ -53,7 +53,7 @@ uint8_t * read_file( const char * const name, long * const file_sizep ) fprintf( stderr, "bbexample: %s: Input file is too large.\n", name ); free( buffer ); fclose( f ); return 0; } - buffer_size = ( buffer_size <= LONG_MAX / 2 ) ? 2 * buffer_size : LONG_MAX; + buffer_size = (buffer_size <= LONG_MAX / 2) ? 2 * buffer_size : LONG_MAX; tmp = (uint8_t *)realloc( buffer, buffer_size ); if( !tmp ) { fputs( "bbexample: read_file: Not enough memory.\n", stderr ); @@ -81,14 +81,14 @@ uint8_t * read_file( const char * const name, long * const file_sizep ) uint8_t * bbcompressl( const uint8_t * const inbuf, const long insize, const int level, long * const outlenp ) { - struct Lzma_options + typedef struct Lzma_options { int dictionary_size; /* 4 KiB .. 512 MiB */ int match_len_limit; /* 5 .. 273 */ - }; + } Lzma_options; /* Mapping from gzip/bzip2 style 0..9 compression levels to the corresponding LZMA compression parameters. */ - const struct Lzma_options option_mapping[] = + const Lzma_options option_mapping[] = { { 65535, 16 }, /* -0 (65535,16 chooses fast encoder) */ { 1 << 20, 5 }, /* -1 */ @@ -100,10 +100,10 @@ uint8_t * bbcompressl( const uint8_t * const inbuf, const long insize, { 1 << 24, 68 }, /* -7 */ { 3 << 23, 132 }, /* -8 */ { 1 << 25, 273 } }; /* -9 */ - struct Lzma_options encoder_options; - struct LZ_Encoder * encoder; + Lzma_options encoder_options; + LZ_Encoder * encoder; uint8_t * outbuf; - const long delta_size = ( insize / 4 ) + 64; /* insize may be zero */ + const long delta_size = insize / 4 + 64; /* insize may be zero */ long outsize = delta_size; /* initial outsize */ long inpos = 0; long outpos = 0; @@ -160,7 +160,7 @@ uint8_t * bbcompressl( const uint8_t * const inbuf, const long insize, uint8_t * bbdecompressl( const uint8_t * const inbuf, const long insize, long * const outlenp ) { - struct LZ_Decoder * const decoder = LZ_decompress_open(); + LZ_Decoder * const decoder = LZ_decompress_open(); const long delta_size = insize; /* insize must be > zero */ long outsize = delta_size; /* initial outsize */ uint8_t * outbuf = (uint8_t *)malloc( outsize ); @@ -242,7 +242,7 @@ bool bbcompress( const uint8_t * const inbuf, const int insize, { int inpos = 0, outpos = 0; bool error = false; - struct LZ_Encoder * const encoder = + LZ_Encoder * const encoder = LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX ); if( !encoder || LZ_compress_errno( encoder ) != LZ_ok ) { LZ_compress_close( encoder ); return false; } @@ -278,7 +278,7 @@ bool bbdecompress( const uint8_t * const inbuf, const int insize, { int inpos = 0, outpos = 0; bool error = false; - struct LZ_Decoder * const decoder = LZ_decompress_open(); + LZ_Decoder * const decoder = LZ_decompress_open(); if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok ) { LZ_decompress_close( decoder ); return false; } @@ -340,7 +340,7 @@ int main( const int argc, const char * const argv[] ) { int retval = 0, i; int open_failures = 0; - const bool verbose = ( argc > 2 ); + const bool verbose = argc > 2; if( argc < 2 ) { diff --git a/carg_parser.c b/carg_parser.c index e16fa73..9400342 100644 --- a/carg_parser.c +++ b/carg_parser.c @@ -32,15 +32,15 @@ static void * ap_resize_buffer( void * buf, const int min_size ) } -static char push_back_record( struct Arg_parser * const ap, const int code, +static char push_back_record( Arg_parser * const ap, const int code, const char * const long_name, const char * const argument ) { - struct ap_Record * p; + ap_Record * p; void * tmp = ap_resize_buffer( ap->data, - ( ap->data_size + 1 ) * sizeof (struct ap_Record) ); + ( ap->data_size + 1 ) * sizeof (ap_Record) ); if( !tmp ) return 0; - ap->data = (struct ap_Record *)tmp; + ap->data = (ap_Record *)tmp; p = &(ap->data[ap->data_size]); p->code = code; if( long_name ) @@ -71,7 +71,7 @@ static char push_back_record( struct Arg_parser * const ap, const int code, } -static char add_error( struct Arg_parser * const ap, const char * const msg ) +static char add_error( Arg_parser * const ap, const char * const msg ) { const int len = strlen( msg ); void * tmp = ap_resize_buffer( ap->error, ap->error_size + len + 1 ); @@ -83,7 +83,7 @@ static char add_error( struct Arg_parser * const ap, const char * const msg ) } -static void free_data( struct Arg_parser * const ap ) +static void free_data( Arg_parser * const ap ) { int i; for( i = 0; i < ap->data_size; ++i ) @@ -94,10 +94,9 @@ static void free_data( struct Arg_parser * const ap ) /* Return 0 only if out of memory. */ -static char parse_long_option( struct Arg_parser * const ap, +static char parse_long_option( Arg_parser * const ap, const char * const opt, const char * const arg, - const struct ap_Option options[], - int * const argindp ) + const ap_Option options[], int * const argindp ) { unsigned len; int index = -1, i; @@ -171,10 +170,9 @@ static char parse_long_option( struct Arg_parser * const ap, /* Return 0 only if out of memory. */ -static char parse_short_option( struct Arg_parser * const ap, +static char parse_short_option( Arg_parser * const ap, const char * const opt, const char * const arg, - const struct ap_Option options[], - int * const argindp ) + const ap_Option options[], int * const argindp ) { int cind = 1; /* character index in opt */ @@ -221,9 +219,9 @@ static char parse_short_option( struct Arg_parser * const ap, } -char ap_init( struct Arg_parser * const ap, +char ap_init( Arg_parser * const ap, const int argc, const char * const argv[], - const struct ap_Option options[], const char in_order ) + const ap_Option options[], const char in_order ) { const char ** non_options = 0; /* skipped non-options */ int non_options_size = 0; /* number of skipped non-options */ @@ -282,7 +280,7 @@ out: if( non_options ) free( non_options ); } -void ap_free( struct Arg_parser * const ap ) +void ap_free( Arg_parser * const ap ) { free_data( ap ); if( ap->error ) { free( ap->error ); ap->error = 0; } @@ -290,29 +288,25 @@ void ap_free( struct Arg_parser * const ap ) } -const char * ap_error( const struct Arg_parser * const ap ) - { return ap->error; } +const char * ap_error( const Arg_parser * const ap ) { return ap->error; } +int ap_arguments( const Arg_parser * const ap ) { return ap->data_size; } -int ap_arguments( const struct Arg_parser * const ap ) - { return ap->data_size; } - - -int ap_code( const struct Arg_parser * const ap, const int i ) +int ap_code( const Arg_parser * const ap, const int i ) { if( i < 0 || i >= ap_arguments( ap ) ) return 0; return ap->data[i].code; } -const char * ap_parsed_name( const struct Arg_parser * const ap, const int i ) +const char * ap_parsed_name( const Arg_parser * const ap, const int i ) { if( i < 0 || i >= ap_arguments( ap ) || !ap->data[i].parsed_name ) return ""; return ap->data[i].parsed_name; } -const char * ap_argument( const struct Arg_parser * const ap, const int i ) +const char * ap_argument( const Arg_parser * const ap, const int i ) { if( i < 0 || i >= ap_arguments( ap ) || !ap->data[i].argument ) return ""; return ap->data[i].argument; diff --git a/carg_parser.h b/carg_parser.h index 65a6d7d..294756c 100644 --- a/carg_parser.h +++ b/carg_parser.h @@ -50,52 +50,52 @@ extern "C" { #endif /* ap_yme = yes but maybe empty */ -enum ap_Has_arg { ap_no, ap_yes, ap_maybe, ap_yme }; +typedef enum ap_Has_arg { ap_no, ap_yes, ap_maybe, ap_yme } ap_Has_arg; -struct ap_Option +typedef struct ap_Option { int code; /* Short option letter or code ( code != 0 ) */ const char * long_name; /* Long option name (maybe null) */ - enum ap_Has_arg has_arg; - }; + ap_Has_arg has_arg; + } ap_Option; -struct ap_Record +typedef struct ap_Record { int code; char * parsed_name; char * argument; - }; + } ap_Record; -struct Arg_parser +typedef struct Arg_parser { - struct ap_Record * data; + ap_Record * data; char * error; int data_size; int error_size; - }; + } Arg_parser; -char ap_init( struct Arg_parser * const ap, +char ap_init( Arg_parser * const ap, const int argc, const char * const argv[], - const struct ap_Option options[], const char in_order ); + const ap_Option options[], const char in_order ); -void ap_free( struct Arg_parser * const ap ); +void ap_free( Arg_parser * const ap ); -const char * ap_error( const struct Arg_parser * const ap ); +const char * ap_error( const Arg_parser * const ap ); /* The number of arguments parsed. May be different from argc. */ -int ap_arguments( const struct Arg_parser * const ap ); +int ap_arguments( const Arg_parser * const ap ); /* If ap_code( i ) is 0, ap_argument( i ) is a non-option. Else ap_argument( i ) is the option's argument (or empty). */ -int ap_code( const struct Arg_parser * const ap, const int i ); +int ap_code( const Arg_parser * const ap, const int i ); /* Full name of the option parsed (short or long). */ -const char * ap_parsed_name( const struct Arg_parser * const ap, const int i ); +const char * ap_parsed_name( const Arg_parser * const ap, const int i ); -const char * ap_argument( const struct Arg_parser * const ap, const int i ); +const char * ap_argument( const Arg_parser * const ap, const int i ); #ifdef __cplusplus } diff --git a/cbuffer.c b/cbuffer.c index 4cadc1e..73bdefe 100644 --- a/cbuffer.c +++ b/cbuffer.c @@ -17,15 +17,15 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ -struct Circular_buffer +typedef struct Circular_buffer { uint8_t * buffer; unsigned buffer_size; /* capacity == buffer_size - 1 */ unsigned get; /* buffer is empty when get == put */ unsigned put; - }; + } Circular_buffer; -static inline bool Cb_init( struct Circular_buffer * const cb, +static inline bool Cb_init( Circular_buffer * const cb, const unsigned buf_size ) { cb->buffer_size = buf_size + 1; @@ -36,38 +36,36 @@ static inline bool Cb_init( struct Circular_buffer * const cb, return cb->buffer != 0; } -static inline void Cb_free( struct Circular_buffer * const cb ) +static inline void Cb_free( Circular_buffer * const cb ) { free( cb->buffer ); cb->buffer = 0; } -static inline void Cb_reset( struct Circular_buffer * const cb ) +static inline void Cb_reset( Circular_buffer * const cb ) { cb->get = 0; cb->put = 0; } -static inline unsigned Cb_empty( const struct Circular_buffer * const cb ) +static inline unsigned Cb_empty( const Circular_buffer * const cb ) { return cb->get == cb->put; } -static inline unsigned Cb_used_bytes( const struct Circular_buffer * const cb ) +static inline unsigned Cb_used_bytes( const Circular_buffer * const cb ) { return ( (cb->get <= cb->put) ? 0 : cb->buffer_size ) + cb->put - cb->get; } -static inline unsigned Cb_free_bytes( const struct Circular_buffer * const cb ) +static inline unsigned Cb_free_bytes( const Circular_buffer * const cb ) { return ( (cb->get <= cb->put) ? cb->buffer_size : 0 ) - cb->put + cb->get - 1; } -static inline uint8_t Cb_get_byte( struct Circular_buffer * const cb ) +static inline uint8_t Cb_get_byte( Circular_buffer * const cb ) { const uint8_t b = cb->buffer[cb->get]; if( ++cb->get >= cb->buffer_size ) cb->get = 0; return b; } -static inline void Cb_put_byte( struct Circular_buffer * const cb, - const uint8_t b ) +static inline void Cb_put_byte( Circular_buffer * const cb, const uint8_t b ) { cb->buffer[cb->put] = b; if( ++cb->put >= cb->buffer_size ) cb->put = 0; } -static bool Cb_unread_data( struct Circular_buffer * const cb, - const unsigned size ) +static bool Cb_unread_data( Circular_buffer * const cb, const unsigned size ) { if( size > Cb_free_bytes( cb ) ) return false; if( cb->get >= size ) cb->get -= size; @@ -80,7 +78,7 @@ static bool Cb_unread_data( struct Circular_buffer * const cb, If 'out_buffer' is null, the bytes are discarded. Return the number of bytes copied or discarded. */ -static unsigned Cb_read_data( struct Circular_buffer * const cb, +static unsigned Cb_read_data( Circular_buffer * const cb, uint8_t * const out_buffer, const unsigned out_size ) { @@ -113,7 +111,7 @@ static unsigned Cb_read_data( struct Circular_buffer * const cb, /* Copy up to 'in_size' bytes from 'in_buffer' and update 'put'. Return the number of bytes copied. */ -static unsigned Cb_write_data( struct Circular_buffer * const cb, +static unsigned Cb_write_data( Circular_buffer * const cb, const uint8_t * const in_buffer, const unsigned in_size ) { diff --git a/configure b/configure index 7fa49d2..26ecfef 100755 --- a/configure +++ b/configure @@ -6,7 +6,7 @@ # to copy, distribute, and modify it. pkgname=lzlib -pkgversion=1.15-pre2 +pkgversion=1.15-rc1 soversion=1 libname=lz libname_static=lib${libname}.a diff --git a/decoder.c b/decoder.c index 7b90d6e..3df0fd3 100644 --- a/decoder.c +++ b/decoder.c @@ -17,7 +17,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ -static int LZd_try_check_trailer( struct LZ_decoder * const d ) +static int LZd_try_check_trailer( LZ_decoder * const d ) { Lzip_trailer trailer; if( Rd_available_bytes( d->rdec ) < Lt_size ) @@ -36,9 +36,9 @@ static int LZd_try_check_trailer( struct LZ_decoder * const d ) /* Return value: 0 = OK, 1 = decoder error, 2 = unexpected EOF, 3 = trailer error, 4 = unknown marker found, 5 = nonzero first LZMA byte found, 6 = library error. */ -static int LZd_decode_member( struct LZ_decoder * const d ) +static int LZd_decode_member( LZ_decoder * const d ) { - struct Range_decoder * const rdec = d->rdec; + Range_decoder * const rdec = d->rdec; State * const state = &d->state; unsigned old_mpos = rdec->member_position; diff --git a/decoder.h b/decoder.h index 57e47cb..f492c36 100644 --- a/decoder.h +++ b/decoder.h @@ -19,17 +19,17 @@ enum { rd_min_available_bytes = 10 }; -struct Range_decoder +typedef struct Range_decoder { - struct Circular_buffer cb; /* input buffer */ + Circular_buffer cb; /* input buffer */ unsigned long long member_position; uint32_t code; uint32_t range; bool at_stream_end; bool reload_pending; - }; + } Range_decoder; -static inline bool Rd_init( struct Range_decoder * const rdec ) +static inline bool Rd_init( Range_decoder * const rdec ) { if( !Cb_init( &rdec->cb, 65536 + rd_min_available_bytes ) ) return false; rdec->member_position = 0; @@ -40,25 +40,25 @@ static inline bool Rd_init( struct Range_decoder * const rdec ) return true; } -static inline void Rd_free( struct Range_decoder * const rdec ) +static inline void Rd_free( Range_decoder * const rdec ) { Cb_free( &rdec->cb ); } -static inline bool Rd_finished( const struct Range_decoder * const rdec ) +static inline bool Rd_finished( const Range_decoder * const rdec ) { return rdec->at_stream_end && Cb_empty( &rdec->cb ); } -static inline void Rd_finish( struct Range_decoder * const rdec ) +static inline void Rd_finish( Range_decoder * const rdec ) { rdec->at_stream_end = true; } -static inline bool Rd_enough_available_bytes( const struct Range_decoder * const rdec ) +static inline bool Rd_enough_available_bytes( const Range_decoder * const rdec ) { return Cb_used_bytes( &rdec->cb ) >= rd_min_available_bytes; } -static inline unsigned Rd_available_bytes( const struct Range_decoder * const rdec ) +static inline unsigned Rd_available_bytes( const Range_decoder * const rdec ) { return Cb_used_bytes( &rdec->cb ); } -static inline unsigned Rd_free_bytes( const struct Range_decoder * const rdec ) +static inline unsigned Rd_free_bytes( const Range_decoder * const rdec ) { return rdec->at_stream_end ? 0 : Cb_free_bytes( &rdec->cb ); } -static inline unsigned long long Rd_purge( struct Range_decoder * const rdec ) +static inline unsigned long long Rd_purge( Range_decoder * const rdec ) { const unsigned long long size = rdec->member_position + Cb_used_bytes( &rdec->cb ); @@ -67,7 +67,7 @@ static inline unsigned long long Rd_purge( struct Range_decoder * const rdec ) return size; } -static inline void Rd_reset( struct Range_decoder * const rdec ) +static inline void Rd_reset( Range_decoder * const rdec ) { Cb_reset( &rdec->cb ); rdec->member_position = 0; rdec->at_stream_end = false; } @@ -75,7 +75,7 @@ static inline void Rd_reset( struct Range_decoder * const rdec ) /* Seek for a member header and update 'get'. Set '*skippedp' to the number of bytes skipped. Return true if a valid header is found. */ -static bool Rd_find_header( struct Range_decoder * const rdec, +static bool Rd_find_header( Range_decoder * const rdec, unsigned * const skippedp ) { *skippedp = 0; @@ -101,14 +101,14 @@ static bool Rd_find_header( struct Range_decoder * const rdec, } -static inline int Rd_write_data( struct Range_decoder * const rdec, +static inline int Rd_write_data( Range_decoder * const rdec, const uint8_t * const inbuf, const int size ) { if( rdec->at_stream_end || size <= 0 ) return 0; return Cb_write_data( &rdec->cb, inbuf, size ); } -static inline uint8_t Rd_get_byte( struct Range_decoder * const rdec ) +static inline uint8_t Rd_get_byte( Range_decoder * const rdec ) { /* 0xFF avoids decoder error if member is truncated at EOS marker */ if( Rd_finished( rdec ) ) return 0xFF; @@ -116,7 +116,7 @@ static inline uint8_t Rd_get_byte( struct Range_decoder * const rdec ) return Cb_get_byte( &rdec->cb ); } -static inline int Rd_read_data( struct Range_decoder * const rdec, +static inline int Rd_read_data( Range_decoder * const rdec, uint8_t * const outbuf, const int size ) { const int sz = Cb_read_data( &rdec->cb, outbuf, size ); @@ -124,7 +124,7 @@ static inline int Rd_read_data( struct Range_decoder * const rdec, return sz; } -static inline bool Rd_unread_data( struct Range_decoder * const rdec, +static inline bool Rd_unread_data( Range_decoder * const rdec, const unsigned size ) { if( size > rdec->member_position || !Cb_unread_data( &rdec->cb, size ) ) @@ -133,7 +133,7 @@ static inline bool Rd_unread_data( struct Range_decoder * const rdec, return true; } -static int Rd_try_reload( struct Range_decoder * const rdec ) +static int Rd_try_reload( Range_decoder * const rdec ) { if( rdec->reload_pending && Rd_available_bytes( rdec ) >= 5 ) { @@ -149,13 +149,13 @@ static int Rd_try_reload( struct Range_decoder * const rdec ) return !rdec->reload_pending; } -static inline void Rd_normalize( struct Range_decoder * const rdec ) +static inline void Rd_normalize( Range_decoder * const rdec ) { if( rdec->range <= 0x00FFFFFFU ) { rdec->range <<= 8; rdec->code = (rdec->code << 8) | Rd_get_byte( rdec ); } } -static inline unsigned Rd_decode( struct Range_decoder * const rdec, +static inline unsigned Rd_decode( Range_decoder * const rdec, const int num_bits ) { unsigned symbol = 0; @@ -173,7 +173,7 @@ static inline unsigned Rd_decode( struct Range_decoder * const rdec, return symbol; } -static inline unsigned Rd_decode_bit( struct Range_decoder * const rdec, +static inline unsigned Rd_decode_bit( Range_decoder * const rdec, Bit_model * const probability ) { Rd_normalize( rdec ); @@ -193,7 +193,7 @@ static inline unsigned Rd_decode_bit( struct Range_decoder * const rdec, } } -static inline void Rd_decode_symbol_bit( struct Range_decoder * const rdec, +static inline void Rd_decode_symbol_bit( Range_decoder * const rdec, Bit_model * const probability, unsigned * symbol ) { Rd_normalize( rdec ); @@ -213,7 +213,7 @@ static inline void Rd_decode_symbol_bit( struct Range_decoder * const rdec, } } -static inline void Rd_decode_symbol_bit_reversed( struct Range_decoder * const rdec, +static inline void Rd_decode_symbol_bit_reversed( Range_decoder * const rdec, Bit_model * const probability, unsigned * model, unsigned * symbol, const int i ) { @@ -235,7 +235,7 @@ static inline void Rd_decode_symbol_bit_reversed( struct Range_decoder * const r } } -static inline unsigned Rd_decode_tree6( struct Range_decoder * const rdec, +static inline unsigned Rd_decode_tree6( Range_decoder * const rdec, Bit_model bm[] ) { unsigned symbol = 1; @@ -248,7 +248,7 @@ static inline unsigned Rd_decode_tree6( struct Range_decoder * const rdec, return symbol & 0x3F; } -static inline unsigned Rd_decode_tree8( struct Range_decoder * const rdec, +static inline unsigned Rd_decode_tree8( Range_decoder * const rdec, Bit_model bm[] ) { unsigned symbol = 1; @@ -264,7 +264,7 @@ static inline unsigned Rd_decode_tree8( struct Range_decoder * const rdec, } static inline unsigned -Rd_decode_tree_reversed( struct Range_decoder * const rdec, +Rd_decode_tree_reversed( Range_decoder * const rdec, Bit_model bm[], const int num_bits ) { unsigned model = 1; @@ -276,7 +276,7 @@ Rd_decode_tree_reversed( struct Range_decoder * const rdec, } static inline unsigned -Rd_decode_tree_reversed4( struct Range_decoder * const rdec, Bit_model bm[] ) +Rd_decode_tree_reversed4( Range_decoder * const rdec, Bit_model bm[] ) { unsigned model = 1; unsigned symbol = 0; @@ -287,7 +287,7 @@ Rd_decode_tree_reversed4( struct Range_decoder * const rdec, Bit_model bm[] ) return symbol; } -static inline unsigned Rd_decode_matched( struct Range_decoder * const rdec, +static inline unsigned Rd_decode_matched( Range_decoder * const rdec, Bit_model bm[], unsigned match_byte ) { unsigned symbol = 1; @@ -302,8 +302,8 @@ static inline unsigned Rd_decode_matched( struct Range_decoder * const rdec, } } -static inline unsigned Rd_decode_len( struct Range_decoder * const rdec, - struct Len_model * const lm, +static inline unsigned Rd_decode_len( Range_decoder * const rdec, + Len_model * const lm, const int pos_state ) { Bit_model * bm; @@ -329,11 +329,11 @@ len3: enum { lzd_min_free_bytes = max_match_len }; -struct LZ_decoder +typedef struct LZ_decoder { - struct Circular_buffer cb; + Circular_buffer cb; unsigned long long partial_data_pos; - struct Range_decoder * rdec; + Range_decoder * rdec; unsigned dictionary_size; uint32_t crc; bool check_trailer_pending; @@ -356,25 +356,25 @@ struct LZ_decoder Bit_model bm_dis[modeled_distances-end_dis_model+1]; Bit_model bm_align[dis_align_size]; - struct Len_model match_len_model; - struct Len_model rep_len_model; - }; + Len_model match_len_model; + Len_model rep_len_model; + } LZ_decoder; -static inline bool LZd_enough_free_bytes( const struct LZ_decoder * const d ) +static inline bool LZd_enough_free_bytes( const LZ_decoder * const d ) { return Cb_free_bytes( &d->cb ) >= lzd_min_free_bytes; } -static inline uint8_t LZd_peek_prev( const struct LZ_decoder * const d ) +static inline uint8_t LZd_peek_prev( const LZ_decoder * const d ) { return d->cb.buffer[((d->cb.put > 0) ? d->cb.put : d->cb.buffer_size)-1]; } -static inline uint8_t LZd_peek( const struct LZ_decoder * const d, +static inline uint8_t LZd_peek( const LZ_decoder * const d, const unsigned distance ) { - const unsigned i = ( ( d->cb.put > distance ) ? 0 : d->cb.buffer_size ) + + const unsigned i = ( (d->cb.put > distance) ? 0 : d->cb.buffer_size ) + d->cb.put - distance - 1; return d->cb.buffer[i]; } -static inline void LZd_put_byte( struct LZ_decoder * const d, const uint8_t b ) +static inline void LZd_put_byte( LZ_decoder * const d, const uint8_t b ) { CRC32_update_byte( &d->crc, b ); d->cb.buffer[d->cb.put] = b; @@ -382,7 +382,7 @@ static inline void LZd_put_byte( struct LZ_decoder * const d, const uint8_t b ) { d->partial_data_pos += d->cb.put; d->cb.put = 0; d->pos_wrapped = true; } } -static inline void LZd_copy_block( struct LZ_decoder * const d, +static inline void LZd_copy_block( LZ_decoder * const d, const unsigned distance, unsigned len ) { unsigned lpos = d->cb.put, i = lpos - distance - 1; @@ -415,8 +415,7 @@ static inline void LZd_copy_block( struct LZ_decoder * const d, } } -static inline bool LZd_init( struct LZ_decoder * const d, - struct Range_decoder * const rde, +static inline bool LZd_init( LZ_decoder * const d, Range_decoder * const rde, const unsigned dict_size ) { if( !Cb_init( &d->cb, max( 65536, dict_size ) + lzd_min_free_bytes ) ) @@ -451,15 +450,14 @@ static inline bool LZd_init( struct LZ_decoder * const d, return true; } -static inline void LZd_free( struct LZ_decoder * const d ) - { Cb_free( &d->cb ); } +static inline void LZd_free( LZ_decoder * const d ) { Cb_free( &d->cb ); } -static inline bool LZd_member_finished( const struct LZ_decoder * const d ) +static inline bool LZd_member_finished( const LZ_decoder * const d ) { return d->member_finished && Cb_empty( &d->cb ); } -static inline unsigned LZd_crc( const struct LZ_decoder * const d ) +static inline unsigned LZd_crc( const LZ_decoder * const d ) { return d->crc ^ 0xFFFFFFFFU; } static inline unsigned long long -LZd_data_position( const struct LZ_decoder * const d ) +LZd_data_position( const LZ_decoder * const d ) { return d->partial_data_pos + d->cb.put; } diff --git a/doc/lzlib.info b/doc/lzlib.info index 44bf3ce..afe2774 100644 --- a/doc/lzlib.info +++ b/doc/lzlib.info @@ -11,7 +11,7 @@ File: lzlib.info, Node: Top, Next: Introduction, Up: (dir) Lzlib Manual ************ -This manual is for Lzlib (version 1.15-pre2, 16 October 2024). +This manual is for Lzlib (version 1.15-rc1, 19 November 2024). * Menu: @@ -46,31 +46,6 @@ decompression functions, including integrity checking of the decompressed data. The compressed data format used by the library is the lzip format. Lzlib is written in C and is distributed under a 2-clause BSD license. - The lzip file format is designed for data sharing and long-term -archiving, taking into account both data integrity and decoder availability: - - * The lzip format provides very safe integrity checking and some data - recovery means. The program lziprecover can repair bit flip errors - (one of the most common forms of data corruption) in lzip files, and - provides data recovery capabilities, including error-checked merging - of damaged copies of a file. *Note Data safety: (lziprecover)Data - safety. - - * The lzip format is as simple as possible (but not simpler). The lzip - manual provides the source code of a simple decompressor along with a - detailed explanation of how it works, so that with the only help of the - lzip manual it would be possible for a digital archaeologist to extract - the data from a lzip file long after quantum computers eventually - render LZMA obsolete. - - * Additionally the lzip reference implementation is copylefted, which - guarantees that it will remain free forever. - - A nice feature of the lzip format is that a corrupt byte is easier to -repair the nearer it is from the beginning of the file. Therefore, with the -help of lziprecover, losing an entire archive just because of a corrupt -byte near the beginning is a thing of the past. - The functions and variables forming the interface of the compression library are declared in the file 'lzlib.h'. Usage examples of the library are given in the files 'bbexample.c', 'ffexample.c', and 'minilzip.c' from @@ -117,10 +92,10 @@ about 2 PiB each. concrete algorithm; it is more like "any algorithm using the LZMA coding scheme". For example, the option '-0' of lzip uses the scheme in almost the simplest way possible; issuing the longest match it can find, or a literal -byte if it can't find a match. Inversely, a much more elaborated way of -finding coding sequences of minimum size than the one currently used by -lzip could be developed, and the resulting sequence could also be coded -using the LZMA coding scheme. +byte if it can't find a match. Inversely, a more elaborate way of finding +coding sequences of minimum size than the one currently used by lzip could +be developed, and the resulting sequence could also be coded using the LZMA +coding scheme. Lzlib currently implements two variants of the LZMA algorithm: fast (used by option '-0' of minilzip) and normal (used by all other compression @@ -269,9 +244,8 @@ them return -1 or 0, for signed and unsigned return values respectively, except 'LZ_compress_open' whose return value must be checked by calling 'LZ_compress_errno' before using it. - -- Function: struct LZ_Encoder * LZ_compress_open ( const int - DICTIONARY_SIZE, const int MATCH_LEN_LIMIT, const unsigned long - long MEMBER_SIZE ) + -- Function: LZ_Encoder * LZ_compress_open ( const int DICTIONARY_SIZE, + const int MATCH_LEN_LIMIT, const unsigned long long MEMBER_SIZE ) Initializes the internal stream state for compression and returns a pointer that can only be used as the ENCODER argument for the other LZ_compress functions, or a null pointer if the encoder could not be @@ -303,14 +277,14 @@ except 'LZ_compress_open' whose return value must be checked by calling produced. Values larger than 2 PiB are reduced to 2 PiB to prevent the uncompressed size of the member from overflowing. - -- Function: int LZ_compress_close ( struct LZ_Encoder * const ENCODER ) + -- Function: int LZ_compress_close ( LZ_Encoder * const ENCODER ) Frees all dynamically allocated data structures for this stream. This function discards any unprocessed input and does not flush any pending output. After a call to 'LZ_compress_close', ENCODER can no longer be used as an argument to any LZ_compress function. It is safe to call 'LZ_compress_close' with a null argument. - -- Function: int LZ_compress_finish ( struct LZ_Encoder * const ENCODER ) + -- Function: int LZ_compress_finish ( LZ_Encoder * const ENCODER ) Use this function to tell 'lzlib' that all the data for this member have already been written (with the function 'LZ_compress_write'). It is safe to call 'LZ_compress_finish' as many times as needed. After @@ -318,27 +292,26 @@ except 'LZ_compress_open' whose return value must be checked by calling 'LZ_compress_member_finished' returns 1, a new member can be started with 'LZ_compress_restart_member'. - -- Function: int LZ_compress_restart_member ( struct LZ_Encoder * const - ENCODER, const unsigned long long MEMBER_SIZE ) + -- Function: int LZ_compress_restart_member ( LZ_Encoder * const ENCODER, + const unsigned long long MEMBER_SIZE ) Use this function to start a new member in a multimember data stream. Call this function only after 'LZ_compress_member_finished' indicates that the current member has been fully read (with the function 'LZ_compress_read'). *Note member_size::, for a description of MEMBER_SIZE. - -- Function: int LZ_compress_sync_flush ( struct LZ_Encoder * const - ENCODER ) + -- Function: int LZ_compress_sync_flush ( LZ_Encoder * const ENCODER ) Use this function to make available to 'LZ_compress_read' all the data already written with the function 'LZ_compress_write'. First call 'LZ_compress_sync_flush'. Then call 'LZ_compress_read' until it returns 0. - This function writes at least one LZMA marker '3' ("Sync Flush" marker) + This function writes at least one LZMA marker '3' ('Sync Flush' marker) to the compressed output. Note that the sync flush marker is not allowed in lzip files; it is a device for interactive communication between applications using lzlib, but is useless and wasteful in a file, and is excluded from the media type 'application/lzip'. The LZMA - marker '2' ("End Of Stream" marker) is the only marker allowed in lzip + marker '2' ('End Of Stream' marker) is the only marker allowed in lzip files. *Note File format::. Repeated use of 'LZ_compress_sync_flush' may degrade compression @@ -353,8 +326,8 @@ except 'LZ_compress_open' whose return value must be checked by calling 'LZ_compress_member_finished' returns 1, followed by a new call to 'LZ_compress_sync_flush'. - -- Function: int LZ_compress_read ( struct LZ_Encoder * const ENCODER, - uint8_t * const BUFFER, const int SIZE ) + -- Function: int LZ_compress_read ( LZ_Encoder * const ENCODER, uint8_t * + const BUFFER, const int SIZE ) Reads up to SIZE bytes from the stream pointed to by ENCODER, storing the results in BUFFER. If LZ_API_VERSION >= 1012, BUFFER may be a null pointer, in which case the bytes read are discarded. @@ -365,14 +338,13 @@ except 'LZ_compress_open' whose return value must be checked by calling 'LZ_compress_write'. Note that reading less than SIZE bytes is not an error. - -- Function: int LZ_compress_write ( struct LZ_Encoder * const ENCODER, - uint8_t * const BUFFER, const int SIZE ) + -- Function: int LZ_compress_write ( LZ_Encoder * const ENCODER, uint8_t * + const BUFFER, const int SIZE ) Writes up to SIZE bytes from BUFFER to the stream pointed to by ENCODER. Returns the number of bytes actually written. This might be less than SIZE. Note that writing less than SIZE bytes is not an error. - -- Function: int LZ_compress_write_size ( struct LZ_Encoder * const - ENCODER ) + -- Function: int LZ_compress_write_size ( LZ_Encoder * const ENCODER ) Returns the maximum number of bytes that can be immediately written through 'LZ_compress_write'. For efficiency reasons, once the input buffer is full and 'LZ_compress_write_size' returns 0, almost all the @@ -383,39 +355,37 @@ except 'LZ_compress_open' whose return value must be checked by calling It is guaranteed that an immediate call to 'LZ_compress_write' will accept a SIZE up to the returned number of bytes. - -- Function: enum LZ_Errno LZ_compress_errno ( struct LZ_Encoder * const - ENCODER ) + -- Function: LZ_Errno LZ_compress_errno ( LZ_Encoder * const ENCODER ) Returns the current error code for ENCODER. *Note Error codes::. It is safe to call 'LZ_compress_errno' with a null argument, in which case it returns 'LZ_bad_argument'. - -- Function: int LZ_compress_finished ( struct LZ_Encoder * const ENCODER ) + -- Function: int LZ_compress_finished ( LZ_Encoder * const ENCODER ) Returns 1 if all the data have been read and 'LZ_compress_close' can be safely called. Otherwise it returns 0. 'LZ_compress_finished' implies 'LZ_compress_member_finished'. - -- Function: int LZ_compress_member_finished ( struct LZ_Encoder * const - ENCODER ) + -- Function: int LZ_compress_member_finished ( LZ_Encoder * const ENCODER ) Returns 1 if the current member, in a multimember data stream, has been fully read and 'LZ_compress_restart_member' can be safely called. Otherwise it returns 0. - -- Function: unsigned long long LZ_compress_data_position ( struct - LZ_Encoder * const ENCODER ) + -- Function: unsigned long long LZ_compress_data_position ( LZ_Encoder * + const ENCODER ) Returns the number of input bytes already compressed in the current member. - -- Function: unsigned long long LZ_compress_member_position ( struct - LZ_Encoder * const ENCODER ) + -- Function: unsigned long long LZ_compress_member_position ( LZ_Encoder * + const ENCODER ) Returns the number of compressed bytes already produced, but perhaps not yet read, in the current member. - -- Function: unsigned long long LZ_compress_total_in_size ( struct - LZ_Encoder * const ENCODER ) + -- Function: unsigned long long LZ_compress_total_in_size ( LZ_Encoder * + const ENCODER ) Returns the total number of input bytes already compressed. - -- Function: unsigned long long LZ_compress_total_out_size ( struct - LZ_Encoder * const ENCODER ) + -- Function: unsigned long long LZ_compress_total_out_size ( LZ_Encoder * + const ENCODER ) Returns the total number of compressed bytes already produced, but perhaps not yet read. @@ -430,7 +400,7 @@ them return -1 or 0, for signed and unsigned return values respectively, except 'LZ_decompress_open' whose return value must be checked by calling 'LZ_decompress_errno' before using it. - -- Function: struct LZ_Decoder * LZ_decompress_open ( void ) + -- Function: LZ_Decoder * LZ_decompress_open ( void ) Initializes the internal stream state for decompression and returns a pointer that can only be used as the DECODER argument for the other LZ_decompress functions, or a null pointer if the decoder could not be @@ -441,14 +411,14 @@ except 'LZ_decompress_open' whose return value must be checked by calling returned pointer must not be used and should be freed with 'LZ_decompress_close' to avoid memory leaks. - -- Function: int LZ_decompress_close ( struct LZ_Decoder * const DECODER ) + -- Function: int LZ_decompress_close ( LZ_Decoder * const DECODER ) Frees all dynamically allocated data structures for this stream. This function discards any unprocessed input and does not flush any pending output. After a call to 'LZ_decompress_close', DECODER can no longer be used as an argument to any LZ_decompress function. It is safe to call 'LZ_decompress_close' with a null argument. - -- Function: int LZ_decompress_finish ( struct LZ_Decoder * const DECODER ) + -- Function: int LZ_decompress_finish ( LZ_Decoder * const DECODER ) Use this function to tell 'lzlib' that all the data for this stream have already been written (with the function 'LZ_decompress_write'). It is safe to call 'LZ_decompress_finish' as many times as needed. It @@ -456,13 +426,13 @@ except 'LZ_decompress_open' whose return value must be checked by calling only contains whole members, but not calling it prevents lzlib from detecting a truncated member. - -- Function: int LZ_decompress_reset ( struct LZ_Decoder * const DECODER ) + -- Function: int LZ_decompress_reset ( LZ_Decoder * const DECODER ) Resets the internal state of DECODER as it was just after opening it with the function 'LZ_decompress_open'. Data stored in the internal buffers are discarded. Position counters are set to 0. - -- Function: int LZ_decompress_sync_to_member ( struct LZ_Decoder * const - DECODER ) + -- Function: int LZ_decompress_sync_to_member ( LZ_Decoder * const DECODER + ) Resets the error state of DECODER and enters a search state that lasts until a new member header (or the end of the stream) is found. After a successful call to 'LZ_decompress_sync_to_member', data written with @@ -474,8 +444,8 @@ except 'LZ_decompress_open' whose return value must be checked by calling case of a data error. If the decoder is already at the beginning of a member, this function does nothing. - -- Function: int LZ_decompress_read ( struct LZ_Decoder * const DECODER, - uint8_t * const BUFFER, const int SIZE ) + -- Function: int LZ_decompress_read ( LZ_Decoder * const DECODER, uint8_t + * const BUFFER, const int SIZE ) Reads up to SIZE bytes from the stream pointed to by DECODER, storing the results in BUFFER. If LZ_API_VERSION >= 1012, BUFFER may be a null pointer, in which case the bytes read are discarded. @@ -500,14 +470,13 @@ except 'LZ_decompress_open' whose return value must be checked by calling allows tools like tarlz to recover as much data as possible from each damaged member. *Note tarlz manual: (tarlz)Top. - -- Function: int LZ_decompress_write ( struct LZ_Decoder * const DECODER, - uint8_t * const BUFFER, const int SIZE ) + -- Function: int LZ_decompress_write ( LZ_Decoder * const DECODER, uint8_t + * const BUFFER, const int SIZE ) Writes up to SIZE bytes from BUFFER to the stream pointed to by DECODER. Returns the number of bytes actually written. This might be less than SIZE. Note that writing less than SIZE bytes is not an error. - -- Function: int LZ_decompress_write_size ( struct LZ_Decoder * const - DECODER ) + -- Function: int LZ_decompress_write_size ( LZ_Decoder * const DECODER ) Returns the maximum number of bytes that can be immediately written through 'LZ_decompress_write'. This number varies smoothly; each compressed byte consumed may be overwritten immediately, increasing by @@ -516,19 +485,17 @@ except 'LZ_decompress_open' whose return value must be checked by calling It is guaranteed that an immediate call to 'LZ_decompress_write' will accept a SIZE up to the returned number of bytes. - -- Function: enum LZ_Errno LZ_decompress_errno ( struct LZ_Decoder * const - DECODER ) + -- Function: LZ_Errno LZ_decompress_errno ( LZ_Decoder * const DECODER ) Returns the current error code for DECODER. *Note Error codes::. It is safe to call 'LZ_decompress_errno' with a null argument, in which case it returns 'LZ_bad_argument'. - -- Function: int LZ_decompress_finished ( struct LZ_Decoder * const - DECODER ) + -- Function: int LZ_decompress_finished ( LZ_Decoder * const DECODER ) Returns 1 if all the data have been read and 'LZ_decompress_close' can be safely called. Otherwise it returns 0. 'LZ_decompress_finished' does not imply 'LZ_decompress_member_finished'. - -- Function: int LZ_decompress_member_finished ( struct LZ_Decoder * const + -- Function: int LZ_decompress_member_finished ( LZ_Decoder * const DECODER ) Returns 1 if the previous call to 'LZ_decompress_read' finished reading the current member, indicating that final values for the member are @@ -536,37 +503,36 @@ except 'LZ_decompress_open' whose return value must be checked by calling 'LZ_decompress_data_position', and 'LZ_decompress_member_position'. Otherwise it returns 0. - -- Function: int LZ_decompress_member_version ( struct LZ_Decoder * const - DECODER ) + -- Function: int LZ_decompress_member_version ( LZ_Decoder * const DECODER + ) Returns the version of the current member, read from the member header. - -- Function: int LZ_decompress_dictionary_size ( struct LZ_Decoder * const + -- Function: int LZ_decompress_dictionary_size ( LZ_Decoder * const DECODER ) Returns the dictionary size of the current member, read from the member header. - -- Function: unsigned LZ_decompress_data_crc ( struct LZ_Decoder * const - DECODER ) + -- Function: unsigned LZ_decompress_data_crc ( LZ_Decoder * const DECODER ) Returns the 32 bit Cyclic Redundancy Check of the data decompressed from the current member. The value returned is valid only when 'LZ_decompress_member_finished' returns 1. - -- Function: unsigned long long LZ_decompress_data_position ( struct - LZ_Decoder * const DECODER ) + -- Function: unsigned long long LZ_decompress_data_position ( LZ_Decoder * + const DECODER ) Returns the number of decompressed bytes already produced, but perhaps not yet read, in the current member. - -- Function: unsigned long long LZ_decompress_member_position ( struct - LZ_Decoder * const DECODER ) + -- Function: unsigned long long LZ_decompress_member_position ( LZ_Decoder + * const DECODER ) Returns the number of input bytes already decompressed in the current member. - -- Function: unsigned long long LZ_decompress_total_in_size ( struct - LZ_Decoder * const DECODER ) + -- Function: unsigned long long LZ_decompress_total_in_size ( LZ_Decoder * + const DECODER ) Returns the total number of input bytes already decompressed. - -- Function: unsigned long long LZ_decompress_total_out_size ( struct - LZ_Decoder * const DECODER ) + -- Function: unsigned long long LZ_decompress_total_out_size ( LZ_Decoder + * const DECODER ) Returns the total number of decompressed bytes already produced, but perhaps not yet read. @@ -587,35 +553,36 @@ what kind of error it was, you need to check the error code by calling and you should not use 'LZ_(de)compress_errno' to determine whether a call failed. If the call failed, then you can examine 'LZ_(de)compress_errno'. - The error codes are defined in the header file 'lzlib.h'. + The error codes are defined in the header file 'lzlib.h'. 'LZ_Errno' is +an enum type: - -- Constant: enum LZ_Errno LZ_ok + -- Constant: LZ_Errno LZ_ok The value of this constant is 0 and is used to indicate that there is no error. - -- Constant: enum LZ_Errno LZ_bad_argument + -- Constant: LZ_Errno LZ_bad_argument At least one of the arguments passed to the library function was invalid. - -- Constant: enum LZ_Errno LZ_mem_error + -- Constant: LZ_Errno LZ_mem_error No memory available. The system cannot allocate more virtual memory because its capacity is full. - -- Constant: enum LZ_Errno LZ_sequence_error + -- Constant: LZ_Errno LZ_sequence_error A library function was called in the wrong order. For example 'LZ_compress_restart_member' was called before - 'LZ_compress_member_finished' indicates that the current member is + 'LZ_compress_member_finished' indicated that the current member is finished. - -- Constant: enum LZ_Errno LZ_header_error + -- Constant: LZ_Errno LZ_header_error An invalid member header (one with the wrong magic bytes) was read. If this happens at the end of the data stream it may indicate trailing data. - -- Constant: enum LZ_Errno LZ_unexpected_eof + -- Constant: LZ_Errno LZ_unexpected_eof The end of the data stream was reached in the middle of a member. - -- Constant: enum LZ_Errno LZ_data_error + -- Constant: LZ_Errno LZ_data_error The data stream is corrupt. If 'LZ_decompress_member_position' is 6 or less, it indicates either a format version not supported, an invalid dictionary size, a nonzero first LZMA byte, a corrupt header in a @@ -623,7 +590,7 @@ failed. If the call failed, then you can examine 'LZ_(de)compress_errno'. header. Lziprecover can be used to repair some of these errors and to remove conflicting trailing data from a file. - -- Constant: enum LZ_Errno LZ_library_error + -- Constant: LZ_Errno LZ_library_error A bug was detected in the library. Please, report it. *Note Problems::.  @@ -632,11 +599,11 @@ File: lzlib.info, Node: Error messages, Next: Invoking minilzip, Prev: Error 8 Error messages **************** - -- Function: const char * LZ_strerror ( const enum LZ_Errno LZ_ERRNO ) - Returns the standard error message for a given error code. The messages - are fairly short; there are no multi-line messages or embedded - newlines. This function makes it easy for your program to report - informative error messages about the failure of a library call. + -- Function: const char * LZ_strerror ( const LZ_Errno LZ_ERRNO ) + Returns the error message corresponding to the error code LZ_ERRNO. + The messages are fairly short; there are no multi-line messages or + embedded newlines. This function makes it easy for your program to + report informative error messages about the failure of a library call. The value of LZ_ERRNO normally comes from a call to 'LZ_(de)compress_errno'. @@ -647,22 +614,22 @@ File: lzlib.info, Node: Invoking minilzip, Next: File format, Prev: Error mes 9 Invoking minilzip ******************* -Minilzip is a test program for the compression library lzlib, compatible -(interoperable) with lzip 1.4 or newer. Minilzip is not intended to be -installed because lzip has more features, but minilzip is well tested and -you can use it as your main compressor if so you wish. +Minilzip is a test program for the compression library lzlib. Minilzip is +not intended to be installed because lzip has more features, but minilzip is +well tested and you can use it as your main compressor if so you wish. +*Note lzip: (lzip)Top. Lzip is a lossless data compressor with a user interface similar to the -one of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov -chain-Algorithm' (LZMA) stream format to maximize interoperability. The -maximum dictionary size is 512 MiB so that any lzip file can be decompressed -on 32-bit machines. Lzip provides accurate and robust 3-factor integrity -checking. Lzip can compress about as fast as gzip (lzip -0) or compress most -files more than bzip2 (lzip -9). Decompression speed is intermediate between -gzip and bzip2. Lzip provides better data recovery capabilities than gzip -and bzip2. Lzip has been designed, written, and tested with great care to -replace gzip and bzip2 as the standard general-purpose compressed format for -Unix-like systems. +one of gzip or bzip2. Lzip uses a simplified form of LZMA (Lempel-Ziv-Markov +chain-Algorithm) designed to achieve complete interoperability between +implementations. The maximum dictionary size is 512 MiB so that any lzip +file can be decompressed on 32-bit machines. Lzip provides accurate and +robust 3-factor integrity checking. 'lzip -0' compresses about as fast as +gzip, while 'lzip -9' compresses most files more than bzip2. Decompression +speed is intermediate between gzip and bzip2. Lzip provides better data +recovery capabilities than gzip and bzip2. Lzip has been designed, written, +and tested with great care to replace gzip and bzip2 as general-purpose +compressed format for Unix-like systems. The format for running minilzip is: @@ -675,7 +642,7 @@ once, the first time it appears in the command line. Remember to prepend './' to any file name beginning with a hyphen, or use '--'. minilzip supports the following options: *Note Argument syntax: -(arg_parser)Argument syntax. +(plzip)Argument syntax. '-h' '--help' @@ -694,11 +661,12 @@ minilzip supports the following options: *Note Argument syntax: '-b BYTES' '--member-size=BYTES' - When compressing, set the member size limit to BYTES. It is advisable - to keep members smaller than RAM size so that they can be repaired with - lziprecover in case of corruption. A small member size may degrade - compression ratio, so use it only when needed. Valid values range from - 100 kB to 2 PiB. Defaults to 2 PiB. + When compressing, set the member size limit to BYTES. If BYTES is + smaller than the compressed size, a multimember file is produced. It is + advisable to keep members smaller than RAM size so that they can be + repaired with lziprecover in case of corruption. A small member size + may degrade compression ratio, so use it only when needed. Valid + values range from 100 kB to 2 PiB. Defaults to 2 PiB. '-c' '--stdout' @@ -719,7 +687,8 @@ minilzip supports the following options: *Note Argument syntax: status 1. If a file fails to decompress, or is a terminal, minilzip exits immediately with error status 2 without decompressing the rest of the files. A terminal is considered an uncompressed file, and - therefore invalid. + therefore invalid. A multimember file with one or more empty members + is accepted if redirected to standard input. '-f' '--force' @@ -772,6 +741,8 @@ minilzip supports the following options: *Note Argument syntax: For maximum compression you should use a dictionary size limit as large as possible, but keep in mind that the decompression memory requirement is affected at compression time by the choice of dictionary size limit. + The dictionary size used for decompression is the same dictionary size + used for compression. '-S BYTES' '--volume-size=BYTES' @@ -791,7 +762,8 @@ minilzip supports the following options: *Note Argument syntax: fails the test, does not exist, can't be opened, or is a terminal, minilzip continues testing the rest of the files. A final diagnostic is shown at verbosity level 1 or higher if any file fails the test - when testing multiple files. + when testing multiple files. A multimember file with one or more empty + members is accepted if redirected to standard input. '-v' '--verbose' @@ -839,7 +811,7 @@ minilzip supports the following options: *Note Argument syntax: When decompressing or testing, allow trailing data whose first bytes are so similar to the magic bytes of a lzip header that they can be confused with a corrupt header. Use this option if a file triggers a - "corrupt header" error and the cause is not indeed a corrupt header. + 'corrupt header' error and the cause is not indeed a corrupt header. '--check-lib' Compare the version of lzlib used to compile minilzip with the version @@ -935,11 +907,11 @@ not allowed in multimember files. Valid values for dictionary size range from 4 KiB to 512 MiB. 'LZMA stream' - The LZMA stream, terminated by an "End Of Stream" marker. Uses default + The LZMA stream, terminated by an 'End Of Stream' marker. Uses default values for encoder properties. *Note Stream format: (lzip)Stream format, for a complete description. - Lzip only uses the LZMA marker '2' ("End Of Stream" marker). Lzlib - also uses the LZMA marker '3' ("Sync Flush" marker). *Note + Lzip only uses the LZMA marker '2' ('End Of Stream' marker). Lzlib + also uses the LZMA marker '3' ('Sync Flush' marker). *Note sync_flush::. 'CRC32 (4 bytes)' @@ -999,7 +971,7 @@ bool bbcompress( const uint8_t * const inbuf, const int insize, { int inpos = 0, outpos = 0; bool error = false; - struct LZ_Encoder * const encoder = + LZ_Encoder * const encoder = LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX ); if( !encoder || LZ_compress_errno( encoder ) != LZ_ok ) { LZ_compress_close( encoder ); return false; } @@ -1042,7 +1014,7 @@ bool bbdecompress( const uint8_t * const inbuf, const int insize, { int inpos = 0, outpos = 0; bool error = false; - struct LZ_Decoder * const decoder = LZ_decompress_open(); + LZ_Decoder * const decoder = LZ_decompress_open(); if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok ) { LZ_decompress_close( decoder ); return false; } @@ -1073,7 +1045,7 @@ File: lzlib.info, Node: File compression, Next: File decompression, Prev: Buf File-to-file compression using LZ_compress_write_size. -int ffcompress( struct LZ_Encoder * const encoder, +int ffcompress( LZ_Encoder * const encoder, FILE * const infile, FILE * const outfile ) { enum { buffer_size = 16384 }; @@ -1106,7 +1078,7 @@ File: lzlib.info, Node: File decompression, Next: File compression mm, Prev: File-to-file decompression using LZ_decompress_write_size. -int ffdecompress( struct LZ_Decoder * const decoder, +int ffdecompress( LZ_Decoder * const decoder, FILE * const infile, FILE * const outfile ) { enum { buffer_size = 16384 }; @@ -1145,8 +1117,7 @@ int ffmmcompress( FILE * const infile, FILE * const outfile ) enum { buffer_size = 16384, member_size = 4096 }; uint8_t buffer[buffer_size]; bool done = false; - struct LZ_Encoder * const encoder = - LZ_compress_open( 65535, 16, member_size ); + LZ_Encoder * const encoder = LZ_compress_open( 65535, 16, member_size ); if( !encoder || LZ_compress_errno( encoder ) != LZ_ok ) { fputs( "ffexample: Not enough memory.\n", stderr ); LZ_compress_close( encoder ); return 1; } @@ -1183,7 +1154,7 @@ LZ_compress_open with MEMBER_SIZE > largest member). for each line of text terminated by a newline character or by EOF. Return 0 if success, 1 if error. */ -int fflfcompress( struct LZ_Encoder * const encoder, +int fflfcompress( LZ_Encoder * const encoder, FILE * const infile, FILE * const outfile ) { enum { buffer_size = 16384 }; @@ -1229,7 +1200,7 @@ File: lzlib.info, Node: Skipping data errors, Prev: File compression mm, Up: next member in case of data error, including the automatic removal of leading garbage. */ -int ffrsdecompress( struct LZ_Decoder * const decoder, +int ffrsdecompress( LZ_Decoder * const decoder, FILE * const infile, FILE * const outfile ) { enum { buffer_size = 16384 }; @@ -1310,27 +1281,27 @@ Concept index Tag Table: Node: Top215 Node: Introduction1343 -Node: Library version6831 -Node: Buffering9382 -Node: Parameter limits10607 -Node: Compression functions11561 -Ref: member_size13354 -Ref: sync_flush15116 -Node: Decompression functions19804 -Node: Error codes27362 -Node: Error messages29719 -Node: Invoking minilzip30298 -Node: File format41020 -Ref: coded-dict-size42518 -Node: Examples43925 -Node: Buffer compression44886 -Node: Buffer decompression46406 -Node: File compression47820 -Node: File decompression48803 -Node: File compression mm49807 -Node: Skipping data errors52836 -Node: Problems54141 -Node: Concept index54702 +Node: Library version5506 +Node: Buffering8057 +Node: Parameter limits9282 +Node: Compression functions10236 +Ref: member_size12012 +Ref: sync_flush13753 +Node: Decompression functions18319 +Node: Error codes25706 +Node: Error messages28051 +Node: Invoking minilzip28634 +Node: File format39716 +Ref: coded-dict-size41214 +Node: Examples42621 +Node: Buffer compression43582 +Node: Buffer decompression45095 +Node: File compression46502 +Node: File decompression47478 +Node: File compression mm48475 +Node: Skipping data errors51486 +Node: Problems52784 +Node: Concept index53345  End Tag Table diff --git a/doc/lzlib.texi b/doc/lzlib.texi index 23bbbfb..4600e0d 100644 --- a/doc/lzlib.texi +++ b/doc/lzlib.texi @@ -6,8 +6,8 @@ @finalout @c %**end of header -@set UPDATED 16 October 2024 -@set VERSION 1.15-pre2 +@set UPDATED 19 November 2024 +@set VERSION 1.15-rc1 @dircategory Compression @direntry @@ -66,42 +66,10 @@ distribute, and modify it. @uref{http://www.nongnu.org/lzip/lzlib.html,,Lzlib} is a data compression library providing in-memory LZMA compression and decompression functions, including integrity checking of the decompressed -data. The compressed data format used by the library is the lzip format. +data. The compressed data format used by the library is the +@uref{http://www.nongnu.org/lzip/lzip.html,,lzip} format. Lzlib is written in C and is distributed under a 2-clause BSD license. -The lzip file format is designed for data sharing and long-term archiving, -taking into account both data integrity and decoder availability: - -@itemize @bullet -@item -The lzip format provides very safe integrity checking and some data -recovery means. The program -@uref{http://www.nongnu.org/lzip/manual/lziprecover_manual.html#Data-safety,,lziprecover} -can repair bit flip errors (one of the most common forms of data corruption) -in lzip files, and provides data recovery capabilities, including -error-checked merging of damaged copies of a file. -@ifnothtml -@xref{Data safety,,,lziprecover}. -@end ifnothtml - -@item -The lzip format is as simple as possible (but not simpler). The lzip -manual provides the source code of a simple decompressor along with a -detailed explanation of how it works, so that with the only help of the -lzip manual it would be possible for a digital archaeologist to extract -the data from a lzip file long after quantum computers eventually -render LZMA obsolete. - -@item -Additionally the lzip reference implementation is copylefted, which -guarantees that it will remain free forever. -@end itemize - -A nice feature of the lzip format is that a corrupt byte is easier to repair -the nearer it is from the beginning of the file. Therefore, with the help of -lziprecover, losing an entire archive just because of a corrupt byte near -the beginning is a thing of the past. - The functions and variables forming the interface of the compression library are declared in the file @file{lzlib.h}. Usage examples of the library are given in the files @file{bbexample.c}, @file{ffexample.c}, and @@ -149,10 +117,10 @@ In spite of its name (Lempel-Ziv-Markov chain-Algorithm), LZMA is not a concrete algorithm; it is more like "any algorithm using the LZMA coding scheme". For example, the option @option{-0} of lzip uses the scheme in almost the simplest way possible; issuing the longest match it can find, or -a literal byte if it can't find a match. Inversely, a much more elaborated -way of finding coding sequences of minimum size than the one currently used -by lzip could be developed, and the resulting sequence could also be coded -using the LZMA coding scheme. +a literal byte if it can't find a match. Inversely, a more elaborate way of +finding coding sequences of minimum size than the one currently used by lzip +could be developed, and the resulting sequence could also be coded using the +LZMA coding scheme. Lzlib currently implements two variants of the LZMA algorithm: fast (used by option @option{-0} of minilzip) and normal (used by all other compression levels). @@ -308,7 +276,7 @@ except @samp{LZ_compress_open} whose return value must be checked by calling @samp{LZ_compress_errno} before using it. -@deftypefun {struct LZ_Encoder *} LZ_compress_open ( const int @var{dictionary_size}, const int @var{match_len_limit}, const unsigned long long @var{member_size} ) +@deftypefun {LZ_Encoder *} LZ_compress_open ( const int @var{dictionary_size}, const int @var{match_len_limit}, const unsigned long long @var{member_size} ) Initializes the internal stream state for compression and returns a pointer that can only be used as the @var{encoder} argument for the other LZ_compress functions, or a null pointer if the encoder could not @@ -344,7 +312,7 @@ the uncompressed size of the member from overflowing. @end deftypefun -@deftypefun int LZ_compress_close ( struct LZ_Encoder * const @var{encoder} ) +@deftypefun int LZ_compress_close ( LZ_Encoder * const @var{encoder} ) Frees all dynamically allocated data structures for this stream. This function discards any unprocessed input and does not flush any pending output. After a call to @samp{LZ_compress_close}, @var{encoder} can no @@ -353,7 +321,7 @@ It is safe to call @samp{LZ_compress_close} with a null argument. @end deftypefun -@deftypefun int LZ_compress_finish ( struct LZ_Encoder * const @var{encoder} ) +@deftypefun int LZ_compress_finish ( LZ_Encoder * const @var{encoder} ) Use this function to tell @samp{lzlib} that all the data for this member have already been written (with the function @samp{LZ_compress_write}). It is safe to call @samp{LZ_compress_finish} as many times as needed. @@ -363,7 +331,7 @@ started with @samp{LZ_compress_restart_member}. @end deftypefun -@deftypefun int LZ_compress_restart_member ( struct LZ_Encoder * const @var{encoder}, const unsigned long long @var{member_size} ) +@deftypefun int LZ_compress_restart_member ( LZ_Encoder * const @var{encoder}, const unsigned long long @var{member_size} ) Use this function to start a new member in a multimember data stream. Call this function only after @samp{LZ_compress_member_finished} indicates that the current member has been fully read (with the function @@ -373,18 +341,18 @@ the current member has been fully read (with the function @anchor{sync_flush} -@deftypefun int LZ_compress_sync_flush ( struct LZ_Encoder * const @var{encoder} ) +@deftypefun int LZ_compress_sync_flush ( LZ_Encoder * const @var{encoder} ) Use this function to make available to @samp{LZ_compress_read} all the data already written with the function @samp{LZ_compress_write}. First call @samp{LZ_compress_sync_flush}. Then call @samp{LZ_compress_read} until it returns 0. -This function writes at least one LZMA marker @samp{3} ("Sync Flush" marker) +This function writes at least one LZMA marker @samp{3} ('Sync Flush' marker) to the compressed output. Note that the sync flush marker is not allowed in lzip files; it is a device for interactive communication between applications using lzlib, but is useless and wasteful in a file, and is excluded from the media type @samp{application/lzip}. The LZMA marker -@samp{2} ("End Of Stream" marker) is the only marker allowed in lzip files. +@samp{2} ('End Of Stream' marker) is the only marker allowed in lzip files. @xref{File format}. Repeated use of @samp{LZ_compress_sync_flush} may degrade compression @@ -401,7 +369,7 @@ are more bytes available than those needed to complete @var{member_size}, @end deftypefun -@deftypefun int LZ_compress_read ( struct LZ_Encoder * const @var{encoder}, uint8_t * const @var{buffer}, const int @var{size} ) +@deftypefun int LZ_compress_read ( LZ_Encoder * const @var{encoder}, uint8_t * const @var{buffer}, const int @var{size} ) Reads up to @var{size} bytes from the stream pointed to by @var{encoder}, storing the results in @var{buffer}. If @w{LZ_API_VERSION >= 1012}, @var{buffer} may be a null pointer, in which case the bytes read are @@ -415,7 +383,7 @@ not an error. @end deftypefun -@deftypefun int LZ_compress_write ( struct LZ_Encoder * const @var{encoder}, uint8_t * const @var{buffer}, const int @var{size} ) +@deftypefun int LZ_compress_write ( LZ_Encoder * const @var{encoder}, uint8_t * const @var{buffer}, const int @var{size} ) Writes up to @var{size} bytes from @var{buffer} to the stream pointed to by @var{encoder}. Returns the number of bytes actually written. This might be less than @var{size}. Note that writing less than @var{size} bytes is not an @@ -423,7 +391,7 @@ error. @end deftypefun -@deftypefun int LZ_compress_write_size ( struct LZ_Encoder * const @var{encoder} ) +@deftypefun int LZ_compress_write_size ( LZ_Encoder * const @var{encoder} ) Returns the maximum number of bytes that can be immediately written through @samp{LZ_compress_write}. For efficiency reasons, once the input buffer is full and @samp{LZ_compress_write_size} returns 0, almost all the buffer must @@ -436,44 +404,44 @@ accept a @var{size} up to the returned number of bytes. @end deftypefun -@deftypefun {enum LZ_Errno} LZ_compress_errno ( struct LZ_Encoder * const @var{encoder} ) +@deftypefun {LZ_Errno} LZ_compress_errno ( LZ_Encoder * const @var{encoder} ) Returns the current error code for @var{encoder}. @xref{Error codes}. It is safe to call @samp{LZ_compress_errno} with a null argument, in which case it returns @samp{LZ_bad_argument}. @end deftypefun -@deftypefun int LZ_compress_finished ( struct LZ_Encoder * const @var{encoder} ) +@deftypefun int LZ_compress_finished ( LZ_Encoder * const @var{encoder} ) Returns 1 if all the data have been read and @samp{LZ_compress_close} can be safely called. Otherwise it returns 0. @samp{LZ_compress_finished} implies @samp{LZ_compress_member_finished}. @end deftypefun -@deftypefun int LZ_compress_member_finished ( struct LZ_Encoder * const @var{encoder} ) +@deftypefun int LZ_compress_member_finished ( LZ_Encoder * const @var{encoder} ) Returns 1 if the current member, in a multimember data stream, has been fully read and @samp{LZ_compress_restart_member} can be safely called. Otherwise it returns 0. @end deftypefun -@deftypefun {unsigned long long} LZ_compress_data_position ( struct LZ_Encoder * const @var{encoder} ) +@deftypefun {unsigned long long} LZ_compress_data_position ( LZ_Encoder * const @var{encoder} ) Returns the number of input bytes already compressed in the current member. @end deftypefun -@deftypefun {unsigned long long} LZ_compress_member_position ( struct LZ_Encoder * const @var{encoder} ) +@deftypefun {unsigned long long} LZ_compress_member_position ( LZ_Encoder * const @var{encoder} ) Returns the number of compressed bytes already produced, but perhaps not yet read, in the current member. @end deftypefun -@deftypefun {unsigned long long} LZ_compress_total_in_size ( struct LZ_Encoder * const @var{encoder} ) +@deftypefun {unsigned long long} LZ_compress_total_in_size ( LZ_Encoder * const @var{encoder} ) Returns the total number of input bytes already compressed. @end deftypefun -@deftypefun {unsigned long long} LZ_compress_total_out_size ( struct LZ_Encoder * const @var{encoder} ) +@deftypefun {unsigned long long} LZ_compress_total_out_size ( LZ_Encoder * const @var{encoder} ) Returns the total number of compressed bytes already produced, but perhaps not yet read. @end deftypefun @@ -489,7 +457,7 @@ except @samp{LZ_decompress_open} whose return value must be checked by calling @samp{LZ_decompress_errno} before using it. -@deftypefun {struct LZ_Decoder *} LZ_decompress_open ( void ) +@deftypefun {LZ_Decoder *} LZ_decompress_open ( void ) Initializes the internal stream state for decompression and returns a pointer that can only be used as the @var{decoder} argument for the other LZ_decompress functions, or a null pointer if the decoder could not be @@ -502,7 +470,7 @@ the returned pointer must not be used and should be freed with @end deftypefun -@deftypefun int LZ_decompress_close ( struct LZ_Decoder * const @var{decoder} ) +@deftypefun int LZ_decompress_close ( LZ_Decoder * const @var{decoder} ) Frees all dynamically allocated data structures for this stream. This function discards any unprocessed input and does not flush any pending output. After a call to @samp{LZ_decompress_close}, @var{decoder} can no @@ -511,7 +479,7 @@ It is safe to call @samp{LZ_decompress_close} with a null argument. @end deftypefun -@deftypefun int LZ_decompress_finish ( struct LZ_Decoder * const @var{decoder} ) +@deftypefun int LZ_decompress_finish ( LZ_Decoder * const @var{decoder} ) Use this function to tell @samp{lzlib} that all the data for this stream have already been written (with the function @samp{LZ_decompress_write}). It is safe to call @samp{LZ_decompress_finish} as many times as needed. @@ -521,14 +489,14 @@ detecting a truncated member. @end deftypefun -@deftypefun int LZ_decompress_reset ( struct LZ_Decoder * const @var{decoder} ) +@deftypefun int LZ_decompress_reset ( LZ_Decoder * const @var{decoder} ) Resets the internal state of @var{decoder} as it was just after opening it with the function @samp{LZ_decompress_open}. Data stored in the internal buffers are discarded. Position counters are set to 0. @end deftypefun -@deftypefun int LZ_decompress_sync_to_member ( struct LZ_Decoder * const @var{decoder} ) +@deftypefun int LZ_decompress_sync_to_member ( LZ_Decoder * const @var{decoder} ) Resets the error state of @var{decoder} and enters a search state that lasts until a new member header (or the end of the stream) is found. After a successful call to @samp{LZ_decompress_sync_to_member}, data written with @@ -542,7 +510,7 @@ does nothing. @end deftypefun -@deftypefun int LZ_decompress_read ( struct LZ_Decoder * const @var{decoder}, uint8_t * const @var{buffer}, const int @var{size} ) +@deftypefun int LZ_decompress_read ( LZ_Decoder * const @var{decoder}, uint8_t * const @var{buffer}, const int @var{size} ) Reads up to @var{size} bytes from the stream pointed to by @var{decoder}, storing the results in @var{buffer}. If @w{LZ_API_VERSION >= 1012}, @var{buffer} may be a null pointer, in which case the bytes read are @@ -574,7 +542,7 @@ recover as much data as possible from each damaged member. @end deftypefun -@deftypefun int LZ_decompress_write ( struct LZ_Decoder * const @var{decoder}, uint8_t * const @var{buffer}, const int @var{size} ) +@deftypefun int LZ_decompress_write ( LZ_Decoder * const @var{decoder}, uint8_t * const @var{buffer}, const int @var{size} ) Writes up to @var{size} bytes from @var{buffer} to the stream pointed to by @var{decoder}. Returns the number of bytes actually written. This might be less than @var{size}. Note that writing less than @var{size} bytes is not an @@ -582,7 +550,7 @@ error. @end deftypefun -@deftypefun int LZ_decompress_write_size ( struct LZ_Decoder * const @var{decoder} ) +@deftypefun int LZ_decompress_write_size ( LZ_Decoder * const @var{decoder} ) Returns the maximum number of bytes that can be immediately written through @samp{LZ_decompress_write}. This number varies smoothly; each compressed byte consumed may be overwritten immediately, increasing by 1 the value @@ -593,21 +561,21 @@ accept a @var{size} up to the returned number of bytes. @end deftypefun -@deftypefun {enum LZ_Errno} LZ_decompress_errno ( struct LZ_Decoder * const @var{decoder} ) +@deftypefun {LZ_Errno} LZ_decompress_errno ( LZ_Decoder * const @var{decoder} ) Returns the current error code for @var{decoder}. @xref{Error codes}. It is safe to call @samp{LZ_decompress_errno} with a null argument, in which case it returns @samp{LZ_bad_argument}. @end deftypefun -@deftypefun int LZ_decompress_finished ( struct LZ_Decoder * const @var{decoder} ) +@deftypefun int LZ_decompress_finished ( LZ_Decoder * const @var{decoder} ) Returns 1 if all the data have been read and @samp{LZ_decompress_close} can be safely called. Otherwise it returns 0. @samp{LZ_decompress_finished} does not imply @samp{LZ_decompress_member_finished}. @end deftypefun -@deftypefun int LZ_decompress_member_finished ( struct LZ_Decoder * const @var{decoder} ) +@deftypefun int LZ_decompress_member_finished ( LZ_Decoder * const @var{decoder} ) Returns 1 if the previous call to @samp{LZ_decompress_read} finished reading the current member, indicating that final values for the member are available through @samp{LZ_decompress_data_crc}, @samp{LZ_decompress_data_position}, @@ -615,40 +583,40 @@ and @samp{LZ_decompress_member_position}. Otherwise it returns 0. @end deftypefun -@deftypefun int LZ_decompress_member_version ( struct LZ_Decoder * const @var{decoder} ) +@deftypefun int LZ_decompress_member_version ( LZ_Decoder * const @var{decoder} ) Returns the version of the current member, read from the member header. @end deftypefun -@deftypefun int LZ_decompress_dictionary_size ( struct LZ_Decoder * const @var{decoder} ) +@deftypefun int LZ_decompress_dictionary_size ( LZ_Decoder * const @var{decoder} ) Returns the dictionary size of the current member, read from the member header. @end deftypefun -@deftypefun {unsigned} LZ_decompress_data_crc ( struct LZ_Decoder * const @var{decoder} ) +@deftypefun {unsigned} LZ_decompress_data_crc ( LZ_Decoder * const @var{decoder} ) Returns the 32 bit Cyclic Redundancy Check of the data decompressed from the current member. The value returned is valid only when @samp{LZ_decompress_member_finished} returns 1. @end deftypefun -@deftypefun {unsigned long long} LZ_decompress_data_position ( struct LZ_Decoder * const @var{decoder} ) +@deftypefun {unsigned long long} LZ_decompress_data_position ( LZ_Decoder * const @var{decoder} ) Returns the number of decompressed bytes already produced, but perhaps not yet read, in the current member. @end deftypefun -@deftypefun {unsigned long long} LZ_decompress_member_position ( struct LZ_Decoder * const @var{decoder} ) +@deftypefun {unsigned long long} LZ_decompress_member_position ( LZ_Decoder * const @var{decoder} ) Returns the number of input bytes already decompressed in the current member. @end deftypefun -@deftypefun {unsigned long long} LZ_decompress_total_in_size ( struct LZ_Decoder * const @var{decoder} ) +@deftypefun {unsigned long long} LZ_decompress_total_in_size ( LZ_Decoder * const @var{decoder} ) Returns the total number of input bytes already decompressed. @end deftypefun -@deftypefun {unsigned long long} LZ_decompress_total_out_size ( struct LZ_Decoder * const @var{decoder} ) +@deftypefun {unsigned long long} LZ_decompress_total_out_size ( LZ_Decoder * const @var{decoder} ) Returns the total number of decompressed bytes already produced, but perhaps not yet read. @end deftypefun @@ -671,37 +639,38 @@ to determine whether a call failed. If the call failed, then you can examine @samp{LZ_(de)compress_errno}. The error codes are defined in the header file @file{lzlib.h}. +@samp{LZ_Errno} is an enum type: -@deftypevr Constant {enum LZ_Errno} LZ_ok +@deftypevr Constant {LZ_Errno} LZ_ok The value of this constant is 0 and is used to indicate that there is no error. @end deftypevr -@deftypevr Constant {enum LZ_Errno} LZ_bad_argument +@deftypevr Constant {LZ_Errno} LZ_bad_argument At least one of the arguments passed to the library function was invalid. @end deftypevr -@deftypevr Constant {enum LZ_Errno} LZ_mem_error -No memory available. The system cannot allocate more virtual memory -because its capacity is full. +@deftypevr Constant {LZ_Errno} LZ_mem_error +No memory available. The system cannot allocate more virtual memory because +its capacity is full. @end deftypevr -@deftypevr Constant {enum LZ_Errno} LZ_sequence_error +@deftypevr Constant {LZ_Errno} LZ_sequence_error A library function was called in the wrong order. For example @samp{LZ_compress_restart_member} was called before -@samp{LZ_compress_member_finished} indicates that the current member is +@samp{LZ_compress_member_finished} indicated that the current member is finished. @end deftypevr -@deftypevr Constant {enum LZ_Errno} LZ_header_error +@deftypevr Constant {LZ_Errno} LZ_header_error An invalid member header (one with the wrong magic bytes) was read. If this happens at the end of the data stream it may indicate trailing data. @end deftypevr -@deftypevr Constant {enum LZ_Errno} LZ_unexpected_eof +@deftypevr Constant {LZ_Errno} LZ_unexpected_eof The end of the data stream was reached in the middle of a member. @end deftypevr -@deftypevr Constant {enum LZ_Errno} LZ_data_error +@deftypevr Constant {LZ_Errno} LZ_data_error The data stream is corrupt. If @samp{LZ_decompress_member_position} is 6 or less, it indicates either a format version not supported, an invalid dictionary size, a nonzero first LZMA byte, a corrupt header in a multimember @@ -710,7 +679,7 @@ Lziprecover can be used to repair some of these errors and to remove conflicting trailing data from a file. @end deftypevr -@deftypevr Constant {enum LZ_Errno} LZ_library_error +@deftypevr Constant {LZ_Errno} LZ_library_error A bug was detected in the library. Please, report it. @xref{Problems}. @end deftypevr @@ -719,11 +688,11 @@ A bug was detected in the library. Please, report it. @xref{Problems}. @chapter Error messages @cindex error messages -@deftypefun {const char *} LZ_strerror ( const enum LZ_Errno @var{lz_errno} ) -Returns the standard error message for a given error code. The messages -are fairly short; there are no multi-line messages or embedded newlines. -This function makes it easy for your program to report informative error -messages about the failure of a library call. +@deftypefun {const char *} LZ_strerror ( const LZ_Errno @var{lz_errno} ) +Returns the error message corresponding to the error code @var{lz_errno}. +The messages are fairly short; there are no multi-line messages or embedded +newlines. This function makes it easy for your program to report informative +error messages about the failure of a library call. The value of @var{lz_errno} normally comes from a call to @samp{LZ_(de)compress_errno}. @@ -735,23 +704,25 @@ The value of @var{lz_errno} normally comes from a call to @cindex invoking @cindex options -Minilzip is a test program for the compression library lzlib, compatible -(interoperable) with lzip 1.4 or newer. Minilzip is not intended to be -installed because lzip has more features, but minilzip is well tested and -you can use it as your main compressor if so you wish. +Minilzip is a test program for the compression library lzlib. Minilzip is +not intended to be installed because lzip has more features, but minilzip is +well tested and you can use it as your main compressor if so you wish. +@ifnothtml +@xref{Top,lzip,,lzip}. +@end ifnothtml @uref{http://www.nongnu.org/lzip/lzip.html,,Lzip} is a lossless data compressor with a user interface similar to the one -of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov -chain-Algorithm' (LZMA) stream format to maximize interoperability. The -maximum dictionary size is 512 MiB so that any lzip file can be decompressed -on 32-bit machines. Lzip provides accurate and robust 3-factor integrity -checking. Lzip can compress about as fast as gzip @w{(lzip -0)} or compress most -files more than bzip2 @w{(lzip -9)}. Decompression speed is intermediate between -gzip and bzip2. Lzip provides better data recovery capabilities than gzip -and bzip2. Lzip has been designed, written, and tested with great care to -replace gzip and bzip2 as the standard general-purpose compressed format for -Unix-like systems. +of gzip or bzip2. Lzip uses a simplified form of LZMA (Lempel-Ziv-Markov +chain-Algorithm) designed to achieve complete interoperability between +implementations. The maximum dictionary size is 512 MiB so that any lzip +file can be decompressed on 32-bit machines. Lzip provides accurate and +robust 3-factor integrity checking. @w{@samp{lzip -0}} compresses about as fast as +gzip, while @w{@samp{lzip -9}} compresses most files more than bzip2. Decompression +speed is intermediate between gzip and bzip2. Lzip provides better data +recovery capabilities than gzip and bzip2. Lzip has been designed, written, +and tested with great care to replace gzip and bzip2 as general-purpose +compressed format for Unix-like systems. @noindent The format for running minilzip is: @@ -769,9 +740,9 @@ prepend @file{./} to any file name beginning with a hyphen, or use @samp{--}. @noindent minilzip supports the following -@uref{http://www.nongnu.org/arg-parser/manual/arg_parser_manual.html#Argument-syntax,,options}: +@uref{http://www.nongnu.org/lzip/manual/plzip_manual.html#Argument-syntax,,options}: @ifnothtml -@xref{Argument syntax,,,arg_parser}. +@xref{Argument syntax,,,plzip}. @end ifnothtml @table @code @@ -792,9 +763,10 @@ garbage that can be safely ignored. @item -b @var{bytes} @itemx --member-size=@var{bytes} -When compressing, set the member size limit to @var{bytes}. It is advisable -to keep members smaller than RAM size so that they can be repaired with -lziprecover in case of corruption. A small member size may degrade +When compressing, set the member size limit to @var{bytes}. If @var{bytes} +is smaller than the compressed size, a multimember file is produced. It is +advisable to keep members smaller than RAM size so that they can be repaired +with lziprecover in case of corruption. A small member size may degrade compression ratio, so use it only when needed. Valid values range from @w{100 kB} to @w{2 PiB}. Defaults to @w{2 PiB}. @@ -816,7 +788,8 @@ already exists and @option{--force} has not been specified, minilzip continues decompressing the rest of the files and exits with error status 1. If a file fails to decompress, or is a terminal, minilzip exits immediately with error status 2 without decompressing the rest of the files. A terminal is -considered an uncompressed file, and therefore invalid. +considered an uncompressed file, and therefore invalid. A multimember file +with one or more empty members is accepted if redirected to standard input. @item -f @itemx --force @@ -870,6 +843,8 @@ to it. For maximum compression you should use a dictionary size limit as large as possible, but keep in mind that the decompression memory requirement is affected at compression time by the choice of dictionary size limit. +The dictionary size used for decompression is the same dictionary size used +for compression. @item -S @var{bytes} @itemx --volume-size=@var{bytes} @@ -889,7 +864,8 @@ together with @option{-v} to see information about the files. If a file fails the test, does not exist, can't be opened, or is a terminal, minilzip continues testing the rest of the files. A final diagnostic is shown at verbosity level 1 or higher if any file fails the test when testing multiple -files. +files. A multimember file with one or more empty members is accepted if +redirected to standard input. @item -v @itemx --verbose @@ -936,8 +912,8 @@ Aliases for GNU gzip compatibility. @item --loose-trailing When decompressing or testing, allow trailing data whose first bytes are so similar to the magic bytes of a lzip header that they can be confused -with a corrupt header. Use this option if a file triggers a "corrupt -header" error and the cause is not indeed a corrupt header. +with a corrupt header. Use this option if a file triggers a 'corrupt +header' error and the cause is not indeed a corrupt header. @item --check-lib Compare the @uref{#Library-version,,version of lzlib} used to compile @@ -1044,7 +1020,7 @@ Example: 0xD3 = 2^19 - 6 * 2^15 = 512 KiB - 6 * 32 KiB = 320 KiB@* Valid values for dictionary size range from 4 KiB to 512 MiB. @item LZMA stream -The LZMA stream, terminated by an "End Of Stream" marker. Uses default values +The LZMA stream, terminated by an 'End Of Stream' marker. Uses default values for encoder properties. @ifnothtml @xref{Stream format,,,lzip}, @@ -1054,8 +1030,8 @@ See @uref{http://www.nongnu.org/lzip/manual/lzip_manual.html#Stream-format,,Stream format} @end ifhtml for a complete description.@* -Lzip only uses the LZMA marker @samp{2} ("End Of Stream" marker). Lzlib -also uses the LZMA marker @samp{3} ("Sync Flush" marker). @xref{sync_flush}. +Lzip only uses the LZMA marker @samp{2} ('End Of Stream' marker). Lzlib +also uses the LZMA marker @samp{3} ('Sync Flush' marker). @xref{sync_flush}. @item CRC32 (4 bytes) Cyclic Redundancy Check (CRC) of the original uncompressed data. @@ -1115,7 +1091,7 @@ bool bbcompress( const uint8_t * const inbuf, const int insize, { int inpos = 0, outpos = 0; bool error = false; - struct LZ_Encoder * const encoder = + LZ_Encoder * const encoder = LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX ); if( !encoder || LZ_compress_errno( encoder ) != LZ_ok ) { LZ_compress_close( encoder ); return false; } @@ -1159,7 +1135,7 @@ bool bbdecompress( const uint8_t * const inbuf, const int insize, { int inpos = 0, outpos = 0; bool error = false; - struct LZ_Decoder * const decoder = LZ_decompress_open(); + LZ_Decoder * const decoder = LZ_decompress_open(); if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok ) { LZ_decompress_close( decoder ); return false; } @@ -1191,7 +1167,7 @@ bool bbdecompress( const uint8_t * const inbuf, const int insize, File-to-file compression using LZ_compress_write_size. @verbatim -int ffcompress( struct LZ_Encoder * const encoder, +int ffcompress( LZ_Encoder * const encoder, FILE * const infile, FILE * const outfile ) { enum { buffer_size = 16384 }; @@ -1225,7 +1201,7 @@ int ffcompress( struct LZ_Encoder * const encoder, File-to-file decompression using LZ_decompress_write_size. @verbatim -int ffdecompress( struct LZ_Decoder * const decoder, +int ffdecompress( LZ_Decoder * const decoder, FILE * const infile, FILE * const outfile ) { enum { buffer_size = 16384 }; @@ -1265,8 +1241,7 @@ int ffmmcompress( FILE * const infile, FILE * const outfile ) enum { buffer_size = 16384, member_size = 4096 }; uint8_t buffer[buffer_size]; bool done = false; - struct LZ_Encoder * const encoder = - LZ_compress_open( 65535, 16, member_size ); + LZ_Encoder * const encoder = LZ_compress_open( 65535, 16, member_size ); if( !encoder || LZ_compress_errno( encoder ) != LZ_ok ) { fputs( "ffexample: Not enough memory.\n", stderr ); LZ_compress_close( encoder ); return 1; } @@ -1306,7 +1281,7 @@ Example 2: Multimember compression (user-restarted members). for each line of text terminated by a newline character or by EOF. Return 0 if success, 1 if error. */ -int fflfcompress( struct LZ_Encoder * const encoder, +int fflfcompress( LZ_Encoder * const encoder, FILE * const infile, FILE * const outfile ) { enum { buffer_size = 16384 }; @@ -1353,7 +1328,7 @@ int fflfcompress( struct LZ_Encoder * const encoder, next member in case of data error, including the automatic removal of leading garbage. */ -int ffrsdecompress( struct LZ_Decoder * const decoder, +int ffrsdecompress( LZ_Decoder * const decoder, FILE * const infile, FILE * const outfile ) { enum { buffer_size = 16384 }; diff --git a/doc/minilzip.1 b/doc/minilzip.1 index c60e528..8d35853 100644 --- a/doc/minilzip.1 +++ b/doc/minilzip.1 @@ -1,25 +1,26 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.2. -.TH MINILZIP "1" "October 2024" "minilzip 1.15-pre2" "User Commands" +.TH MINILZIP "1" "November 2024" "minilzip 1.15-rc1" "User Commands" .SH NAME minilzip \- reduces the size of files .SH SYNOPSIS .B minilzip [\fI\,options\/\fR] [\fI\,files\/\fR] .SH DESCRIPTION -Minilzip is a test program for the compression library lzlib, compatible -(interoperable) with lzip 1.4 or newer. +Minilzip is a test program for the compression library lzlib. Minilzip is +not intended to be installed because lzip has more features, but minilzip is +well tested and you can use it as your main compressor if so you wish. .PP Lzip is a lossless data compressor with a user interface similar to the one -of gzip or bzip2. Lzip uses a simplified form of the 'Lempel\-Ziv\-Markov -chain\-Algorithm' (LZMA) stream format to maximize interoperability. The -maximum dictionary size is 512 MiB so that any lzip file can be decompressed -on 32\-bit machines. Lzip provides accurate and robust 3\-factor integrity -checking. Lzip can compress about as fast as gzip (lzip \fB\-0\fR) or compress most -files more than bzip2 (lzip \fB\-9\fR). Decompression speed is intermediate between -gzip and bzip2. Lzip provides better data recovery capabilities than gzip -and bzip2. Lzip has been designed, written, and tested with great care to -replace gzip and bzip2 as the standard general\-purpose compressed format for -Unix\-like systems. +of gzip or bzip2. Lzip uses a simplified form of LZMA (Lempel\-Ziv\-Markov +chain\-Algorithm) designed to achieve complete interoperability between +implementations. The maximum dictionary size is 512 MiB so that any lzip +file can be decompressed on 32\-bit machines. Lzip provides accurate and +robust 3\-factor integrity checking. 'lzip \fB\-0\fR' compresses about as fast as +gzip, while 'lzip \fB\-9\fR' compresses most files more than bzip2. Decompression +speed is intermediate between gzip and bzip2. Lzip provides better data +recovery capabilities than gzip and bzip2. Lzip has been designed, written, +and tested with great care to replace gzip and bzip2 as general\-purpose +compressed format for Unix\-like systems. .SH OPTIONS .TP \fB\-h\fR, \fB\-\-help\fR @@ -32,7 +33,7 @@ output version information and exit exit with error status if trailing data .TP \fB\-b\fR, \fB\-\-member\-size=\fR -set member size limit in bytes +set member size limit of multimember files .TP \fB\-c\fR, \fB\-\-stdout\fR write to standard output, keep input files @@ -120,7 +121,7 @@ License GPLv2+: GNU GPL version 2 or later .br This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. -Using lzlib 1.15\-pre2 +Using lzlib 1.15\-rc1 Using LZ_API_VERSION = 1015 .SH "SEE ALSO" The full documentation for diff --git a/encoder.c b/encoder.c index c6190ea..30254ce 100644 --- a/encoder.c +++ b/encoder.c @@ -17,7 +17,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ -static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs ) +static int LZe_get_match_pairs( LZ_encoder * const e, Pair * pairs ) { int32_t * ptr0 = e->eb.mb.pos_array + ( e->eb.mb.cyclic_pos << 1 ); int32_t * ptr1 = ptr0 + 1; @@ -31,8 +31,8 @@ static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs int maxlen = 3; /* only used if pairs != 0 */ int num_pairs = 0; - const int min_pos = ( e->eb.mb.pos > e->eb.mb.dictionary_size ) ? - e->eb.mb.pos - e->eb.mb.dictionary_size : 0; + const int min_pos = (e->eb.mb.pos > e->eb.mb.dictionary_size) ? + e->eb.mb.pos - e->eb.mb.dictionary_size : 0; const uint8_t * const data = Mb_ptr_to_current_pos( &e->eb.mb ); unsigned tmp = crc32[data[0]] ^ data[1]; @@ -121,7 +121,7 @@ static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs } -static void LZe_update_distance_prices( struct LZ_encoder * const e ) +static void LZe_update_distance_prices( LZ_encoder * const e ) { int dis, len_state; for( dis = start_dis_model; dis < modeled_distances; ++dis ) @@ -160,7 +160,7 @@ static void LZe_update_distance_prices( struct LZ_encoder * const e ) ( trials[0].dis4 == -1 ) means literal. A match/rep longer or equal than match_len_limit finishes the sequence. */ -static int LZe_sequence_optimizer( struct LZ_encoder * const e, +static int LZe_sequence_optimizer( LZ_encoder * const e, const int reps[num_rep_distances], const State state ) { @@ -174,7 +174,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, } else num_pairs = LZe_read_match_distances( e ); - const int main_len = ( num_pairs > 0 ) ? e->pairs[num_pairs-1].len : 0; + const int main_len = (num_pairs > 0) ? e->pairs[num_pairs-1].len : 0; int replens[num_rep_distances]; int rep_index = 0; @@ -270,7 +270,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, } const int num_pairs = LZe_read_match_distances( e ); - const int newlen = ( num_pairs > 0 ) ? e->pairs[num_pairs-1].len : 0; + const int newlen = (num_pairs > 0) ? e->pairs[num_pairs-1].len : 0; if( newlen >= e->match_len_limit ) { e->pending_num_pairs = num_pairs; @@ -279,7 +279,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, } /* give final values to current trial */ - struct Trial * cur_trial = &e->trials[cur]; + Trial * cur_trial = &e->trials[cur]; State cur_state; { const int dis4 = cur_trial->dis4; @@ -324,7 +324,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, next_price += LZeb_price_matched( &e->eb, prev_byte, cur_byte, match_byte ); /* try last updates to next trial */ - struct Trial * next_trial = &e->trials[cur+1]; + Trial * next_trial = &e->trials[cur+1]; Tr_update( next_trial, next_price, -1, cur ); /* literal */ @@ -466,12 +466,12 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e, } -static bool LZe_encode_member( struct LZ_encoder * const e ) +static bool LZe_encode_member( LZ_encoder * const e ) { - const bool best = ( e->match_len_limit > 12 ); + const bool best = e->match_len_limit > 12; const int dis_price_count = best ? 1 : 512; const int align_price_count = best ? 1 : dis_align_size; - const int price_count = ( e->match_len_limit > 36 ) ? 1013 : 4093; + const int price_count = (e->match_len_limit > 36) ? 1013 : 4093; int i; State * const state = &e->eb.state; @@ -522,7 +522,7 @@ static bool LZe_encode_member( struct LZ_encoder * const e ) const int len = e->trials[i].price; int dis = e->trials[i].dis4; - bool bit = ( dis < 0 ); + bool bit = dis < 0; Re_encode_bit( &e->eb.renc, &e->eb.bm_match[*state][pos_state], !bit ); if( bit ) /* literal byte */ { @@ -541,11 +541,11 @@ static bool LZe_encode_member( struct LZ_encoder * const e ) { CRC32_update_buf( &e->eb.crc, Mb_ptr_to_current_pos( &e->eb.mb ) - ahead, len ); mtf_reps( dis, e->eb.reps ); - bit = ( dis < num_rep_distances ); + bit = dis < num_rep_distances; Re_encode_bit( &e->eb.renc, &e->eb.bm_rep[*state], bit ); if( bit ) /* repeated match */ { - bit = ( dis == 0 ); + bit = dis == 0; Re_encode_bit( &e->eb.renc, &e->eb.bm_rep0[*state], !bit ); if( bit ) Re_encode_bit( &e->eb.renc, &e->eb.bm_len[*state][pos_state], len > 1 ); diff --git a/encoder.h b/encoder.h index edac815..fd5a312 100644 --- a/encoder.h +++ b/encoder.h @@ -17,16 +17,16 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ -struct Len_prices +typedef struct Len_prices { - const struct Len_model * lm; + const Len_model * lm; int len_symbols; int count; int prices[pos_states][max_len_symbols]; int counters[pos_states]; /* may decrement below 0 */ - }; + } Len_prices; -static inline void Lp_update_low_mid_prices( struct Len_prices * const lp, +static inline void Lp_update_low_mid_prices( Len_prices * const lp, const int pos_state ) { int * const pps = lp->prices[pos_state]; @@ -41,7 +41,7 @@ static inline void Lp_update_low_mid_prices( struct Len_prices * const lp, price_symbol3( lp->lm->bm_mid[pos_state], len - len_low_symbols ); } -static inline void Lp_update_high_prices( struct Len_prices * const lp ) +static inline void Lp_update_high_prices( Len_prices * const lp ) { const int tmp = price1( lp->lm->choice1 ) + price1( lp->lm->choice2 ); int len; @@ -52,24 +52,23 @@ static inline void Lp_update_high_prices( struct Len_prices * const lp ) price_symbol8( lp->lm->bm_high, len - len_low_symbols - len_mid_symbols ); } -static inline void Lp_reset( struct Len_prices * const lp ) +static inline void Lp_reset( Len_prices * const lp ) { int i; for( i = 0; i < pos_states; ++i ) lp->counters[i] = 0; } -static inline void Lp_init( struct Len_prices * const lp, - const struct Len_model * const lm, +static inline void Lp_init( Len_prices * const lp, const Len_model * const lm, const int match_len_limit ) { lp->lm = lm; lp->len_symbols = match_len_limit + 1 - min_match_len; - lp->count = ( match_len_limit > 12 ) ? 1 : lp->len_symbols; + lp->count = (match_len_limit > 12) ? 1 : lp->len_symbols; Lp_reset( lp ); } -static inline void Lp_decrement_counter( struct Len_prices * const lp, +static inline void Lp_decrement_counter( Len_prices * const lp, const int pos_state ) { --lp->counters[pos_state]; } -static inline void Lp_update_prices( struct Len_prices * const lp ) +static inline void Lp_update_prices( Len_prices * const lp ) { int pos_state; bool high_pending = false; @@ -81,23 +80,23 @@ static inline void Lp_update_prices( struct Len_prices * const lp ) Lp_update_high_prices( lp ); } -static inline int Lp_price( const struct Len_prices * const lp, +static inline int Lp_price( const Len_prices * const lp, const int len, const int pos_state ) { return lp->prices[pos_state][len - min_match_len]; } -struct Pair /* distance-length pair */ +typedef struct Pair /* distance-length pair */ { int dis; int len; - }; + } Pair; enum { infinite_price = 0x0FFFFFFF, max_num_trials = 1 << 13, single_step_trial = -2, dual_step_trial = -1 }; -struct Trial +typedef struct Trial { State state; int price; /* dual use var; cumulative price, match length */ @@ -107,9 +106,9 @@ struct Trial /* -1 literal + rep0 */ /* >= 0 ( rep or match ) + literal + rep0 */ int reps[num_rep_distances]; - }; + } Trial; -static inline void Tr_update( struct Trial * const trial, const int pr, +static inline void Tr_update( Trial * const trial, const int pr, const int distance4, const int p_i ) { if( pr < trial->price ) @@ -117,7 +116,7 @@ static inline void Tr_update( struct Trial * const trial, const int pr, trial->prev_index2 = single_step_trial; } } -static inline void Tr_update2( struct Trial * const trial, const int pr, +static inline void Tr_update2( Trial * const trial, const int pr, const int p_i ) { if( pr < trial->price ) @@ -125,7 +124,7 @@ static inline void Tr_update2( struct Trial * const trial, const int pr, trial->prev_index2 = dual_step_trial; } } -static inline void Tr_update3( struct Trial * const trial, const int pr, +static inline void Tr_update3( Trial * const trial, const int pr, const int distance4, const int p_i, const int p_i2 ) { @@ -135,16 +134,16 @@ static inline void Tr_update3( struct Trial * const trial, const int pr, } -struct LZ_encoder +typedef struct LZ_encoder { - struct LZ_encoder_base eb; + LZ_encoder_base eb; int cycles; int match_len_limit; - struct Len_prices match_len_prices; - struct Len_prices rep_len_prices; + Len_prices match_len_prices; + Len_prices rep_len_prices; int pending_num_pairs; - struct Pair pairs[max_match_len+1]; - struct Trial trials[max_num_trials]; + Pair pairs[max_match_len+1]; + Trial trials[max_num_trials]; int dis_slot_prices[len_states][2*max_dictionary_bits]; int dis_prices[len_states][modeled_distances]; @@ -154,10 +153,9 @@ struct LZ_encoder int dis_price_counter; int align_price_counter; bool been_flushed; - }; + } LZ_encoder; -static inline bool Mb_dec_pos( struct Matchfinder_base * const mb, - const int ahead ) +static inline bool Mb_dec_pos( Matchfinder_base * const mb, const int ahead ) { if( ahead < 0 || mb->pos < ahead ) return false; mb->pos -= ahead; @@ -166,7 +164,7 @@ static inline bool Mb_dec_pos( struct Matchfinder_base * const mb, return true; } -static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs ); +static int LZe_get_match_pairs( LZ_encoder * const e, Pair * pairs ); /* move-to-front dis in/into reps; do nothing if( dis4 <= 0 ) */ static inline void mtf_reps( const int dis4, int reps[num_rep_distances] ) @@ -184,13 +182,13 @@ static inline void mtf_reps( const int dis4, int reps[num_rep_distances] ) } } -static inline int LZeb_price_shortrep( const struct LZ_encoder_base * const eb, +static inline int LZeb_price_shortrep( const LZ_encoder_base * const eb, const State state, const int pos_state ) { return price0( eb->bm_rep0[state] ) + price0( eb->bm_len[state][pos_state] ); } -static inline int LZeb_price_rep( const struct LZ_encoder_base * const eb, +static inline int LZeb_price_rep( const LZ_encoder_base * const eb, const int rep, const State state, const int pos_state ) { @@ -207,7 +205,7 @@ static inline int LZeb_price_rep( const struct LZ_encoder_base * const eb, return price; } -static inline int LZe_price_rep0_len( const struct LZ_encoder * const e, +static inline int LZe_price_rep0_len( const LZ_encoder * const e, const int len, const State state, const int pos_state ) { @@ -215,7 +213,7 @@ static inline int LZe_price_rep0_len( const struct LZ_encoder * const e, Lp_price( &e->rep_len_prices, len, pos_state ); } -static inline int LZe_price_pair( const struct LZ_encoder * const e, +static inline int LZe_price_pair( const LZ_encoder * const e, const int dis, const int len, const int pos_state ) { @@ -228,7 +226,7 @@ static inline int LZe_price_pair( const struct LZ_encoder * const e, e->align_prices[dis & (dis_align_size - 1)]; } -static inline int LZe_read_match_distances( struct LZ_encoder * const e ) +static inline int LZe_read_match_distances( LZ_encoder * const e ) { const int num_pairs = LZe_get_match_pairs( e, e->pairs ); if( num_pairs > 0 ) @@ -241,7 +239,7 @@ static inline int LZe_read_match_distances( struct LZ_encoder * const e ) return num_pairs; } -static inline bool LZe_move_and_update( struct LZ_encoder * const e, int n ) +static inline bool LZe_move_and_update( LZ_encoder * const e, int n ) { while( true ) { @@ -252,13 +250,13 @@ static inline bool LZe_move_and_update( struct LZ_encoder * const e, int n ) return true; } -static inline void LZe_backward( struct LZ_encoder * const e, int cur ) +static inline void LZe_backward( LZ_encoder * const e, int cur ) { int dis4 = e->trials[cur].dis4; while( cur > 0 ) { const int prev_index = e->trials[cur].prev_index; - struct Trial * const prev_trial = &e->trials[prev_index]; + Trial * const prev_trial = &e->trials[prev_index]; if( e->trials[cur].prev_index2 != single_step_trial ) { @@ -267,7 +265,7 @@ static inline void LZe_backward( struct LZ_encoder * const e, int cur ) prev_trial->prev_index2 = single_step_trial; if( e->trials[cur].prev_index2 >= 0 ) { - struct Trial * const prev_trial2 = &e->trials[prev_index-1]; + Trial * const prev_trial2 = &e->trials[prev_index-1]; prev_trial2->dis4 = dis4; dis4 = 0; /* rep0 */ prev_trial2->prev_index = e->trials[cur].prev_index2; prev_trial2->prev_index2 = single_step_trial; @@ -282,7 +280,7 @@ static inline void LZe_backward( struct LZ_encoder * const e, int cur ) enum { num_prev_positions3 = 1 << 16, num_prev_positions2 = 1 << 10 }; -static inline bool LZe_init( struct LZ_encoder * const e, +static inline bool LZe_init( LZ_encoder * const e, const int dict_size, const int len_limit, const unsigned long long member_size ) { @@ -297,7 +295,7 @@ static inline bool LZe_init( struct LZ_encoder * const e, if( !LZeb_init( &e->eb, before_size, dict_size, after_size, dict_factor, num_prev_positions23, pos_array_factor, min_free_bytes, member_size ) ) return false; - e->cycles = ( len_limit < max_match_len ) ? 16 + ( len_limit / 2 ) : 256; + e->cycles = (len_limit < max_match_len) ? 16 + ( len_limit / 2 ) : 256; e->match_len_limit = len_limit; Lp_init( &e->match_len_prices, &e->eb.match_len_model, e->match_len_limit ); Lp_init( &e->rep_len_prices, &e->eb.rep_len_model, e->match_len_limit ); @@ -312,7 +310,7 @@ static inline bool LZe_init( struct LZ_encoder * const e, return true; } -static inline void LZe_reset( struct LZ_encoder * const e, +static inline void LZe_reset( LZ_encoder * const e, const unsigned long long member_size ) { LZeb_reset( &e->eb, member_size ); diff --git a/encoder_base.c b/encoder_base.c index cd790fb..2773887 100644 --- a/encoder_base.c +++ b/encoder_base.c @@ -17,7 +17,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ -static bool Mb_normalize_pos( struct Matchfinder_base * const mb ) +static bool Mb_normalize_pos( Matchfinder_base * const mb ) { if( mb->pos > mb->stream_pos ) { mb->pos = mb->stream_pos; return false; } @@ -40,7 +40,7 @@ static bool Mb_normalize_pos( struct Matchfinder_base * const mb ) } -static bool Mb_init( struct Matchfinder_base * const mb, const int before_size, +static bool Mb_init( Matchfinder_base * const mb, const int before_size, const int dict_size, const int after_size, const int dict_factor, const int num_prev_positions23, const int pos_array_factor ) @@ -83,7 +83,7 @@ static bool Mb_init( struct Matchfinder_base * const mb, const int before_size, } -static void Mb_adjust_array( struct Matchfinder_base * const mb ) +static void Mb_adjust_array( Matchfinder_base * const mb ) { int size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 ); if( mb->dictionary_size > 1 << 26 ) size >>= 1; /* 64 MiB */ @@ -94,7 +94,7 @@ static void Mb_adjust_array( struct Matchfinder_base * const mb ) } -static void Mb_adjust_dictionary_size( struct Matchfinder_base * const mb ) +static void Mb_adjust_dictionary_size( Matchfinder_base * const mb ) { if( mb->stream_pos < mb->dictionary_size ) { @@ -105,7 +105,7 @@ static void Mb_adjust_dictionary_size( struct Matchfinder_base * const mb ) } -static void Mb_reset( struct Matchfinder_base * const mb ) +static void Mb_reset( Matchfinder_base * const mb ) { int i; if( mb->stream_pos > mb->pos ) @@ -124,7 +124,7 @@ static void Mb_reset( struct Matchfinder_base * const mb ) /* End Of Stream marker => (dis == 0xFFFFFFFFU, len == min_match_len) */ -static void LZeb_try_full_flush( struct LZ_encoder_base * const eb ) +static void LZeb_try_full_flush( LZ_encoder_base * const eb ) { if( eb->member_finished || Cb_free_bytes( &eb->renc.cb ) < max_marker_size + eb->renc.ff_count + Lt_size ) return; @@ -144,7 +144,7 @@ static void LZeb_try_full_flush( struct LZ_encoder_base * const eb ) /* Sync Flush marker => (dis == 0xFFFFFFFFU, len == min_match_len + 1) */ -static void LZeb_try_sync_flush( struct LZ_encoder_base * const eb ) +static void LZeb_try_sync_flush( LZ_encoder_base * const eb ) { const unsigned min_size = eb->renc.ff_count + max_marker_size; if( eb->member_finished || @@ -163,7 +163,7 @@ static void LZeb_try_sync_flush( struct LZ_encoder_base * const eb ) } -static void LZeb_reset( struct LZ_encoder_base * const eb, +static void LZeb_reset( LZ_encoder_base * const eb, const unsigned long long member_size ) { const unsigned long long min_member_size = min_dictionary_size; diff --git a/encoder_base.h b/encoder_base.h index 094f679..56165d4 100644 --- a/encoder_base.h +++ b/encoder_base.h @@ -217,7 +217,7 @@ static inline int price_matched( const Bit_model bm[], unsigned symbol, } -struct Matchfinder_base +typedef struct Matchfinder_base { unsigned long long partial_data_pos; uint8_t * buffer; /* input buffer */ @@ -238,52 +238,52 @@ struct Matchfinder_base int saved_dictionary_size; /* dictionary_size restored by Mb_reset */ bool at_stream_end; /* stream_pos shows real end of file */ bool sync_flush_pending; - }; + } Matchfinder_base; -static bool Mb_normalize_pos( struct Matchfinder_base * const mb ); +static bool Mb_normalize_pos( Matchfinder_base * const mb ); -static bool Mb_init( struct Matchfinder_base * const mb, const int before_size, +static bool Mb_init( Matchfinder_base * const mb, const int before_size, const int dict_size, const int after_size, const int dict_factor, const int num_prev_positions23, const int pos_array_factor ); -static inline void Mb_free( struct Matchfinder_base * const mb ) +static inline void Mb_free( Matchfinder_base * const mb ) { free( mb->prev_positions ); free( mb->buffer ); } -static inline uint8_t Mb_peek( const struct Matchfinder_base * const mb, +static inline uint8_t Mb_peek( const Matchfinder_base * const mb, const int distance ) { return mb->buffer[mb->pos-distance]; } -static inline int Mb_available_bytes( const struct Matchfinder_base * const mb ) +static inline int Mb_available_bytes( const Matchfinder_base * const mb ) { return mb->stream_pos - mb->pos; } static inline unsigned long long -Mb_data_position( const struct Matchfinder_base * const mb ) +Mb_data_position( const Matchfinder_base * const mb ) { return mb->partial_data_pos + mb->pos; } -static inline void Mb_finish( struct Matchfinder_base * const mb ) +static inline void Mb_finish( Matchfinder_base * const mb ) { mb->at_stream_end = true; mb->sync_flush_pending = false; } -static inline bool Mb_data_finished( const struct Matchfinder_base * const mb ) +static inline bool Mb_data_finished( const Matchfinder_base * const mb ) { return mb->at_stream_end && mb->pos >= mb->stream_pos; } -static inline bool Mb_flushing_or_end( const struct Matchfinder_base * const mb ) +static inline bool Mb_flushing_or_end( const Matchfinder_base * const mb ) { return mb->at_stream_end || mb->sync_flush_pending; } -static inline int Mb_free_bytes( const struct Matchfinder_base * const mb ) +static inline int Mb_free_bytes( const Matchfinder_base * const mb ) { if( Mb_flushing_or_end( mb ) ) return 0; return mb->buffer_size - mb->stream_pos; } static inline bool -Mb_enough_available_bytes( const struct Matchfinder_base * const mb ) +Mb_enough_available_bytes( const Matchfinder_base * const mb ) { return mb->pos + mb->after_size <= mb->stream_pos || ( Mb_flushing_or_end( mb ) && mb->pos < mb->stream_pos ); } static inline const uint8_t * -Mb_ptr_to_current_pos( const struct Matchfinder_base * const mb ) +Mb_ptr_to_current_pos( const Matchfinder_base * const mb ) { return mb->buffer + mb->pos; } -static int Mb_write_data( struct Matchfinder_base * const mb, +static int Mb_write_data( Matchfinder_base * const mb, const uint8_t * const inbuf, const int size ) { const int sz = min( mb->buffer_size - mb->stream_pos, size ); @@ -293,7 +293,7 @@ static int Mb_write_data( struct Matchfinder_base * const mb, return sz; } -static inline int Mb_true_match_len( const struct Matchfinder_base * const mb, +static inline int Mb_true_match_len( const Matchfinder_base * const mb, const int index, const int distance ) { const uint8_t * const data = mb->buffer + mb->pos; @@ -303,7 +303,7 @@ static inline int Mb_true_match_len( const struct Matchfinder_base * const mb, return i; } -static inline bool Mb_move_pos( struct Matchfinder_base * const mb ) +static inline bool Mb_move_pos( Matchfinder_base * const mb ) { if( ++mb->cyclic_pos > mb->dictionary_size ) mb->cyclic_pos = 0; if( ++mb->pos >= mb->pos_limit ) return Mb_normalize_pos( mb ); @@ -311,9 +311,9 @@ static inline bool Mb_move_pos( struct Matchfinder_base * const mb ) } -struct Range_encoder +typedef struct Range_encoder { - struct Circular_buffer cb; + Circular_buffer cb; unsigned min_free_bytes; uint64_t low; unsigned long long partial_member_pos; @@ -321,13 +321,13 @@ struct Range_encoder unsigned ff_count; uint8_t cache; Lzip_header header; - }; + } Range_encoder; -static inline void Re_shift_low( struct Range_encoder * const renc ) +static inline void Re_shift_low( Range_encoder * const renc ) { if( renc->low >> 24 != 0xFF ) { - const bool carry = ( renc->low > 0xFFFFFFFFU ); + const bool carry = renc->low > 0xFFFFFFFFU; Cb_put_byte( &renc->cb, renc->cache + carry ); for( ; renc->ff_count > 0; --renc->ff_count ) Cb_put_byte( &renc->cb, 0xFF + carry ); @@ -337,7 +337,7 @@ static inline void Re_shift_low( struct Range_encoder * const renc ) renc->low = ( renc->low & 0x00FFFFFFU ) << 8; } -static inline void Re_reset( struct Range_encoder * const renc, +static inline void Re_reset( Range_encoder * const renc, const unsigned dictionary_size ) { Cb_reset( &renc->cb ); @@ -350,7 +350,7 @@ static inline void Re_reset( struct Range_encoder * const renc, int i; for( i = 0; i < Lh_size; ++i ) Cb_put_byte( &renc->cb, renc->header[i] ); } -static inline bool Re_init( struct Range_encoder * const renc, +static inline bool Re_init( Range_encoder * const renc, const unsigned dictionary_size, const unsigned min_free_bytes ) { @@ -361,17 +361,17 @@ static inline bool Re_init( struct Range_encoder * const renc, return true; } -static inline void Re_free( struct Range_encoder * const renc ) +static inline void Re_free( Range_encoder * const renc ) { Cb_free( &renc->cb ); } static inline unsigned long long -Re_member_position( const struct Range_encoder * const renc ) +Re_member_position( const Range_encoder * const renc ) { return renc->partial_member_pos + Cb_used_bytes( &renc->cb ) + renc->ff_count; } -static inline bool Re_enough_free_bytes( const struct Range_encoder * const renc ) +static inline bool Re_enough_free_bytes( const Range_encoder * const renc ) { return Cb_free_bytes( &renc->cb ) >= renc->min_free_bytes + renc->ff_count; } -static inline int Re_read_data( struct Range_encoder * const renc, +static inline int Re_read_data( Range_encoder * const renc, uint8_t * const out_buffer, const int out_size ) { const int size = Cb_read_data( &renc->cb, out_buffer, out_size ); @@ -379,7 +379,7 @@ static inline int Re_read_data( struct Range_encoder * const renc, return size; } -static inline void Re_flush( struct Range_encoder * const renc ) +static inline void Re_flush( Range_encoder * const renc ) { int i; for( i = 0; i < 5; ++i ) Re_shift_low( renc ); renc->low = 0; @@ -388,7 +388,7 @@ static inline void Re_flush( struct Range_encoder * const renc ) renc->cache = 0; } -static inline void Re_encode( struct Range_encoder * const renc, +static inline void Re_encode( Range_encoder * const renc, const int symbol, const int num_bits ) { unsigned mask; @@ -400,7 +400,7 @@ static inline void Re_encode( struct Range_encoder * const renc, } } -static inline void Re_encode_bit( struct Range_encoder * const renc, +static inline void Re_encode_bit( Range_encoder * const renc, Bit_model * const probability, const bool bit ) { const uint32_t bound = ( renc->range >> bit_model_total_bits ) * *probability; @@ -418,7 +418,7 @@ static inline void Re_encode_bit( struct Range_encoder * const renc, if( renc->range <= 0x00FFFFFFU ) { renc->range <<= 8; Re_shift_low( renc ); } } -static inline void Re_encode_tree3( struct Range_encoder * const renc, +static inline void Re_encode_tree3( Range_encoder * const renc, Bit_model bm[], const int symbol ) { bool bit = ( symbol >> 2 ) & 1; @@ -429,7 +429,7 @@ static inline void Re_encode_tree3( struct Range_encoder * const renc, Re_encode_bit( renc, &bm[model], symbol & 1 ); } -static inline void Re_encode_tree6( struct Range_encoder * const renc, +static inline void Re_encode_tree6( Range_encoder * const renc, Bit_model bm[], const unsigned symbol ) { bool bit = ( symbol >> 5 ) & 1; @@ -446,7 +446,7 @@ static inline void Re_encode_tree6( struct Range_encoder * const renc, Re_encode_bit( renc, &bm[model], symbol & 1 ); } -static inline void Re_encode_tree8( struct Range_encoder * const renc, +static inline void Re_encode_tree8( Range_encoder * const renc, Bit_model bm[], const int symbol ) { int model = 1; @@ -459,7 +459,7 @@ static inline void Re_encode_tree8( struct Range_encoder * const renc, } } -static inline void Re_encode_tree_reversed( struct Range_encoder * const renc, +static inline void Re_encode_tree_reversed( Range_encoder * const renc, Bit_model bm[], int symbol, const int num_bits ) { int model = 1; @@ -473,7 +473,7 @@ static inline void Re_encode_tree_reversed( struct Range_encoder * const renc, } } -static inline void Re_encode_matched( struct Range_encoder * const renc, +static inline void Re_encode_matched( Range_encoder * const renc, Bit_model bm[], unsigned symbol, unsigned match_byte ) { @@ -489,17 +489,17 @@ static inline void Re_encode_matched( struct Range_encoder * const renc, } } -static inline void Re_encode_len( struct Range_encoder * const renc, - struct Len_model * const lm, +static inline void Re_encode_len( Range_encoder * const renc, + Len_model * const lm, int symbol, const int pos_state ) { - bool bit = ( ( symbol -= min_match_len ) >= len_low_symbols ); + bool bit = ( symbol -= min_match_len ) >= len_low_symbols; Re_encode_bit( renc, &lm->choice1, bit ); if( !bit ) Re_encode_tree3( renc, lm->bm_low[pos_state], symbol ); else { - bit = ( ( symbol -= len_low_symbols ) >= len_mid_symbols ); + bit = ( symbol -= len_low_symbols ) >= len_mid_symbols; Re_encode_bit( renc, &lm->choice2, bit ); if( !bit ) Re_encode_tree3( renc, lm->bm_mid[pos_state], symbol ); @@ -512,9 +512,9 @@ static inline void Re_encode_len( struct Range_encoder * const renc, enum { max_marker_size = 16, num_rep_distances = 4 }; /* must be 4 */ -struct LZ_encoder_base +typedef struct LZ_encoder_base { - struct Matchfinder_base mb; + Matchfinder_base mb; unsigned long long member_size_limit; uint32_t crc; @@ -528,18 +528,18 @@ struct LZ_encoder_base Bit_model bm_dis_slot[len_states][1<member_finished && Cb_empty( &eb->renc.cb ); } -static inline void LZeb_free( struct LZ_encoder_base * const eb ) +static inline void LZeb_free( LZ_encoder_base * const eb ) { Re_free( &eb->renc ); Mb_free( &eb->mb ); } -static inline unsigned LZeb_crc( const struct LZ_encoder_base * const eb ) +static inline unsigned LZeb_crc( const LZ_encoder_base * const eb ) { return eb->crc ^ 0xFFFFFFFFU; } -static inline int LZeb_price_literal( const struct LZ_encoder_base * const eb, +static inline int LZeb_price_literal( const LZ_encoder_base * const eb, const uint8_t prev_byte, const uint8_t symbol ) { return price_symbol8( eb->bm_literal[get_lit_state(prev_byte)], symbol ); } -static inline int LZeb_price_matched( const struct LZ_encoder_base * const eb, +static inline int LZeb_price_matched( const LZ_encoder_base * const eb, const uint8_t prev_byte, const uint8_t symbol, const uint8_t match_byte ) { return price_matched( eb->bm_literal[get_lit_state(prev_byte)], symbol, match_byte ); } -static inline void LZeb_encode_literal( struct LZ_encoder_base * const eb, +static inline void LZeb_encode_literal( LZ_encoder_base * const eb, const uint8_t prev_byte, const uint8_t symbol ) { Re_encode_tree8( &eb->renc, eb->bm_literal[get_lit_state(prev_byte)], symbol ); } -static inline void LZeb_encode_matched( struct LZ_encoder_base * const eb, +static inline void LZeb_encode_matched( LZ_encoder_base * const eb, const uint8_t prev_byte, const uint8_t symbol, const uint8_t match_byte ) { Re_encode_matched( &eb->renc, eb->bm_literal[get_lit_state(prev_byte)], symbol, match_byte ); } -static inline void LZeb_encode_pair( struct LZ_encoder_base * const eb, +static inline void LZeb_encode_pair( LZ_encoder_base * const eb, const unsigned dis, const int len, const int pos_state ) { diff --git a/fast_encoder.c b/fast_encoder.c index bb6363a..8b0db25 100644 --- a/fast_encoder.c +++ b/fast_encoder.c @@ -17,7 +17,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ -static int FLZe_longest_match_len( struct FLZ_encoder * const fe, int * const distance ) +static int FLZe_longest_match_len( FLZ_encoder * const fe, int * const distance ) { enum { len_limit = 16 }; int32_t * ptr0 = fe->eb.mb.pos_array + fe->eb.mb.cyclic_pos; @@ -58,7 +58,7 @@ static int FLZe_longest_match_len( struct FLZ_encoder * const fe, int * const di } -static bool FLZe_encode_member( struct FLZ_encoder * const fe ) +static bool FLZe_encode_member( FLZ_encoder * const fe ) { int rep = 0, i; State * const state = &fe->eb.state; diff --git a/fast_encoder.h b/fast_encoder.h index b9421f4..f4b2d3c 100644 --- a/fast_encoder.h +++ b/fast_encoder.h @@ -17,13 +17,13 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ -struct FLZ_encoder +typedef struct FLZ_encoder { - struct LZ_encoder_base eb; + LZ_encoder_base eb; unsigned key4; /* key made from latest 4 bytes */ - }; + } FLZ_encoder; -static inline void FLZe_reset_key4( struct FLZ_encoder * const fe ) +static inline void FLZe_reset_key4( FLZ_encoder * const fe ) { int i; fe->key4 = 0; @@ -31,9 +31,9 @@ static inline void FLZe_reset_key4( struct FLZ_encoder * const fe ) fe->key4 = ( fe->key4 << 4 ) ^ fe->eb.mb.buffer[i]; } -static inline bool FLZe_update_and_move( struct FLZ_encoder * const fe, int n ) +static inline bool FLZe_update_and_move( FLZ_encoder * const fe, int n ) { - struct Matchfinder_base * const mb = &fe->eb.mb; + Matchfinder_base * const mb = &fe->eb.mb; while( --n >= 0 ) { if( Mb_available_bytes( mb ) >= 4 ) @@ -48,7 +48,7 @@ static inline bool FLZe_update_and_move( struct FLZ_encoder * const fe, int n ) return true; } -static inline bool FLZe_init( struct FLZ_encoder * const fe, +static inline bool FLZe_init( FLZ_encoder * const fe, const unsigned long long member_size ) { enum { before_size = 0, @@ -65,6 +65,6 @@ static inline bool FLZe_init( struct FLZ_encoder * const fe, member_size ); } -static inline void FLZe_reset( struct FLZ_encoder * const fe, +static inline void FLZe_reset( FLZ_encoder * const fe, const unsigned long long member_size ) { LZeb_reset( &fe->eb, member_size ); } diff --git a/ffexample.c b/ffexample.c index 826abcd..0c87046 100644 --- a/ffexample.c +++ b/ffexample.c @@ -53,7 +53,7 @@ static void show_help( void ) } -int ffcompress( struct LZ_Encoder * const encoder, +int ffcompress( LZ_Encoder * const encoder, FILE * const infile, FILE * const outfile ) { enum { buffer_size = 16384 }; @@ -79,7 +79,7 @@ int ffcompress( struct LZ_Encoder * const encoder, } -int ffdecompress( struct LZ_Decoder * const decoder, +int ffdecompress( LZ_Decoder * const decoder, FILE * const infile, FILE * const outfile ) { enum { buffer_size = 16384 }; @@ -105,8 +105,7 @@ int ffdecompress( struct LZ_Decoder * const decoder, } -int ffboth( struct LZ_Encoder * const encoder, - struct LZ_Decoder * const decoder, +int ffboth( LZ_Encoder * const encoder, LZ_Decoder * const decoder, FILE * const infile, FILE * const outfile ) { enum { buffer_size = 16384 }; @@ -147,8 +146,7 @@ int ffmmcompress( FILE * const infile, FILE * const outfile ) enum { buffer_size = 16384, member_size = 4096 }; uint8_t buffer[buffer_size]; bool done = false; - struct LZ_Encoder * const encoder = - LZ_compress_open( 65535, 16, member_size ); + LZ_Encoder * const encoder = LZ_compress_open( 65535, 16, member_size ); if( !encoder || LZ_compress_errno( encoder ) != LZ_ok ) { fputs( "ffexample: Not enough memory.\n", stderr ); LZ_compress_close( encoder ); return 1; } @@ -182,7 +180,7 @@ int ffmmcompress( FILE * const infile, FILE * const outfile ) for each line of text terminated by a newline character or by EOF. Return 0 if success, 1 if error. */ -int fflfcompress( struct LZ_Encoder * const encoder, +int fflfcompress( LZ_Encoder * const encoder, FILE * const infile, FILE * const outfile ) { enum { buffer_size = 16384 }; @@ -223,7 +221,7 @@ int fflfcompress( struct LZ_Encoder * const encoder, next member in case of data error, including the automatic removal of leading garbage. */ -int ffrsdecompress( struct LZ_Decoder * const decoder, +int ffrsdecompress( LZ_Decoder * const decoder, FILE * const infile, FILE * const outfile ) { enum { buffer_size = 16384 }; @@ -262,11 +260,11 @@ int main( const int argc, const char * const argv[] ) setmode( STDOUT_FILENO, O_BINARY ); #endif - struct LZ_Encoder * const encoder = LZ_compress_open( 65535, 16, INT64_MAX ); - struct LZ_Decoder * const decoder = LZ_decompress_open(); - FILE * const infile = ( argc >= 3 && strcmp( argv[2], "-" ) != 0 ) ? + LZ_Encoder * const encoder = LZ_compress_open( 65535, 16, INT64_MAX ); + LZ_Decoder * const decoder = LZ_decompress_open(); + FILE * const infile = (argc >= 3 && strcmp( argv[2], "-" ) != 0) ? fopen( argv[2], "rb" ) : stdin; - FILE * const outfile = ( argc >= 4 && strcmp( argv[3], "-" ) != 0 ) ? + FILE * const outfile = (argc >= 4 && strcmp( argv[3], "-" ) != 0) ? fopen( argv[3], "wb" ) : stdout; int retval; diff --git a/lzcheck.c b/lzcheck.c index 4f4bf9f..a393c7d 100644 --- a/lzcheck.c +++ b/lzcheck.c @@ -41,10 +41,10 @@ static void show_line( const uint8_t * const buffer, const int size ) } -static struct LZ_Encoder * xopen_encoder( const int dictionary_size ) +static LZ_Encoder * xopen_encoder( const int dictionary_size ) { const int match_len_limit = 16; - struct LZ_Encoder * const encoder = + LZ_Encoder * const encoder = LZ_compress_open( dictionary_size, match_len_limit, member_size ); if( !encoder || LZ_compress_errno( encoder ) != LZ_ok ) { @@ -63,9 +63,9 @@ static struct LZ_Encoder * xopen_encoder( const int dictionary_size ) } -static struct LZ_Decoder * xopen_decoder( void ) +static LZ_Decoder * xopen_decoder( void ) { - struct LZ_Decoder * const decoder = LZ_decompress_open(); + LZ_Decoder * const decoder = LZ_decompress_open(); if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok ) { LZ_decompress_close( decoder ); @@ -76,8 +76,7 @@ static struct LZ_Decoder * xopen_decoder( void ) } -static void xclose_encoder( struct LZ_Encoder * const encoder, - const bool finish ) +static void xclose_encoder( LZ_Encoder * const encoder, const bool finish ) { if( finish ) { @@ -105,8 +104,7 @@ static void xclose_encoder( struct LZ_Encoder * const encoder, } -static void xclose_decoder( struct LZ_Decoder * const decoder, - const bool finish ) +static void xclose_decoder( LZ_Decoder * const decoder, const bool finish ) { if( finish ) { @@ -160,8 +158,8 @@ static const uint8_t * next_line( FILE * const file, int * const sizep ) static int check_sync_flush( FILE * const file, const int dictionary_size ) { - struct LZ_Encoder * const encoder = xopen_encoder( dictionary_size ); - struct LZ_Decoder * const decoder = xopen_decoder(); + LZ_Encoder * const encoder = xopen_encoder( dictionary_size ); + LZ_Decoder * const decoder = xopen_decoder(); int retval = 0; while( retval <= 1 ) /* test LZ_compress_sync_flush */ @@ -267,8 +265,8 @@ static int check_sync_flush( FILE * const file, const int dictionary_size ) */ static int check_members( FILE * const file, const int dictionary_size ) { - struct LZ_Encoder * const encoder = xopen_encoder( dictionary_size ); - struct LZ_Decoder * const decoder = xopen_decoder(); + LZ_Encoder * const encoder = xopen_encoder( dictionary_size ); + LZ_Decoder * const decoder = xopen_decoder(); int retval = 0; while( retval <= 1 ) /* test LZ_compress_restart_member */ @@ -362,7 +360,7 @@ int main( const int argc, const char * const argv[] ) ( strcmp( argv[1], "-m" ) == 0 || strcmp( argv[1], "-s" ) == 0 ) ) ? argv[1][1] : 0; const int first = opt ? 2 : 1; - const bool verbose = ( opt != 0 || argc > first + 1 ); + const bool verbose = opt != 0 || argc > first + 1; if( argc < 2 ) { diff --git a/lzip.h b/lzip.h index e0bdae9..8c4cfdb 100644 --- a/lzip.h +++ b/lzip.h @@ -94,16 +94,16 @@ static inline void Bm_init( Bit_model * const probability ) static inline void Bm_array_init( Bit_model bm[], const int size ) { int i; for( i = 0; i < size; ++i ) Bm_init( &bm[i] ); } -struct Len_model +typedef struct Len_model { Bit_model choice1; Bit_model choice2; Bit_model bm_low[pos_states][len_low_symbols]; Bit_model bm_mid[pos_states][len_mid_symbols]; Bit_model bm_high[len_high_symbols]; - }; + } Len_model; -static inline void Lm_init( struct Len_model * const lm ) +static inline void Lm_init( Len_model * const lm ) { Bm_init( &lm->choice1 ); Bm_init( &lm->choice2 ); diff --git a/lzlib.c b/lzlib.c index 23dd0ac..b3e4d18 100644 --- a/lzlib.c +++ b/lzlib.c @@ -39,14 +39,14 @@ struct LZ_Encoder { unsigned long long partial_in_size; unsigned long long partial_out_size; - struct LZ_encoder_base * lz_encoder_base; /* these 3 pointers make a */ - struct LZ_encoder * lz_encoder; /* polymorphic encoder */ - struct FLZ_encoder * flz_encoder; - enum LZ_Errno lz_errno; + LZ_encoder_base * lz_encoder_base; /* these 3 pointers make a */ + LZ_encoder * lz_encoder; /* polymorphic encoder */ + FLZ_encoder * flz_encoder; + LZ_Errno lz_errno; bool fatal; }; -static void LZ_Encoder_init( struct LZ_Encoder * const e ) +static void LZ_Encoder_init( LZ_Encoder * const e ) { e->partial_in_size = 0; e->partial_out_size = 0; @@ -62,16 +62,16 @@ struct LZ_Decoder { unsigned long long partial_in_size; unsigned long long partial_out_size; - struct Range_decoder * rdec; - struct LZ_decoder * lz_decoder; - enum LZ_Errno lz_errno; + Range_decoder * rdec; + LZ_decoder * lz_decoder; + LZ_Errno lz_errno; Lzip_header member_header; /* header of current member */ bool fatal; bool first_header; /* true until first header is read */ bool seeking; }; -static void LZ_Decoder_init( struct LZ_Decoder * const d ) +static void LZ_Decoder_init( LZ_Decoder * const d ) { int i; d->partial_in_size = 0; @@ -86,7 +86,7 @@ static void LZ_Decoder_init( struct LZ_Decoder * const d ) } -static bool check_encoder( struct LZ_Encoder * const e ) +static bool check_encoder( LZ_Encoder * const e ) { if( !e ) return false; if( !e->lz_encoder_base || ( !e->lz_encoder && !e->flz_encoder ) || @@ -96,7 +96,7 @@ static bool check_encoder( struct LZ_Encoder * const e ) } -static bool check_decoder( struct LZ_Decoder * const d ) +static bool check_decoder( LZ_Decoder * const d ) { if( !d ) return false; if( !d->rdec ) @@ -111,7 +111,7 @@ int LZ_api_version( void ) { return LZ_API_VERSION; } const char * LZ_version( void ) { return LZ_version_string; } -const char * LZ_strerror( const enum LZ_Errno lz_errno ) +const char * LZ_strerror( const LZ_Errno lz_errno ) { switch( lz_errno ) { @@ -138,13 +138,12 @@ int LZ_max_match_len_limit( void ) { return max_match_len; } /* --------------------- Compression Functions --------------------- */ -struct LZ_Encoder * LZ_compress_open( const int dictionary_size, - const int match_len_limit, - const unsigned long long member_size ) +LZ_Encoder * LZ_compress_open( const int dictionary_size, + const int match_len_limit, + const unsigned long long member_size ) { Lzip_header header; - struct LZ_Encoder * const e = - (struct LZ_Encoder *)malloc( sizeof (struct LZ_Encoder) ); + LZ_Encoder * const e = (LZ_Encoder *)malloc( sizeof (LZ_Encoder) ); if( !e ) return 0; LZ_Encoder_init( e ); if( !Lh_set_dictionary_size( header, dictionary_size ) || @@ -156,14 +155,14 @@ struct LZ_Encoder * LZ_compress_open( const int dictionary_size, { if( dictionary_size == 65535 && match_len_limit == 16 ) { - e->flz_encoder = (struct FLZ_encoder *)malloc( sizeof (struct FLZ_encoder) ); + e->flz_encoder = (FLZ_encoder *)malloc( sizeof (FLZ_encoder) ); if( e->flz_encoder && FLZe_init( e->flz_encoder, member_size ) ) { e->lz_encoder_base = &e->flz_encoder->eb; return e; } free( e->flz_encoder ); e->flz_encoder = 0; } else { - e->lz_encoder = (struct LZ_encoder *)malloc( sizeof (struct LZ_encoder) ); + e->lz_encoder = (LZ_encoder *)malloc( sizeof (LZ_encoder) ); if( e->lz_encoder && LZe_init( e->lz_encoder, Lh_get_dictionary_size( header ), match_len_limit, member_size ) ) { e->lz_encoder_base = &e->lz_encoder->eb; return e; } @@ -176,7 +175,7 @@ struct LZ_Encoder * LZ_compress_open( const int dictionary_size, } -int LZ_compress_close( struct LZ_Encoder * const e ) +int LZ_compress_close( LZ_Encoder * const e ) { if( !e ) return -1; if( e->lz_encoder_base ) @@ -187,7 +186,7 @@ int LZ_compress_close( struct LZ_Encoder * const e ) } -int LZ_compress_finish( struct LZ_Encoder * const e ) +int LZ_compress_finish( LZ_Encoder * const e ) { if( !check_encoder( e ) || e->fatal ) return -1; Mb_finish( &e->lz_encoder_base->mb ); @@ -205,7 +204,7 @@ int LZ_compress_finish( struct LZ_Encoder * const e ) } -int LZ_compress_restart_member( struct LZ_Encoder * const e, +int LZ_compress_restart_member( LZ_Encoder * const e, const unsigned long long member_size ) { if( !check_encoder( e ) || e->fatal ) return -1; @@ -224,7 +223,7 @@ int LZ_compress_restart_member( struct LZ_Encoder * const e, } -int LZ_compress_sync_flush( struct LZ_Encoder * const e ) +int LZ_compress_sync_flush( LZ_Encoder * const e ) { if( !check_encoder( e ) || e->fatal ) return -1; if( !e->lz_encoder_base->mb.at_stream_end ) @@ -233,13 +232,13 @@ int LZ_compress_sync_flush( struct LZ_Encoder * const e ) } -int LZ_compress_read( struct LZ_Encoder * const e, +int LZ_compress_read( LZ_Encoder * const e, uint8_t * const buffer, const int size ) { if( !check_encoder( e ) || e->fatal ) return -1; if( size < 0 ) return 0; - { struct LZ_encoder_base * const eb = e->lz_encoder_base; + { LZ_encoder_base * const eb = e->lz_encoder_base; int out_size = Re_read_data( &eb->renc, buffer, size ); /* minimize number of calls to encode_member */ if( out_size < size || size == 0 ) @@ -255,7 +254,7 @@ int LZ_compress_read( struct LZ_Encoder * const e, } -int LZ_compress_write( struct LZ_Encoder * const e, +int LZ_compress_write( LZ_Encoder * const e, const uint8_t * const buffer, const int size ) { if( !check_encoder( e ) || e->fatal ) return -1; @@ -263,21 +262,21 @@ int LZ_compress_write( struct LZ_Encoder * const e, } -int LZ_compress_write_size( struct LZ_Encoder * const e ) +int LZ_compress_write_size( LZ_Encoder * const e ) { if( !check_encoder( e ) || e->fatal ) return -1; return Mb_free_bytes( &e->lz_encoder_base->mb ); } -enum LZ_Errno LZ_compress_errno( struct LZ_Encoder * const e ) +LZ_Errno LZ_compress_errno( LZ_Encoder * const e ) { if( !e ) return LZ_bad_argument; return e->lz_errno; } -int LZ_compress_finished( struct LZ_Encoder * const e ) +int LZ_compress_finished( LZ_Encoder * const e ) { if( !check_encoder( e ) ) return -1; return Mb_data_finished( &e->lz_encoder_base->mb ) && @@ -285,35 +284,35 @@ int LZ_compress_finished( struct LZ_Encoder * const e ) } -int LZ_compress_member_finished( struct LZ_Encoder * const e ) +int LZ_compress_member_finished( LZ_Encoder * const e ) { if( !check_encoder( e ) ) return -1; return LZeb_member_finished( e->lz_encoder_base ); } -unsigned long long LZ_compress_data_position( struct LZ_Encoder * const e ) +unsigned long long LZ_compress_data_position( LZ_Encoder * const e ) { if( !check_encoder( e ) ) return 0; return Mb_data_position( &e->lz_encoder_base->mb ); } -unsigned long long LZ_compress_member_position( struct LZ_Encoder * const e ) +unsigned long long LZ_compress_member_position( LZ_Encoder * const e ) { if( !check_encoder( e ) ) return 0; return Re_member_position( &e->lz_encoder_base->renc ); } -unsigned long long LZ_compress_total_in_size( struct LZ_Encoder * const e ) +unsigned long long LZ_compress_total_in_size( LZ_Encoder * const e ) { if( !check_encoder( e ) ) return 0; return e->partial_in_size + Mb_data_position( &e->lz_encoder_base->mb ); } -unsigned long long LZ_compress_total_out_size( struct LZ_Encoder * const e ) +unsigned long long LZ_compress_total_out_size( LZ_Encoder * const e ) { if( !check_encoder( e ) ) return 0; return e->partial_out_size + Re_member_position( &e->lz_encoder_base->renc ); @@ -322,14 +321,13 @@ unsigned long long LZ_compress_total_out_size( struct LZ_Encoder * const e ) /* -------------------- Decompression Functions -------------------- */ -struct LZ_Decoder * LZ_decompress_open( void ) +LZ_Decoder * LZ_decompress_open( void ) { - struct LZ_Decoder * const d = - (struct LZ_Decoder *)malloc( sizeof (struct LZ_Decoder) ); + LZ_Decoder * const d = (LZ_Decoder *)malloc( sizeof (LZ_Decoder) ); if( !d ) return 0; LZ_Decoder_init( d ); - d->rdec = (struct Range_decoder *)malloc( sizeof (struct Range_decoder) ); + d->rdec = (Range_decoder *)malloc( sizeof (Range_decoder) ); if( !d->rdec || !Rd_init( d->rdec ) ) { if( d->rdec ) { Rd_free( d->rdec ); free( d->rdec ); d->rdec = 0; } @@ -339,7 +337,7 @@ struct LZ_Decoder * LZ_decompress_open( void ) } -int LZ_decompress_close( struct LZ_Decoder * const d ) +int LZ_decompress_close( LZ_Decoder * const d ) { if( !d ) return -1; if( d->lz_decoder ) @@ -350,7 +348,7 @@ int LZ_decompress_close( struct LZ_Decoder * const d ) } -int LZ_decompress_finish( struct LZ_Decoder * const d ) +int LZ_decompress_finish( LZ_Decoder * const d ) { if( !check_decoder( d ) || d->fatal ) return -1; if( d->seeking ) @@ -360,7 +358,7 @@ int LZ_decompress_finish( struct LZ_Decoder * const d ) } -int LZ_decompress_reset( struct LZ_Decoder * const d ) +int LZ_decompress_reset( LZ_Decoder * const d ) { if( !check_decoder( d ) ) return -1; if( d->lz_decoder ) @@ -376,7 +374,7 @@ int LZ_decompress_reset( struct LZ_Decoder * const d ) } -int LZ_decompress_sync_to_member( struct LZ_Decoder * const d ) +int LZ_decompress_sync_to_member( LZ_Decoder * const d ) { unsigned skipped = 0; if( !check_decoder( d ) ) return -1; @@ -395,7 +393,7 @@ int LZ_decompress_sync_to_member( struct LZ_Decoder * const d ) } -int LZ_decompress_read( struct LZ_Decoder * const d, +int LZ_decompress_read( LZ_Decoder * const d, uint8_t * const buffer, const int size ) { int result; @@ -467,7 +465,7 @@ int LZ_decompress_read( struct LZ_Decoder * const d, d->fatal = true; return -1; } - d->lz_decoder = (struct LZ_decoder *)malloc( sizeof (struct LZ_decoder) ); + d->lz_decoder = (LZ_decoder *)malloc( sizeof (LZ_decoder) ); if( !d->lz_decoder || !LZd_init( d->lz_decoder, d->rdec, Lh_get_dictionary_size( d->member_header ) ) ) { /* not enough free memory */ @@ -496,7 +494,7 @@ get_data: } -int LZ_decompress_write( struct LZ_Decoder * const d, +int LZ_decompress_write( LZ_Decoder * const d, const uint8_t * const buffer, const int size ) { int result; @@ -519,21 +517,21 @@ int LZ_decompress_write( struct LZ_Decoder * const d, } -int LZ_decompress_write_size( struct LZ_Decoder * const d ) +int LZ_decompress_write_size( LZ_Decoder * const d ) { if( !check_decoder( d ) || d->fatal ) return -1; return Rd_free_bytes( d->rdec ); } -enum LZ_Errno LZ_decompress_errno( struct LZ_Decoder * const d ) +LZ_Errno LZ_decompress_errno( LZ_Decoder * const d ) { if( !d ) return LZ_bad_argument; return d->lz_errno; } -int LZ_decompress_finished( struct LZ_Decoder * const d ) +int LZ_decompress_finished( LZ_Decoder * const d ) { if( !check_decoder( d ) || d->fatal ) return -1; return Rd_finished( d->rdec ) && @@ -541,28 +539,28 @@ int LZ_decompress_finished( struct LZ_Decoder * const d ) } -int LZ_decompress_member_finished( struct LZ_Decoder * const d ) +int LZ_decompress_member_finished( LZ_Decoder * const d ) { if( !check_decoder( d ) || d->fatal ) return -1; return d->lz_decoder && LZd_member_finished( d->lz_decoder ); } -int LZ_decompress_member_version( struct LZ_Decoder * const d ) +int LZ_decompress_member_version( LZ_Decoder * const d ) { if( !check_decoder( d ) ) return -1; return Lh_version( d->member_header ); } -int LZ_decompress_dictionary_size( struct LZ_Decoder * const d ) +int LZ_decompress_dictionary_size( LZ_Decoder * const d ) { if( !check_decoder( d ) ) return -1; return Lh_get_dictionary_size( d->member_header ); } -unsigned LZ_decompress_data_crc( struct LZ_Decoder * const d ) +unsigned LZ_decompress_data_crc( LZ_Decoder * const d ) { if( check_decoder( d ) && d->lz_decoder ) return LZd_crc( d->lz_decoder ); @@ -570,7 +568,7 @@ unsigned LZ_decompress_data_crc( struct LZ_Decoder * const d ) } -unsigned long long LZ_decompress_data_position( struct LZ_Decoder * const d ) +unsigned long long LZ_decompress_data_position( LZ_Decoder * const d ) { if( check_decoder( d ) && d->lz_decoder ) return LZd_data_position( d->lz_decoder ); @@ -578,21 +576,21 @@ unsigned long long LZ_decompress_data_position( struct LZ_Decoder * const d ) } -unsigned long long LZ_decompress_member_position( struct LZ_Decoder * const d ) +unsigned long long LZ_decompress_member_position( LZ_Decoder * const d ) { if( !check_decoder( d ) ) return 0; return d->rdec->member_position; } -unsigned long long LZ_decompress_total_in_size( struct LZ_Decoder * const d ) +unsigned long long LZ_decompress_total_in_size( LZ_Decoder * const d ) { if( !check_decoder( d ) ) return 0; return d->partial_in_size + d->rdec->member_position; } -unsigned long long LZ_decompress_total_out_size( struct LZ_Decoder * const d ) +unsigned long long LZ_decompress_total_out_size( LZ_Decoder * const d ) { if( !check_decoder( d ) ) return 0; if( d->lz_decoder ) diff --git a/lzlib.h b/lzlib.h index 431a736..c304ffa 100644 --- a/lzlib.h +++ b/lzlib.h @@ -26,16 +26,17 @@ extern "C" { #define LZ_API_VERSION 1015 -static const char * const LZ_version_string = "1.15-pre2"; +static const char * const LZ_version_string = "1.15-rc1"; -enum LZ_Errno { LZ_ok = 0, LZ_bad_argument, LZ_mem_error, - LZ_sequence_error, LZ_header_error, LZ_unexpected_eof, - LZ_data_error, LZ_library_error }; +typedef enum LZ_Errno + { LZ_ok = 0, LZ_bad_argument, LZ_mem_error, + LZ_sequence_error, LZ_header_error, LZ_unexpected_eof, + LZ_data_error, LZ_library_error } LZ_Errno; int LZ_api_version( void ); /* new in 1.12 */ const char * LZ_version( void ); -const char * LZ_strerror( const enum LZ_Errno lz_errno ); +const char * LZ_strerror( const LZ_Errno lz_errno ); int LZ_min_dictionary_bits( void ); int LZ_min_dictionary_size( void ); @@ -47,63 +48,63 @@ int LZ_max_match_len_limit( void ); /* --------------------- Compression Functions --------------------- */ -struct LZ_Encoder; +typedef struct LZ_Encoder LZ_Encoder; -struct LZ_Encoder * LZ_compress_open( const int dictionary_size, - const int match_len_limit, - const unsigned long long member_size ); -int LZ_compress_close( struct LZ_Encoder * const encoder ); +LZ_Encoder * LZ_compress_open( const int dictionary_size, + const int match_len_limit, + const unsigned long long member_size ); +int LZ_compress_close( LZ_Encoder * const encoder ); -int LZ_compress_finish( struct LZ_Encoder * const encoder ); -int LZ_compress_restart_member( struct LZ_Encoder * const encoder, +int LZ_compress_finish( LZ_Encoder * const encoder ); +int LZ_compress_restart_member( LZ_Encoder * const encoder, const unsigned long long member_size ); -int LZ_compress_sync_flush( struct LZ_Encoder * const encoder ); +int LZ_compress_sync_flush( LZ_Encoder * const encoder ); -int LZ_compress_read( struct LZ_Encoder * const encoder, +int LZ_compress_read( LZ_Encoder * const encoder, uint8_t * const buffer, const int size ); -int LZ_compress_write( struct LZ_Encoder * const encoder, +int LZ_compress_write( LZ_Encoder * const encoder, const uint8_t * const buffer, const int size ); -int LZ_compress_write_size( struct LZ_Encoder * const encoder ); +int LZ_compress_write_size( LZ_Encoder * const encoder ); -enum LZ_Errno LZ_compress_errno( struct LZ_Encoder * const encoder ); -int LZ_compress_finished( struct LZ_Encoder * const encoder ); -int LZ_compress_member_finished( struct LZ_Encoder * const encoder ); +LZ_Errno LZ_compress_errno( LZ_Encoder * const encoder ); +int LZ_compress_finished( LZ_Encoder * const encoder ); +int LZ_compress_member_finished( LZ_Encoder * const encoder ); -unsigned long long LZ_compress_data_position( struct LZ_Encoder * const encoder ); -unsigned long long LZ_compress_member_position( struct LZ_Encoder * const encoder ); -unsigned long long LZ_compress_total_in_size( struct LZ_Encoder * const encoder ); -unsigned long long LZ_compress_total_out_size( struct LZ_Encoder * const encoder ); +unsigned long long LZ_compress_data_position( LZ_Encoder * const encoder ); +unsigned long long LZ_compress_member_position( LZ_Encoder * const encoder ); +unsigned long long LZ_compress_total_in_size( LZ_Encoder * const encoder ); +unsigned long long LZ_compress_total_out_size( LZ_Encoder * const encoder ); /* -------------------- Decompression Functions -------------------- */ -struct LZ_Decoder; +typedef struct LZ_Decoder LZ_Decoder; -struct LZ_Decoder * LZ_decompress_open( void ); -int LZ_decompress_close( struct LZ_Decoder * const decoder ); +LZ_Decoder * LZ_decompress_open( void ); +int LZ_decompress_close( LZ_Decoder * const decoder ); -int LZ_decompress_finish( struct LZ_Decoder * const decoder ); -int LZ_decompress_reset( struct LZ_Decoder * const decoder ); -int LZ_decompress_sync_to_member( struct LZ_Decoder * const decoder ); +int LZ_decompress_finish( LZ_Decoder * const decoder ); +int LZ_decompress_reset( LZ_Decoder * const decoder ); +int LZ_decompress_sync_to_member( LZ_Decoder * const decoder ); -int LZ_decompress_read( struct LZ_Decoder * const decoder, +int LZ_decompress_read( LZ_Decoder * const decoder, uint8_t * const buffer, const int size ); -int LZ_decompress_write( struct LZ_Decoder * const decoder, +int LZ_decompress_write( LZ_Decoder * const decoder, const uint8_t * const buffer, const int size ); -int LZ_decompress_write_size( struct LZ_Decoder * const decoder ); +int LZ_decompress_write_size( LZ_Decoder * const decoder ); -enum LZ_Errno LZ_decompress_errno( struct LZ_Decoder * const decoder ); -int LZ_decompress_finished( struct LZ_Decoder * const decoder ); -int LZ_decompress_member_finished( struct LZ_Decoder * const decoder ); +LZ_Errno LZ_decompress_errno( LZ_Decoder * const decoder ); +int LZ_decompress_finished( LZ_Decoder * const decoder ); +int LZ_decompress_member_finished( LZ_Decoder * const decoder ); -int LZ_decompress_member_version( struct LZ_Decoder * const decoder ); -int LZ_decompress_dictionary_size( struct LZ_Decoder * const decoder ); -unsigned LZ_decompress_data_crc( struct LZ_Decoder * const decoder ); +int LZ_decompress_member_version( LZ_Decoder * const decoder ); +int LZ_decompress_dictionary_size( LZ_Decoder * const decoder ); +unsigned LZ_decompress_data_crc( LZ_Decoder * const decoder ); -unsigned long long LZ_decompress_data_position( struct LZ_Decoder * const decoder ); -unsigned long long LZ_decompress_member_position( struct LZ_Decoder * const decoder ); -unsigned long long LZ_decompress_total_in_size( struct LZ_Decoder * const decoder ); -unsigned long long LZ_decompress_total_out_size( struct LZ_Decoder * const decoder ); +unsigned long long LZ_decompress_data_position( LZ_Decoder * const decoder ); +unsigned long long LZ_decompress_member_position( LZ_Decoder * const decoder ); +unsigned long long LZ_decompress_total_in_size( LZ_Decoder * const decoder ); +unsigned long long LZ_decompress_total_out_size( LZ_Decoder * const decoder ); #ifdef __cplusplus } diff --git a/minilzip.c b/minilzip.c index db6a4d0..15adf78 100644 --- a/minilzip.c +++ b/minilzip.c @@ -99,13 +99,13 @@ static const struct { const char * from; const char * to; } known_extensions[] = { ".tlz", ".tar" }, { 0, 0 } }; -struct Lzma_options +typedef struct Lzma_options { int dictionary_size; /* 4 KiB .. 512 MiB */ int match_len_limit; /* 5 .. 273 */ - }; + } Lzma_options; -enum Mode { m_compress, m_decompress, m_test }; +typedef enum Mode { m_compress, m_decompress, m_test } Mode; /* Variables used in signal handler context. They are not declared volatile because the handler never returns. */ @@ -116,25 +116,26 @@ static bool delete_output_on_interrupt = false; static void show_help( void ) { - printf( "Minilzip is a test program for the compression library lzlib, compatible\n" - "(interoperable) with lzip 1.4 or newer.\n" + printf( "Minilzip is a test program for the compression library lzlib. Minilzip is\n" + "not intended to be installed because lzip has more features, but minilzip is\n" + "well tested and you can use it as your main compressor if so you wish.\n" "\nLzip is a lossless data compressor with a user interface similar to the one\n" - "of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov\n" - "chain-Algorithm' (LZMA) stream format to maximize interoperability. The\n" - "maximum dictionary size is 512 MiB so that any lzip file can be decompressed\n" - "on 32-bit machines. Lzip provides accurate and robust 3-factor integrity\n" - "checking. Lzip can compress about as fast as gzip (lzip -0) or compress most\n" - "files more than bzip2 (lzip -9). Decompression speed is intermediate between\n" - "gzip and bzip2. Lzip provides better data recovery capabilities than gzip\n" - "and bzip2. Lzip has been designed, written, and tested with great care to\n" - "replace gzip and bzip2 as the standard general-purpose compressed format for\n" - "Unix-like systems.\n" + "of gzip or bzip2. Lzip uses a simplified form of LZMA (Lempel-Ziv-Markov\n" + "chain-Algorithm) designed to achieve complete interoperability between\n" + "implementations. The maximum dictionary size is 512 MiB so that any lzip\n" + "file can be decompressed on 32-bit machines. Lzip provides accurate and\n" + "robust 3-factor integrity checking. 'lzip -0' compresses about as fast as\n" + "gzip, while 'lzip -9' compresses most files more than bzip2. Decompression\n" + "speed is intermediate between gzip and bzip2. Lzip provides better data\n" + "recovery capabilities than gzip and bzip2. Lzip has been designed, written,\n" + "and tested with great care to replace gzip and bzip2 as general-purpose\n" + "compressed format for Unix-like systems.\n" "\nUsage: %s [options] [files]\n", invocation_name ); printf( "\nOptions:\n" " -h, --help display this help and exit\n" " -V, --version output version information and exit\n" " -a, --trailing-error exit with error status if trailing data\n" - " -b, --member-size= set member size limit in bytes\n" + " -b, --member-size= set member size limit of multimember files\n" " -c, --stdout write to standard output, keep input files\n" " -d, --decompress decompress, test compressed file integrity\n" " -f, --force overwrite existing output files\n" @@ -264,16 +265,16 @@ static void * resize_buffer( void * buf, const unsigned min_size ) } -struct Pretty_print +typedef struct Pretty_print { const char * name; char * padded_name; const char * stdin_name; unsigned longest_name; bool first_post; - }; + } Pretty_print; -static void Pp_init( struct Pretty_print * const pp, +static void Pp_init( Pretty_print * const pp, const char * const filenames[], const int num_filenames ) { pp->name = 0; @@ -294,11 +295,10 @@ static void Pp_init( struct Pretty_print * const pp, if( pp->longest_name == 0 ) pp->longest_name = stdin_name_len; } -void Pp_free( struct Pretty_print * const pp ) +void Pp_free( Pretty_print * const pp ) { if( pp->padded_name ) { free( pp->padded_name ); pp->padded_name = 0; } } -static void Pp_set_name( struct Pretty_print * const pp, - const char * const filename ) +static void Pp_set_name( Pretty_print * const pp, const char * const filename ) { unsigned name_len, padded_name_len, i = 0; @@ -316,10 +316,10 @@ static void Pp_set_name( struct Pretty_print * const pp, pp->first_post = true; } -static void Pp_reset( struct Pretty_print * const pp ) +static void Pp_reset( Pretty_print * const pp ) { if( pp->name && pp->name[0] ) pp->first_post = true; } -static void Pp_show_msg( struct Pretty_print * const pp, const char * const msg ) +static void Pp_show_msg( Pretty_print * const pp, const char * const msg ) { if( verbosity < 0 ) return; if( pp->first_post ) @@ -339,7 +339,7 @@ static void show_header( const unsigned dictionary_size ) const char * p = ""; const char * np = " "; unsigned num = dictionary_size; - bool exact = ( num % factor == 0 ); + bool exact = num % factor == 0; int i; for( i = 0; i < n && ( num > 9999 || ( exact && num >= factor ) ); ++i ) { num /= factor; if( num % factor != 0 ) exact = false; @@ -406,7 +406,7 @@ static unsigned long long getnum( const char * const arg, if( !errno && tail[0] ) { - const unsigned factor = ( tail[1] == 'i' ) ? 1024 : 1000; + const unsigned factor = (tail[1] == 'i') ? 1024 : 1000; int exponent = 0; /* 0 = bad multiplier */ int i; switch( tail[0] ) @@ -459,7 +459,7 @@ static int get_dict_size( const char * const arg, const char * const option_name } -static void set_mode( enum Mode * const program_modep, const enum Mode new_mode ) +static void set_mode( Mode * const program_modep, const Mode new_mode ) { if( *program_modep != m_compress && *program_modep != new_mode ) { @@ -524,7 +524,7 @@ static void set_d_outname( const char * const name, const int eindex ) static int open_instream( const char * const name, struct stat * const in_statsp, - const enum Mode program_mode, const int eindex, + const Mode program_mode, const int eindex, const bool one_to_one, const bool recompress ) { if( program_mode == m_compress && !recompress && eindex >= 0 ) @@ -541,9 +541,9 @@ static int open_instream( const char * const name, struct stat * const in_statsp { const int i = fstat( infd, in_statsp ); const mode_t mode = in_statsp->st_mode; - const bool can_read = ( i == 0 && - ( S_ISBLK( mode ) || S_ISCHR( mode ) || - S_ISFIFO( mode ) || S_ISSOCK( mode ) ) ); + const bool can_read = i == 0 && + ( S_ISBLK( mode ) || S_ISCHR( mode ) || + S_ISFIFO( mode ) || S_ISSOCK( mode ) ); if( i != 0 || ( !S_ISREG( mode ) && ( !can_read || one_to_one ) ) ) { if( verbosity >= 0 ) @@ -609,7 +609,7 @@ static void signal_handler( int sig ) static bool check_tty_in( const char * const input_filename, const int infd, - const enum Mode program_mode, int * const retval ) + const Mode program_mode, int * const retval ) { if( ( program_mode == m_decompress || program_mode == m_test ) && isatty( infd ) ) /* for example /dev/tty */ @@ -621,7 +621,7 @@ static bool check_tty_in( const char * const input_filename, const int infd, return true; } -static bool check_tty_out( const enum Mode program_mode ) +static bool check_tty_out( const Mode program_mode ) { if( program_mode == m_compress && isatty( outfd ) ) { show_file_error( output_filename[0] ? @@ -717,10 +717,10 @@ static bool next_filename( void ) } -static int do_compress( struct LZ_Encoder * const encoder, +static int do_compress( LZ_Encoder * const encoder, const unsigned long long member_size, const unsigned long long volume_size, const int infd, - struct Pretty_print * const pp, + Pretty_print * const pp, const struct stat * const in_statsp ) { unsigned long long partial_volume_size = 0; @@ -819,11 +819,11 @@ static int do_compress( struct LZ_Encoder * const encoder, static int compress( const unsigned long long member_size, const unsigned long long volume_size, const int infd, - const struct Lzma_options * const encoder_options, - struct Pretty_print * const pp, + const Lzma_options * const encoder_options, + Pretty_print * const pp, const struct stat * const in_statsp ) { - struct LZ_Encoder * const encoder = + LZ_Encoder * const encoder = LZ_compress_open( encoder_options->dictionary_size, encoder_options->match_len_limit, ( volume_size > 0 ) ? min( member_size, volume_size ) : member_size ); @@ -844,8 +844,8 @@ static int compress( const unsigned long long member_size, } -static int do_decompress( struct LZ_Decoder * const decoder, const int infd, - struct Pretty_print * const pp, const bool from_stdin, +static int do_decompress( LZ_Decoder * const decoder, const int infd, + Pretty_print * const pp, const bool from_stdin, const bool ignore_trailing, const bool loose_trailing, const bool testing ) { @@ -853,7 +853,7 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd, uint8_t buffer[buffer_size]; /* read/write buffer */ unsigned long long total_in = 0; /* to detect library stall */ bool first_member; - bool empty = false, nonempty = false; + bool empty = false, multi = false; for( first_member = true; ; ) { @@ -894,10 +894,11 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd, { const unsigned long long data_size = LZ_decompress_data_position( decoder ); if( !from_stdin ) - { if( data_size == 0 ) empty = true; else nonempty = true; } + { multi = !first_member; if( data_size == 0 ) empty = true; } if( verbosity >= 1 ) { - const unsigned long long member_size = LZ_decompress_member_position( decoder ); + const unsigned long long member_size = + LZ_decompress_member_position( decoder ); if( verbosity >= 2 || ( verbosity == 1 && first_member ) ) Pp_show_msg( pp, 0 ); if( verbosity >= 2 ) @@ -925,7 +926,7 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd, if( out_size < 0 || ( first_member && out_size == 0 ) ) { const unsigned long long member_pos = LZ_decompress_member_position( decoder ); - const enum LZ_Errno lz_errno = LZ_decompress_errno( decoder ); + const LZ_Errno lz_errno = LZ_decompress_errno( decoder ); if( lz_errno == LZ_library_error ) internal_error( "library error (LZ_decompress_read)." ); if( member_pos <= 6 ) @@ -988,17 +989,17 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd, } } if( verbosity == 1 ) fputs( testing ? "ok\n" : "done\n", stderr ); - if( empty && nonempty ) + if( empty && multi ) { show_file_error( pp->name, "Empty member not allowed.", 0 ); return 2; } return 0; } -static int decompress( const int infd, struct Pretty_print * const pp, +static int decompress( const int infd, Pretty_print * const pp, const bool from_stdin, const bool ignore_trailing, const bool loose_trailing, const bool testing ) { - struct LZ_Decoder * const decoder = LZ_decompress_open(); + LZ_Decoder * const decoder = LZ_decompress_open(); int retval; if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok ) @@ -1046,7 +1047,7 @@ int main( const int argc, const char * const argv[] ) { /* Mapping from gzip/bzip2 style 0..9 compression levels to the corresponding LZMA compression parameters. */ - const struct Lzma_options option_mapping[] = + const Lzma_options option_mapping[] = { { 65535, 16 }, /* -0 (65535,16 chooses fast encoder) */ { 1 << 20, 5 }, /* -1 */ @@ -1058,14 +1059,13 @@ int main( const int argc, const char * const argv[] ) { 1 << 24, 68 }, /* -7 */ { 3 << 23, 132 }, /* -8 */ { 1 << 25, 273 } }; /* -9 */ - struct Lzma_options encoder_options = option_mapping[6]; /* default = "-6" */ + Lzma_options encoder_options = option_mapping[6]; /* default = "-6" */ const unsigned long long max_member_size = 0x0008000000000000ULL; /* 2 PiB */ const unsigned long long max_volume_size = 0x4000000000000000ULL; /* 4 EiB */ unsigned long long member_size = max_member_size; unsigned long long volume_size = 0; const char * default_output_filename = ""; - enum Mode program_mode = m_compress; - int i; + Mode program_mode = m_compress; bool force = false; bool ignore_trailing = true; bool keep_input_files = false; @@ -1075,7 +1075,7 @@ int main( const int argc, const char * const argv[] ) if( argc > 0 ) invocation_name = argv[0]; enum { opt_chk = 256, opt_lt }; - const struct ap_Option options[] = + const ap_Option options[] = { { '0', "fast", ap_no }, { '1', 0, ap_no }, @@ -1109,7 +1109,7 @@ int main( const int argc, const char * const argv[] ) { 0, 0, ap_no } }; /* static because valgrind complains and memory management in C sucks */ - static struct Arg_parser parser; + static Arg_parser parser; if( !ap_init( &parser, argc, argv, options, 0 ) ) { show_error( mem_msg, 0, false ); return 1; } if( ap_error( &parser ) ) /* bad option */ @@ -1179,6 +1179,7 @@ int main( const int argc, const char * const argv[] ) filenames = resize_buffer( filenames, num_filenames * sizeof filenames[0] ); filenames[0] = "-"; + int i; bool filenames_given = false; for( i = 0; argind + i < ap_arguments( &parser ); ++i ) { @@ -1208,7 +1209,7 @@ int main( const int argc, const char * const argv[] ) if( !to_stdout && program_mode != m_test && ( filenames_given || to_file ) ) set_signals( signal_handler ); - static struct Pretty_print pp; + static Pretty_print pp; Pp_init( &pp, filenames, num_filenames ); int failed_tests = 0; diff --git a/testsuite/check.sh b/testsuite/check.sh index 21f6def..c52cceb 100755 --- a/testsuite/check.sh +++ b/testsuite/check.sh @@ -73,7 +73,7 @@ done "${LZIP}" -q -o out.lz nx_file [ $? = 1 ] || test_failed $LINENO [ ! -e out.lz ] || test_failed $LINENO -"${LZIP}" -qf -S100k -o out in in +"${LZIP}" -qf -S100k -o out in in # only one file with -o and -S [ $? = 1 ] || test_failed $LINENO { [ ! -e out ] && [ ! -e out.lz ] ; } || test_failed $LINENO # these are for code coverage @@ -143,7 +143,6 @@ cmp in out || test_failed $LINENO printf "to be overwritten" > out || framework_failure "${LZIP}" -df -o out < "${in_lz}" || test_failed $LINENO cmp in out || test_failed $LINENO -rm -f out || framework_failure "${LZIP}" -d -o ./- "${in_lz}" || test_failed $LINENO cmp in ./- || test_failed $LINENO rm -f ./- || framework_failure @@ -156,7 +155,7 @@ cp "${in_lz}" anyothername || framework_failure test_failed $LINENO cmp in out || test_failed $LINENO cmp in anyothername.out || test_failed $LINENO -rm -f out anyothername.out || framework_failure +rm -f anyothername.out || framework_failure "${LZIP}" -tq in "${in_lz}" [ $? = 2 ] || test_failed $LINENO @@ -222,7 +221,9 @@ touch empty em || framework_failure "${LZIP}" -0 em || test_failed $LINENO "${LZIP}" -dk em.lz || test_failed $LINENO cmp empty em || test_failed $LINENO -rm -f empty em || framework_failure +cat em.lz em.lz | "${LZIP}" -t || test_failed $LINENO +cat em.lz em.lz | "${LZIP}" -d > em || test_failed $LINENO +cmp empty em || test_failed $LINENO cat em.lz "${in_lz}" | "${LZIP}" -t || test_failed $LINENO cat em.lz "${in_lz}" | "${LZIP}" -d > out || test_failed $LINENO cmp in out || test_failed $LINENO @@ -352,6 +353,19 @@ rm -f in8 || framework_failure printf "\ntesting bad input..." +cat em.lz em.lz > ee.lz || framework_failure +"${LZIP}" -t < ee.lz || test_failed $LINENO +"${LZIP}" -d < ee.lz > em || test_failed $LINENO +cmp empty em || test_failed $LINENO +"${LZIP}" -tq ee.lz +[ $? = 2 ] || test_failed $LINENO +"${LZIP}" -dq ee.lz +[ $? = 2 ] || test_failed $LINENO +[ ! -e ee ] || test_failed $LINENO +"${LZIP}" -cdq ee.lz > em +[ $? = 2 ] || test_failed $LINENO +cmp empty em || test_failed $LINENO +rm -f empty em || framework_failure cat "${in_lz}" em.lz "${in_lz}" > inein.lz || framework_failure "${LZIP}" -t < inein.lz || test_failed $LINENO "${LZIP}" -d < inein.lz > out2 || test_failed $LINENO @@ -364,13 +378,13 @@ cmp in2 out2 || test_failed $LINENO "${LZIP}" -cdq inein.lz > out2 [ $? = 2 ] || test_failed $LINENO cmp in2 out2 || test_failed $LINENO -rm -f out2 inein.lz || framework_failure +rm -f out2 inein.lz em.lz || framework_failure headers='LZIp LZiP LZip LzIP LzIp LziP lZIP lZIp lZiP lzIP' body='\001\014\000\000\101\376\367\377\377\340\000\200\000\215\357\002\322\001\000\000\000\000\000\000\000\045\000\000\000\000\000\000\000' cp "${in_lz}" int.lz || framework_failure printf "LZIP${body}" >> int.lz || framework_failure -if "${LZIP}" -tq int.lz ; then +if "${LZIP}" -t int.lz ; then for header in ${headers} ; do printf "${header}${body}" > int.lz || framework_failure "${LZIP}" -tq int.lz # first member @@ -407,7 +421,7 @@ if "${LZIP}" -tq int.lz ; then [ $? = 2 ] || test_failed $LINENO ${header} done else - printf "\nwarning: skipping header test: 'printf' does not work on your system." + printf "warning: skipping header test: 'printf' does not work on your system." fi rm -f int.lz || framework_failure @@ -425,12 +439,12 @@ for i in fox_bcrc.lz fox_crc0.lz fox_das46.lz fox_mes81.lz ; do [ $? = 2 ] || test_failed $LINENO $i cmp fox out || test_failed $LINENO $i done -rm -f fox out || framework_failure +rm -f fox || framework_failure cat "${in_lz}" "${in_lz}" > in2.lz || framework_failure cat "${in_lz}" "${in_lz}" "${in_lz}" > in3.lz || framework_failure if dd if=in3.lz of=trunc.lz bs=14682 count=1 2> /dev/null && - [ -e trunc.lz ] && cmp in2.lz trunc.lz > /dev/null 2>&1 ; then + [ -e trunc.lz ] && cmp in2.lz trunc.lz ; then for i in 6 20 14664 14683 14684 14685 14686 14687 14688 ; do dd if=in3.lz of=trunc.lz bs=$i count=1 2> /dev/null "${LZIP}" -tq trunc.lz @@ -443,7 +457,7 @@ if dd if=in3.lz of=trunc.lz bs=14682 count=1 2> /dev/null && [ $? = 2 ] || test_failed $LINENO $i done else - printf "\nwarning: skipping truncation test: 'dd' does not work on your system." + printf "warning: skipping truncation test: 'dd' does not work on your system." fi rm -f in2.lz in3.lz trunc.lz || framework_failure @@ -454,10 +468,12 @@ cat "${in_lz}" >> ingin.lz || framework_failure [ $? = 2 ] || test_failed $LINENO "${LZIP}" -atq < ingin.lz [ $? = 2 ] || test_failed $LINENO -"${LZIP}" -acdq ingin.lz > /dev/null +"${LZIP}" -acdq ingin.lz > out [ $? = 2 ] || test_failed $LINENO -"${LZIP}" -adq < ingin.lz > /dev/null +cmp in out || test_failed $LINENO +"${LZIP}" -adq < ingin.lz > out [ $? = 2 ] || test_failed $LINENO +cmp in out || test_failed $LINENO "${LZIP}" -t ingin.lz || test_failed $LINENO "${LZIP}" -t < ingin.lz || test_failed $LINENO "${LZIP}" -dk ingin.lz || test_failed $LINENO From 9ea10ecd968aebe5dfdc86594c3c55f25f2de97c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 20 Feb 2025 21:35:13 +0100 Subject: [PATCH 10/10] Adding upstream version 1.15. Signed-off-by: Daniel Baumann --- ChangeLog | 23 +++++++-------------- INSTALL | 5 +++-- NEWS | 6 ++++-- README | 9 +++++++-- bbexample.c | 2 +- carg_parser.c | 2 +- carg_parser.h | 2 +- cbuffer.c | 2 +- configure | 6 +++--- decoder.c | 4 ++-- decoder.h | 2 +- doc/lzlib.info | 50 +++++++++++++++++++++++----------------------- doc/lzlib.texi | 8 ++++---- doc/minilzip.1 | 6 +++--- encoder.c | 6 +++--- encoder.h | 2 +- encoder_base.c | 2 +- encoder_base.h | 2 +- fast_encoder.c | 14 ++++++------- fast_encoder.h | 2 +- ffexample.c | 2 +- lzcheck.c | 2 +- lzip.h | 4 ++-- lzlib.c | 2 +- lzlib.h | 4 ++-- minilzip.c | 8 ++++---- testsuite/check.sh | 2 +- 27 files changed, 89 insertions(+), 90 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3125f0e..d3e52e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,27 +1,18 @@ -2024-11-19 Antonio Diaz Diaz +2025-01-09 Antonio Diaz Diaz - * Version 1.15-rc1 released. - * lzlib.h: Declare LZ_Errno, LZ_Encoder, and LZ_Decoder as typedef. - * configure, Makefile.in: Use '--soname' conditionally. - * check.sh: Use 'cp' instead of 'cat'. - -2024-10-16 Antonio Diaz Diaz - - * Version 1.15-pre2 released. + * Version 1.15 released. * decoder.h (Rd_try_reload): Reject a nonzero first LZMA byte. * minilzip.c (do_decompress): Reject empty member in multimember. (Pp_free): New function. - * configure, Makefile.in: Don't use '--soname'; create 'liblz.so.1'. - (Reported by Michael Sullivan). - -2024-04-19 Antonio Diaz Diaz - - * Version 1.15-pre1 released. + * lzlib.h: Declare LZ_Errno, LZ_Encoder, and LZ_Decoder as typedef. * Makefile.in: New target 'lib' which builds just the library. New target 'bin' which builds the library and minilzip. 'lib' is now the default; minilzip is no longer built by default. 'install-bin' installs minilzip and its man page again. + * configure, Makefile.in: Use '--soname' conditionally. + (Reported by Michael Sullivan). * INSTALL: Document use of 'make bin'. + * check.sh: Use 'cp' instead of 'cat'. 2024-01-20 Antonio Diaz Diaz @@ -282,7 +273,7 @@ * Version 0.1 released. -Copyright (C) 2009-2024 Antonio Diaz Diaz. +Copyright (C) 2009-2025 Antonio Diaz Diaz. This file is a collection of facts, and thus it is not copyrightable, but just in case, you have unlimited permission to copy, distribute, and modify it. diff --git a/INSTALL b/INSTALL index 570247e..ba3337e 100644 --- a/INSTALL +++ b/INSTALL @@ -3,7 +3,8 @@ Requirements You will need a C99 compiler. (gcc 3.3.6 or newer is recommended). I use gcc 6.1.0 and 3.3.6, but the code should compile with any standards compliant compiler. -Gcc is available at http://gcc.gnu.org. +Gcc is available at http://gcc.gnu.org +Lzip is available at http://www.nongnu.org/lzip/lzip.html The operating system must allow signal handlers read access to objects with static storage duration so that the cleanup handler for Control-C can delete @@ -85,7 +86,7 @@ After running 'configure', you can run 'make' and 'make install' as explained above. -Copyright (C) 2009-2024 Antonio Diaz Diaz. +Copyright (C) 2009-2025 Antonio Diaz Diaz. This file is free documentation: you have unlimited permission to copy, distribute, and modify it. diff --git a/NEWS b/NEWS index 4651f38..1528dce 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ Lzlib now reports a nonzero first LZMA byte as a LZ_data_error. minilzip now exits with error status 2 if any empty member is found in a multimember file. +LZ_Errno, LZ_Encoder, and LZ_Decoder are now declared in lzlib.h as typedef. + The targets 'lib' and 'bin' have been added to Makefile.in. 'lib' is the new default and builds just the library. 'bin' builds both the library and minilzip. @@ -13,7 +15,7 @@ minilzip is no longer built by default. 'install-bin' installs minilzip and its man page again. -The use of the target 'bin' has been documented in INSTALL. - To improve portability, the linker option '--soname' is now used conditionally. (Reported by Michael Sullivan). + +The use of the target 'bin' has been documented in INSTALL. diff --git a/README b/README index 4f94c31..b52806d 100644 --- a/README +++ b/README @@ -1,3 +1,5 @@ +See the file INSTALL for compilation and installation instructions. + Description Lzlib is a data compression library providing in-memory LZMA compression and @@ -10,7 +12,7 @@ are declared in the file 'lzlib.h'. Usage examples of the library are given in the files 'bbexample.c', 'ffexample.c', and 'minilzip.c' from the source distribution. -As 'lzlib.h' can be used by C and C++ programs, it must not impose a choice +As 'lzlib.h' can be used in C and C++ programs, it must not impose a choice of system headers on the program by including one of them. Therefore it is the responsibility of the program using lzlib to include before 'lzlib.h' some header that declares the type 'uint8_t'. There are at least four such @@ -74,8 +76,11 @@ LANGUAGE NOTE: Uncompressed = not compressed = plain data; it may never have been compressed. Decompressed is used to refer to data which have undergone the process of decompression. +minilzip uses Arg_parser for command-line argument parsing: +http://www.nongnu.org/arg-parser/arg_parser.html -Copyright (C) 2009-2024 Antonio Diaz Diaz. + +Copyright (C) 2009-2025 Antonio Diaz Diaz. This file is free documentation: you have unlimited permission to copy, distribute, and modify it. diff --git a/bbexample.c b/bbexample.c index d7c324b..4370c7e 100644 --- a/bbexample.c +++ b/bbexample.c @@ -1,5 +1,5 @@ /* Buffer to buffer example - Test program for the library lzlib - Copyright (C) 2010-2024 Antonio Diaz Diaz. + Copyright (C) 2010-2025 Antonio Diaz Diaz. This program is free software: you have unlimited permission to copy, distribute, and modify it. diff --git a/carg_parser.c b/carg_parser.c index 9400342..20b8a16 100644 --- a/carg_parser.c +++ b/carg_parser.c @@ -1,5 +1,5 @@ /* Arg_parser - POSIX/GNU command-line argument parser. (C version) - Copyright (C) 2006-2024 Antonio Diaz Diaz. + Copyright (C) 2006-2025 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/carg_parser.h b/carg_parser.h index 294756c..28eabee 100644 --- a/carg_parser.h +++ b/carg_parser.h @@ -1,5 +1,5 @@ /* Arg_parser - POSIX/GNU command-line argument parser. (C version) - Copyright (C) 2006-2024 Antonio Diaz Diaz. + Copyright (C) 2006-2025 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/cbuffer.c b/cbuffer.c index 73bdefe..23d95e1 100644 --- a/cbuffer.c +++ b/cbuffer.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2024 Antonio Diaz Diaz. + Copyright (C) 2009-2025 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/configure b/configure index 26ecfef..90ab72d 100755 --- a/configure +++ b/configure @@ -1,12 +1,12 @@ #! /bin/sh # configure script for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2024 Antonio Diaz Diaz. +# Copyright (C) 2009-2025 Antonio Diaz Diaz. # # This configure script is free software: you have unlimited permission # to copy, distribute, and modify it. pkgname=lzlib -pkgversion=1.15-rc1 +pkgversion=1.15 soversion=1 libname=lz libname_static=lib${libname}.a @@ -212,7 +212,7 @@ echo "MAKEINFO = ${MAKEINFO}" rm -f Makefile cat > Makefile << EOF # Makefile for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2024 Antonio Diaz Diaz. +# Copyright (C) 2009-2025 Antonio Diaz Diaz. # This file was generated automatically by configure. Don't edit. # # This Makefile is free software: you have unlimited permission diff --git a/decoder.c b/decoder.c index 3df0fd3..83a128c 100644 --- a/decoder.c +++ b/decoder.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2024 Antonio Diaz Diaz. + Copyright (C) 2009-2025 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -75,7 +75,7 @@ static int LZd_decode_member( LZ_decoder * const d ) if( Rd_decode_bit( rdec, &d->bm_rep0[*state] ) == 0 ) /* 3rd bit */ { if( Rd_decode_bit( rdec, &d->bm_len[*state][pos_state] ) == 0 ) /* 4th bit */ - { *state = St_set_short_rep( *state ); + { *state = St_set_shortrep( *state ); LZd_put_byte( d, LZd_peek( d, d->rep0 ) ); continue; } } else diff --git a/decoder.h b/decoder.h index f492c36..f880849 100644 --- a/decoder.h +++ b/decoder.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2024 Antonio Diaz Diaz. + Copyright (C) 2009-2025 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/doc/lzlib.info b/doc/lzlib.info index afe2774..4e8d079 100644 --- a/doc/lzlib.info +++ b/doc/lzlib.info @@ -11,7 +11,7 @@ File: lzlib.info, Node: Top, Next: Introduction, Up: (dir) Lzlib Manual ************ -This manual is for Lzlib (version 1.15-rc1, 19 November 2024). +This manual is for Lzlib (version 1.15, 9 January 2025). * Menu: @@ -30,7 +30,7 @@ This manual is for Lzlib (version 1.15-rc1, 19 November 2024). * Concept index:: Index of concepts - Copyright (C) 2009-2024 Antonio Diaz Diaz. + Copyright (C) 2009-2025 Antonio Diaz Diaz. This manual is free documentation: you have unlimited permission to copy, distribute, and modify it. @@ -51,7 +51,7 @@ library are declared in the file 'lzlib.h'. Usage examples of the library are given in the files 'bbexample.c', 'ffexample.c', and 'minilzip.c' from the source distribution. - As 'lzlib.h' can be used by C and C++ programs, it must not impose a + As 'lzlib.h' can be used in C and C++ programs, it must not impose a choice of system headers on the program by including one of them. Therefore it is the responsibility of the program using lzlib to include before 'lzlib.h' some header that declares the type 'uint8_t'. There are at least @@ -1280,28 +1280,28 @@ Concept index  Tag Table: Node: Top215 -Node: Introduction1343 -Node: Library version5506 -Node: Buffering8057 -Node: Parameter limits9282 -Node: Compression functions10236 -Ref: member_size12012 -Ref: sync_flush13753 -Node: Decompression functions18319 -Node: Error codes25706 -Node: Error messages28051 -Node: Invoking minilzip28634 -Node: File format39716 -Ref: coded-dict-size41214 -Node: Examples42621 -Node: Buffer compression43582 -Node: Buffer decompression45095 -Node: File compression46502 -Node: File decompression47478 -Node: File compression mm48475 -Node: Skipping data errors51486 -Node: Problems52784 -Node: Concept index53345 +Node: Introduction1337 +Node: Library version5500 +Node: Buffering8051 +Node: Parameter limits9276 +Node: Compression functions10230 +Ref: member_size12006 +Ref: sync_flush13747 +Node: Decompression functions18313 +Node: Error codes25700 +Node: Error messages28045 +Node: Invoking minilzip28628 +Node: File format39710 +Ref: coded-dict-size41208 +Node: Examples42615 +Node: Buffer compression43576 +Node: Buffer decompression45089 +Node: File compression46496 +Node: File decompression47472 +Node: File compression mm48469 +Node: Skipping data errors51480 +Node: Problems52778 +Node: Concept index53339  End Tag Table diff --git a/doc/lzlib.texi b/doc/lzlib.texi index 4600e0d..3e15079 100644 --- a/doc/lzlib.texi +++ b/doc/lzlib.texi @@ -6,8 +6,8 @@ @finalout @c %**end of header -@set UPDATED 19 November 2024 -@set VERSION 1.15-rc1 +@set UPDATED 9 January 2025 +@set VERSION 1.15 @dircategory Compression @direntry @@ -52,7 +52,7 @@ This manual is for Lzlib (version @value{VERSION}, @value{UPDATED}). @end menu @sp 1 -Copyright @copyright{} 2009-2024 Antonio Diaz Diaz. +Copyright @copyright{} 2009-2025 Antonio Diaz Diaz. This manual is free documentation: you have unlimited permission to copy, distribute, and modify it. @@ -75,7 +75,7 @@ are declared in the file @file{lzlib.h}. Usage examples of the library are given in the files @file{bbexample.c}, @file{ffexample.c}, and @file{minilzip.c} from the source distribution. -As @file{lzlib.h} can be used by C and C++ programs, it must not impose a +As @file{lzlib.h} can be used in C and C++ programs, it must not impose a choice of system headers on the program by including one of them. Therefore it is the responsibility of the program using lzlib to include before @file{lzlib.h} some header that declares the type @samp{uint8_t}. There are diff --git a/doc/minilzip.1 b/doc/minilzip.1 index 8d35853..e375123 100644 --- a/doc/minilzip.1 +++ b/doc/minilzip.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.2. -.TH MINILZIP "1" "November 2024" "minilzip 1.15-rc1" "User Commands" +.TH MINILZIP "1" "January 2025" "minilzip 1.15" "User Commands" .SH NAME minilzip \- reduces the size of files .SH SYNOPSIS @@ -116,12 +116,12 @@ Report bugs to lzip\-bug@nongnu.org .br Lzlib home page: http://www.nongnu.org/lzip/lzlib.html .SH COPYRIGHT -Copyright \(co 2024 Antonio Diaz Diaz. +Copyright \(co 2025 Antonio Diaz Diaz. License GPLv2+: GNU GPL version 2 or later .br This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. -Using lzlib 1.15\-rc1 +Using lzlib 1.15 Using LZ_API_VERSION = 1015 .SH "SEE ALSO" The full documentation for diff --git a/encoder.c b/encoder.c index 30254ce..442670a 100644 --- a/encoder.c +++ b/encoder.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2024 Antonio Diaz Diaz. + Copyright (C) 2009-2025 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -291,7 +291,7 @@ static int LZe_sequence_optimizer( LZ_encoder * const e, cur_state = e->trials[prev_index].state; if( prev_index + 1 == cur ) /* len == 1 */ { - if( dis4 == 0 ) cur_state = St_set_short_rep( cur_state ); + if( dis4 == 0 ) cur_state = St_set_shortrep( cur_state ); else cur_state = St_set_char( cur_state ); /* literal */ } else if( dis4 < num_rep_distances ) cur_state = St_set_rep( cur_state ); @@ -555,7 +555,7 @@ static bool LZe_encode_member( LZ_encoder * const e ) if( dis > 1 ) Re_encode_bit( &e->eb.renc, &e->eb.bm_rep2[*state], dis > 2 ); } - if( len == 1 ) *state = St_set_short_rep( *state ); + if( len == 1 ) *state = St_set_shortrep( *state ); else { Re_encode_len( &e->eb.renc, &e->eb.rep_len_model, len, pos_state ); diff --git a/encoder.h b/encoder.h index fd5a312..cb9689e 100644 --- a/encoder.h +++ b/encoder.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2024 Antonio Diaz Diaz. + Copyright (C) 2009-2025 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/encoder_base.c b/encoder_base.c index 2773887..b823dfa 100644 --- a/encoder_base.c +++ b/encoder_base.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2024 Antonio Diaz Diaz. + Copyright (C) 2009-2025 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/encoder_base.h b/encoder_base.h index 56165d4..b4a6f02 100644 --- a/encoder_base.h +++ b/encoder_base.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2024 Antonio Diaz Diaz. + Copyright (C) 2009-2025 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/fast_encoder.c b/fast_encoder.c index 8b0db25..bd675bb 100644 --- a/fast_encoder.c +++ b/fast_encoder.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2024 Antonio Diaz Diaz. + Copyright (C) 2009-2025 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -142,22 +142,22 @@ static bool FLZe_encode_member( FLZ_encoder * const fe ) if( match_byte == cur_byte ) { - const int short_rep_price = price1( fe->eb.bm_match[*state][pos_state] ) + - price1( fe->eb.bm_rep[*state] ) + - price0( fe->eb.bm_rep0[*state] ) + - price0( fe->eb.bm_len[*state][pos_state] ); + const int shortrep_price = price1( fe->eb.bm_match[*state][pos_state] ) + + price1( fe->eb.bm_rep[*state] ) + + price0( fe->eb.bm_rep0[*state] ) + + price0( fe->eb.bm_len[*state][pos_state] ); int price = price0( fe->eb.bm_match[*state][pos_state] ); if( St_is_char( *state ) ) price += LZeb_price_literal( &fe->eb, prev_byte, cur_byte ); else price += LZeb_price_matched( &fe->eb, prev_byte, cur_byte, match_byte ); - if( short_rep_price < price ) + if( shortrep_price < price ) { Re_encode_bit( &fe->eb.renc, &fe->eb.bm_match[*state][pos_state], 1 ); Re_encode_bit( &fe->eb.renc, &fe->eb.bm_rep[*state], 1 ); Re_encode_bit( &fe->eb.renc, &fe->eb.bm_rep0[*state], 0 ); Re_encode_bit( &fe->eb.renc, &fe->eb.bm_len[*state][pos_state], 0 ); - *state = St_set_short_rep( *state ); + *state = St_set_shortrep( *state ); continue; } } diff --git a/fast_encoder.h b/fast_encoder.h index f4b2d3c..bce1b26 100644 --- a/fast_encoder.h +++ b/fast_encoder.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2024 Antonio Diaz Diaz. + Copyright (C) 2009-2025 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/ffexample.c b/ffexample.c index 0c87046..9f313ae 100644 --- a/ffexample.c +++ b/ffexample.c @@ -1,5 +1,5 @@ /* File to file example - Test program for the library lzlib - Copyright (C) 2010-2024 Antonio Diaz Diaz. + Copyright (C) 2010-2025 Antonio Diaz Diaz. This program is free software: you have unlimited permission to copy, distribute, and modify it. diff --git a/lzcheck.c b/lzcheck.c index a393c7d..86ce87d 100644 --- a/lzcheck.c +++ b/lzcheck.c @@ -1,5 +1,5 @@ /* Lzcheck - Test program for the library lzlib - Copyright (C) 2009-2024 Antonio Diaz Diaz. + Copyright (C) 2009-2025 Antonio Diaz Diaz. This program is free software: you have unlimited permission to copy, distribute, and modify it. diff --git a/lzip.h b/lzip.h index 8c4cfdb..0f2c1ed 100644 --- a/lzip.h +++ b/lzip.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2024 Antonio Diaz Diaz. + Copyright (C) 2009-2025 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -40,7 +40,7 @@ static inline State St_set_match( const State st ) { return ( st < 7 ) ? 7 : 10; } static inline State St_set_rep( const State st ) { return ( st < 7 ) ? 8 : 11; } -static inline State St_set_short_rep( const State st ) +static inline State St_set_shortrep( const State st ) { return ( st < 7 ) ? 9 : 11; } diff --git a/lzlib.c b/lzlib.c index b3e4d18..3dd2566 100644 --- a/lzlib.c +++ b/lzlib.c @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2024 Antonio Diaz Diaz. + Copyright (C) 2009-2025 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided diff --git a/lzlib.h b/lzlib.h index c304ffa..926124a 100644 --- a/lzlib.h +++ b/lzlib.h @@ -1,5 +1,5 @@ /* Lzlib - Compression library for the lzip format - Copyright (C) 2009-2024 Antonio Diaz Diaz. + Copyright (C) 2009-2025 Antonio Diaz Diaz. This library is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided @@ -26,7 +26,7 @@ extern "C" { #define LZ_API_VERSION 1015 -static const char * const LZ_version_string = "1.15-rc1"; +static const char * const LZ_version_string = "1.15"; typedef enum LZ_Errno { LZ_ok = 0, LZ_bad_argument, LZ_mem_error, diff --git a/minilzip.c b/minilzip.c index 15adf78..733506c 100644 --- a/minilzip.c +++ b/minilzip.c @@ -1,5 +1,5 @@ /* Minilzip - Test program for the library lzlib - Copyright (C) 2009-2024 Antonio Diaz Diaz. + Copyright (C) 2009-2025 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 @@ -91,7 +91,7 @@ static const char * const mem_msg = "Not enough memory."; int verbosity = 0; static const char * const program_name = "minilzip"; -static const char * const program_year = "2024"; +static const char * const program_year = "2025"; static const char * invocation_name = "minilzip"; /* default value */ static const struct { const char * from; const char * to; } known_extensions[] = { @@ -348,7 +348,7 @@ static void show_header( const unsigned dictionary_size ) } -/* separate numbers of 6 or more digits in groups of 3 digits using '_' */ +/* separate numbers of 5 or more digits in groups of 3 digits using '_' */ static const char * format_num3( unsigned long long num ) { enum { buffers = 8, bufsize = 4 * sizeof num, n = 10 }; @@ -371,7 +371,7 @@ static const char * format_num3( unsigned long long num ) { num /= 1000; prefix = si_prefix[i]; } if( prefix ) *(--p) = prefix; } - const bool split = num >= 100000; + const bool split = num >= 10000; for( i = 0; ; ) { diff --git a/testsuite/check.sh b/testsuite/check.sh index c52cceb..d4c5eff 100755 --- a/testsuite/check.sh +++ b/testsuite/check.sh @@ -1,6 +1,6 @@ #! /bin/sh # check script for Lzlib - Compression library for the lzip format -# Copyright (C) 2009-2024 Antonio Diaz Diaz. +# Copyright (C) 2009-2025 Antonio Diaz Diaz. # # This script is free software: you have unlimited permission # to copy, distribute, and modify it.