1
0
Fork 0

Merging upstream version 1.13~rc1.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-23 19:27:49 +01:00
parent 8a20f7e45f
commit fab8025fd0
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
12 changed files with 289 additions and 250 deletions

View file

@ -1,3 +1,12 @@
2023-12-21 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.13-rc1 released.
* main.c: Reformat file diagnostics as 'PROGRAM: FILE: MESSAGE'.
(show_option_error): New function showing argument and option name.
* lzip.h: Rename verify_* to check_*.
* configure, Makefile.in: New variable 'MAKEINFO'.
* INSTALL: Document use of CFLAGS+='--std=c99 -D_XOPEN_SOURCE=500'.
2022-01-21 Antonio Diaz Diaz <antonio@gnu.org> 2022-01-21 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.12 released. * Version 1.12 released.
@ -109,7 +118,7 @@
* Using LZMA SDK 9.10 (public domain) from Igor Pavlov. * Using LZMA SDK 9.10 (public domain) from Igor Pavlov.
Copyright (C) 2010-2022 Antonio Diaz Diaz. Copyright (C) 2010-2023 Antonio Diaz Diaz.
This file is a collection of facts, and thus it is not copyrightable, 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

17
INSTALL
View file

@ -18,8 +18,8 @@ Procedure
or or
lzip -cd pdlzip[version].tar.lz | tar -xf - lzip -cd pdlzip[version].tar.lz | tar -xf -
This creates the directory ./pdlzip[version] containing the source from This creates the directory ./pdlzip[version] containing the source code
the main archive. extracted from the archive.
2. Change to pdlzip directory and run configure. 2. Change to pdlzip directory and run configure.
(Try 'configure --help' for usage instructions). (Try 'configure --help' for usage instructions).
@ -27,6 +27,10 @@ the main archive.
cd pdlzip[version] cd pdlzip[version]
./configure ./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: If you are compiling on MinGW, use:
./configure CFLAGS+='-D __USE_MINGW_ANSI_STDIO' ./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 pdlzip. 4. Optionally, type 'make check' to run the tests that come with pdlzip.
5. Type 'make install' to install the program and any data files and 5. Type 'make install' to install the program and any data files and
documentation. documentation. You need root privileges to install into a prefix owned
by root.
Or type 'make install-compress', which additionally compresses the Or type 'make install-compress', which additionally compresses the
man page after installation. man page after installation.
@ -61,15 +66,15 @@ 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. in the directory that 'configure' is in.
'configure' recognizes the option '--srcdir=DIR' to control where to 'configure' recognizes the option '--srcdir=DIR' to control where to look
look for the sources. Usually 'configure' can determine that directory for the source code. Usually 'configure' can determine that directory
automatically. automatically.
After running 'configure', you can run 'make' and 'make install' as After running 'configure', you can run 'make' and 'make install' as
explained above. explained above.
Copyright (C) 2010-2022 Antonio Diaz Diaz. Copyright (C) 2010-2023 Antonio Diaz Diaz.
This file is free documentation: you have unlimited permission to copy, This file is free documentation: you have unlimited permission to copy,
distribute, and modify it. distribute, and modify it.

View file

@ -28,6 +28,10 @@ main.o : main.c
%.o : %.c %.o : %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
# prevent 'make' from trying to remake source files
$(VPATH)/configure $(VPATH)/Makefile.in $(VPATH)/doc/$(pkgname).texi : ;
%.h %.c : ;
$(objs) : Makefile $(objs) : Makefile
carg_parser.o : carg_parser.h carg_parser.o : carg_parser.h
LzmaDec.o : lzip.h LzmaDec.h LzmaDec.o : lzip.h LzmaDec.h
@ -35,13 +39,12 @@ LzFind.o : lzip.h LzFind.h
LzmaEnc.o : lzip.h LzFind.h LzmaEnc.h LzmaEnc.o : lzip.h LzFind.h LzmaEnc.h
main.o : carg_parser.h lzip.h LzmaDec.h LzmaEnc.h main.o : carg_parser.h lzip.h LzmaDec.h LzmaEnc.h
doc : man doc : man
info : $(VPATH)/doc/$(pkgname).info info : $(VPATH)/doc/$(pkgname).info
$(VPATH)/doc/$(pkgname).info : $(VPATH)/doc/$(pkgname).texi $(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 man : $(VPATH)/doc/$(progname).1

14
NEWS
View file

@ -1,4 +1,12 @@
Changes in version 1.12: Changes in version 1.13:
In case of error in a numerical argument to a command line option, pdlzip File diagnostics have been reformatted as 'PROGRAM: FILE: MESSAGE'.
now shows the name of the option and the range of valid values.
Diagnostics caused by invalid arguments to command-line options now show the
argument and the name of the option.
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'

19
README
View file

@ -7,14 +7,15 @@ Pdlzip is written in C and is (hope)fully compatible with lzip 1.4 or newer.
Lzip is a lossless data compressor with a user interface similar to the one 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 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 chain-Algorithm' (LZMA) stream format to maximize interoperability. The
checking to maximize interoperability and optimize safety. Lzip can compress maximum dictionary size is 512 MiB so that any lzip file can be decompressed
about as fast as gzip (lzip -0) or compress most files more than bzip2 on 32-bit machines. Lzip provides accurate and robust 3-factor integrity
(lzip -9). Decompression speed is intermediate between gzip and bzip2. checking. Lzip can compress about as fast as gzip (lzip -0) or compress most
Lzip is better than gzip and bzip2 from a data recovery perspective. Lzip files more than bzip2 (lzip -9). Decompression speed is intermediate between
has been designed, written, and tested with great care to replace gzip and gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery
bzip2 as the standard general-purpose compressed format for unix-like perspective. Lzip has been designed, written, and tested with great care to
systems. replace gzip and bzip2 as the standard general-purpose compressed format for
Unix-like systems.
The lzip file format is designed for data sharing and long-term archiving, The lzip file format is designed for data sharing and long-term archiving,
taking into account both data integrity and decoder availability: taking into account both data integrity and decoder availability:
@ -56,7 +57,7 @@ users of the most non-free platforms can share lzip files with everybody
else. else.
Copyright (C) 2010-2022 Antonio Diaz Diaz. Copyright (C) 2010-2023 Antonio Diaz Diaz.
This file is free documentation: you have unlimited permission to copy, This file is free documentation: you have unlimited permission to copy,
distribute, and modify it. distribute, and modify it.

View file

@ -1,5 +1,5 @@
/* Arg_parser - POSIX/GNU command line argument parser. (C version) /* Arg_parser - POSIX/GNU command-line argument parser. (C version)
Copyright (C) 2006-2022 Antonio Diaz Diaz. Copyright (C) 2006-2023 Antonio Diaz Diaz.
This library is free software. Redistribution and use in source and This library is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided binary forms, with or without modification, are permitted provided

View file

@ -1,5 +1,5 @@
/* Arg_parser - POSIX/GNU command line argument parser. (C version) /* Arg_parser - POSIX/GNU command-line argument parser. (C version)
Copyright (C) 2006-2022 Antonio Diaz Diaz. Copyright (C) 2006-2023 Antonio Diaz Diaz.
This library is free software. Redistribution and use in source and This library is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided binary forms, with or without modification, are permitted provided

25
configure vendored
View file

@ -1,12 +1,12 @@
#! /bin/sh #! /bin/sh
# configure script for Pdlzip - LZMA lossless data compressor # configure script for Pdlzip - LZMA lossless data compressor
# Copyright (C) 2010-2022 Antonio Diaz Diaz. # Copyright (C) 2010-2023 Antonio Diaz Diaz.
# #
# This configure script is free software: you have unlimited permission # This configure script is free software: you have unlimited permission
# to copy, distribute, and modify it. # to copy, distribute, and modify it.
pkgname=pdlzip pkgname=pdlzip
pkgversion=1.12 pkgversion=1.13-rc1
progname=pdlzip progname=pdlzip
srctrigger=doc/${progname}.1 srctrigger=doc/${progname}.1
@ -24,6 +24,7 @@ CC=gcc
CPPFLAGS= CPPFLAGS=
CFLAGS='-Wall -W -O2' CFLAGS='-Wall -W -O2'
LDFLAGS= LDFLAGS=
MAKEINFO=makeinfo
# checking whether we are using GNU C. # 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 ; }
@ -57,7 +58,7 @@ while [ $# != 0 ] ; do
echo "Options and variables: [defaults in brackets]" echo "Options and variables: [defaults in brackets]"
echo " -h, --help display this help and exit" echo " -h, --help display this help and exit"
echo " -V, --version output version information 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 " --prefix=DIR install into DIR [${prefix}]"
echo " --exec-prefix=DIR base directory for arch-dependent files [${exec_prefix}]" echo " --exec-prefix=DIR base directory for arch-dependent files [${exec_prefix}]"
echo " --bindir=DIR user executables directory [${bindir}]" echo " --bindir=DIR user executables directory [${bindir}]"
@ -65,10 +66,11 @@ while [ $# != 0 ] ; do
echo " --infodir=DIR info files directory [${infodir}]" echo " --infodir=DIR info files directory [${infodir}]"
echo " --mandir=DIR man pages directory [${mandir}]" echo " --mandir=DIR man pages directory [${mandir}]"
echo " CC=COMPILER C compiler to use [${CC}]" echo " CC=COMPILER C compiler to use [${CC}]"
echo " CPPFLAGS=OPTIONS command line options for the preprocessor [${CPPFLAGS}]" echo " CPPFLAGS=OPTIONS command-line options for the preprocessor [${CPPFLAGS}]"
echo " CFLAGS=OPTIONS command line options for the C compiler [${CFLAGS}]" echo " CFLAGS=OPTIONS command-line options for the C compiler [${CFLAGS}]"
echo " CFLAGS+=OPTIONS append options to the current value of CFLAGS" echo " CFLAGS+=OPTIONS append options to the current value of CFLAGS"
echo " LDFLAGS=OPTIONS command line options for the linker [${LDFLAGS}]" echo " LDFLAGS=OPTIONS command-line options for the linker [${LDFLAGS}]"
echo " MAKEINFO=NAME makeinfo program to use [${MAKEINFO}]"
echo echo
exit 0 ;; exit 0 ;;
--version | -V) --version | -V)
@ -96,6 +98,7 @@ while [ $# != 0 ] ; do
CFLAGS=*) CFLAGS=${optarg} ;; CFLAGS=*) CFLAGS=${optarg} ;;
CFLAGS+=*) CFLAGS="${CFLAGS} ${optarg}" ;; CFLAGS+=*) CFLAGS="${CFLAGS} ${optarg}" ;;
LDFLAGS=*) LDFLAGS=${optarg} ;; LDFLAGS=*) LDFLAGS=${optarg} ;;
MAKEINFO=*) MAKEINFO=${optarg} ;;
--*) --*)
echo "configure: WARNING: unrecognized option: '${option}'" 1>&2 ;; echo "configure: WARNING: unrecognized option: '${option}'" 1>&2 ;;
@ -115,7 +118,7 @@ while [ $# != 0 ] ; do
fi fi
done done
# Find the source files, if location was not specified. # Find the source code, if location was not specified.
srcdirtext= srcdirtext=
if [ -z "${srcdir}" ] ; then if [ -z "${srcdir}" ] ; then
srcdirtext="or . or .." ; srcdir=. srcdirtext="or . or .." ; srcdir=.
@ -127,7 +130,7 @@ if [ -z "${srcdir}" ] ; then
fi fi
if [ ! -r "${srcdir}/${srctrigger}" ] ; then 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 echo "configure: (At least ${srctrigger} is missing)." 1>&2
exit 1 exit 1
fi fi
@ -147,7 +150,7 @@ if [ -z "${no_create}" ] ; then
# This script is free software: you have unlimited permission # 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 exec /bin/sh "$0" ${args} --no-create
EOF EOF
chmod +x config.status chmod +x config.status
fi fi
@ -164,10 +167,11 @@ echo "CC = ${CC}"
echo "CPPFLAGS = ${CPPFLAGS}" echo "CPPFLAGS = ${CPPFLAGS}"
echo "CFLAGS = ${CFLAGS}" echo "CFLAGS = ${CFLAGS}"
echo "LDFLAGS = ${LDFLAGS}" echo "LDFLAGS = ${LDFLAGS}"
echo "MAKEINFO = ${MAKEINFO}"
rm -f Makefile rm -f Makefile
cat > Makefile << EOF cat > Makefile << EOF
# Makefile for Pdlzip - LZMA lossless data compressor # Makefile for Pdlzip - LZMA lossless data compressor
# Copyright (C) 2010-2022 Antonio Diaz Diaz. # Copyright (C) 2010-2023 Antonio Diaz Diaz.
# This file was generated automatically by configure. Don't edit. # This file was generated automatically by configure. Don't edit.
# #
# This Makefile is free software: you have unlimited permission # This Makefile is free software: you have unlimited permission
@ -187,6 +191,7 @@ CC = ${CC}
CPPFLAGS = ${CPPFLAGS} CPPFLAGS = ${CPPFLAGS}
CFLAGS = ${CFLAGS} CFLAGS = ${CFLAGS}
LDFLAGS = ${LDFLAGS} LDFLAGS = ${LDFLAGS}
MAKEINFO = ${MAKEINFO}
EOF EOF
cat "${srcdir}/Makefile.in" >> Makefile cat "${srcdir}/Makefile.in" >> Makefile

View file

@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.16. .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.2.
.TH PDLZIP "1" "January 2022" "pdlzip 1.12" "User Commands" .TH PDLZIP "1" "December 2023" "pdlzip 1.13-rc1" "User Commands"
.SH NAME .SH NAME
pdlzip \- reduces the size of files pdlzip \- reduces the size of files
.SH SYNOPSIS .SH SYNOPSIS
@ -13,14 +13,15 @@ Pdlzip is written in C and is (hope)fully compatible with lzip 1.4 or newer.
.PP .PP
Lzip is a lossless data compressor with a user interface similar to the one 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 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 chain\-Algorithm' (LZMA) stream format to maximize interoperability. The
checking to maximize interoperability and optimize safety. Lzip can compress maximum dictionary size is 512 MiB so that any lzip file can be decompressed
about as fast as gzip (lzip \fB\-0\fR) or compress most files more than bzip2 on 32\-bit machines. Lzip provides accurate and robust 3\-factor integrity
(lzip \fB\-9\fR). Decompression speed is intermediate between gzip and bzip2. checking. Lzip can compress about as fast as gzip (lzip \fB\-0\fR) or compress most
Lzip is better than gzip and bzip2 from a data recovery perspective. Lzip files more than bzip2 (lzip \fB\-9\fR). Decompression speed is intermediate between
has been designed, written, and tested with great care to replace gzip and gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery
bzip2 as the standard general\-purpose compressed format for unix\-like perspective. Lzip has been designed, written, and tested with great care to
systems. replace gzip and bzip2 as the standard general\-purpose compressed format for
Unix\-like systems.
.PP .PP
Pdlzip is also able to decompress legacy lzma\-alone (.lzma) files. Pdlzip is also able to decompress legacy lzma\-alone (.lzma) files.
Lzma\-alone is a very bad format; it is essentially a raw LZMA stream. Lzma\-alone is a very bad format; it is essentially a raw LZMA stream.
@ -42,7 +43,7 @@ exit with error status if trailing data
write to standard output, keep input files write to standard output, keep input files
.TP .TP
\fB\-d\fR, \fB\-\-decompress\fR \fB\-d\fR, \fB\-\-decompress\fR
decompress decompress, test compressed file integrity
.TP .TP
\fB\-f\fR, \fB\-\-force\fR \fB\-f\fR, \fB\-\-force\fR
overwrite existing output files overwrite existing output files
@ -87,22 +88,22 @@ If no file names are given, or if a file is '\-', pdlzip compresses or
decompresses from standard input to standard output. decompresses from standard input to standard output.
Numbers may be followed by a multiplier: k = kB = 10^3 = 1000, 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... Ki = KiB = 2^10 = 1024, M = 10^6, Mi = 2^20, G = 10^9, Gi = 2^30, etc...
Dictionary sizes 12 to 27 are interpreted as powers of two, meaning 2^12 Dictionary sizes 12 to 27 are interpreted as powers of two, meaning 2^12 to
to 2^27 bytes. 2^27 bytes.
.PP .PP
The bidimensional parameter space of LZMA can't be mapped to a linear The bidimensional parameter space of LZMA can't be mapped to a linear scale
scale optimal for all files. If your files are large, very repetitive, optimal for all files. If your files are large, very repetitive, etc, you
etc, you may need to use the options \fB\-\-dictionary\-size\fR and \fB\-\-match\-length\fR may need to use the options \fB\-\-dictionary\-size\fR and \fB\-\-match\-length\fR directly
directly to achieve optimal performance. For example, \fB\-9m64\fR usually to achieve optimal performance. For example, \fB\-9m64\fR usually compresses
compresses executables more (and faster) than \fB\-9\fR. executables more (and faster) than \fB\-9\fR.
.PP .PP
To extract all the files from archive 'foo.tar.lz', use the commands To extract all the files from archive 'foo.tar.lz', use the commands
\&'tar \fB\-xf\fR foo.tar.lz' or 'pdlzip \fB\-cd\fR foo.tar.lz | tar \fB\-xf\fR \-'. \&'tar \fB\-xf\fR foo.tar.lz' or 'pdlzip \fB\-cd\fR foo.tar.lz | tar \fB\-xf\fR \-'.
.PP .PP
Exit status: 0 for a normal exit, 1 for environmental problems (file Exit status: 0 for a normal exit, 1 for environmental problems
not found, invalid flags, I/O errors, etc), 2 to indicate a corrupt or (file not found, invalid command\-line options, I/O errors, etc), 2 to
invalid input file, 3 for an internal consistency error (e.g., bug) which indicate a corrupt or invalid input file, 3 for an internal consistency
caused pdlzip to panic. error (e.g., bug) which caused pdlzip to panic.
.PP .PP
Pdlzip includes public domain compression/decompression code from the LZMA Pdlzip includes public domain compression/decompression code from the LZMA
SDK (Software Development Kit) written by Igor Pavlov. SDK (Software Development Kit) written by Igor Pavlov.
@ -111,7 +112,7 @@ Report bugs to lzip\-bug@nongnu.org
.br .br
Pdlzip home page: http://www.nongnu.org/lzip/pdlzip.html Pdlzip home page: http://www.nongnu.org/lzip/pdlzip.html
.SH COPYRIGHT .SH COPYRIGHT
Copyright \(co 2022 Antonio Diaz Diaz. Copyright \(co 2023 Antonio Diaz Diaz.
Public Domain 2009 Igor Pavlov. Public Domain 2009 Igor Pavlov.
License 2\-clause BSD. License 2\-clause BSD.
.br .br

34
lzip.h
View file

@ -1,5 +1,5 @@
/* Pdlzip - LZMA lossless data compressor /* Pdlzip - LZMA lossless data compressor
Copyright (C) 2010-2022 Antonio Diaz Diaz. Copyright (C) 2010-2023 Antonio Diaz Diaz.
This program is free software. Redistribution and use in source and This program is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided binary forms, with or without modification, are permitted provided
@ -78,8 +78,8 @@ static inline void CRC32_update_buf( uint32_t * const crc,
static inline bool isvalid_ds( const unsigned dictionary_size ) static inline bool isvalid_ds( const unsigned dictionary_size )
{ return ( dictionary_size >= min_dictionary_size && { return dictionary_size >= min_dictionary_size &&
dictionary_size <= max_dictionary_size ); } dictionary_size <= max_dictionary_size; }
static inline int real_bits( unsigned value ) static inline int real_bits( unsigned value )
@ -92,43 +92,43 @@ static inline int real_bits( unsigned value )
static const uint8_t lzip_magic[4] = { 0x4C, 0x5A, 0x49, 0x50 }; /* "LZIP" */ 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 */ /* 4 version */
/* 5 coded dictionary size */ /* 5 coded dictionary size */
enum { Lh_size = 6 };
static inline void Lh_set_magic( Lzip_header data ) static inline void Lh_set_magic( Lzip_header data )
{ memcpy( data, lzip_magic, 4 ); data[4] = 1; } { memcpy( data, lzip_magic, 4 ); data[4] = 1; }
static inline bool Lh_verify_magic( const Lzip_header data ) static inline bool Lh_check_magic( const Lzip_header data )
{ return ( memcmp( data, lzip_magic, 4 ) == 0 ); } { return memcmp( data, lzip_magic, 4 ) == 0; }
/* detect (truncated) header */ /* 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 ) int i; for( i = 0; i < sz && i < 4; ++i )
if( data[i] != lzip_magic[i] ) return false; if( data[i] != lzip_magic[i] ) return false;
return ( sz > 0 ); return sz > 0;
} }
/* detect corrupt header */ /* 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 matches = 0;
int i; for( i = 0; i < 4; ++i ) int i; for( i = 0; i < 4; ++i )
if( data[i] == lzip_magic[i] ) ++matches; 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 ) static inline uint8_t Lh_version( const Lzip_header data )
{ return data[4]; } { return data[4]; }
static inline bool Lh_verify_version( const Lzip_header data ) static inline bool Lh_check_version( const Lzip_header data )
{ return ( data[4] == 1 ); } { return data[4] == 1; }
static inline unsigned Lh_get_dictionary_size( const Lzip_header data ) 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 ) if( sz > min_dictionary_size )
sz -= ( sz / 16 ) * ( ( data[5] >> 5 ) & 7 ); sz -= ( sz / 16 ) * ( ( data[5] >> 5 ) & 7 );
return sz; return sz;
@ -145,17 +145,17 @@ static inline bool Lh_set_dictionary_size( Lzip_header data, const unsigned sz )
unsigned i; unsigned i;
for( i = 7; i >= 1; --i ) for( i = 7; i >= 1; --i )
if( base_size - ( i * fraction ) >= sz ) if( base_size - ( i * fraction ) >= sz )
{ data[5] |= ( i << 5 ); break; } { data[5] |= i << 5; break; }
} }
return true; return true;
} }
typedef uint8_t Lzip_trailer[20]; enum { Lt_size = 20 };
typedef uint8_t Lzip_trailer[Lt_size];
/* 0-3 CRC32 of the uncompressed data */ /* 0-3 CRC32 of the uncompressed data */
/* 4-11 size of the uncompressed data */ /* 4-11 size of the uncompressed data */
/* 12-19 member size including header and trailer */ /* 12-19 member size including header and trailer */
enum { Lt_size = 20 };
static inline unsigned Lt_get_data_crc( const Lzip_trailer data ) static inline unsigned Lt_get_data_crc( const Lzip_trailer data )
{ {

177
main.c
View file

@ -1,6 +1,6 @@
/* Pdlzip - LZMA lossless data compressor /* Pdlzip - LZMA lossless data compressor
2009-08-14 : Igor Pavlov : Public domain 2009-08-14 : Igor Pavlov : Public domain
Copyright (C) 2010-2022 Antonio Diaz Diaz. Copyright (C) 2010-2023 Antonio Diaz Diaz.
This program is free software. Redistribution and use in source and This program is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided binary forms, with or without modification, are permitted provided
@ -19,19 +19,19 @@
*/ */
/* /*
Exit status: 0 for a normal exit, 1 for environmental problems Exit status: 0 for a normal exit, 1 for environmental problems
(file not found, invalid flags, I/O errors, etc), 2 to indicate a (file not found, invalid command-line options, I/O errors, etc), 2 to
corrupt or invalid input file, 3 for an internal consistency error indicate a corrupt or invalid input file, 3 for an internal consistency
(e.g., bug) which caused pdlzip to panic. error (e.g., bug) which caused pdlzip to panic.
*/ */
#define _FILE_OFFSET_BITS 64 #define _FILE_OFFSET_BITS 64
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <limits.h> #include <limits.h> /* SSIZE_MAX */
#include <signal.h> #include <signal.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h> /* SIZE_MAX */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -85,7 +85,7 @@ static void show_file_error( const char * const filename,
static void internal_error( const char * const msg ); static void internal_error( const char * const msg );
static const char * const program_name = "pdlzip"; static const char * const program_name = "pdlzip";
static const char * const program_year = "2022"; static const char * const program_year = "2023";
static const char * invocation_name = "pdlzip"; /* default value */ static const char * invocation_name = "pdlzip"; /* default value */
static const struct { const char * from; const char * to; } known_extensions[] = { static const struct { const char * from; const char * to; } known_extensions[] = {
@ -117,14 +117,15 @@ static void show_help( void )
"Pdlzip is written in C and is (hope)fully compatible with lzip 1.4 or newer.\n" "Pdlzip is written in C and is (hope)fully compatible with lzip 1.4 or newer.\n"
"\nLzip is a lossless data compressor with a user interface similar to the one\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" "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" "chain-Algorithm' (LZMA) stream format to maximize interoperability. The\n"
"checking to maximize interoperability and optimize safety. Lzip can compress\n" "maximum dictionary size is 512 MiB so that any lzip file can be decompressed\n"
"about as fast as gzip (lzip -0) or compress most files more than bzip2\n" "on 32-bit machines. Lzip provides accurate and robust 3-factor integrity\n"
"(lzip -9). Decompression speed is intermediate between gzip and bzip2.\n" "checking. Lzip can compress about as fast as gzip (lzip -0) or compress most\n"
"Lzip is better than gzip and bzip2 from a data recovery perspective. Lzip\n" "files more than bzip2 (lzip -9). Decompression speed is intermediate between\n"
"has been designed, written, and tested with great care to replace gzip and\n" "gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery\n"
"bzip2 as the standard general-purpose compressed format for unix-like\n" "perspective. Lzip has been designed, written, and tested with great care to\n"
"systems.\n" "replace gzip and bzip2 as the standard general-purpose compressed format for\n"
"Unix-like systems.\n"
"\nPdlzip is also able to decompress legacy lzma-alone (.lzma) files.\n" "\nPdlzip is also able to decompress legacy lzma-alone (.lzma) files.\n"
"Lzma-alone is a very bad format; it is essentially a raw LZMA stream.\n" "Lzma-alone is a very bad format; it is essentially a raw LZMA stream.\n"
"If you keep any lzma-alone files, it is advisable to recompress them to\n" "If you keep any lzma-alone files, it is advisable to recompress them to\n"
@ -136,7 +137,7 @@ static void show_help( void )
" -V, --version output version information and exit\n" " -V, --version output version information and exit\n"
" -a, --trailing-error exit with error status if trailing data\n" " -a, --trailing-error exit with error status if trailing data\n"
" -c, --stdout write to standard output, keep input files\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, --force overwrite existing output files\n"
" -F, --recompress force re-compression of compressed files\n" " -F, --recompress force re-compression of compressed files\n"
" -k, --keep keep (don't delete) input files\n" " -k, --keep keep (don't delete) input files\n"
@ -154,19 +155,19 @@ static void show_help( void )
"decompresses from standard input to standard output.\n" "decompresses from standard input to standard output.\n"
"Numbers may be followed by a multiplier: k = kB = 10^3 = 1000,\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" "Ki = KiB = 2^10 = 1024, M = 10^6, Mi = 2^20, G = 10^9, Gi = 2^30, etc...\n"
"Dictionary sizes 12 to 27 are interpreted as powers of two, meaning 2^12\n" "Dictionary sizes 12 to 27 are interpreted as powers of two, meaning 2^12 to\n"
"to 2^27 bytes.\n" "2^27 bytes.\n"
"\nThe bidimensional parameter space of LZMA can't be mapped to a linear\n" "\nThe bidimensional parameter space of LZMA can't be mapped to a linear scale\n"
"scale optimal for all files. If your files are large, very repetitive,\n" "optimal for all files. If your files are large, very repetitive, etc, you\n"
"etc, you may need to use the options --dictionary-size and --match-length\n" "may need to use the options --dictionary-size and --match-length directly\n"
"directly to achieve optimal performance. For example, -9m64 usually\n" "to achieve optimal performance. For example, -9m64 usually compresses\n"
"compresses executables more (and faster) than -9.\n" "executables more (and faster) than -9.\n"
"\nTo extract all the files from archive 'foo.tar.lz', use the commands\n" "\nTo extract all the files from archive 'foo.tar.lz', use the commands\n"
"'tar -xf foo.tar.lz' or 'pdlzip -cd foo.tar.lz | tar -xf -'.\n" "'tar -xf foo.tar.lz' or 'pdlzip -cd foo.tar.lz | tar -xf -'.\n"
"\nExit status: 0 for a normal exit, 1 for environmental problems (file\n" "\nExit status: 0 for a normal exit, 1 for environmental problems\n"
"not found, invalid flags, I/O errors, etc), 2 to indicate a corrupt or\n" "(file not found, invalid command-line options, I/O errors, etc), 2 to\n"
"invalid input file, 3 for an internal consistency error (e.g., bug) which\n" "indicate a corrupt or invalid input file, 3 for an internal consistency\n"
"caused pdlzip to panic.\n" "error (e.g., bug) which caused pdlzip to panic.\n"
"\nPdlzip includes public domain compression/decompression code from the LZMA\n" "\nPdlzip includes public domain compression/decompression code from the LZMA\n"
"SDK (Software Development Kit) written by Igor Pavlov.\n" "SDK (Software Development Kit) written by Igor Pavlov.\n"
"\nReport bugs to lzip-bug@nongnu.org\n" "\nReport bugs to lzip-bug@nongnu.org\n"
@ -262,27 +263,26 @@ static void Pp_show_msg( struct Pretty_print * const pp, const char * const msg
static void show_header( const unsigned dictionary_size ) static void show_header( const unsigned dictionary_size )
{ {
enum { factor = 1024 }; enum { factor = 1024, n = 3 };
const char * const prefix[8] = const char * const prefix[n] = { "Ki", "Mi", "Gi" };
{ "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" };
const char * p = ""; const char * p = "";
const char * np = " "; const char * np = " ";
unsigned num = dictionary_size; unsigned num = dictionary_size;
bool exact = ( num % factor == 0 ); 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; { num /= factor; if( num % factor != 0 ) exact = false;
p = prefix[i]; np = ""; } p = prefix[i]; np = ""; }
fprintf( stderr, "dict %s%4u %sB, ", np, num, p ); 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 ) static const char * format_num3( unsigned long long num )
{ {
const char * const si_prefix = "kMGTPEZY"; enum { buffers = 8, bufsize = 4 * sizeof num, n = 10 };
const char * const binary_prefix = "KMGTPEZY"; const char * const si_prefix = "kMGTPEZYRQ";
enum { buffers = 8, bufsize = 4 * sizeof (long long) }; const char * const binary_prefix = "KMGTPEZYRQ";
static char buffer[buffers][bufsize]; /* circle of static buffers for printf */ static char buffer[buffers][bufsize]; /* circle of static buffers for printf */
static int current = 0; static int current = 0;
int i; int i;
@ -292,15 +292,15 @@ static const char * format_num3( unsigned long long num )
if( num > 1024 ) if( num > 1024 )
{ {
char prefix = 0; /* try binary first, then si */ 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]; } { num /= 1024; prefix = binary_prefix[i]; }
if( prefix ) *(--p) = 'i'; if( prefix ) *(--p) = 'i';
else 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]; } { num /= 1000; prefix = si_prefix[i]; }
if( prefix ) *(--p) = prefix; if( prefix ) *(--p) = prefix;
} }
const bool split = num >= 100000; const bool split = num >= 10000;
for( i = 0; ; ) for( i = 0; ; )
{ {
@ -311,6 +311,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: <num>k, <num>Ki, <num>[MGTPEZYRQ][i] */
static unsigned long getnum( const char * const arg, static unsigned long getnum( const char * const arg,
const char * const option_name, const char * const option_name,
const unsigned long llimit, const unsigned long llimit,
@ -320,12 +330,8 @@ static unsigned long getnum( const char * const arg,
errno = 0; errno = 0;
unsigned long result = strtoul( arg, &tail, 0 ); unsigned long result = strtoul( arg, &tail, 0 );
if( tail == arg ) if( tail == arg )
{ { show_option_error( arg, "Bad or missing numerical argument in",
if( verbosity >= 0 ) option_name ); exit( 1 ); }
fprintf( stderr, "%s: Bad or missing numerical argument in "
"option '%s'.\n", program_name, option_name );
exit( 1 );
}
if( !errno && tail[0] ) if( !errno && tail[0] )
{ {
@ -334,6 +340,8 @@ static unsigned long getnum( const char * const arg,
int i; int i;
switch( tail[0] ) switch( tail[0] )
{ {
case 'Q': exponent = 10; break;
case 'R': exponent = 9; break;
case 'Y': exponent = 8; break; case 'Y': exponent = 8; break;
case 'Z': exponent = 7; break; case 'Z': exponent = 7; break;
case 'E': exponent = 6; break; case 'E': exponent = 6; break;
@ -345,12 +353,8 @@ static unsigned long getnum( const char * const arg,
case 'k': if( factor == 1000 ) exponent = 1; break; case 'k': if( factor == 1000 ) exponent = 1; break;
} }
if( exponent <= 0 ) if( exponent <= 0 )
{ { show_option_error( arg, "Bad multiplier in numerical argument of",
if( verbosity >= 0 ) option_name ); exit( 1 ); }
fprintf( stderr, "%s: Bad multiplier in numerical argument of "
"option '%s'.\n", program_name, option_name );
exit( 1 );
}
for( i = 0; i < exponent; ++i ) for( i = 0; i < exponent; ++i )
{ {
if( ulimit / factor >= result ) result *= factor; if( ulimit / factor >= result ) result *= factor;
@ -361,8 +365,8 @@ static unsigned long getnum( const char * const arg,
if( errno ) if( errno )
{ {
if( verbosity >= 0 ) if( verbosity >= 0 )
fprintf( stderr, "%s: Numerical argument out of limits [%s,%s] " fprintf( stderr, "%s: '%s': Value out of limits [%s,%s] in "
"in option '%s'.\n", program_name, format_num3( llimit ), "option '%s'.\n", program_name, arg, format_num3( llimit ),
format_num3( ulimit ), option_name ); format_num3( ulimit ), option_name );
exit( 1 ); exit( 1 );
} }
@ -442,7 +446,7 @@ static void set_d_outname( const char * const name, const int eindex )
strcpy( output_filename, name ); strcpy( output_filename, name );
strcat( output_filename, ".out" ); strcat( output_filename, ".out" );
if( verbosity >= 1 ) 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 ); program_name, name, output_filename );
} }
@ -454,7 +458,7 @@ static int open_instream( const char * const name, struct stat * const in_statsp
if( program_mode == m_compress && !recompress && eindex >= 0 ) if( program_mode == m_compress && !recompress && eindex >= 0 )
{ {
if( verbosity >= 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 ); program_name, name, known_extensions[eindex].from );
return -1; return -1;
} }
@ -471,9 +475,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( i != 0 || ( !S_ISREG( mode ) && ( !can_read || one_to_one ) ) )
{ {
if( verbosity >= 0 ) 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 ) ? 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 ); close( infd );
infd = -1; infd = -1;
} }
@ -492,16 +496,12 @@ static bool open_outstream( const bool force, const bool protect )
outfd = open( output_filename, flags, outfd_mode ); outfd = open( output_filename, flags, outfd_mode );
if( outfd >= 0 ) delete_output_on_interrupt = true; if( outfd >= 0 ) delete_output_on_interrupt = true;
else if( verbosity >= 0 ) else if( errno == EEXIST )
{ show_file_error( output_filename,
if( errno == EEXIST ) "Output file already exists, skipping.", 0 );
fprintf( stderr, "%s: Output file '%s' already exists, skipping.\n", else
program_name, output_filename ); show_file_error( output_filename, "Can't create output file", errno );
else return outfd >= 0;
fprintf( stderr, "%s: Can't create output file '%s': %s\n",
program_name, output_filename, strerror( errno ) );
}
return ( outfd >= 0 );
} }
@ -519,12 +519,10 @@ static void cleanup_and_fail( const int retval )
if( delete_output_on_interrupt ) if( delete_output_on_interrupt )
{ {
delete_output_on_interrupt = false; delete_output_on_interrupt = false;
if( verbosity >= 0 ) show_file_error( output_filename, "Deleting output file, if it exists.", 0 );
fprintf( stderr, "%s: Deleting output file '%s', if it exists.\n",
program_name, output_filename );
if( outfd >= 0 ) { close( outfd ); outfd = -1; } if( outfd >= 0 ) { close( outfd ); outfd = -1; }
if( remove( output_filename ) != 0 && errno != ENOENT ) 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 ); exit( retval );
} }
@ -578,10 +576,8 @@ static void close_and_set_permissions( const struct stat * const in_statsp )
warning = true; warning = true;
} }
if( close( outfd ) != 0 ) if( close( outfd ) != 0 )
{ { show_file_error( output_filename, "Error closing output file", errno );
show_error( "Error closing output file", errno, false ); cleanup_and_fail( 1 ); }
cleanup_and_fail( 1 );
}
outfd = -1; outfd = -1;
delete_output_on_interrupt = false; delete_output_on_interrupt = false;
if( in_statsp ) if( in_statsp )
@ -592,12 +588,13 @@ static void close_and_set_permissions( const struct stat * const in_statsp )
if( utime( output_filename, &t ) != 0 ) warning = true; if( utime( output_filename, &t ) != 0 ) warning = true;
} }
if( warning && verbosity >= 1 ) 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 );
} }
static int compress( const struct Lzma_options * const encoder_options, static int compress( const int infd, const struct Lzma_options * const
struct Pretty_print * const pp, const int infd ) encoder_options, struct Pretty_print * const pp )
{ {
int retval = 0; int retval = 0;
CLzmaEncHandle encoder = 0; CLzmaEncHandle encoder = 0;
@ -855,7 +852,7 @@ static int decompress( const int infd, struct Pretty_print * const pp,
for( first_member = true; ; first_member = false ) for( first_member = true; ; first_member = false )
{ {
int i; int i;
unsigned dictionary_size = 0; /* keep gcc 3.3.6 happy */ unsigned dictionary_size = 0; /* keep gcc 3.3.6 quiet */
Lzip_header header; Lzip_header header;
if( inSize - inPos < lzma_header_size && if( inSize - inPos < lzma_header_size &&
!read_inbuf( infd, inBuf, &inPos, &inSize ) ) return 1; !read_inbuf( infd, inBuf, &inPos, &inSize ) ) return 1;
@ -867,18 +864,18 @@ static int decompress( const int infd, struct Pretty_print * const pp,
if( first_member ) if( first_member )
{ show_file_error( pp->name, "File ends unexpectedly at member header.", 0 ); { show_file_error( pp->name, "File ends unexpectedly at member header.", 0 );
retval = 2; } retval = 2; }
else if( Lh_verify_prefix( header, size ) ) else if( Lh_check_prefix( header, size ) )
{ Pp_show_msg( pp, "Truncated header in multimember file." ); { Pp_show_msg( pp, "Truncated header in multimember file." );
retval = 2; } retval = 2; }
else if( size > 0 && !ignore_trailing ) else if( size > 0 && !ignore_trailing )
{ Pp_show_msg( pp, trailing_msg ); retval = 2; } { Pp_show_msg( pp, trailing_msg ); retval = 2; }
break; break;
} }
if( !Lh_verify_magic( header ) ) if( !Lh_check_magic( header ) )
{ {
if( !first_member ) if( !first_member )
{ {
if( !loose_trailing && Lh_verify_corrupt( header ) ) if( !loose_trailing && Lh_check_corrupt( header ) )
{ Pp_show_msg( pp, "Corrupt header in multimember file." ); { Pp_show_msg( pp, "Corrupt header in multimember file." );
retval = 2; } retval = 2; }
else if( !ignore_trailing ) else if( !ignore_trailing )
@ -909,7 +906,7 @@ static int decompress( const int infd, struct Pretty_print * const pp,
} }
if( lzip_mode ) if( lzip_mode )
{ {
if( !Lh_verify_version( header ) ) if( !Lh_check_version( header ) )
{ {
if( verbosity >= 0 ) if( verbosity >= 0 )
{ Pp_show_msg( pp, 0 ); { Pp_show_msg( pp, 0 );
@ -1023,8 +1020,8 @@ static void internal_error( const char * const msg )
int main( const int argc, const char * const argv[] ) int main( const int argc, const char * const argv[] )
{ {
/* Mapping from gzip/bzip2 style 1..9 compression modes /* Mapping from gzip/bzip2 style 0..9 compression levels to the
to the corresponding LZMA compression modes. */ corresponding LZMA compression parameters. */
const struct Lzma_options option_mapping[] = const struct Lzma_options option_mapping[] =
{ {
{ 1 << 16, 5 }, /* -0 */ { 1 << 16, 5 }, /* -0 */
@ -1124,7 +1121,7 @@ int main( const int argc, const char * const argv[] )
case 'v': if( verbosity < 4 ) ++verbosity; break; case 'v': if( verbosity < 4 ) ++verbosity; break;
case 'V': show_version(); return 0; case 'V': show_version(); return 0;
case opt_lt: loose_trailing = true; break; case opt_lt: loose_trailing = true; break;
default : internal_error( "uncaught option." ); default: internal_error( "uncaught option." );
} }
} /* end process options */ } /* end process options */
@ -1187,7 +1184,7 @@ int main( const int argc, const char * const argv[] )
eindex, one_to_one, recompress ); eindex, one_to_one, recompress );
if( infd < 0 ) { set_retval( &retval, 1 ); continue; } if( infd < 0 ) { set_retval( &retval, 1 ); continue; }
if( !check_tty_in( pp.name, infd, program_mode, &retval ) ) 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 ) if( program_mode == m_compress )
set_c_outname( input_filename, true, true ); set_c_outname( input_filename, true, true );
@ -1200,7 +1197,7 @@ int main( const int argc, const char * const argv[] )
if( one_to_one && !check_tty_out( program_mode ) ) if( one_to_one && !check_tty_out( program_mode ) )
{ set_retval( &retval, 1 ); return retval; } /* don't delete a tty */ { 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, if( program_mode == m_compress ) set_c_outname( default_output_filename,
filenames_given, false ); filenames_given, false );
@ -1216,10 +1213,10 @@ int main( const int argc, const char * const argv[] )
( input_filename[0] && one_to_one ) ? &in_stats : 0; ( input_filename[0] && one_to_one ) ? &in_stats : 0;
int tmp; int tmp;
if( program_mode == m_compress ) if( program_mode == m_compress )
tmp = compress( &encoder_options, &pp, infd ); tmp = compress( infd, &encoder_options, &pp );
else else
tmp = decompress( infd, &pp, ignore_trailing, tmp = decompress( infd, &pp, ignore_trailing, loose_trailing,
loose_trailing, program_mode == m_test ); program_mode == m_test );
if( close( infd ) != 0 ) if( close( infd ) != 0 )
{ show_file_error( pp.name, "Error closing input file", errno ); { show_file_error( pp.name, "Error closing input file", errno );
set_retval( &tmp, 1 ); } set_retval( &tmp, 1 ); }

View file

@ -1,6 +1,6 @@
#! /bin/sh #! /bin/sh
# check script for Pdlzip - LZMA lossless data compressor # check script for Pdlzip - LZMA lossless data compressor
# Copyright (C) 2010-2022 Antonio Diaz Diaz. # Copyright (C) 2010-2023 Antonio Diaz Diaz.
# #
# This script is free software: you have unlimited permission # This script is free software: you have unlimited permission
# to copy, distribute, and modify it. # to copy, distribute, and modify it.
@ -67,7 +67,7 @@ done
[ $? = 1 ] || test_failed $LINENO [ $? = 1 ] || test_failed $LINENO
[ ! -e out.lz ] || test_failed $LINENO [ ! -e out.lz ] || test_failed $LINENO
# these are for code coverage # these are for code coverage
"${LZIP}" -cdt "${in_lz}" > out 2> /dev/null "${LZIP}" -cdt "${in_lz}" 2> /dev/null
[ $? = 1 ] || test_failed $LINENO [ $? = 1 ] || test_failed $LINENO
"${LZIP}" -t -- nx_file.lz 2> /dev/null "${LZIP}" -t -- nx_file.lz 2> /dev/null
[ $? = 1 ] || test_failed $LINENO [ $? = 1 ] || test_failed $LINENO
@ -92,46 +92,46 @@ done
printf "LZIP\001-.............................." | "${LZIP}" -t 2> /dev/null printf "LZIP\001-.............................." | "${LZIP}" -t 2> /dev/null
printf "LZIP\002-.............................." | "${LZIP}" -t 2> /dev/null printf "LZIP\002-.............................." | "${LZIP}" -t 2> /dev/null
printf "LZIP\001+.............................." | "${LZIP}" -t 2> /dev/null printf "LZIP\001+.............................." | "${LZIP}" -t 2> /dev/null
rm -f out || framework_failure
printf "\ntesting decompression..." printf "\ntesting decompression..."
for i in "${in_lz}" "${in_em}" "${testdir}"/test.txt.lzma ; do for i in "${in_lz}" "${in_em}" "${testdir}"/test.txt.lzma ; do
"${LZIP}" -t "$i" || test_failed $LINENO "$i" "${LZIP}" -t "$i" || test_failed $LINENO "$i"
"${LZIP}" -d "$i" -o copy || test_failed $LINENO "$i" "${LZIP}" -d "$i" -o out || test_failed $LINENO "$i"
cmp in copy || test_failed $LINENO "$i" cmp in out || test_failed $LINENO "$i"
"${LZIP}" -cd "$i" > copy || test_failed $LINENO "$i" "${LZIP}" -cd "$i" > out || test_failed $LINENO "$i"
cmp in copy || test_failed $LINENO "$i" cmp in out || test_failed $LINENO "$i"
"${LZIP}" -d "$i" -o - > copy || test_failed $LINENO "$i" "${LZIP}" -d "$i" -o - > out || test_failed $LINENO "$i"
cmp in copy || test_failed $LINENO "$i" cmp in out || test_failed $LINENO "$i"
"${LZIP}" -d < "$i" > copy || test_failed $LINENO "$i" "${LZIP}" -d < "$i" > out || test_failed $LINENO "$i"
cmp in copy || test_failed $LINENO "$i" cmp in out || test_failed $LINENO "$i"
rm -f copy || framework_failure rm -f out || framework_failure
done 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}" [ "${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 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 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 "${LZIP}" -d copy.lz out.lz 2> /dev/null # skip copy, decompress out
[ $? = 1 ] || test_failed $LINENO [ $? = 1 ] || test_failed $LINENO
[ ! -e out.lz ] || test_failed $LINENO
cmp fox copy || test_failed $LINENO cmp fox copy || test_failed $LINENO
cmp in out || test_failed $LINENO cmp in out || test_failed $LINENO
"${LZIP}" -df copy.lz || test_failed $LINENO "${LZIP}" -df copy.lz || test_failed $LINENO
[ ! -e copy.lz ] || test_failed $LINENO [ ! -e copy.lz ] || test_failed $LINENO
cmp in copy || test_failed $LINENO cmp in copy || test_failed $LINENO
rm -f out || framework_failure rm -f copy out || framework_failure
printf "to be overwritten" > copy || framework_failure printf "to be overwritten" > out || framework_failure
"${LZIP}" -df -o copy < "${in_lz}" || test_failed $LINENO "${LZIP}" -df -o out < "${in_lz}" || test_failed $LINENO
cmp in copy || test_failed $LINENO cmp in out || test_failed $LINENO
rm -f out copy || framework_failure rm -f out || framework_failure
"${LZIP}" -d -o ./- "${in_lz}" || test_failed $LINENO "${LZIP}" -d -o ./- "${in_lz}" || test_failed $LINENO
cmp in ./- || test_failed $LINENO cmp in ./- || test_failed $LINENO
rm -f ./- || framework_failure rm -f ./- || framework_failure
@ -140,75 +140,85 @@ cmp in ./- || test_failed $LINENO
rm -f ./- || framework_failure rm -f ./- || framework_failure
cat "${in_lz}" > anyothername || 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 test_failed $LINENO
cmp in copy || test_failed $LINENO cmp in out || test_failed $LINENO
cmp in anyothername.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}" "${LZIP}" -tq in "${in_lz}"
[ $? = 2 ] || test_failed $LINENO [ $? = 2 ] || test_failed $LINENO
"${LZIP}" -tq nx_file.lz "${in_lz}" "${LZIP}" -tq nx_file.lz "${in_lz}"
[ $? = 1 ] || test_failed $LINENO [ $? = 1 ] || test_failed $LINENO
"${LZIP}" -cdq in "${in_lz}" > copy "${LZIP}" -cdq in "${in_lz}" > out
[ $? = 2 ] || test_failed $LINENO [ $? = 2 ] || test_failed $LINENO
cat copy in | cmp in - || test_failed $LINENO # copy must be empty cat out in | cmp in - || test_failed $LINENO # out must be empty
"${LZIP}" -cdq nx_file.lz "${in_lz}" > copy "${LZIP}" -cdq nx_file.lz "${in_lz}" > out # skip nx_file, decompress in
[ $? = 1 ] || test_failed $LINENO [ $? = 1 ] || test_failed $LINENO
cmp in copy || test_failed $LINENO cmp in out || test_failed $LINENO
rm -f copy || framework_failure rm -f out || framework_failure
cat "${in_lz}" > copy.lz || framework_failure cat "${in_lz}" > out.lz || framework_failure
for i in 1 2 3 4 5 6 7 ; do for i in 1 2 3 4 5 6 7 ; do
printf "g" >> copy.lz || framework_failure printf "g" >> out.lz || framework_failure
"${LZIP}" -atvvvv copy.lz "${in_lz}" 2> /dev/null "${LZIP}" -atvvvv out.lz "${in_lz}" 2> /dev/null
[ $? = 2 ] || test_failed $LINENO $i [ $? = 2 ] || test_failed $LINENO $i
done done
"${LZIP}" -dq in copy.lz "${LZIP}" -dq in out.lz
[ $? = 2 ] || test_failed $LINENO [ $? = 2 ] || test_failed $LINENO
[ -e copy.lz ] || test_failed $LINENO [ -e out.lz ] || test_failed $LINENO
[ ! -e copy ] || test_failed $LINENO [ ! -e out ] || test_failed $LINENO
[ ! -e in.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 [ $? = 1 ] || test_failed $LINENO
[ ! -e copy.lz ] || test_failed $LINENO [ ! -e out.lz ] || test_failed $LINENO
[ ! -e nx_file ] || 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 cat in in > in2 || framework_failure
"${LZIP}" -t "${in_lz}" "${in_lz}" || test_failed $LINENO "${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 [ ! -e out ] || test_failed $LINENO # override -o
cmp in2 copy2 || test_failed $LINENO cmp in2 out2 || test_failed $LINENO
rm -f copy2 || framework_failure rm -f out2 || framework_failure
"${LZIP}" -d "${in_lz}" "${in_lz}" -o copy2 || test_failed $LINENO "${LZIP}" -d "${in_lz}" "${in_lz}" -o out2 || test_failed $LINENO
cmp in2 copy2 || test_failed $LINENO cmp in2 out2 || test_failed $LINENO
rm -f copy2 || framework_failure rm -f out2 || framework_failure
cat "${in_lz}" "${in_lz}" > copy2.lz || framework_failure cat "${in_lz}" "${in_lz}" > out2.lz || framework_failure
printf "\ngarbage" >> copy2.lz || framework_failure printf "\ngarbage" >> out2.lz || framework_failure
"${LZIP}" -tvvvv copy2.lz 2> /dev/null || test_failed $LINENO "${LZIP}" -tvvvv out2.lz 2> /dev/null || test_failed $LINENO
"${LZIP}" -atq copy2.lz "${LZIP}" -atq out2.lz
[ $? = 2 ] || test_failed $LINENO [ $? = 2 ] || test_failed $LINENO
"${LZIP}" -atq < copy2.lz "${LZIP}" -atq < out2.lz
[ $? = 2 ] || test_failed $LINENO [ $? = 2 ] || test_failed $LINENO
"${LZIP}" -adkq copy2.lz "${LZIP}" -adkq out2.lz
[ $? = 2 ] || test_failed $LINENO [ $? = 2 ] || test_failed $LINENO
[ ! -e copy2 ] || test_failed $LINENO [ ! -e out2 ] || test_failed $LINENO
"${LZIP}" -adkq -o copy2 < copy2.lz "${LZIP}" -adkq -o out2 < out2.lz
[ $? = 2 ] || test_failed $LINENO [ $? = 2 ] || test_failed $LINENO
[ ! -e copy2 ] || test_failed $LINENO [ ! -e out2 ] || test_failed $LINENO
printf "to be overwritten" > copy2 || framework_failure printf "to be overwritten" > out2 || framework_failure
"${LZIP}" -df copy2.lz || test_failed $LINENO "${LZIP}" -df out2.lz || test_failed $LINENO
cmp in2 copy2 || test_failed $LINENO cmp in2 out2 || test_failed $LINENO
rm -f in2 copy2 || framework_failure rm -f out2 || framework_failure
printf "\ntesting compression..." printf "\ntesting compression..."
"${LZIP}" -cf "${in_lz}" > out 2> /dev/null # /dev/null is a tty on OS/2 "${LZIP}" -c -0 in in in -o out3.lz > copy2.lz || test_failed $LINENO
[ ! -e out3.lz ] || test_failed $LINENO # override -o
"${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 in2 out2 copy2.lz || framework_failure
"${LZIP}" -cf "${in_lz}" > lzlz 2> /dev/null # /dev/null is a tty on OS/2
[ $? = 1 ] || test_failed $LINENO [ $? = 1 ] || test_failed $LINENO
"${LZIP}" -Fvvm36 -o - -s16 "${in_lz}" > out 2> /dev/null || test_failed $LINENO "${LZIP}" -Fvvm36 -o - -s16 "${in_lz}" > lzlz 2> /dev/null || test_failed $LINENO
"${LZIP}" -cd out | "${LZIP}" -d > copy || test_failed $LINENO "${LZIP}" -cd lzlz | "${LZIP}" -d > out || test_failed $LINENO
cmp in copy || test_failed $LINENO cmp in out || test_failed $LINENO
rm -f lzlz out || framework_failure
"${LZIP}" -0 -o ./- in || test_failed $LINENO "${LZIP}" -0 -o ./- in || test_failed $LINENO
"${LZIP}" -cd ./- | cmp in - || test_failed $LINENO "${LZIP}" -cd ./- | cmp in - || test_failed $LINENO
@ -220,10 +230,10 @@ rm -f ./-.lz || framework_failure
for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do
"${LZIP}" -k -$i -s16 in || test_failed $LINENO $i "${LZIP}" -k -$i -s16 in || test_failed $LINENO $i
mv -f in.lz copy.lz || test_failed $LINENO $i mv in.lz out.lz || test_failed $LINENO $i
printf "garbage" >> copy.lz || framework_failure printf "garbage" >> out.lz || framework_failure
"${LZIP}" -df copy.lz || test_failed $LINENO $i "${LZIP}" -df out.lz || test_failed $LINENO $i
cmp in copy || 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 -c > out || test_failed $LINENO $i
"${LZIP}" -$i -s16 in -o o_out || test_failed $LINENO $i # don't add .lz "${LZIP}" -$i -s16 in -o o_out || test_failed $LINENO $i # don't add .lz
@ -245,18 +255,18 @@ 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 "${LZIP}" -df -o copy < out.lz || test_failed $LINENO $i
cmp in copy || test_failed $LINENO $i cmp in copy || test_failed $LINENO $i
done done
rm -f out out.lz || framework_failure rm -f copy out.lz || framework_failure
printf "\ntesting bad input..." printf "\ntesting bad input..."
headers='LZIp LZiP LZip LzIP LzIp LziP lZIP lZIp lZiP lzIP' 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' 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 cat "${in_lz}" > int.lz || framework_failure
printf "LZIP${body}" >> int.lz printf "LZIP${body}" >> int.lz || framework_failure
if "${LZIP}" -tq int.lz ; then if "${LZIP}" -tq int.lz ; then
for header in ${headers} ; do for header in ${headers} ; do
printf "${header}${body}" > int.lz # first member printf "${header}${body}" > int.lz || framework_failure
"${LZIP}" -tq int.lz "${LZIP}" -tq int.lz # first member
[ $? = 2 ] || test_failed $LINENO ${header} [ $? = 2 ] || test_failed $LINENO ${header}
"${LZIP}" -tq < int.lz "${LZIP}" -tq < int.lz
[ $? = 2 ] || test_failed $LINENO ${header} [ $? = 2 ] || test_failed $LINENO ${header}
@ -268,9 +278,9 @@ if "${LZIP}" -tq int.lz ; then
[ $? = 2 ] || test_failed $LINENO ${header} [ $? = 2 ] || test_failed $LINENO ${header}
"${LZIP}" -cdq --loose-trailing int.lz > /dev/null "${LZIP}" -cdq --loose-trailing int.lz > /dev/null
[ $? = 2 ] || test_failed $LINENO ${header} [ $? = 2 ] || test_failed $LINENO ${header}
cat "${in_lz}" > int.lz cat "${in_lz}" > int.lz || framework_failure
printf "${header}${body}" >> int.lz # trailing data printf "${header}${body}" >> int.lz || framework_failure
"${LZIP}" -tq int.lz "${LZIP}" -tq int.lz # trailing data
[ $? = 2 ] || test_failed $LINENO ${header} [ $? = 2 ] || test_failed $LINENO ${header}
"${LZIP}" -tq < int.lz "${LZIP}" -tq < int.lz
[ $? = 2 ] || test_failed $LINENO ${header} [ $? = 2 ] || test_failed $LINENO ${header}
@ -317,15 +327,15 @@ if dd if=in3.lz of=trunc.lz bs=14752 count=1 2> /dev/null &&
[ $? = 2 ] || test_failed $LINENO $i [ $? = 2 ] || test_failed $LINENO $i
"${LZIP}" -tq < trunc.lz "${LZIP}" -tq < trunc.lz
[ $? = 2 ] || test_failed $LINENO $i [ $? = 2 ] || test_failed $LINENO $i
"${LZIP}" -cdq trunc.lz > out "${LZIP}" -cdq trunc.lz > /dev/null
[ $? = 2 ] || test_failed $LINENO $i [ $? = 2 ] || test_failed $LINENO $i
"${LZIP}" -dq < trunc.lz > out "${LZIP}" -dq < trunc.lz > /dev/null
[ $? = 2 ] || test_failed $LINENO $i [ $? = 2 ] || test_failed $LINENO $i
done done
else else
printf "\nwarning: skipping truncation test: 'dd' does not work on your system." printf "\nwarning: skipping truncation test: 'dd' does not work on your system."
fi 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 cat "${in_lz}" > ingin.lz || framework_failure
printf "g" >> ingin.lz || framework_failure printf "g" >> ingin.lz || framework_failure
@ -334,17 +344,17 @@ cat "${in_lz}" >> ingin.lz || framework_failure
[ $? = 2 ] || test_failed $LINENO [ $? = 2 ] || test_failed $LINENO
"${LZIP}" -atq < ingin.lz "${LZIP}" -atq < ingin.lz
[ $? = 2 ] || test_failed $LINENO [ $? = 2 ] || test_failed $LINENO
"${LZIP}" -acdq ingin.lz > out "${LZIP}" -acdq ingin.lz > /dev/null
[ $? = 2 ] || test_failed $LINENO [ $? = 2 ] || test_failed $LINENO
"${LZIP}" -adq < ingin.lz > out "${LZIP}" -adq < ingin.lz > /dev/null
[ $? = 2 ] || test_failed $LINENO [ $? = 2 ] || test_failed $LINENO
"${LZIP}" -t ingin.lz || test_failed $LINENO "${LZIP}" -t ingin.lz || 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 "${LZIP}" -cd ingin.lz > out || test_failed $LINENO
cmp in copy || test_failed $LINENO cmp in out || test_failed $LINENO
"${LZIP}" -d < ingin.lz > copy || test_failed $LINENO "${LZIP}" -d < ingin.lz > out || test_failed $LINENO
cmp in copy || test_failed $LINENO cmp in out || test_failed $LINENO
rm -f copy ingin.lz out || framework_failure rm -f out ingin.lz || framework_failure
echo echo
if [ ${fail} = 0 ] ; then if [ ${fail} = 0 ] ; then