458 Commits

Author SHA1 Message Date
Lasse Collin
682efdc1f9 "make dist" fixes 2009-08-27 18:36:59 +03:00
Lasse Collin
c8c184db1c Update xz man page date. 2009-08-27 17:08:33 +03:00
Lasse Collin
9756fce565 Fix the debug directory.
6a2eb54092 and
71f18e8a06 required
some changes that weren't applied in debug.
2009-08-27 17:00:22 +03:00
Lasse Collin
77007a7fb2 Add missing files to EXTRA_DIST. 2009-08-27 16:36:40 +03:00
Lasse Collin
04dcbfdeb9 Bumped version to 4.999.9beta. 2009-08-27 16:21:22 +03:00
Lasse Collin
fd7618611a Updated THANKS. 2009-08-27 16:17:47 +03:00
Lasse Collin
c29e76c0f9 .xz file format specification 1.0.4 (probably).
Thanks to Christian von Roques, Peter Lawler,
and Jim Meyering for the fixes.
2009-08-27 16:12:52 +03:00
Lasse Collin
696d7ee395 Require GNU libtool 2.2. 2009-08-27 15:43:54 +03:00
Lasse Collin
4c3558aa83 Add "dos" to EXTRA_DIST. 2009-08-27 15:34:45 +03:00
Lasse Collin
35b29e4424 Updated TODO. 2009-08-27 15:23:27 +03:00
Lasse Collin
2341437719 Some xz man page improvements. 2009-08-27 15:17:00 +03:00
Lasse Collin
371b04e19f Removed doc/bugs.txt. 2009-08-27 10:41:01 +03:00
Lasse Collin
d88c4072b3 Updated README.
It now includes bug reporting instructions/tips.
2009-08-27 10:40:25 +03:00
Lasse Collin
92e536d8b8 Fix a typo in FAQ.
Thanks to Jim Meyering.

(From now on, I try to always remember to put
the relevant thanks to commit messages.)
2009-08-27 10:21:18 +03:00
Lasse Collin
3e2ba8b585 Updates to liblzma API headers.
Added lzma_nothrow for every function. It adds
throw() when the header is used in C++ code.

Some lzma_attrs were added or removed.

Lots of comments were improved.
2009-08-27 10:13:46 +03:00
Lasse Collin
8e8ebc17c5 Install faq.txt. 2009-08-18 00:30:09 +03:00
Lasse Collin
b198e770a1 Updated faq.txt.
Some questions worth answering were removed, because I
currently don't have good up to date answers to them.
2009-08-18 00:26:48 +03:00
Lasse Collin
fe111a25cd Some xz man changes. 2009-08-17 22:45:50 +03:00
Lasse Collin
10242a21e9 Updated THANKS. 2009-08-16 22:15:42 +03:00
Lasse Collin
3ce1916c83 Fix data corruption in LZ/LZMA2 encoder.
Thanks to Jonathan Stott for the bug report.
2009-08-16 22:15:13 +03:00
Lasse Collin
66da129c8e Updated INSTALL and PACKAGERS to match the changes
made in --enable-dynamic.
2009-08-13 15:15:37 +03:00
Lasse Collin
8238c4b240 Link lzmainfo against shared liblzma by default. 2009-08-13 15:03:46 +03:00
Lasse Collin
71f18e8a06 Make --enable-dynamic a tristate option.
Some programs will by default be linked against static
liblzma and some against shared liblzma. --enable-dynamic
now allows overriding the default to both directions
(all dynamic or all static) even when building both
shared and static liblzma.

This is quite messy compared to how simple thing it is supposed
to be. The complexity is mostly due to Windows support.
2009-08-13 15:00:21 +03:00
Lasse Collin
5aa4678b23 Fix xz Makefile.am for the man page.
install-exec-hook -> install-data-hook
2009-08-13 12:56:47 +03:00
Lasse Collin
e51b4e49e8 Add lzmainfo for backward compatibility with LZMA Utils.
lzmainfo now links against static liblzma. In contrast
to other command line tools in XZ Utils, linking lzmainfo
against static liblzma by default is dumb. This will be
fixed once I have fixed some related issues in configure.ac.
2009-08-13 12:55:45 +03:00
Lasse Collin
a4165d0584 Sync some error messages from xz to xzdec.
Make xz error message translation usable outside
xz (at least in upcoming lzmainfo).
2009-08-13 12:42:36 +03:00
Lasse Collin
df636eb4e0 Add xz man page to manfiles in toplevel Makefile.am. 2009-08-13 09:37:21 +03:00
Lasse Collin
180bdf58ea Fix first line of xz man page. 2009-08-13 09:37:01 +03:00
Lasse Collin
e1ce2291e7 Added a rough version of the xz man page. 2009-08-10 11:22:31 +03:00
Jonathan Nieder
e71903fc61 “xzdiff a.xz b.xz” always fails
Attempts to compare two compressed files result in no output and
exit status 2.

Instead of going to standard output, ‘diff’ output is being
captured in the xz_status variable along with the exit status from
the decompression commands.  Later, when this variable is examined
for nonzero status codes, numerals from dates in the ‘diff’ output
make it appear as though decompression failed.

So let the ‘diff’ output leak to standard output with another file
descriptor.  (This trick is used in all similar contexts elsewhere
in xzdiff and in the analogous context in gzip’s zdiff script.)
2009-08-09 22:55:19 +03:00
Jonathan Nieder
1d314b81aa xzless: Support compressed standard input
It can be somewhat confusing that

	less < some_file.txt

works fine, whereas

	xzless < some_file.txt.xz

does not.  Since version 429, ‘less’ allows a filter specified in
the LESSOPEN environment variable to preprocess its input even if
it comes from standard input, if $LESSOPEN begins with ‘|-’.  So
set $LESSOPEN to take advantage of this feature.

Check less’s version at runtime so xzless can continue to work
with older versions.
2009-08-09 22:27:22 +03:00
Lasse Collin
a7f5d2fe48 GPLv2+ not GPLv2 for Doxyfile.in is probably OK. 2009-08-09 20:57:46 +03:00
Lasse Collin
b735cde20c Added a copyright notice to Doxyfile.in since it contains
lots of comments from Doxygen.

It seems that the Doxygen authors' intent is to not apply
their copyright on generated files, but since it doesn't
matter for XZ Utils at all, better safe than sorry.
2009-08-02 00:27:29 +03:00
Lasse Collin
0fd157cc00 Updated THANKS. 2009-08-02 00:11:37 +03:00
Lasse Collin
b198da96ff Updated TODO. 2009-08-02 00:10:22 +03:00
Lasse Collin
669413bb2d Updated THANKS. 2009-07-30 12:25:55 +03:00
Jonathan Nieder
dbbd8fb870 xzdiff: add missing ;; to case statement 2009-07-30 12:23:45 +03:00
Lasse Collin
adbad2d16c Added history.txt to doc_DATA. 2009-07-24 13:15:06 +03:00
Lasse Collin
e0236f1256 Updated .gitignore files. 2009-07-24 12:00:40 +03:00
Lasse Collin
2f34fb2692 Minor improvements to COPYING. 2009-07-24 11:34:02 +03:00
Lasse Collin
0db1befcfb Fix incorrect usage of getopt_long(), which caused
invalid memory access if XZ_OPT was defined.
2009-07-23 19:10:55 +03:00
Lasse Collin
8f8ec942d6 Avoid internal error with --format=xz --lzma1. 2009-07-20 15:43:32 +03:00
Lasse Collin
99f9e879a6 Major documentation update.
Installation and packaging instructions were added.
README and other generic docs were revised.

Some of the documentation files are now installed to $docdir.
2009-07-19 13:14:20 +03:00
Lasse Collin
ef4cf1851d Added missing author notice to xzless.in. 2009-07-19 11:09:31 +03:00
Lasse Collin
4c9c989d45 Use AC_CONFIG_AUX_DIR to clean up the toplevel directory
a little.

Fixed a related bug in the toplevel Makefile.am.

Added the build-aux directory to .gitignore.
2009-07-18 18:54:55 +03:00
Lasse Collin
366e436090 Updated the totally outdated TODO file. 2009-07-18 14:34:08 +03:00
Lasse Collin
64e498c89d Added public domain notice into a few files. 2009-07-18 11:26:39 +03:00
Lasse Collin
a35755c5de Allow extra commas in filter-specific options on xz command line.
This may slightly ease writing scripts that construct
filter-specific option strings dynamically.
2009-07-14 21:10:36 +03:00
Lasse Collin
98f3cac1ad Accept --lzma2=preset=6e where "e" is equivalent to --extreme
when no custom chain is in use.
2009-07-14 18:04:31 +03:00
Lasse Collin
d873a09e95 Add dist-hook to create ChangeLog from the commit log,
and to conver the man pages to PDF and plain text, which
may be convenient to those who cannot render man pages.
2009-07-12 19:08:30 +03:00
Lasse Collin
cd69a5a6c1 BCJ filters: Reject invalid start offsets with LZMA_OPTIONS_ERROR.
This is a quick and slightly dirty fix to make the code
conform to the latest file format specification. Without
this patch, it's possible to make corrupt files by
specifying start offset that is not a multiple of the
filter's alignment. Custom start offset is almost never
used, so this was only a minor bug.

The xz command line tool doesn't validate the start offset,
so one will get a bit unclear error message if trying to use
an invalid start offset.
2009-07-10 11:39:38 +03:00
Lasse Collin
eed9953732 Look for full command names instead of substrings
like "un", "cat", and "lz" when determining if
xz is run as unxz, xzcat, lzma, unlzma, or lzcat.

This is to ensure that if xz is renamed (e.g. via
--program-transform-name), it doesn't so easily
work in wrong mode.
2009-07-10 11:33:21 +03:00
Lasse Collin
6f62fa88f4 Updated THANKS. 2009-07-08 23:06:46 +03:00
Lasse Collin
1754b7e03e Portability improvement to version.sh. 2009-07-08 23:05:29 +03:00
Lasse Collin
3bdb53792c Remove --force from xzdec.
It was ignored for compatibility with xz, but now that
--decompress --stdout --force copies unrecognized files
as is to stdout, simply ignoring --force in xzdec would
be wrong. xzdec will not support copying unrecognized
data as is to stdout, so it cannot support --force.
2009-07-08 22:50:16 +03:00
Lasse Collin
5f16ef4abf Use sed instead of $(SED) so that we don't need to
use AC_PROG_SED. We don't do anything fancy with sed,
so this should work OK. libtool 2.2 sets SED but 1.5
doesn't, so $(SED) happened to work when using libtool 2.2.
2009-07-06 10:36:04 +03:00
Lasse Collin
96e4b257e1 Major update to the xzgrep and other scripts based on
the latest versions found from gzip CVS repository.

configure will try to find a POSIX shell to be used by
the scripts. This should ease portability on systems
which have pre-POSIX /bin/sh.

xzgrep and xzdiff support .xz, .lzma, .gz, and .bz2 files.
xzmore and xzless support only .xz and .lzma files.

The name of the xz executable used in these scripts is
now correct even if --program-transform-name has been used.
2009-07-05 22:25:17 +03:00
Lasse Collin
25cc7a6e8c Use @PACKAGE_HOMEPAGE@ in liblzma.pc.in. 2009-07-05 19:26:53 +03:00
Lasse Collin
18c10c30d2 Make "xz --decompress --stdout --force" copy unrecognized
files as is to standard output.

This feature is needed to be more compatible with gzip's
behavior. This was more complicated to implement than it
sounds, because the way liblzma is able to return errors with
files of only a few bytes in size. xz now has its own file
type detection code and no longer uses lzma_auto_decoder().
2009-07-04 00:40:44 +03:00
Lasse Collin
0a289c01ac Define PACKAGE_HOMEPAGE in configure.ac and use it in
xz and xzdec.

Use also PACKAGE_NAME instead of hardcoding "XZ Utils".
2009-07-02 14:30:38 +03:00
Lasse Collin
5cc99db5ba Avoid visibility related compiler warnings on Windows. 2009-07-01 12:21:24 +03:00
Lasse Collin
7653d1cf48 Use static liblzma by default also for tests. 2009-06-30 17:14:39 +03:00
Lasse Collin
f42ee98166 Build system fixes
Don't use libtool convenience libraries to avoid recently
discovered long-standing subtle but somewhat severe bugs
in libtool (at least 1.5.22 and 2.2.6 are affected). It
was found when porting XZ Utils to Windows
<http://lists.gnu.org/archive/html/libtool/2009-06/msg00070.html>
but the problem is significant also e.g. on GNU/Linux.

Unless --disable-shared is passed to configure, static
library built from a set of convenience libraries will
contain PIC objects. That is, while libtool builds non-PIC
objects too, only PIC objects will be used from the
convenience libraries. On 32-bit x86 (tested on mobile XP2400+),
using PIC instead of non-PIC makes the decompressor 10 % slower
with the default CFLAGS.

So while xz was linked against static liblzma by default,
it got the slower PIC objects unless --disable-shared was
used. I tend develop and benchmark with --disable-shared
due to faster build time, so I hadn't noticed the problem
in benchmarks earlier.

This commit also adds support for building Windows resources
into liblzma and executables.
2009-06-30 17:09:57 +03:00
Lasse Collin
89dac1db6f Added a comment about "autoconf -fi" to autogen.sh. 2009-06-29 22:19:51 +03:00
Lasse Collin
6e685aae45 Add -no-undefined to get shared liblzma on Windows. 2009-06-28 10:04:24 +03:00
Lasse Collin
73f560ee5f Make physmem() work on Cygwin 1.5 and older. 2009-06-27 22:57:15 +03:00
Lasse Collin
7ff0004fbc Moved the Windows resource files outside the windows directory
to prepare for building them with Autotools.
2009-06-27 17:28:01 +03:00
Lasse Collin
449c634674 Added missing $(EXEEXT). 2009-06-27 13:05:03 +03:00
Lasse Collin
792db79f27 Create correct symlinks even when
--program-{prefix,suffix,transform} is passed to configure.
2009-06-27 12:32:40 +03:00
Lasse Collin
0adc72feb8 Silence a compiler warning on DOS-like systems. 2009-06-27 10:02:24 +03:00
Lasse Collin
ad12edc952 Updated the filenames in POTFILES.in too. 2009-06-27 09:35:15 +03:00
Lasse Collin
b2b1f86753 Hopefully improved portability of the assembler code in
Autotools based builds on Windows.
2009-06-27 00:43:06 +03:00
Lasse Collin
c393055947 Updated THANKS (most of today's commits are based on
Charles Wilson's patches).
2009-06-26 21:17:29 +03:00
Lasse Collin
da0af22e4b Updated comments to match renamed files. 2009-06-26 21:00:35 +03:00
Lasse Collin
65014fd211 Rename process.[hc] to coder.[hc] and io.[hc] to file_io.[hc]
to avoid problems on systems with system headers with those
names.
2009-06-26 20:49:54 +03:00
Lasse Collin
5e1257466d Rename process_file() to coder_run(). 2009-06-26 20:43:36 +03:00
Lasse Collin
cad62551c5 Ugly hack to make it possible to use the thousand separator
format character with snprintf() on POSIX systems but not
on non-POSIX systems and still keep xgettext working.
2009-06-26 20:36:45 +03:00
Lasse Collin
fe378d4707 Added missing source files to windows/Makefile. 2009-06-26 15:40:40 +03:00
Lasse Collin
390a640856 Basic support for building with Cygwin and MinGW using
the Autotools based build system. It's not good yet, more
fixes will follow.
2009-06-26 15:37:53 +03:00
Lasse Collin
1c9360b7d1 Fix @variables@ to $(variables) in Makefile.am files.
Fix the ordering of libgnu.a and LTLIBINTL on the linker
command line and added missing LTLIBINTL to tests/Makefile.am.
2009-06-26 14:47:31 +03:00
Lasse Collin
d45615c555 Allow to explicitly specify autotool versions in autogen.sh. 2009-06-26 14:20:02 +03:00
Lasse Collin
eaf8367368 Add version.sh to EXTRA_DIST. 2009-06-26 14:18:32 +03:00
Lasse Collin
b317b218e2 Support HW_PHYSMEM64 2009-06-24 20:14:10 +03:00
Lasse Collin
ae82dde5d9 Cast a char argument to isspace() to unsigned char. 2009-06-24 13:01:59 +03:00
Lasse Collin
1735d31ea3 A few more spelling fixes. Released the .xz spec 1.0.3. 2009-06-05 13:46:26 +03:00
Lasse Collin
8ed156ce89 Added xzdec man page. 2009-06-04 23:42:12 +03:00
Lasse Collin
f6df39afaa Harmonized xzdec --memory with xz --memory and made
minor cleanups.
2009-06-04 23:26:47 +03:00
Lasse Collin
1774f27c61 Fix purporse -> purpose. Thanks to Andrew Dudman.
Released .xz spec 1.0.2 due to this fix too.
2009-06-04 22:59:55 +03:00
Lasse Collin
cb61345564 The .xz file format version 1.0.1 2009-06-01 14:53:57 +03:00
Lasse Collin
083c23c680 Make the raw value of the Check field available to applications
via lzma_block structure.

This changes ABI but not doesn't break API.
2009-05-26 14:48:48 +03:00
Lasse Collin
b4f5c81409 Remove undocumented alternative option names --bcj, --ppc,
and --itanium.
2009-05-23 16:57:21 +03:00
Lasse Collin
b1edee2cdc Add support for specifying the BCJ filter start offset
in the xz command line tool.
2009-05-23 15:12:23 +03:00
Lasse Collin
72aa0e9c5f Updated THANKS. 2009-05-23 14:51:09 +03:00
Lasse Collin
dcedb6998c Added support for --quiet and --no-warn to xzdec.
Cleaned up the --help message a little.
2009-05-22 16:40:50 +03:00
Lasse Collin
5f735dae80 Use the 40 % of RAM memory usage limit in xzdec too.
Update the memory usage info text in --help to match
the text in xz --long-help.
2009-05-22 15:11:52 +03:00
Lasse Collin
b60376249e Add --no-warn. 2009-05-22 14:43:00 +03:00
Lasse Collin
b4f92f522d Fix a comment. 2009-05-22 14:27:40 +03:00
Lasse Collin
4dd21d23f2 Remove the --info option, which was an alias for --list. 2009-05-22 14:21:20 +03:00
Lasse Collin
8836139b63 If xz is run as lzma, unlzma, or lzcat, simply imply
--format=lzma. This means that xz emulating lzma
doesn't decompress .xz files, while before this
commit it did. The new way is slightly simpler in
code and especially in upcoming documentation.
2009-05-22 12:27:43 +03:00
Lasse Collin
b0063023f8 Make the default memory usage limit 40 % of RAM for both
compressing and decompressing. This should be OK now that
xz automatically scales down the compression settings if
they would exceed the memory usage limit (earlier, the limit
for compression was increased to 90 % because low limit broke
scripts that used "xz -9" on systems with low RAM).

Support spcifying the memory usage limit as a percentage
of RAM (e.g. --memory=50%).

Support --threads=0 to reset the thread limit to the default
value (number of available CPU cores). Use UINT32_MAX instead
of SIZE_MAX as the maximum in args.c. hardware.c was already
expecting uint32_t value.

Cleaned up the output of --help and --long-help.
2009-05-22 11:29:50 +03:00
Lasse Collin
071b825b23 Support special value "max" where xz and xzdec accept an integer.
Don't round the memory usage limit in xzdec --help to avoid
an integer overflow and to not give wrong impression that
the limit is high enough when it may not actually be.
2009-05-21 17:22:01 +03:00
ABCD
03ca67fd37 Install lzdiff, lzgrep, and lzmore as symlinks
This adds lzdiff, lzgrep, and lzmore to the list of symlinks to install.
It also installs symlinks for the manual pages and removes the new
symlinks on uninstall.
2009-05-21 16:25:36 +03:00
Lasse Collin
a6f43e6412 Use a GCC-specific #pragma instead of GCC-specific
-Wno-uninitialized to silence a bogus warning.
2009-05-02 16:16:28 +03:00
Lasse Collin
f6ce63ebdb Removed --disable-encoder and --disable-decoder. Use the values
given to --enable-encoders and --enable-decoders to determine
if any encoder or decoder support is wanted.
2009-05-02 14:46:50 +03:00
Lasse Collin
be06858d5c Remove docs that are too outdated to be updated
(rewrite will be better).
2009-05-01 11:28:52 +03:00
Lasse Collin
0255401e57 Added documentation about the legacy .lzma file format. 2009-05-01 11:21:46 +03:00
Lasse Collin
1496ff437c Renamed the file format specification to xz-file-format.txt
which is the filename used on the WWW.
2009-05-01 11:20:23 +03:00
Lasse Collin
21c6b94373 Fixed a crash in liblzma.
liblzma tries to avoid useless free()/malloc() pairs in
initialization when multiple files are handled using the
same lzma_stream. This didn't work with filter chains
due to comparison of wrong pointers in lzma_next_coder_init(),
making liblzma think that no memory reallocation is needed
even when it actually is.

Easy way to trigger this bug is to decompress two files with
a single xz command. The first file should have e.g. x86+LZMA2
as the filter chain, and the second file just LZMA2.
2009-04-28 23:08:32 +03:00
Lasse Collin
e518d167aa Fix uint32_t -> size_t in ARM and ARM-Thumb filters.
On 64-bit system it would have gone into infinite
loop if a single input buffer was over 4 GiB (unlikely).
2009-04-15 14:13:38 +03:00
Lasse Collin
31decdce04 Minor fixes to test files' README. 2009-04-14 11:48:46 +03:00
Lasse Collin
4787d65443 Updated history.txt. 2009-04-13 16:36:41 +03:00
Lasse Collin
2f0bc9cd40 Quick & dirty update to support xz in diff/grep/more scripts. 2009-04-13 14:49:48 +03:00
Lasse Collin
02ddf09bc3 Put the interesting parts of XZ Utils into the public domain.
Some minor documentation cleanups were made at the same time.
2009-04-13 11:27:40 +03:00
Lasse Collin
e79c42d854 Fix off-by-one in LZ decoder.
Fortunately, this bug had no security risk other than accepting
some corrupt files as valid.
2009-04-10 11:17:02 +03:00
Pavel Roskin
94eb9ad46f Fix minor typos in README 2009-03-31 21:54:06 +03:00
Lasse Collin
9bab5336eb Add a note and work-around instructions to README about
problems detecting a C99 compiler when some standard
headers are missing.
2009-03-31 21:52:51 +03:00
Lasse Collin
a0497ff7a0 Updated THANKS. 2009-03-18 16:54:38 +02:00
Lasse Collin
390e69887f Fix wrong macro names in lc_cpucores.m4 and cpucores.h.
Thanks to Bert Wesarg.
2009-03-18 16:51:41 +02:00
Lasse Collin
0df9299e24 Test for Linux-specific sysinfo() only on Linux systems.
Some other systems have sysinfo() with different semantics.
2009-03-01 09:03:08 +02:00
Lasse Collin
cf751edfde Added AC_CONFIG_MACRO_DIR to configure.ac. 2009-03-01 09:00:06 +02:00
Lasse Collin
63df14c57d Fix the Autoconf test for getopt_long replacement.
It was broken by e114502b2b.
2009-03-01 08:58:41 +02:00
Lasse Collin
fd6a380f4e Add a rough explanation of --extreme to output of --help. 2009-02-22 19:07:54 +02:00
Lasse Collin
68bf7ac298 Fixes to progress message handling in xz:
- Don't use Windows-specific code on Windows. The old code
    required at least Windows 2000. Now it should work on
    Windows 98 and later, and maybe on Windows 95 too.

  - Use less precision when showing estimated remaining time.

  - Fix some small design issues.
2009-02-22 18:52:49 +02:00
Lasse Collin
47c2e21f82 Added files missing from the previous commit. 2009-02-18 13:00:10 +02:00
Lasse Collin
489a3dbaa0 Added lzma_easy_buffer_encode(). Splitted easy.c into small
pieces to avoid unneeded dependencies making statically
linked applications bigger than needed.
2009-02-17 10:43:00 +02:00
Lasse Collin
7494816ab0 Make physmem.h work on old Windows versions.
Thanks to Hongbo Ni for the original patch.
2009-02-15 15:48:45 +02:00
Lasse Collin
11ae4ae35f Fix microsecond vs. nanosecond confusion in my_time(). 2009-02-14 20:44:52 +02:00
Lasse Collin
3084d662d2 Cleanups to the code that detects the amount of RAM and
the number of CPU cores. Added support for using sysinfo()
on Linux systems whose libc lacks appropriate sysconf()
support (at least dietlibc). The Autoconf macros were
split into separate files, and CPU core count detection
was moved from hardware.c to cpucores.h. The core count
isn't used for anything real for now, so a problematic
part in process.c was commented out.
2009-02-14 00:45:29 +02:00
Lasse Collin
9c62371eab Initial port to DOS using DJGPP. 2009-02-13 18:23:50 +02:00
Lasse Collin
0dae8b7751 Windows port: Take advantage of the version number macros.
Now the version number is not duplicated in the
Windows-specific files anymore.
2009-02-13 18:02:05 +02:00
Lasse Collin
fdbc0cfa71 Changed how the version number is specified in various places.
Now configure.ac will get the version number directly from
src/liblzma/api/lzma/version.h. The intent is to reduce the
number of places where the version number is duplicated. In
future, support for displaying Git commit ID may be added too.
2009-02-13 18:00:03 +02:00
Lasse Collin
1d924e584b Fix handling of integrity check type in the xz command line tool. 2009-02-13 17:30:30 +02:00
Lasse Collin
96c46df7de Improve support for DOS-like systems.
Here DOS-like means DOS, Windows, and OS/2.
2009-02-13 17:29:02 +02:00
Lasse Collin
b6a30ee8c2 Remove dead directories from .gitignore. 2009-02-11 20:02:32 +02:00
Jim Meyering
1ec5b00279 .gitignore vs. Makefiles
How about this for those of us who do srcdir builds?
2009-02-11 20:01:10 +02:00
Lasse Collin
154f5aec2d Removed Makefile from .gitignore since not all Makefiles
in the repository are generated by Autotools. People
should do test builds in a separate build directory anyway.
2009-02-10 21:48:35 +02:00
Lasse Collin
e605c26636 Added resource files for the Windows build. 2009-02-10 21:48:05 +02:00
Lasse Collin
a3bbbe05d3 Let the user specify custom CFLAGS on the make command
line. Previously custom CFLAGS worked only when they were
passed to configure.
2009-02-09 14:54:31 +02:00
Lasse Collin
53f7598998 Fix aliasing issue in physmem.h. 2009-02-08 21:35:11 +02:00
Lasse Collin
0e27028d74 Add a separate internal function to initialize the CRC32
table, which is used also by LZ encoder. This was needed
because calling lzma_crc32() and ignoring the result is
a no-op due to lzma_attr_pure.
2009-02-08 18:24:50 +02:00
Lasse Collin
ae1ad9af54 Make "xz --force" to write to terminal as the error
message suggests.
2009-02-08 18:17:05 +02:00
Lasse Collin
79e25eded4 Support both slash and backslash as path component
separator on Windows when parsing argv[0].
2009-02-08 10:37:50 +02:00
Lasse Collin
bc7c7109cc Omit the wrong and (even if corrected) nowadays useless rm
from autogen.sh.
2009-02-07 23:18:13 +02:00
Lasse Collin
edfc2031e5 Updated THANKS. 2009-02-07 21:41:52 +02:00
Lasse Collin
880c330938 Make it easy to choose if command line tools should be
linked statically or dynamically against liblzma. The
default is still to use static liblzma, but it can now
be changed by passing --enable-dynamic to configure.
Thanks to Mike Frysinger for the original patch.

Fixed a few minor bugs in configure.ac.
2009-02-07 21:17:07 +02:00
Mike Frysinger
3f86532407 add gitignore files
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2009-02-07 20:26:09 +02:00
Lasse Collin
bd7ca1dad5 Assume 32 MiB of RAM on unsupported operating systems like
the comment in hardware.c already said.
2009-02-07 17:07:52 +02:00
Lasse Collin
d0ab8c1c73 MinGW support: Don't build fastpos_tablegen.c as part of
liblzma. Build both static and dynamic liblzma, and also
static and dynamic versions of the command line tools.
2009-02-07 16:26:58 +02:00
Lasse Collin
bfd91198e4 Support LZMA_API_STATIC in assembler files to
avoid __declspec(dllexport) equivalent.
2009-02-07 15:55:47 +02:00
Lasse Collin
3306cf3883 Introduced LZMA_API_STATIC macro, which the applications
need to #define when linking against static liblzma on
platforms like Windows. Most developers don't need to
care about LZMA_API_STATIC at all.
2009-02-07 11:11:50 +02:00
Lasse Collin
b719e63c5f Another grammar fix 2009-02-06 16:55:45 +02:00
Lasse Collin
fe5434f940 Grammar fix in README. 2009-02-06 12:30:23 +02:00
Lasse Collin
3dfa58a9ee Some MSYS installations (e.g. MsysGit) don't include
install.exe, so don't rely on it.
2009-02-06 10:06:32 +02:00
Lasse Collin
975d8fd72a Recreated the BCJ test files for x86 and SPARC. The old files
were linked with crt*.o, which are copyrighted, and thus the
old test files were not in the public domain as a whole. They
are freely distributable though, but it is better to be careful
and avoid including any copyrighted pieces in the test files.
The new files are just compiled and assembled object files,
and thus don't contain any copyrighted code.
2009-02-06 09:13:15 +02:00
Lasse Collin
094b1b09a5 Add the "windows" directory to EXTRA_DIST. 2009-02-05 21:21:27 +02:00
Lasse Collin
e1c3412eec Added initial experimental makefile for use with MinGW. 2009-02-05 09:17:51 +02:00
Lasse Collin
75905a9afc Various code cleanups the the xz command line tool.
It now builds with MinGW.
2009-02-05 09:12:57 +02:00
Lasse Collin
d0c0b9e94e Another utime() fix. 2009-02-03 12:15:17 +02:00
Lasse Collin
ccf92a29e8 Fix wrong filename argument for utime() and utimes().
This doesn't affect most systems, since most systems
have better functions available.
2009-02-03 10:41:11 +02:00
Lasse Collin
99c1c2abfa Updated the x86 assembler code:
- Use call/ret pair to get instruction pointer for PIC.
  - Use PIC only if PIC or __PIC__ is #defined.
  - The code should work on MinGW and Darwin in addition
    to GNU/Linux and Solaris.
2009-02-02 21:19:01 +02:00
Lasse Collin
22a0c6dd94 Modify LZMA_API macro so that it works on Windows with
other compilers than MinGW. This may hurt readability
of the API headers slightly, but I don't know any
better way to do this.
2009-02-02 20:14:03 +02:00
Lasse Collin
8dd7b6052e Fix a bug in lzma_block_buffer_decode(), although this
function should be rewritten anyway.
2009-02-01 22:40:35 +02:00
Lasse Collin
55fd41431e Added initial version of raw buffer-to-buffer coding
functions, and cleaned up filter.h API header a little.
May be very buggy, not tested yet.
2009-02-01 22:39:07 +02:00
Lasse Collin
3e54ecee5c Fix missing newlines in xzdec.c. 2009-02-01 00:11:20 +02:00
Lasse Collin
d64ca34f1b Use __cdecl also for function pointers in liblzma API when
on Windows.
2009-02-01 00:10:07 +02:00
Lasse Collin
6a2eb54092 Add LZMA_API to liblzma API headers. It's useful at least
on Windows. sysdefs.h no longer #includes lzma.h, so lzma.h
has to be #included separately where needed.
2009-01-31 11:01:48 +02:00
Lasse Collin
d9993fcb4d Use _WIN32 instead of WIN32 in xzdec.c to test if compiling on Windows. 2009-01-31 10:13:09 +02:00
Lasse Collin
2dbdc5befb Fix two lines in lzma.h on which the # wasn't at the
beginning of the line.
2009-01-31 10:02:52 +02:00
Lasse Collin
4ab7601091 Add support for using liblzma headers in MSVC, which has no
stdint.h or inttypes.h.
2009-01-31 09:55:05 +02:00
Lasse Collin
b2172cf823 Fix # -> ## in a macro in lzma.h. 2009-01-31 08:49:54 +02:00
Lasse Collin
1aae869874 Updated README. 2009-01-30 18:50:16 +02:00
Lasse Collin
f54bcf6f80 Remove dangling crc64_init.c. 2009-01-30 00:29:58 +02:00
Lasse Collin
982da7ed31 The .xz file format specification version 1.0.0 is now
officially released. The format has been technically the same
since 2008-11-19, but now that it is frozen, people can start
using it without a fear that the format will break.
2009-01-28 17:16:38 +02:00
Lasse Collin
c4683a660b Updated THANKS. 2009-01-28 08:45:59 +02:00
Lasse Collin
3241317093 Fix uninitialized variables in alone_decoder.c. This bug was
triggered by the previous commit, since these variables were
not used by anything before support for a preset dictionary.
2009-01-28 08:43:26 +02:00
Lasse Collin
f76e39cf93 Added initial support for preset dictionary for raw LZMA1
and LZMA2. It is not supported by the .xz format or the xz
command line tool yet.
2009-01-27 18:36:05 +02:00
Lasse Collin
449b8c832b Regenerate the CRC tables without trailing blanks. 2009-01-26 20:09:17 +02:00
Jim Meyering
850f740042 remove trailing blanks from all but .xz files 2009-01-26 20:01:51 +02:00
Lasse Collin
667481f1aa Add lzma_block_buffer_decode(). 2009-01-26 14:34:10 +02:00
Lasse Collin
5fb34d8324 Add more sanity checks to lzma_stream_buffer_decode(). 2009-01-26 14:33:28 +02:00
Lasse Collin
c129748675 Avoid hardcoded constant in easy.c. 2009-01-26 14:33:13 +02:00
Lasse Collin
1859d22d75 Tiny bit better sanity check in block_util.c 2009-01-26 13:06:49 +02:00
Lasse Collin
2c5fe958e4 Fix a dumb bug in Block decoder, which made it return
LZMA_DATA_ERROR with valid data. The bug was added in
e114502b2b.
2009-01-25 01:35:56 +02:00
Lasse Collin
c81f13ff29 Added lzma_stream_buffer_decode() and made minor cleanups. 2009-01-23 22:27:50 +02:00
Lasse Collin
0b3318661c Fix a comment. 2009-01-22 12:53:33 +02:00
Lasse Collin
9ec80355a7 Add some single-call buffer-to-buffer coding functions. 2009-01-20 16:37:27 +02:00
Lasse Collin
d8b58d0993 Block encoder cleanups 2009-01-20 13:45:41 +02:00
Lasse Collin
0c09810cb3 Use LZMA_PROG_ERROR in lzma_code() as documented in base.h. 2009-01-20 10:35:15 +02:00
Lasse Collin
2f1a8e8eb8 Fix handling of non-fatal errors in lzma_code(). 2009-01-19 22:53:18 +02:00
Lasse Collin
4810b6bc25 Move some LZMA2 constants to lzma2_encoder.h so that they
can be used outside lzma2_encoder.c.
2009-01-19 14:00:33 +02:00
Lasse Collin
00be5d2e09 Remove dead code. 2009-01-19 13:52:36 +02:00
Lasse Collin
128586213f Beta was supposed to be API stable but I had forgot to rename
lzma_memlimit_encoder and lzma_memlimit_decoder to
lzma_raw_encoder_memlimit and lzma_raw_decoder_memlimit. :-(
Now it is fixed. Hopefully it doesn't cause too much trouble
to those who already thought API is stable.
2009-01-17 14:24:25 +02:00
Lasse Collin
b056379490 Updated THANKS. 2009-01-15 14:29:22 +02:00
Lasse Collin
dc8f3be06d Fixed a bug in 7z2lzma.bash to make it work with .7z files
that use something else than 2^n as the dictionary size.
Thanks to Dan Shechter for the bug report.
2009-01-15 14:27:32 +02:00
Lasse Collin
8286a60b8f Use pthread_sigmask() instead of sigprocmask() when pthreads
are enabled.
2009-01-07 18:41:15 +02:00
Lasse Collin
4fd43cb3a9 Bumped version to 4.999.8beta right after the release
of 4.999.7beta.
2008-12-31 20:01:00 +02:00
Lasse Collin
061748f593 Disable Subblock filter from test_compress.sh since it is
disabled by default in configure.ac.
2008-12-31 18:59:02 +02:00
Lasse Collin
9c45658ddc Disable both Subblock encoder and decoder my default,
since they are not finished and may have security issues too.
2008-12-31 17:44:20 +02:00
Lasse Collin
b59f1e98f5 Update some files in debug directory. 2008-12-31 17:42:50 +02:00
Lasse Collin
d1d17a40d3 Prepare for 4.999.7beta release. 2008-12-31 17:41:46 +02:00
Lasse Collin
88d3e6b0b1 Cleaned up some comments in the API headers. 2008-12-31 17:15:03 +02:00
Lasse Collin
322ecf93c9 Renamed lzma_options_simple to lzma_options_bcj in the API.
The internal implementation is still using the name "simple".
It may need some cleanups, so I look at it later.
2008-12-31 16:29:39 +02:00
Lasse Collin
7eea8bec3a Fixed missing quoting in configure.ac. 2008-12-31 00:57:27 +02:00
Lasse Collin
28e75f7086 Updated src/liblzma/Makefile.am to use liblzma.pc.in, which
should have been in the previous commit.
2008-12-31 00:48:23 +02:00
Lasse Collin
7ed9d943b3 Remove lzma_init() and other init functions from liblzma API.
Half of developers were already forgetting to use these
functions, which could have caused total breakage in some future
liblzma version or even now if --enable-small was used. Now
liblzma uses pthread_once() to do the initializations unless
it has been built with --disable-threads which make these
initializations thread-unsafe.

When --enable-small isn't used, liblzma currently gets needlessly
linked against libpthread (on systems that have it). While it is
stupid for now, liblzma will need threads in future anyway, so
this stupidity will be temporary only.

When --enable-small is used, different code CRC32 and CRC64 is
now used than without --enable-small. This made the resulting
binary slightly smaller, but the main reason was to clean it up
and to handle the lack of lzma_init_check().

The pkg-config file lzma.pc was renamed to liblzma.pc. I'm not
sure if it works correctly and portably for static linking
(Libs.private includes -pthread or other operating system
specific flags). Hopefully someone complains if it is bad.

lzma_rc_prices[] is now included as a precomputed array even
with --enable-small. It's just 128 bytes now that it uses uint8_t
instead of uint32_t. Smaller array seemed to be at least as fast
as the more bloated uint32_t array on x86; hopefully it's not bad
on other architectures.
2008-12-31 00:30:49 +02:00
Lasse Collin
5cda29b566 Use 28 MiB as memory usage limit for encoding in test_compress.sh. 2008-12-27 19:40:31 +02:00
Lasse Collin
050eb14d29 Revert a change made in 3b34851de1
that was related to LZMA_MODE_FAST. The original code is slightly
faster although it compresses slightly worse. But since it is fast
mode, it is better to select the faster version.
2008-12-27 19:32:20 +02:00
Lasse Collin
4820f10d0f Some xz command line tool improvements. 2008-12-27 19:30:19 +02:00
Lasse Collin
e33194e79d Bunch of liblzma tweaks, including some API changes.
The API and ABI should now be very close to stable,
although the code behind it isn't yet.
2008-12-27 19:27:49 +02:00
Lasse Collin
4d00652e75 Updated Makefile.am that was missing from the previous commit. 2008-12-18 13:42:52 +02:00
Lasse Collin
634636fa56 Remove the alignment functions for now. Maybe they will
be added back in some form later, but the current version
wasn't modular, so it would need fixing anyway.
2008-12-17 21:49:53 +02:00
Lasse Collin
4fed98417d xz message handling improvements 2008-12-17 20:11:23 +02:00
Lasse Collin
653e457e37 Fix a dumb bug in .lzma decoder which was introduced in
the previous commit. (Probably the previous commit has
other bugs too, it wasn't tested.)
2008-12-15 23:26:43 +02:00
Lasse Collin
671a5adf1e Bunch of liblzma API cleanups and fixes. 2008-12-15 19:39:13 +02:00
Lasse Collin
17781c2c20 The LZMA2 decoder fix introduced a bug to LZ decoder,
which made LZ decoder return too early after dictionary
reset. This fixes it.
2008-12-15 14:26:52 +02:00
Lasse Collin
f9f2d1e743 Added two new test files. 2008-12-15 11:20:22 +02:00
Lasse Collin
ff7fb2c605 Fix data corruption in LZMA2 decoder. 2008-12-15 10:01:59 +02:00
Lasse Collin
1ceebcf7e1 Name the package "xz" in configure.ac. 2008-12-13 00:54:11 +02:00
Lasse Collin
a94bf00d0a Some adjustments to GCC warning flags. The important change
is the removal of -pedantic. It messes up -Werror (which I
really want to keep so that I don't miss any warnings) with
printf format strings that are in POSIX but not in C99.
2008-12-12 22:43:21 +02:00
Lasse Collin
8582d392ba Remove obsolete comment. 2008-12-10 01:31:00 +02:00
Lasse Collin
b1ae6dd731 Use "decompression" consistently in --long-help. 2008-12-10 01:27:15 +02:00
Lasse Collin
1ea9e7f15a Added preset=NUM to --lzma1 and --lzma2. This makes it easy
to take a preset as a template and modify it a little.
2008-12-10 01:23:58 +02:00
Lasse Collin
bceb3918db Put the file format specification into the public domain.
Same will be done to the actual code later.
2008-12-09 17:43:31 +02:00
Lasse Collin
6efa2d80d4 Make the memusage functions of LZMA1 and LZMA2 encoders
to validate the filter options. Add missing validation
to LZMA2 encoder when options are changed in the middle
of encoding.
2008-12-09 17:41:49 +02:00
Lasse Collin
f20a03206b Updated THANKS. 2008-12-09 10:36:24 +02:00
Lasse Collin
ef7890d564 In command line tool, take advantage of memusage calculation's
ability to also validate the filter chain and options (not
implemented yet for all filters).
2008-12-01 23:04:12 +02:00
Lasse Collin
ccd57afa09 Validate the filter chain before checking filter-specific
memory usage.
2008-12-01 22:59:28 +02:00
Lasse Collin
c596fda40b Make the memusage functions of LZMA1 and LZMA2 decoders
to validate the filter options.
2008-12-01 22:58:22 +02:00
Lasse Collin
c58f469be5 Added the changes for Delta filter that should have been
part of 656ec87882.
2008-12-01 22:55:18 +02:00
Lasse Collin
cd70801520 LZMA2 decoder cleanups. Make it require new LZMA properties
also in the first LZMA chunk after a dictionary reset in
uncompressed chunk.
2008-12-01 22:50:28 +02:00
Lasse Collin
656ec87882 Added lzma_delta_coder_memusage() which also validates
the options.
2008-12-01 16:30:11 +02:00
Lasse Collin
691a9155b7 Automake includes the m4 directory, so don't add it in
Makefile.am separately.

Updated THANKS.
2008-11-29 10:03:49 +02:00
Lasse Collin
c7007ddf06 Tested using COLUMNS environment variable to avoid broken
progress indicator but since COLUMNS isn't usually available,
the code was left commented out.
2008-11-28 12:00:48 +02:00
Lasse Collin
ae65dcfde2 Cleanups to message.c. 2008-11-27 19:28:59 +02:00
Lasse Collin
a8368b75cd Remove the nowadays unneeded memory limitting malloc() wrapper. 2008-11-25 02:37:47 +02:00
Lasse Collin
69472ee5f0 VLI encoder and decoder cleanups. Made encoder return
LZMA_PROG_ERROR in single-call mode if there's no output
space.
2008-11-23 15:09:03 +02:00
Lasse Collin
4249c8c15a Typo fix 2008-11-22 17:44:33 +02:00
Lasse Collin
6d1d6f4598 Support NetBSD's errno for O_NOFOLLOW. 2008-11-20 22:59:10 +02:00
Lasse Collin
f901a290ee Build xzdec and lzmadec from xzdec.c. xzdec supports only .xz
files and lzmadec only .lzma files.
2008-11-20 18:05:52 +02:00
Lasse Collin
86a0ed8f01 Minor cleanups to xzdec. 2008-11-20 11:01:29 +02:00
Lasse Collin
54f716ba89 Added missing check for uint16_t. 2008-11-19 23:55:22 +02:00
Lasse Collin
1880a3927b Renamed lzma to xz and lzmadec to xzdec. We create symlinks
lzma, unlzma, and lzcat in "make install" for backwards
compatibility with LZMA Utils 4.32.x; I'm not sure if this
should be the default though.
2008-11-19 23:52:24 +02:00
Lasse Collin
e114502b2b Oh well, big messy commit again. Some highlights:
- Updated to the latest, probably final file format version.
  - Command line tool reworked to not use threads anymore.
    Threading will probably go into liblzma anyway.
  - Memory usage limit is now about 30 % for uncompression
    and about 90 % for compression.
  - Progress indicator with --verbose
  - Simplified --help and full --long-help
  - Upgraded to the last LGPLv2.1+ getopt_long from gnulib.
  - Some bug fixes
2008-11-19 20:46:52 +02:00
Lasse Collin
3c3905b534 Fixed the test that should have been fixed as part
of 1e8e4fd1f3.
2008-10-09 11:12:29 +03:00
Lasse Collin
0f295bf7a3 Fixed some help messages. 2008-10-07 16:42:18 +03:00
Lasse Collin
1e8e4fd1f3 Made the preset numbering more logical in liblzma API. 2008-10-07 09:40:31 +03:00
Lasse Collin
5e4df4c3c0 Removed fi from po/LINGUAS. 2008-10-03 19:36:09 +03:00
Lasse Collin
fcfb86c777 Fixed suffix handling with --format=raw. 2008-10-03 07:06:48 +03:00
Lasse Collin
bd137524f2 Initial changes to change the suffix of the new format to .xz.
This also fixes a bug related to --suffix option. Some issues
with suffixes with --format=raw were not fixed.
2008-10-02 22:51:46 +03:00
Lasse Collin
4c321a41c4 Renamed the test files from .lzma suffix to .xz suffix. 2008-09-30 17:43:55 +03:00
Lasse Collin
8e60c889a2 Fixed Stream decoder to actually use the first_stream variable. 2008-09-30 13:57:44 +03:00
Lasse Collin
3bdbc12c05 Added one more test file. 2008-09-30 13:56:57 +03:00
Lasse Collin
a6639022fd Fixed uninitialized variable in Stream decoder. 2008-09-30 13:34:07 +03:00
Lasse Collin
ed3709000a Added two test files. 2008-09-30 13:27:28 +03:00
Lasse Collin
ea560b0ea8 Fix conflicting Subblock helper filter's ID. 2008-09-27 23:49:24 +03:00
Lasse Collin
ad97483b6e Changed magic bytes to match the updated spec. Filename
suffix wasn't changed yet.
2008-09-27 23:37:13 +03:00
Lasse Collin
7a57069167 Remove po/fi.po since I'm not keeping it updated for now. 2008-09-27 23:16:09 +03:00
Lasse Collin
018ae09df8 Fix also test_compress.sh. 2008-09-27 23:13:54 +03:00
Lasse Collin
3a62a5fb85 Fixed compilation of test_filter_flags.c, which was broken by
1dcecfb09b.
2008-09-27 23:01:15 +03:00
Lasse Collin
c6ca26eef7 Updated file format specification. It changes the suffix
of the new format to .xz and removes the recently added
LZMA filter.
2008-09-27 19:11:02 +03:00
Lasse Collin
1dcecfb09b Some API changes, bug fixes, cleanups etc. 2008-09-27 19:09:21 +03:00
Lasse Collin
5cc5064cae Added 7z2lzma.bash. 2008-09-27 11:28:49 +03:00
Lasse Collin
f147666a5c Miscellaneous LZ and LZMA encoder cleanups 2008-09-17 22:11:39 +03:00
Lasse Collin
13d68b0698 LZ decoder cleanup 2008-09-13 13:54:00 +03:00
Lasse Collin
13a74b78e3 Renamed constants:
- LZMA_VLI_VALUE_MAX -> LZMA_VLI_MAX
  - LZMA_VLI_VALUE_UNKNOWN -> LZMA_VLI_UNKNOWN
  - LZMA_HEADER_ERRRO -> LZMA_OPTIONS_ERROR
2008-09-13 12:10:43 +03:00
Lasse Collin
320601b2c7 Improved the Stream Flags handling API. 2008-09-12 22:41:40 +03:00
Lasse Collin
ec490da522 Simplified debug/known_sizes.c to match the relaxed
requirements of Block encoder.
2008-09-11 23:10:44 +03:00
Lasse Collin
16e8b98f26 Remove a check from Block encoder that should have already
been removed in 2ba01bfa75.
2008-09-11 23:09:24 +03:00
Lasse Collin
5a710c3805 Remove bogus #includes. 2008-09-11 20:02:38 +03:00
Lasse Collin
01892b2ca5 Updated THANKS. 2008-09-11 10:49:14 +03:00
Lasse Collin
962f2231d4 Fix a compiler error on big endian systems that don't
support unaligned memory access.
2008-09-11 10:48:12 +03:00
Lasse Collin
fa3ab0df8a Silence a compiler warning. 2008-09-11 10:46:14 +03:00
Lasse Collin
9373e81e18 Bumped version to 4.999.6alpha. 2008-09-10 19:16:32 +03:00
Lasse Collin
cb072b7c84 Check for LZMA_FILTER_RESERVED_START in filter_flags_encoder.c.
Use LZMA_PROG_ERROR instead of LZMA_HEADER_ERROR if the Filter ID
is in the reserved range. This allows Block Header encoder to
detect unallowed Filter IDs, which is good for Stream encoder.
2008-09-10 17:02:00 +03:00
Lasse Collin
123ab0acec Filter handling cleanups 2008-09-10 16:44:32 +03:00
Lasse Collin
9cfcd0c4f2 Comments 2008-09-10 00:33:00 +03:00
Lasse Collin
2ba01bfa75 Cleaned up Block encoder and moved the no longer shared
code from block_private.h to block_decoder.c. Now the Block
encoder doesn't need compressed_size and uncompressed_size
from lzma_block structure to be initialized.
2008-09-10 00:27:02 +03:00
Lasse Collin
07efcb5a6b Changed Filter ID of LZMA to 0x20. 2008-09-07 10:23:13 +03:00
Lasse Collin
32fe5fa541 Comments 2008-09-06 23:42:50 +03:00
Lasse Collin
0a31ed9d5e Some API cleanups 2008-09-06 15:14:30 +03:00
Lasse Collin
da98df5440 Added support for raw encoding and decoding to the command
line tool, and made various cleanups. --lzma was renamed to
--lzma1 to prevent people from accidentally using LZMA when
they want LZMA2.
2008-09-04 11:53:06 +03:00
Lasse Collin
2496aee8a7 Don't allow LZMA_SYNC_FLUSH with decoders anymore. There's
simply nothing that would use it. Allow LZMA_FINISH to the
decoders, which will usually ignore it (auto decoder and
Stream decoder being exceptions).
2008-09-04 10:39:15 +03:00
Lasse Collin
bea301c26d Minor updates to the file format specification. 2008-09-03 17:06:25 +03:00
Lasse Collin
9c75b089b4 Command line tool fixes 2008-09-02 19:33:32 +03:00
Lasse Collin
bab0590504 Auto decoder cleanup 2008-09-02 19:31:42 +03:00
Lasse Collin
689602336d Updated auto decoder to handle LZMA_CONCATENATED when decoding
LZMA_Alone files. Decoding of concatenated LZMA_Alone files is
intentionally not supported, so it is better to put this in
auto decoder than LZMA_Alone decoder.
2008-09-02 19:12:12 +03:00
Lasse Collin
80c4158f19 Stream decoder cleanups 2008-09-02 14:56:52 +03:00
Lasse Collin
fc68165745 Some fixes to LZ encoder. 2008-09-02 11:45:39 +03:00
Lasse Collin
ede675f9ac Fix wrong pointer calculation in LZMA encoder. 2008-08-31 11:47:01 +03:00
Lasse Collin
3b34851de1 Sort of garbage collection commit. :-| Many things are still
broken. API has changed a lot and it will still change a
little more here and there. The command line tool doesn't
have all the required changes to reflect the API changes, so
it's easy to get "internal error" or trigger assertions.
2008-08-28 22:53:15 +03:00
Lasse Collin
57b9a145a5 Fix test_filter_flags to match the new restriction of lc+lp. 2008-06-20 17:16:32 +03:00
Lasse Collin
eaafc4367c Remove some redundant code from LZMA encoder. 2008-06-20 16:19:54 +03:00
Lasse Collin
0809c46534 Add limit of lc + lp <= 4. Now we can allocate the
literal coder as part of the main LZMA encoder or
decoder structure.

Make the LZMA decoder to rely on the current internal API
to free the allocated memory in case an error occurs.
2008-06-19 16:35:08 +03:00
Lasse Collin
d25ab1b961 Comments 2008-06-18 21:45:19 +03:00
Lasse Collin
6368a2fa59 Delete old code that was supposed to be already deleted
from test_block_header.c.
2008-06-18 19:19:02 +03:00
Lasse Collin
7d17818cec Update the code to mostly match the new simpler file format
specification. Simplify things by removing most of the
support for known uncompressed size in most places.
There are some miscellaneous changes here and there too.

The API of liblzma has got many changes and still some
more will be done soon. While most of the code has been
updated, some things are not fixed (the command line tool
will choke with invalid filter chain, if nothing else).

Subblock filter is somewhat broken for now. It will be
updated once the encoded format of the Subblock filter
has been decided.
2008-06-18 18:02:10 +03:00
Lasse Collin
bf6348d1a3 Update the file format specification draft. The new one is
a lot simpler than the previous versions, but it also means
that the existing code will change a lot.
2008-06-17 15:03:46 +03:00
Lasse Collin
803194ddd2 Fix uninitialized variable in LZMA encoder. This was
introduced in 369f72fd65.
2008-06-11 21:42:47 +03:00
Lasse Collin
0ea98e52ba Improve command line integer parsing a little in lzma and
lzmadec to make them accept also KiB in addition Ki etc.
Fix also memory usage information in lzmadec --help.
2008-06-11 15:08:44 +03:00
Lasse Collin
436fa5fae9 s/decompressed/compressed/ in the command line tool's
error message.
2008-06-10 20:36:12 +03:00
Lasse Collin
369f72fd65 Fix a buffer overflow in the LZMA encoder. It was due to my
misunderstanding of the code. There's no tiny fix for this
problem, so I also cleaned up the code in general.

This reduces the speed of the encoder 2-5 % in the fastest
compression mode ("lzma -1"). High compression modes should
have no noticeable performance difference.

This commit breaks things (especially LZMA_SYNC_FLUSH) but I
will fix them once the new format and LZMA2 has been roughly
implemented. Plain LZMA won't support LZMA_SYNC_FLUSH at all
and won't be supported in the new .lzma format. This may
change still but this is what it looks like now.

Support for known uncompressed size (that is, LZMA or LZMA2
without EOPM) is likely to go away. This means there will
be API changes.
2008-06-01 12:48:17 +03:00
Lasse Collin
e55e0e873c Typo fixes from meyering. 2008-05-30 11:53:41 +03:00
Lasse Collin
ed6664146f Remove support for pre-C89 libc versions that lack memcpy,
memmove, and memset.
2008-05-11 14:24:42 +03:00
Lasse Collin
b09464bf9a Improved C99 compiler detection in configure.ac. It will
pass -std=gnu99 instead of -std=c99 to GCC now, but -pedantic
should still give warnings about GNU extensions like before
except with some special keywords like asm().
2008-05-11 14:17:21 +03:00
Lasse Collin
11de5d5267 Bunch of grammar fixes from meyering. 2008-05-06 15:15:07 +03:00
Lasse Collin
dc192b6343 Typo fix 2008-05-06 13:41:05 +03:00
Lasse Collin
944b62b932 Don't print an error message on broken pipe unless --verbose
is used.
2008-05-04 22:29:27 +03:00
Lasse Collin
8e074349e4 Fix a crash with --format=alone if other filters than LZMA
are specified on the command line.
2008-04-30 22:16:17 +03:00
Lasse Collin
2f361ac19b Updated THANKS. 2008-04-28 17:08:27 +03:00
Lasse Collin
3be21fb12f Fixed wrong spelling "limitter" to "limiter". This affects
liblzma's API.
2008-04-28 17:06:34 +03:00
Lasse Collin
beeb810608 Prevent LZ encoder from hanging with known uncompressed
size. The "fix" breaks LZMA_SYNC_FLUSH at end of stream
with known uncompressed size, but since it currently seems
likely that support for encoding with known uncompressed
size will go away anyway, I'm not fixing this problem now.
2008-04-25 15:39:50 +03:00
Lasse Collin
c324325f9f Removed src/liblzma/common/sysdefs.h symlink, which was
annoying, because "make dist" put two copies of sysdefs.h
into the tarball instead of the symlink.
2008-04-25 13:58:56 +03:00
Lasse Collin
d3ba30243c Added memusage.c to debug directory. 2008-04-25 13:41:29 +03:00
Lasse Collin
8f804c29aa Bumped version number to 4.999.3alpha. It will become 5.0.0
once we have a stable release (won't be very soon). The
version number is no longer related to version of LZMA SDK.

Made some small Automake-related changes to toplevel
Makefile.am and configure.ac.
2008-04-25 13:32:35 +03:00
Lasse Collin
c99037ea10 Fix a memory leak by calling free(extra->data) in
lzma_extra_free().
2008-04-24 20:25:39 +03:00
Lasse Collin
22ba3b0b50 Make unlzma and lzcat symlinks. 2008-04-24 20:23:05 +03:00
Lasse Collin
17c36422d4 Fixed a bug in command line option parsing. 2008-04-24 20:20:27 +03:00
Lasse Collin
283f939974 Added two assert()s. 2008-04-24 20:19:20 +03:00
Lasse Collin
eb348a60b6 Switch to uint16_t as the type of range coder probabilities. 2008-04-24 19:22:53 +03:00
Lasse Collin
6c5306e312 Fix wrong return type (uint32_t -> bool). 2008-04-24 18:39:57 +03:00
Lasse Collin
712cfe3ebf Fix data corruption in LZ encoder with LZMA_SYNC_FLUSH. 2008-04-24 18:38:00 +03:00
Lasse Collin
bc04486e36 Fix fastpos problem in Makefile.am when built with --enable-small. 2008-04-24 17:33:01 +03:00
Lasse Collin
7ab493924e Use 64-bit integer as range encoder's cache size. This fixes a
theoretical data corruption, which should be very hard to trigger
even intentionally.
2008-04-24 17:30:51 +03:00
Lasse Collin
641998c3e1 Replaced the range decoder optimization that used arithmetic
right shift with as fast version that doesn't need
arithmetic right shift. Removed the related check from
configure.ac.
2008-03-24 16:38:40 +02:00
Lasse Collin
ad999efd27 Take advantage of arithmetic right shift in range decoder. 2008-03-22 14:39:34 +02:00
Lasse Collin
03e0e8a0d7 Added autoconf check to detect if we can use arithmetic
right shift for optimizations.
2008-03-22 14:18:29 +02:00
Lasse Collin
7521bbdc83 Update a comment to use the variable name rep_len_decoder.
(And BTW, the previous commit actually did change the
program logic slightly.)
2008-03-22 01:26:36 +02:00
Lasse Collin
63b74d000e Demystified the "state" variable in LZMA code. Use the
word literal instead of char for better consistency.
There are still some names with _char instead of _literal
in lzma_optimum, these may be changed later.

Renamed length coder variables.

This commit doesn't change the program logic.
2008-03-22 00:57:33 +02:00
Lasse Collin
e6eb0a2675 Fix data corruption in LZMA encoder. Note that this bug was
specific to liblzma and was *not* present in LZMA SDK.
2008-03-14 23:16:11 +02:00
Lasse Collin
7d516f5129 Fix a comment API header. 2008-03-14 21:32:37 +02:00
Lasse Collin
748d6e4274 Make lzma_stream.next_in const. Let's see if anyone complains. 2008-03-12 23:14:50 +02:00
Lasse Collin
bfde3b24a5 Apply a minor speed optimization to LZMA decoder. 2008-03-11 15:35:34 +02:00
Lasse Collin
f310c50286 Initialize the last byte of the dictionary to zero so that
lz_get_byte(lz, 0) returns zero. This was broken by
1a3b218598.
2008-03-11 15:17:16 +02:00
Lasse Collin
5ead36cf7f Really fix the price count initialization. 2008-03-10 15:57:55 +02:00
Lasse Collin
d4d7feb83d Updated THANKS. 2008-03-10 13:47:17 +02:00
Lasse Collin
0541c5ea63 Initialize align_price_count and match_price_count in
lzma_encoder_init.c. While we don't call
fill_distances_prices() and fill_align_prices() in
lzma_lzma_encoder_init(), we still need to initialize
these two variables so that the fill functions get
called in lzma_encoder_getoptimum.c in the beginning
of a stream.
2008-03-10 13:46:48 +02:00
Lasse Collin
596fa1fac7 Always initialize lz->temp_size in lz_decoder.c. temp_size did
get initialized as a side-effect after allocating a new decoder,
but not when the decoder was reused.
2008-03-10 13:44:29 +02:00
Lasse Collin
45e43e1695 Don't fill allocated memory with 0xFD when debugging is
enabled. It hides errors from Valgrind.
2008-03-10 13:41:25 +02:00
Lasse Collin
c0e19e0662 Remove two redundant validity checks from the LZMA decoder.
These are already checked elsewhere, so omitting these
gives (very) tiny speed up.
2008-02-28 10:24:31 +02:00
Lasse Collin
de74858062 Tiny clean up to file-format.txt. 2008-02-06 13:25:32 +02:00
Lasse Collin
1a3b218598 Don't memzero() the history buffer when initializing LZ
decoder. There's no danger of information leak here, so
it isn't required. Doing memzero() takes a lot of time
with large dictionaries, which could make it easier to
construct DoS attack to consume too much CPU time.
2008-02-02 14:51:06 +02:00
Lasse Collin
7e796e312b Do uncompressed size validation in raw encoder. This way
it gets done for not only raw encoder, but also Block
and LZMA_Alone encoders.
2008-02-01 08:39:26 +02:00
Lasse Collin
7dd48578a3 Avoid unneeded function call in raw_common.c. 2008-02-01 08:32:05 +02:00
Lasse Collin
b596fac963 Updated THANKS. 2008-01-26 21:42:38 +02:00
Lasse Collin
e9f6e9c075 Added note.GNU-stack to x86 assembler files. It is needed
when using non-executable stack.
2008-01-26 21:40:23 +02:00
Lasse Collin
4c7ad179c7 Added api/lzma/easy.h. I had forgot to add this to the
git repo. Thanks to Stephan Kulow.
2008-01-26 19:12:50 +02:00
Lasse Collin
288b232f54 Added more test files. 2008-01-26 11:09:17 +02:00
Lasse Collin
c467b0defc Added more test files. 2008-01-26 10:47:55 +02:00
Lasse Collin
f9842f7127 Return LZMA_HEADER_ERROR if LZMA_SYNC_FLUSH is used with any
of the so called simple filters. If there is demand, limited
support for LZMA_SYNC_FLUSH may be added in future.

After this commit, using LZMA_SYNC_FLUSH shouldn't cause
undefined behavior in any situation.
2008-01-26 00:25:34 +02:00
Lasse Collin
e988ea1d1a Added more Multi-Block test files. Improved some
descriptions in the test files' README.
2008-01-25 23:50:35 +02:00
Lasse Collin
4441e00418 Combine lzma_options_block validation needed by both Block
encoder and decoder, and put the shared things to
block_private.h. Improved the checks a little so that
they may detect too big Compressed Size at initialization
time if lzma_options_block.total_size or .total_limit is
known.

Allow encoding and decoding Blocks with combinations of
fields that are not allowed by the file format specification.
Doing this requires that the application passes such a
combination in lzma_options_lzma; liblzma doesn't do that,
but it's not impossible that someone could find them useful
in some custom file format.
2008-01-25 23:12:36 +02:00
Lasse Collin
bf4200c818 Added test_memlimit.c. 2008-01-25 19:21:22 +02:00
Lasse Collin
7b8fc7e6b5 Improved the memory limitter:
- Added lzma_memlimit_max() and lzma_memlimit_reached()
    API functions.
  - Added simple estimation of malloc()'s memory usage
    overhead.
  - Fixed integer overflow detection in lzma_memlimit_alloc().
  - Made some white space cleanups and added more comments.

The description of lzma_memlimit_max() in memlimit.h is bad
and should be improved.
2008-01-25 19:20:28 +02:00
Lasse Collin
e0c3d0043d Use more parenthesis in succeed() macro in tests/tests.h. 2008-01-25 13:55:52 +02:00
Lasse Collin
1fd76d4881 Added more Multi-Block Stream test files. 2008-01-24 14:49:34 +02:00
Lasse Collin
6e27b1098a Added bunch of test files containing Multi-Block Streams. 2008-01-24 00:46:05 +02:00
Lasse Collin
db9df0a960 Fix decoding of empty Metadata Blocks, that don't have
even the Metadata Flags field. Earlier the code allowed
such files; now they are prohibited as the file format
specification requires.
2008-01-23 23:43:00 +02:00
Lasse Collin
765f0b05f6 Fix a bug related to 99e12af4e2.
lzma_metadata.header_metadata_size was not properly set to
zero if the Metadata had only the Metadata Flags field.
2008-01-23 23:38:18 +02:00
Lasse Collin
3a7cc5c3de Fix decoding of Extra Records that have empty Data. 2008-01-23 23:35:49 +02:00
Lasse Collin
e5fdec93e2 Add the trailing '\0' to lzma_extra.data as the API header
already documents.
2008-01-23 22:02:38 +02:00
Lasse Collin
ed40dc5a2c Added debug/full_flush.c. 2008-01-23 21:21:21 +02:00
Lasse Collin
ae0cd09a66 Return LZMA_STREAM_END instead of LZMA_OK if
LZMA_SYNC_FLUSH or LZMA_FULL_FLUSH is used when
there's no unfinished Block open.
2008-01-23 21:05:33 +02:00
Lasse Collin
0e80ded13d Added bad-single-none-footer_filter_flags.lzma and
bad-single-none-too_long_vli.lzma.
2008-01-23 20:05:01 +02:00
Lasse Collin
8c8eb14055 Fixed a typo. 2008-01-23 13:42:35 +02:00
Lasse Collin
980f65a9a1 Fix a memory leak in the Subblock encoder. 2008-01-23 13:40:45 +02:00
Lasse Collin
99e12af4e2 Fix Size of Header Metadata Block handling. Now
lzma_metadata.header_metadata_size == LZMA_VLI_VALUE_UNKNOWN
is not allowed at all. To indicate missing Header Metadata
Block, header_metadata_size must be set to zero. This is
what Metadata decoder does after this patch too.

Note that other missing fields in lzma_metadata are still
indicated with LZMA_VLI_VALUE_UNKNOWN. This isn't as
illogical as it sounds at first, because missing Size of
Header Metadata Block means that Header Metadata Block is
not present in the Stream. With other Metadata fields,
a missing field means only that the value is unknown.
2008-01-23 13:36:07 +02:00
Lasse Collin
58b78ab20c Fix a memory leak in metadata_decoder.c. 2008-01-23 13:15:55 +02:00
Lasse Collin
4d8cdbdab4 Fix the fix 863028cb7a which
just moved to problem. Now it's really fixed.
2008-01-23 13:13:58 +02:00
Lasse Collin
67321de963 Take advantage of return_if_error() macro in
lzma_info_metadata_set() in info.c.
2008-01-23 00:21:04 +02:00
Lasse Collin
863028cb7a Fixed a dangling pointer that caused invalid free(). 2008-01-23 00:18:32 +02:00
Lasse Collin
cf49f42a6b Added lzma_easy_* functions. These should make using
liblzma as easy as using zlib, because the easy API
don't require developers to know any fancy LZMA options.

Note that Multi-Block Stream encoding is currently broken.
The easy API should be OK, the bug(s) are elsewhere.
2008-01-22 22:49:24 +02:00
Lasse Collin
1747b85a43 Fix Multi-Block Stream encoder's EOPM usage. 2008-01-22 21:16:22 +02:00
Lasse Collin
0ed6f1adce Made lzma_extra pointers const in lzma_options_stream. 2008-01-22 00:15:11 +02:00
Lasse Collin
305afa38f6 Updated debug/sync_flush.c. 2008-01-20 20:15:21 +02:00
Lasse Collin
d53e9b7705 Added debug/repeat.c. 2008-01-20 20:14:26 +02:00
Lasse Collin
107259e306 Fix alignment handling bugs in Subblock encoder.
This leaves one known alignment bug unfixed: If repeat count
doesn't fit into 28-bit integer, the encoder has to split
this to multiple Subblocks with Subblock Type `Repeating Data'.
The extra Subblocks may have wrong alignment. Correct alignment
is restored after the split Repeating Data has been completely
written out.

Since the encoder doesn't even try to fix the alignment unless
the size of Data is at least 4 bytes, to trigger this bug you
need at least 4 GiB of repeating data with sequence length of
4 or more bytes. Since the worst thing done by this bug is
misaligned data (no data corruption), this bug simply isn't
worth fixing, because a proper fix isn't simple.
2008-01-20 20:12:58 +02:00
Lasse Collin
e141fe1895 Implemented LZMA_SYNC_FLUSH support to the Subblock encoder.
The API for handing Subfilters was changed to make it
consistent with LZMA_SYNC_FLUSH.

A few sanity checks were added for Subfilter handling. Some
small bugs were fixed. More comments were added.
2008-01-19 21:16:33 +02:00
Lasse Collin
23c227a864 Revised the Delta filter implementation. The initialization
function is still shared between encoder and decoder, but the
actual coding is in separate files for encoder and decoder.

There are now separate functions for the actual delta
calculation depending on if Delta is the last filter in the
chain or not. If it is the last, the new code copies the
data from input to output buffer and does the delta
calculation at the same time. The old code first copied the
data, then did the delta in the target buffer, which required
reading through the data twice.

Support for LZMA_SYNC_FLUSH was added to the Delta encoder.
This doesn't change anything in the file format.
2008-01-19 15:19:21 +02:00
Lasse Collin
61dc82f3e3 Added the debug directory and the first debug tool
(sync_flush). These tools are not built unless the
user runs "make" in the debug directory.
2008-01-18 20:18:08 +02:00
Lasse Collin
0ae3208db9 Added test files to test usage of flush marker in LZMA. 2008-01-18 20:13:00 +02:00
Lasse Collin
ab5feaf1fc Fix LZMA_SYNC_FLUSH handling in LZ and LZMA encoders.
That code is now almost completely in LZ coder, where
it can be shared with other LZ77-based algorithms in
future.
2008-01-18 20:02:52 +02:00
Lasse Collin
079c4f7fc2 Don't add -g to CFLAGS when --enable-debug is specified.
It's the job of the user to put that in CFLAGS.
2008-01-18 17:21:24 +02:00
Lasse Collin
61d1784d8f Set stdin and stdout to binary mode on Windows. This patch is
a forward port of b7b22fcb979a16d3a47c8001f058c9f7d4416068
from lzma-utils-legacy.git. I don't know if the new code base
builds on Windows, but this is a start.
2008-01-18 14:17:37 +02:00
Lasse Collin
c9cba97691 Added test_compress.sh and bunch of files needed by it.
This new set of tests compress and decompress several
test files with many different compression options.
This set of tests will be extended later.
2008-01-18 00:50:29 +02:00
Lasse Collin
33be3c0e24 Subblock decoder: Don't exit the main loop in decode_buffer()
too early if we hit End of Input while decoding a Subblock of
type Repeating Data. To keep the loop termination condition
elegant, the order of enumerations in coder->sequence were
changed.

To keep the case-labels in roughly the same order as the
enumerations in coder->sequence, large chunks of code was
moved around. This made the diff big and ugly compared to
the amount of the actual changes made.
2008-01-17 18:56:53 +02:00
Lasse Collin
b254bd97b1 Fix wrong too small size of argument unfiltered_max
in ia64_coder_init(). It triggered assert() in
simple_coder.c, and could have caused a buffer overflow.

This error was probably a copypaste mistake, since most
of the simple filters use unfiltered_max = 4.
2008-01-17 17:39:42 +02:00
Lasse Collin
8f5794c8f1 Added --delta to the output of "lzma --help". 2008-01-17 17:27:45 +02:00
Lasse Collin
f88590e001 Fix Subblock docoder: If Subblock filter was used with known
Uncompressed Size, and the last output byte was from RLE,
the code didn't stop decoding as it should have done.
2008-01-17 13:14:20 +02:00
Lasse Collin
bc0b945ca3 Tiny non-technical edits to file-format.txt. 2008-01-16 16:33:37 +02:00
Lasse Collin
7599bb7064 Plugged a memory leak in stream_decoder.c. 2008-01-16 14:48:04 +02:00
Lasse Collin
0b58153931 Added memory leak detection to lzmadec.c. 2008-01-16 14:47:27 +02:00
Lasse Collin
5b5b13c7bb Added lzma_memlimit_count(). 2008-01-16 14:46:50 +02:00
Lasse Collin
19389f2b82 Added ARRAY_SIZE(array) macro. 2008-01-16 14:31:44 +02:00
Lasse Collin
9bc33a54cb Make Uncompresed Size validation more strict
in alone_decoder.c.
2008-01-16 13:27:03 +02:00
Lasse Collin
01d71d60b7 Free the allocated memory in lzmadec if debugging is
enabled. This should make it possible to detect possible
memory leaks with Valgrind.
2008-01-15 17:46:59 +02:00
Lasse Collin
8235e6e5b2 Fix memory leaks from test_block_header.c. 2008-01-15 16:25:38 +02:00
Lasse Collin
f10fc6a69d Use fastpos.h when encoding LZMA dictionary size in
Filter Flags encoder.
2008-01-15 14:23:35 +02:00
Lasse Collin
e5728142a2 Revised the fastpos code. It now uses the slightly faster
table-based version from LZMA SDK 4.57. This should be
fast on most systems.

A simpler and smaller alternative version is also provided.
On some CPUs this can be even a little faster than the
default table-based version (see comments in fastpos.h),
but on most systems the table-based code is faster.
2008-01-15 14:02:22 +02:00
Lasse Collin
10437b5b56 Added bsr.h. 2008-01-15 13:32:13 +02:00
Lasse Collin
f3c88e8b8d Fixed assembler detection in configure.ac, and added
detection for x86_64.
2008-01-15 13:29:14 +02:00
Lasse Collin
54ec204f58 Omit invalid space from printf() format string
in price_table_gen.c.
2008-01-15 12:20:41 +02:00
Lasse Collin
01b4b19f49 Removed a few unused macros from lzma_common.h. 2008-01-15 09:54:34 +02:00
Lasse Collin
19bd7f3cf2 Fix a typo in lzma_encoder.c. 2008-01-15 08:37:42 +02:00
Lasse Collin
9f9b198301 Convert bittree_get_price() and bittree_reverse_get_price()
from macros to inline functions.
2008-01-15 08:36:25 +02:00
Lasse Collin
78e85cb1a7 Fix CRC code in case --enable-small is used. 2008-01-15 07:44:59 +02:00
Lasse Collin
949d4346e2 Fix typo in test_index.c. 2008-01-15 07:41:39 +02:00
Lasse Collin
d13d693155 Added precomputed range coder probability price table. 2008-01-15 07:40:21 +02:00
Lasse Collin
362dc3843b Remove RC_BUFFER_SIZE from lzma_encoder_private.h
and replace it with a sanity check.
2008-01-14 13:42:43 +02:00
Lasse Collin
e22b37968d Major changes to LZ encoder, LZMA encoder, and range encoder.
These changes implement support for LZMA_SYNC_FLUSH in LZMA
encoder, and move the temporary buffer needed by range encoder
from lzma_range_encoder structure to lzma_lz_encoder.
2008-01-14 13:39:54 +02:00
Lasse Collin
b59ef39737 Added one assert() to process.c of the command line tool. 2008-01-14 13:34:29 +02:00
Lasse Collin
9547e734a0 Don't use coder->lz.stream_end_was_reached in assertions
in match_c.h.
2008-01-14 12:09:52 +02:00
Lasse Collin
3e09e1c058 In lzma_read_match_distances(), don't use
coder->lz.stream_end_was_reached. That variable
will be removed, and the check isn't required anyway.
Rearrange the check so that it doesn't make one to
think that there could be an integer overflow.
2008-01-14 12:08:02 +02:00
Lasse Collin
a670fec802 Small LZMA_SYNC_FLUSH fixes to Block and Single-Stream encoders. 2008-01-14 11:56:41 +02:00
Lasse Collin
3599dba957 More fixes to LZMA decoder's flush marker handling. 2008-01-14 11:54:56 +02:00
Lasse Collin
f73c2ab607 Eliminate lzma_lz_encoder.must_move_pos. It's needed
only in one place which isn't performance criticial.
2008-01-10 17:13:42 +02:00
Lasse Collin
382808514a Define HAVE_ASM_X86 when x86 assembler optimizations are
used. This #define will be useful for inline assembly.
2008-01-09 20:05:57 +02:00
Lasse Collin
0e70fbe403 Added good-single-none-empty_3.lzma and
bad-single-none-empty.lzma.
2008-01-09 12:06:46 +02:00
Lasse Collin
379fbbe84d Take advantage of return_if_error() in block_decoder.c. 2008-01-08 23:11:59 +02:00
Lasse Collin
97d5fa8207 Updated tests/files/README. 2008-01-08 23:10:57 +02:00
Lasse Collin
3bb9bb3109 Added test files with empty Compressed Data. 2008-01-08 23:05:40 +02:00
Lasse Collin
7054c5f588 Fix decoding of Blocks that have only Block Header. 2008-01-08 22:58:42 +02:00
Lasse Collin
753e4d95cd Added good-single-subblock_implicit.lzma. 2008-01-08 22:27:46 +02:00
Lasse Collin
faeac7b7ac Disable CRC32 from Block Headers when --check=none
has been specified.
2008-01-08 18:50:30 +02:00
Lasse Collin
a751126dbb Fixed encoding of empty files. Arguments to is_size_valid()
were in wrong order in block_encoder.c.
2008-01-08 13:36:29 +02:00
Lasse Collin
9080267603 Added a few test files. 2008-01-08 13:35:36 +02:00
Lasse Collin
b4943ccf73 Avoid using ! in test_files.sh, because that doesn't work
with some ancient /bin/sh versions.
2008-01-08 12:29:58 +02:00
Lasse Collin
e2417b2b91 More pre-C99 inttypes.h compatibility fixes. Now the code
should work even if the system has no inttypes.h.
2008-01-08 00:48:30 +02:00
Lasse Collin
5d227e51c2 Updated fi.po although it's currently pretty much crap. 2008-01-07 23:25:32 +02:00
Lasse Collin
c7189d981a Test for $GCC = yes instead of if it is non-empty. This
way it is possible to use ac_cv_c_compiler_gnu=no to
force configure to think it is using non-GNU C compiler.
2008-01-07 23:14:25 +02:00
Lasse Collin
3dbbea82b7 Added test_files.sh to tests/Makefile.am so it gets
included in the tarball with "make dist".
2008-01-07 21:49:41 +02:00
Lasse Collin
2fd2d18154 Cosmetic edit to test_files.sh. 2008-01-07 18:22:24 +02:00
Lasse Collin
9a71d57310 Added tests/files/README. 2008-01-07 18:09:44 +02:00
Lasse Collin
47f48fe993 Tell in COPYING that everything in tests/files is
public domain.
2008-01-07 14:20:57 +02:00
Lasse Collin
3502b3e1d0 Cleaned up the tests/files directory. 2008-01-07 14:19:05 +02:00
Lasse Collin
908b2ac604 Added test_files.sh to test decoding of the files in
the tests/files directory. It doesn't test the malicious
files yet.
2008-01-07 13:49:19 +02:00
Lasse Collin
ecb2a6548f Updated README regarding the assembler optimizations. 2008-01-07 11:23:13 +02:00
Lasse Collin
eacb805043 Updated THANKS. 2008-01-07 10:58:00 +02:00
Lasse Collin
1239649f96 Cosmetic changes to configure.ac. 2008-01-06 21:47:17 +02:00
Lasse Collin
88ee301ec2 Automatically disable assembler code on Darwin x86.
Darwin has different ABI than GNU+Linux and Solaris,
thus the assembler code doesn't assemble on Darwin.
2008-01-06 19:46:38 +02:00
Lasse Collin
c15a7abf66 With printf(), use PRIu64 with a cast to uint64_t instead
of %zu, because some pre-C99 libc versions don't support %zu.
2008-01-06 19:45:27 +02:00
Lasse Collin
4e7e54c4c5 Introduced compatibility with systems that have pre-C99
or no inttypes.h. This is useful when the compiler has
good enough support for C99, but libc headers don't.

Changed liblzma API so that sys/types.h and inttypes.h
have to be #included before #including lzma.h. On systems
that don't have C99 inttypes.h, it's the problem of the
applications to provide the required types and macros
before #including lzma.h.

If lzma.h defined the missing types and macros, it could
conflict with third-party applications whose configure
has detected that the types are missing and defined them
in config.h already. An alternative would have been
introducing lzma_uint32 and similar types, but that would
just be an extra pain on modern systems.
2008-01-06 16:27:41 +02:00
Lasse Collin
a71864f77d Fix typo in comment (INT64_MAX -> UINT64_MAX). 2008-01-05 19:57:00 +02:00
Lasse Collin
072927905a Rearranged testing of GCC-specific flags. 2008-01-05 19:42:04 +02:00
Lasse Collin
d160ee3259 Another bug fix for flush marker detection. 2008-01-05 01:20:24 +02:00
Lasse Collin
fc67f79f60 Fix stupid bugs in flush marker detection. 2008-01-04 21:37:01 +02:00
Lasse Collin
0029cbbabe Added support for flush marker, which will be in files
that use LZMA_SYNC_FLUSH with encoder (not implemented
yet). This is a new feature in the raw LZMA format,
which isn't supported by old decoders. This shouldn't
be a problem in practice, since lzma_alone_encoder()
will not allow LZMA_SYNC_FLUSH, and thus not allow
creating files on decodable with old decoders.

Made lzma_decoder.c to require tab width of 4 characters
if one wants to fit the code in 80 columns. This makes
the code easier to read.
2008-01-04 21:30:33 +02:00
Lasse Collin
bbfd1f6ab0 Moved range decoder initialization (reading the first
five input bytes) from LZMA decoder to range decoder
header. Did the same for decoding of direct bits.
2008-01-04 20:45:05 +02:00
Lasse Collin
5db745cd2a Added a note to README that --disable-assembler
must be used on Darwin.
2007-12-14 11:15:21 +02:00
Lasse Collin
44b333d461 Use the filename suffix .S instead of .s for assembler files
so that the preprocessor removes the /* */ style comments,
which are not supported by some non-GNU assemblers (Solaris)
that otherwise work with this code.
2007-12-14 10:07:10 +02:00
Lasse Collin
ec1c82b2e8 Fixed wrong symbol name in crc64_x86.s. 2007-12-14 09:59:05 +02:00
Lasse Collin
2881570df6 Use .globl instead of .global in x86 assembler code for
better portability. Still needs fixing the commenting.
2007-12-14 09:53:24 +02:00
Lasse Collin
698470b8f3 Fixed a few short options that take an argument.
short_opts[] was missing colons to indicate
required argument. Thanks to Fabio Pedretti for
the bug report.
2007-12-13 20:14:37 +02:00
Lasse Collin
918bcb0e07 Removed uncompressed size tracking from Delta encoder too. 2007-12-11 17:08:04 +02:00
Lasse Collin
3e16d51dd6 Remove uncompressed size tracking from the filter encoders.
It's not strictly needed there, and just complicates the
code. LZ encoder never even had this feature.

The primary reason to have uncompressed size tracking in
filter encoders was validating that the application
doesn't give different amount of input that it had
promised. A side effect was to validate internal workings
of liblzma.

Uncompressed size tracking is still present in the Block
encoder. Maybe it should be added to LZMA_Alone and raw
encoders too. It's simpler to have one coder just to
validate the uncompressed size instead of having it
in every filter.
2007-12-11 16:49:19 +02:00
Lasse Collin
5286723e0d Get rid of no-NLS gnulib. I don't know how to get it
working with Automake. People who want smaller lzmadec
should use --disable-nls on non-GNU systems.
2007-12-11 14:10:53 +02:00
Lasse Collin
ce8b036a6c Fixed a typo in tests/Makefile.am which prevented
building the tests if gnulib was needed.
2007-12-11 14:09:35 +02:00
Lasse Collin
7c1ad41eb6 Fixed wrong type of flags_size in Subblock encoder. 2007-12-11 11:18:58 +02:00
Lasse Collin
ce64df7162 Bumped version number to 4.42.3alpha. 2007-12-10 20:44:16 +02:00
460 changed files with 35534 additions and 29005 deletions

54
.gitignore vendored Normal file
View File

@@ -0,0 +1,54 @@
*~
*.bak
*.bak[0-9]
.deps
.libs
*.la
*.lo
*.o
Makefile.in
/ABOUT-NLS
/autom4te.cache
/Doxyfile
/aclocal.m4
/build-aux
/config.h
/config.h.in
/config.log
/config.status
/configure
/libtool
/stamp-h1
/src/liblzma/liblzma.pc
/src/xz/xz
/src/xzdec/lzmadec
/src/xzdec/xzdec
/src/scripts/xzdiff
/src/scripts/xzgrep
/src/scripts/xzless
/src/scripts/xzmore
/tests/compress_generated_abc
/tests/compress_generated_random
/tests/compress_generated_text
/tests/create_compress_files
/tests/test_block_header
/tests/test_check
/tests/test_filter_flags
/tests/test_index
/tests/test_stream_flags
/lib/Makefile
/tests/Makefile
/Makefile
/debug/Makefile
/src/scripts/Makefile
/src/xz/Makefile
/src/Makefile
/src/liblzma/Makefile
/src/liblzma/api/Makefile
/src/xzdec/Makefile

35
AUTHORS
View File

@@ -1,18 +1,27 @@
Authors of LZMA Utils
---------------------
Authors of XZ Utils
===================
Igor Pavlov
* designed LZMA as an algorithm;
* wrote an implementation known as LZMA SDK, which is part of
the bigger 7-Zip project.
XZ Utils is developed and maintained by Lasse Collin
<lasse.collin@tukaani.org>.
Ville Koskinen
* wrote the first version of the gzip-like lzma command line
utility (C++)
* helped a lot with the documentation.
Major parts of liblzma are based on code written by Igor Pavlov,
specifically the LZMA SDK <http://7-zip.org/sdk.html>. Without
this code, XZ Utils wouldn't exist.
Lasse Collin
* ported LZMA SDK to C and zlib-like API (liblzma);
* rewrote the command line tool again to use liblzma and pthreads.
The SHA-256 implementation in liblzma is based on the code found from
7-Zip <http://7-zip.org/>, which has a modified version of the SHA-256
code found from Crypto++ <http://www.cryptopp.com/>. The SHA-256 code
in Crypto++ was written by Kevin Springle and Wei Dai.
Some scripts have been adapted from gzip. The original versions
were written by Jean-loup Gailly, Charles Levert, and Paul Eggert.
Andrew Dudman helped adapting the script and their man pages for
XZ Utils.
The GNU Autotools based build system contains files from many authors,
which I'm not trying list here.
Several people have contributed fixes or reported bugs. Most of them
are mentioned in the file THANKS.

69
COPYING
View File

@@ -1,24 +1,65 @@
LZMA Utils Licenses
-------------------
XZ Utils Licensing
==================
Different licenses apply to different files in this package. Here
is a rough summary of which license apply to which parts of this
is a rough summary of which licenses apply to which parts of this
package (but check the individual files to be sure!):
- Everything under src/liblzma/check is public domain.
- Everything else under the src directory is under the GNU LGPL
2.1 or (at your opinion) any later version.
- Outside the src directory, there are some files that are under
the GNU GPL 2 or (at your opinion) any later version, or under
the GNU GPL 3 or (at your opinion) any later version.
- Most documentation files are under an all-permissive license.
The following license texts are included in the following files
in this package:
- liblzma is in the public domain.
- xz, xzdec, and lzmadec command line tools are in the public
domain unless GNU getopt_long had to be compiled and linked
in from the lib directory. The getopt_long code is under
GNU LGPLv2.1+.
- The scripts to grep, diff, and view compressed files have been
adapted from gzip. These scripts and their documentation are
under GNU GPLv2+.
- All the documentation in the doc directory and most of the
XZ Utils specific documentation files in other directories
are in the public domain.
- Translated messages are in the public domain.
- The build system contains public domain files, and files that
are under GNU GPLv2+ or GNU GPLv3+. None of these files end up
in the binaries being built.
- Test files and test code in the tests directory, and debugging
utilities in the debug directory are in the public domain.
- The extra directory may contain public domain files, and files
that are under various free software licenses.
You can do whatever you want with the files that have been put into
the public domain. If you find public domain legally problematic,
take the previous sentence as a license grant. If you still find
the lack of copyright legally problematic, you have too many
lawyers.
As usual, this software is provided "as is", without any warranty.
If you copy significant amounts of public domain code from XZ Utils
into your project, acknowledging this somewhere in your software is
polite (especially if it is proprietary, non-free software), but
naturally it is not legally required. Here is an example of a good
notice to put into "about box" or into documentation:
This software includes code from XZ Utils <http://tukaani.org/xz/>.
The following license texts are included in the following files:
- COPYING.LGPLv2.1: GNU Lesser General Public License version 2.1
- COPYING.GPLv2: GNU General Public License version 2
- COPYING.GPLv3: GNU General Public License version 3
If you have questions, don't hesitate to ask the copyright holder(s)
for more information.
Note that the toolchain (compiler, linker etc.) may add some code
pieces that are copyrighted. Thus, it is possible that e.g. liblzma
binary wouldn't actually be in the public domain in its entirety
even though it contains no copyrighted code from the XZ Utils source
package.
If you have questions, don't hesitate to ask the author(s) for more
information.

View File

@@ -1,2 +1,7 @@
See the commit log in the git repository:
git://ctrl.tukaani.org/lzma-utils.git
git://ctrl.tukaani.org/xz.git
Note that "make dist" doesn't put this tiny file into the package.
Instead, the git commit log is used as ChangeLog. See dist-hook in
Makefile.am for details.

View File

@@ -1,5 +1,8 @@
# Doxyfile 1.4.7
# Copyright (C) 1997-2007 by Dimitri van Heesch
# License: GNU GPLv2+
# This file describes the settings to be used by the documentation system
# doxygen (www.doxygen.org) for a project
#
@@ -955,13 +958,13 @@ ENABLE_PREPROCESSING = YES
# compilation will be performed. Macro expansion can be done in a controlled
# way by setting EXPAND_ONLY_PREDEF to YES.
MACRO_EXPANSION = NO
MACRO_EXPANSION = YES
# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
# then the macro expansion is limited to the macros specified with the
# PREDEFINED and EXPAND_AS_DEFINED tags.
EXPAND_ONLY_PREDEF = NO
EXPAND_ONLY_PREDEF = YES
# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
# in the INCLUDE_PATH (see below) will be search if a #include is found.
@@ -989,7 +992,9 @@ INCLUDE_FILE_PATTERNS =
# undefined via #undef or recursively expanded use the := operator
# instead of the = operator.
PREDEFINED =
PREDEFINED = LZMA_API(type)=type \
LZMA_API_IMPORT \
LZMA_API_CALL=
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
# this tag can be used to specify a list of macro names that should be expanded.

339
INSTALL Normal file
View File

@@ -0,0 +1,339 @@
XZ Utils Installation
=====================
0. Preface
1. Supported platforms
1.1. Compilers
1.2. Platform-specific notes
1.2.1. Darwin (Mac OS X)
1.2.2. Tru64
1.2.3. Windows
1.2.4. DOS
1.2.5. OS/2
1.3. Adding support for new platforms
2. configure options
3. xzgrep and other scripts
3.1. Dependencies
3.2. PATH
4. Troubleshooting
4.1. "No C99 compiler was found."
4.1. "No POSIX conforming shell (sh) was found."
4.2. configure works but build fails at crc32_x86.S
0. Preface
----------
If you aren't familiar with building packages that use GNU Autotools,
see the file INSTALL.generic for generic instructions before reading
further.
If you are going to build a package for distribution, see also the
file PACKAGERS. It contains information that should help making the
binary packages as good as possible, but the information isn't very
interesting to those making local builds for private use or for use
in special situations like embedded systems.
1. Supported platforms
----------------------
XZ Utils are developed on GNU/Linux, but they should work on many
POSIX-like operating systems like *BSDs and Solaris, and even on
a few non-POSIX operating systems.
1.1. Compilers
A C99 compiler is required to compile XZ Utils. If you use GCC, you
need at least version 3.x.x. GCC version 2.xx.x doesn't support some
C99 features used in XZ Utils source code, thus GCC 2 won't compile
XZ Utils.
XZ Utils takes advantage of some GNU C extensions when building
with GCC. Because these extensions are used only when building
with GCC, it should be possible to use any C99 compiler.
1.2. Platform-specific notes
1.2.1. Darwin (Mac OS X)
You may need --disable-assembler if building universal binaries on
Darwin. This is because different files are built when assembler is
enabled, and there's no way to make it work with universal build.
If you want to keep the assembler code, consider building one
architecture at a time, and then combining the results to create
universal binaries (see lipo(1)).
1.2.2. Tru64
If you try to use the native C compiler on Tru64 (passing CC=cc to
configure), it is possible that the configure script will complain
that no C99 compiler was found even when the native compiler supports
C99. You can safely override the test for C99 compiler by passing
ac_cv_prog_cc_c99= as the argument to the configure script.
1.2.3. Windows
Building XZ Utils on Windows is supported under MinGW and Cygwin.
If the Autotools based build gives you trouble with MinGW, you may
want try the alternative method found from the "windows" directory.
MSVC doesn't support C99, thus it is not possible to use MSVC to
compile XZ Utils. However, it is possible to use liblzma.dll from
MSVC once liblzma.dll has been built with MinGW. The required
import library for MSVC can be created from liblzma.def using the
"lib" command shipped in MSVC:
lib /def:liblzma.def /out:liblzma.lib /machine:ix86
On x86-64, the /machine argument has to naturally be changed:
lib /def:liblzma.def /out:liblzma.lib /machine:x64
1.2.4. DOS
There is an experimental Makefile in the "dos" directory to build
XZ Utils on DOS using DJGPP. Support for long file names (LFN) is
needed.
GNU Autotools based build hasn't been tried on DOS.
1.2.5. OS/2
You will need to pass --disable-assembler to configure when building
on OS/2.
1.3. Adding support for new platforms
If you have written patches to make XZ Utils to work on previously
unsupported platform, please send the patches to me! I will consider
including them to the official version. It's nice to minimize the
need of third-party patching.
One exception: Don't request or send patches to change the whole
source package to C89. I find C99 substantially nicer to write and
maintain. However, the public library headers must be in C89 to
avoid frustrating those who maintain programs, which are strictly
in C89 or C++.
2. configure options
--------------------
In most cases, the defaults are what you want. Most of the options
below are useful only when building a size-optimized version of
liblzma or command line tools.
--enable-encoders=LIST
--disable-encoders
Specify a comma-separated LIST of filter encoders to
build. See "./configure --help" for exact list of
available filter encoders. The default is to build all
supported encoders.
If LIST is empty or --disable-encoders is used, no filter
encoders will be built and also the code shared between
encoders will be omitted.
Disabling encoders will remove some symbols from the
liblzma ABI, so this option should be used only when it
is known to not cause problems.
--enable-decoders=LIST
--disable-decoders
This is like --enable-encoders but for decoders. The
default is to build all supported decoders.
--enable-match-finders=LIST
liblzma includes two categories of match finders:
hash chains and binary trees. Hash chains (hc3 and hc4)
are quite fast but they don't provide the best compression
ratio. Binary trees (bt2, bt3 and bt4) give excellent
compression ratio, but they are slower and need more
memory than hash chains.
You need to enable at least one match finder to build the
LZMA1 or LZMA2 filter encoders. Usually hash chains are
used only in the fast mode, while binary trees are used to
when the best compression ratio is wanted.
The default is to build all the match finders if LZMA1
or LZMA2 filter encoders are being built.
--enable-checks=LIST
liblzma support multiple integrity checks. CRC32 is
mandatory, and cannot be omitted. See "./configure --help"
for exact list of available integrity check types.
liblzma and the command line tools can decompress files
which use unsupported integrity check type, but naturally
the file integrity cannot be verified in that case.
Disabling integrity checks may remove some symbols from
the liblzma ABI, so this option should be used only when
it is known to not cause problems.
--disable-assembler
liblzma includes some assembler optimizations. Currently
there is only assembler code for CRC32 and CRC64 for
32-bit x86.
All the assembler code in liblzma is position-independent
code, which is suitable for use in shared libraries and
position-independent executables. So far only i386
instructions are used, but the code is optimized for i686
class CPUs. If you are compiling liblzma exclusively for
pre-i686 systems, you may want to disable the assembler
code.
--enable-unaligned-access
Allow liblzma to use unaligned memory access for 16-bit
and 32-bit loads and stores. This should be enabled only
when the hardware supports this, i.e. when unaligned
access is fast. Some operating system kernels emulate
unaligned access, which is extremely slow. This option
shouldn't be used on systems that rely on such emulation.
Unaligned access is enabled by default on x86, x86-64,
and big endian PowerPC.
--enable-small
Reduce the size of liblzma by selecting smaller but
semantically equivalent version of some functions, and
omit precomputed lookup tables. This option tends to
make liblzma slightly slower.
Note that while omitting the precomputed tables makes
liblzma smaller on disk, the tables are still needed at
run time, and need to be computed at startup. This also
means that the RAM holding the tables won't be shared
between applications linked against shared liblzma.
--disable-threads
Disable threading support. This makes some things
thread-unsafe, meaning that if multithreaded application
calls liblzma functions from more than one thread,
something bad may happen.
Use this option if threading support causes you trouble,
or if you know that you will use liblzma only from
single-threaded applications and want to avoid dependency
on libpthread.
--enable-dynamic=TYPE
Specify how command line tools should be linked against
liblzma. Possible TYPES:
yes All command line tools are linked against
shared liblzma (if shared liblzma was built).
This is equivalent to --enable-dynamic (i.e.
no =TYPE).
mixed Some tools are linked against static liblzma
and some against shared liblzma. This is the
default and recommended way.
no All command line tools are linked against
static liblzma (if static liblzma was built).
This is equivalent to --disable-dynamic.
This option is mostly useful for packagers, if distro
policy requires linking against shared libaries. See the
file PACKAGERS for more information about pros and cons
of this option.
--enable-debug
This enables the assert() macro and possibly some other
run-time consistency checks. It makes the code slower, so
you normally don't want to have this enabled.
--enable-werror
If building with GCC, make all compiler warnings an error,
that abort the compilation. This may help catching bugs,
and should work on most systems. This has no effect on the
resulting binaries.
3. xzgrep and other scripts
---------------------------
3.1. Dependencies
POSIX shell (sh) and bunch of other standard POSIX tools are required
to run the scripts. The configure script tries to find a POSIX
compliant sh, but if it fails, you can force the shell by passing
gl_cv_posix_shell=/path/to/posix-sh as an argument to the configure
script.
Some of the scripts require also mktemp. The original mktemp can be
found from <http://www.mktemp.org/>. On GNU, most will use the mktemp
program from GNU coreutils instead of the original implementation.
Both mktemp versions are fine for XZ Utils (and practically for
everything else too).
3.2. PATH
The scripts assume that the required tools (standard POSIX utilities,
mktemp, and xz) are in PATH; the scripts don't set the PATH themselves.
Some people like this while some think this is a bug. Those in the
latter group can easily patch the scripts before running the configure
script by taking advantage of a placeholder line in the scripts.
For example, to make the scripts prefix /usr/bin:/bin to PATH:
perl -pi -e 's|^#SET_PATH.*$|PATH=/usr/bin:/bin:\$PATH|' \
src/scripts/xz*.in
4. Troubleshooting
------------------
4.1. "No C99 compiler was found."
You need a C99 compiler to build XZ Utils. If the configure script
cannot find a C99 compiler and you think you have such a compiler
installed, set the compiler command by passing CC=/path/to/c99 as
an argument to the configure script.
If you get this error even when you think your compiler supports C99,
you can override the test by passing ac_cv_prog_cc_c99= as an argument
to the configure script. The test for C99 compiler is not perfect (and
it is not as easy to make it perfect as it sounds), so sometimes this
may be needed. You will get a compile error if your compiler doesn't
support enough C99.
4.1. "No POSIX conforming shell (sh) was found."
xzgrep and other scripts need a shell that (roughly) conforms
to POSIX. The configure script tries to find such a shell. If
it fails, you can force the shell to be used by passing
gl_cv_posix_shell=/path/to/posix-sh as an argument to the configure
script.
4.2. configure works but build fails at crc32_x86.S
The easy fix is to pass --disable-assembler to the configure script.
The configure script determines if assembler code can be used by
looking at the configure triplet; there is currently no check if
the assembler code can actually actually be built. The x86 assembler
code should work on x86 GNU/Linux, *BSDs, Solaris, Darwin, MinGW,
Cygwin, and DJGPP. On other x86 systems, there may be problems and
the assembler code may need to be disabled with the configure option.
If you get this error when building for x86-64, you have specified or
the configure script has misguessed your architecture. Pass the
correct configure triplet using the --build=CPU-COMPANY-SYSTEM option
(see INSTALL.generic).

302
INSTALL.generic Normal file
View File

@@ -0,0 +1,302 @@
Installation Instructions
*************************
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
2006, 2007, 2008, 2009 Free Software Foundation, Inc.
This file is free documentation; the Free Software Foundation gives
unlimited permission to copy, distribute and modify it.
Basic Installation
==================
Briefly, the shell commands `./configure; make; make install' should
configure, build, and install this package. The following
more-detailed instructions are generic; see the `README' file for
instructions specific to this package.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
you can run in the future to recreate the current configuration, and a
file `config.log' containing compiler output (useful mainly for
debugging `configure').
It can also use an optional file (typically called `config.cache'
and enabled with `--cache-file=config.cache' or simply `-C') that saves
the results of its tests to speed up reconfiguring. Caching is
disabled by default to prevent problems with accidental use of stale
cache files.
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
diffs or instructions to the address given in the `README' so they can
be considered for the next release. If you are using the cache, and at
some point `config.cache' contains results you don't want to keep, you
may remove or edit it.
The file `configure.ac' (or `configure.in') is used to create
`configure' by a program called `autoconf'. You need `configure.ac' if
you want to change it or regenerate `configure' using a newer version
of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system.
Running `configure' might take a while. While running, it prints
some messages telling which features it is checking for.
2. Type `make' to compile the package.
3. Optionally, type `make check' to run any self-tests that come with
the package.
4. Type `make install' to install the programs and any data files and
documentation.
5. You can remove the program binaries and object files from the
source code directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile the package for
a different kind of computer), type `make distclean'. There is
also a `make maintainer-clean' target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
6. Often, you can also type `make uninstall' to remove the installed
files again.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that
the `configure' script does not know about. Run `./configure --help'
for details on some of the pertinent environment variables.
You can give `configure' initial values for configuration parameters
by setting variables in the command line or in the environment. Here
is an example:
./configure CC=c99 CFLAGS=-g LIBS=-lposix
*Note Defining Variables::, for more details.
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you can use 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 the directory that `configure' is in and in `..'.
With a non-GNU `make', it is safer to compile the package for one
architecture at a time in the source code directory. After you have
installed the package for one architecture, use `make distclean' before
reconfiguring for another architecture.
On MacOS X 10.5 and later systems, you can create libraries and
executables that work on multiple system types--known as "fat" or
"universal" binaries--by specifying multiple `-arch' options to the
compiler but only a single `-arch' option to the preprocessor. Like
this:
./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
CPP="gcc -E" CXXCPP="g++ -E"
This is not guaranteed to produce working output in all cases, you
may have to build one architecture at a time and combine the results
using the `lipo' tool if you have problems.
Installation Names
==================
By default, `make install' installs the package's commands under
`/usr/local/bin', include files under `/usr/local/include', etc. You
can specify an installation prefix other than `/usr/local' by giving
`configure' the option `--prefix=PREFIX'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
PREFIX as the prefix for installing programs and libraries.
Documentation and other data files still use the regular prefix.
In addition, if you use an unusual directory layout you can give
options like `--bindir=DIR' to specify different values for particular
kinds of files. Run `configure --help' for a list of the directories
you can set and what kinds of files go in them.
If the package supports it, you can cause programs to be installed
with an extra prefix or suffix on their names by giving `configure' the
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Optional Features
=================
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
`README' should mention any `--enable-' and `--with-' options that the
package recognizes.
For packages that use the X Window System, `configure' can usually
find the X include and library files automatically, but if it doesn't,
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
Particular systems
==================
On HP-UX, the default C compiler is not ANSI C compatible. If GNU
CC is not installed, it is recommended to use the following options in
order to use an ANSI C compiler:
./configure CC="cc -Ae -D_XOPEN_SOURCE=500"
and if that doesn't work, install pre-built binaries of GCC for HP-UX.
On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
parse its `<wchar.h>' header file. The option `-nodtk' can be used as
a workaround. If GNU CC is not installed, it is therefore recommended
to try
./configure CC="cc"
and if that doesn't work, try
./configure CC="cc -nodtk"
On Solaris, don't put `/usr/ucb' early in your `PATH'. This
directory contains several dysfunctional programs; working variants of
these programs are available in `/usr/bin'. So, if you need `/usr/ucb'
in your `PATH', put it _after_ `/usr/bin'.
On Haiku, software installed for all users goes in `/boot/common',
not `/usr/local'. It is recommended to use the following options:
./configure --prefix=/boot/common
Specifying the System Type
==========================
There may be some features `configure' cannot figure out
automatically, but needs to determine by the type of machine the package
will run on. Usually, assuming the package is built to be run on the
_same_ architectures, `configure' can figure that out, but if it prints
a message saying it cannot guess the machine type, give it the
`--build=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name which has the form:
CPU-COMPANY-SYSTEM
where SYSTEM can have one of these forms:
OS
KERNEL-OS
See the file `config.sub' for the possible values of each field. If
`config.sub' isn't included in this package, then this package doesn't
need to know the machine type.
If you are _building_ compiler tools for cross-compiling, you should
use the option `--target=TYPE' to select the type of system they will
produce code for.
If you want to _use_ a cross compiler, that generates code for a
platform different from the build platform, you should specify the
"host" platform (i.e., that on which the generated programs will
eventually be run) with `--host=TYPE'.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share,
you can create a site shell script called `config.site' that gives
default values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
A warning: not all `configure' scripts look for a site script.
Defining Variables
==================
Variables not defined in a site shell script can be set in the
environment passed to `configure'. However, some packages may run
configure again during the build, and the customized values of these
variables may be lost. In order to avoid this problem, you should set
them in the `configure' command line, using `VAR=value'. For example:
./configure CC=/usr/local2/bin/gcc
causes the specified `gcc' to be used as the C compiler (unless it is
overridden in the site shell script).
Unfortunately, this technique does not work for `CONFIG_SHELL' due to
an Autoconf bug. Until the bug is fixed you can use this workaround:
CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
`configure' Invocation
======================
`configure' recognizes the following options to control how it
operates.
`--help'
`-h'
Print a summary of all of the options to `configure', and exit.
`--help=short'
`--help=recursive'
Print a summary of the options unique to this package's
`configure', and exit. The `short' variant lists options used
only in the top level, while the `recursive' variant lists options
also present in any nested packages.
`--version'
`-V'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`--cache-file=FILE'
Enable the cache: use and save the results of the tests in FILE,
traditionally `config.cache'. FILE defaults to `/dev/null' to
disable caching.
`--config-cache'
`-C'
Alias for `--cache-file=config.cache'.
`--quiet'
`--silent'
`-q'
Do not print messages saying which checks are being made. To
suppress all normal output, redirect it to `/dev/null' (any error
messages will still be shown).
`--srcdir=DIR'
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
`--prefix=DIR'
Use DIR as the installation prefix. *Note Installation Names::
for more details, including other options available for fine-tuning
the installation locations.
`--no-create'
`-n'
Run the configure checks, but stop before creating any output
files.
`configure' also accepts some other, not widely useful, options. Run
`configure --help' for more details.

View File

@@ -1,17 +1,11 @@
##
## Copyright (C) 2007 Lasse Collin
## Author: Lasse Collin
##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public
## License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
##
## 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
## Lesser General Public License for more details.
## This file has been put into the public domain.
## You can do whatever you want with this file.
##
DIST_SUBDIRS = lib src po tests debug
SUBDIRS =
if COND_GNULIB
@@ -20,16 +14,67 @@ endif
SUBDIRS += src po tests
dist_doc_DATA = \
AUTHORS \
COPYING \
COPYING.GPLv2 \
NEWS \
README \
THANKS \
TODO \
doc/faq.txt \
doc/history.txt \
doc/xz-file-format.txt \
doc/lzma-file-format.txt
EXTRA_DIST = \
m4 \
config.rpath \
Doxyfile.in \
extra \
doc \
dos \
windows \
autogen.sh \
version.sh \
Doxyfile.in \
COPYING.GPLv2 \
COPYING.GPLv3 \
COPYING.LGPLv2.1
COPYING.LGPLv2.1 \
INSTALL.generic \
PACKAGERS
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = foreign
# List of man pages to conver to PDF and plain text in the dist-hook target.
manfiles = \
src/xz/xz.1 \
src/xzdec/xzdec.1 \
src/scripts/xzdiff.1 \
src/scripts/xzgrep.1 \
src/scripts/xzless.1 \
src/scripts/xzmore.1
# Create ChangeLog from output of "git log --date=iso --stat".
# Convert the man pages to PDF and plain text (ASCII only) formats.
dist-hook:
if test -d "$(srcdir)/.git" && type git > /dev/null 2>&1; then \
( cd "$(srcdir)" && git log --date=iso --stat ) \
> "$(distdir)/ChangeLog"; \
fi
if type groff > /dev/null 2>&1 && type ps2pdf > /dev/null 2>&1; then \
dest="$(distdir)/doc/man" && \
$(MKDIR_P) "$$dest/pdf-a4" "$$dest/pdf-letter" "$$dest/txt" && \
for FILE in $(manfiles); do \
BASE=`basename $$FILE .1` && \
groff -man -t -Tps -P-pa4 < "$(srcdir)/$$FILE" \
| ps2pdf - - \
> "$$dest/pdf-a4/$$BASE-a4.pdf" && \
groff -man -t -Tps -P-pletter < "$(srcdir)/$$FILE" \
| ps2pdf - - \
> "$$dest/pdf-letter/$$BASE-letter.pdf" && \
groff -man -t -Tascii < "$(srcdir)/$$FILE" \
| col -bx > "$$dest/txt/$$BASE.txt"; \
done; \
fi
# This works with GNU tar and gives cleaner package than normal 'make dist'.
mydist:
TAR_OPTIONS='--owner=0 --group=0 --numeric-owner --mode=u+rw,go+r-w' \
$(MAKE) dist-gzip

279
PACKAGERS Normal file
View File

@@ -0,0 +1,279 @@
Information to packagers of XZ Utils
====================================
0. Preface
1. Package naming
2. Package description
3. License
4. configure options
4.1. Static vs. dynamic linking of liblzma
4.2. Optimizing xzdec and lzmadec
5. Additional documentation
6. Extra files
7. Installing XZ Utils and LZMA Utils in parallel
8. Example
0. Preface
----------
This document is meant for people who create and maintain XZ Utils
packages for operating system distributions. The focus is on GNU/Linux
systems, but most things apply to other systems too.
While the standard "configure && make DESTDIR=$PKG install" should
give a pretty good package, there are some details which packagers
may want to tweak.
Packagers should also read the INSTALL file.
1. Package naming
-----------------
The preferred name for the XZ Utils package is "xz", because that's
the name of the upstream tarball. Naturally you may have good reasons
to use some other name; I won't get angry about it. ;-) It's just nice
to be able to point people to the correct package name without asking
what distro they have.
If your distro policy is to split things into small pieces, here is
one suggestion:
xz xz, xzdec, scripts (xzdiff, xzgrep, etc.), docs
xz-lzma lzma, unlzma, lzcat, lzgrep etc. symlinks and
lzmadec binary for compatibility with LZMA Utils
liblzma liblzma.so.*
liblzma-devel liblzma.so, liblzma.a, API headers
2. Package description
----------------------
Here is a suggestion which you may use as the package description.
If you can use only one-line description, pick only the first line.
Naturally, feel free to use some other description if you find it
better, and maybe send it to me too.
Library and command line tools for XZ and LZMA compressed files
XZ Utils provide a general purpose data compression library
and command line tools. The native file format is the .xz
format, but also the legacy .lzma format is supported. The .xz
format supports multiple compression algorithms, of which LZMA2
is currently the primary algorithm. With typical files, XZ Utils
create about 30 % smaller files than gzip.
If you are splitting XZ Utils into multiple packages, here are some
suggestions for package descriptions:
xz:
Command line tools for XZ and LZMA compressed files
This package includes the xz compression tool and other command
line tools from XZ Utils. xz has command line syntax similar to
that of gzip. The native file format is the .xz format, but also
the legacy .lzma format is supported. The .xz format supports
multiple compression algorithms, of which LZMA2 is currently the
primary algorithm. With typical files, XZ Utils create about 30 %
smaller files than gzip.
Note that this package doesn't include the files needed for
LZMA Utils 4.32.x compatibility. Install also the xz-lzma
package to make XZ Utils emulate LZMA Utils 4.32.x.
xz-lzma:
LZMA Utils emulation with XZ Utils
This package includes executables and symlinks to make
XZ Utils emulate lzma, unlzma, lzcat, and other command
line tools found from the legacy LZMA Utils 4.32.x package.
liblzma:
Library for XZ and LZMA compressed files
liblzma is a general purpose data compression library with
an API similar to that of zlib. liblzma supports multiple
algorithms, of which LZMA2 is currently the primary algorithm.
The native file format is .xz, but also the legacy .lzma
format and raw streams (no headers at all) are supported.
This package includes the shared library.
liblzma-devel:
Library for XZ and LZMA compressed files
This package includes the API headers, static library, and
other development files related to liblzma.
3. License
----------
If the package manager supports a license field, you probably should
put GPLv2+ there (GNU GPL v2 or later). The interesting parts of
XZ Utils are in the public domain, but some less important files
ending up into the binary package are under GPLv2+. So it is simplest
to just say GPLv2+ if you cannot specify "public domain and GPLv2+".
If you split XZ Utils into multiple packages as described earlier
in this file, liblzma and liblzma-dev packages will contain only
public domain code (from XZ Utils at least; compiler or linker may
add some third-party code, which may be copyrighted).
4. configure options
--------------------
Unless you are building a package for a distribution that is meant
only for embedded systems, don't use the following configure options:
--enable-debug
--enable-encoders (*)
--enable-decoders
--enable-match-finders
--enable-checks
--enable-small (*)
--disable-threads (*)
(*) These are OK when building xzdec and lzmadec as explained later.
You may use --enable-werror but be careful with it since it may break
the build due to some useless warning when the build environment
changes (like CPU architecture or compiler version).
4.1. Static vs. dynamic linking of liblzma
The default is to link the most important command line tools against
static liblzma, and the less important tools against shared liblzma.
This can be changed by passing --enable-dynamic to configure, or by
not building static libraries at all by passing --disable-static
to configure. It is mildly recommended that you use the default, but
the configure options make it easy to do otherwise if the distro policy
so requires.
On 32-bit x86, linking against static liblzma can give a minor
speed improvement. Static libraries on x86 are usually compiled as
position-dependent code (non-PIC) and shared libraries are built as
position-independent code (PIC). PIC wastes one register, which can
make the code slightly slower compared to a non-PIC version. (Note
that this doesn't apply to x86-64.)
Linking against static liblzma avoids a dependency on liblzma shared
library, and makes it slightly easier to copy the command line tools
between systems (e.g. quick 'n' dirty emergency recovery of some
files). It also allows putting the command line tools to /bin while
leaving liblzma to /usr/lib (assuming that your distribution uses
such a file system hierarchy), if no other file in /bin would require
liblzma.
If you don't want to distribute static libraries but you still
want to link the command line tools against static liblzma, it is
probably easiest to build both static and shared liblzma, but after
"make DESTDIR=$PKG install" remove liblzma.a and modify liblzma.la
to not contain a reference to liblzma.a.
4.2. Optimizing xzdec and lzmadec
xzdec and lzmadec are intended to be relatively small instead of
optimizing for the best speed. Thus, it is a good idea to build
xzdec and lzmadec separately:
- Only decoder code is needed, so you can speed up the build
slightly by passing --disable-encoders to configure. This
shouldn't affect the final size of the executables though,
because the linker is able to omit the encoder code anyway.
- xzdec and lzmadec will never use multithreading capabilities of
liblzma. You can avoid dependency on libpthread by passing
--disable-threads to configure.
- There are and will be no translated messages for xzdec and
lzmadec, so it is fine to pass also --disable-nls to configure.
- To select somewhat size-optimized variant of some things in
liblzma, pass --enable-small to configure.
- Tell the compiler to optimize for size instead of speed.
E.g. with GCC, put -Os into CFLAGS.
5. Additional documentation
---------------------------
"make install" copies some additional documentation to $docdir
(--docdir in configure). These a copy of the GNU GPL v2, which can
be replaced with a symlink if your distro ships with shared copies
of the common license texts.
6. Extra files
--------------
The "extra" directory contains some small extra tools or other files.
The exact set of extra files can vary between XZ Utils releases. The
extra files have only limited use or they are too dangerous to be
put directly to $bindir (7z2lzma.sh is a good example, since it can
silently create corrupt output if certain conditions are not met).
If you feel like it, you may copy the extra directory under the doc
directory (e.g. /usr/share/doc/xz/extra). Maybe some people will find
them useful. However, most people needing these tools probably are
able to find them from the source package too.
The "debug" directory contains some tools that are useful only when
hacking on XZ Utils. Don't package these tools.
7. Installing XZ Utils and LZMA Utils in parallel
-------------------------------------------------
XZ Utils and LZMA Utils 4.32.x can be installed in parallel by
omitting the compatibility symlinks (lzma, unlzma, lzcat, lzgrep etc.)
from the XZ Utils package. It's probably a good idea to still package
the symlinks into a separate package so that users may choose if they
want to use XZ Utils or LZMA Utils for handling .lzma files.
8. Example
----------
Here is an example for i686 GNU/Linux that
- links xz against static liblzma;
- includes only shared liblzma in the final package;
- links xzdec and lzmadec against static liblzma while
avoiding libpthread dependency.
PKG=/tmp/xz-pkg
tar xf xz-x.y.z.tar.gz
cd xz-x.y.z
./configure \
--prefix=/usr \
--sysconfdir=/etc \
CFLAGS='-march=i686 -O2'
make
make DESTDIR=$PKG install-strip
rm -f $PKG/usr/lib/lib*.a
sed -i "s/^old_library=.*$/old_library=''/" $PKG/usr/lib/lib*.la
make clean
./configure \
--prefix=/usr \
--sysconfdir=/etc \
--disable-shared \
--disable-nls \
--disable-encoders \
--enable-small \
--disable-threads \
CFLAGS='-march=i686 -Os'
make -C src/liblzma
make -C src/xzdec
make -C src/xzdec DESTDIR=$PKG install-strip
cp -a extra $PKG/usr/share/doc/xz

320
README
View File

@@ -1,151 +1,217 @@
LZMA Utils
----------
XZ Utils
========
Warning
This is an early alpha version. Don't trust the files produced by
this version of the software - not even if the software can
uncompress the files properly! This is because the file format
isn't completely frozen yet.
So please test a lot, but don't use for anything serious yet.
0. Overview
1. Documentation
1.1. Overall documentation
1.2. Documentation for command line tools
1.3. Documentation for liblzma
2. Version numbering
3. Reporting bugs
4. Other implementations of the .xz format
5. Contact information
Overview
0. Overview
-----------
LZMA is a general purporse compression algorithm designed by
Igor Pavlov as part of 7-Zip. It provides high compression ratio
while keeping the decompression speed fast.
XZ Utils provide a general purporse data compression library and
command line tools. The native file format is the .xz format, but
also the legacy .lzma format is supported. The .xz format supports
multiple compression algorithms, which are called "filters" in
context of XZ Utils. The primary filter is currently LZMA2. With
typical files, XZ Utils create about 30 % smaller files than gzip.
LZMA Utils are an attempt to make LZMA compression easy to use
on free (as in freedom) operating systems. This is achieved by
providing tools and libraries which are similar to use than the
equivalents of the most popular existing compression algorithms.
To ease adapting support for the .xz format into existing applications
and scripts, the API of liblzma is somewhat similar to the API of the
popular zlib library. For the same reason, the command line tool xz
has similar command line syntax than that of gzip.
LZMA Utils consist of a few relatively separate parts:
* liblzma is an encoder/decoder library with support for several
filters (algorithm implementations). The primary filter is LZMA.
* libzfile enables reading from and writing to gzip, bzip2 and
LZMA compressed and uncompressed files with an API similar to
the standard ANSI-C file I/O.
[ NOTE: libzfile is not implemented yet. ]
* lzma command line tool has almost identical syntax than gzip
and bzip2. It makes LZMA easy for average users, but also
provides advanced options to finetune the compression settings.
* A few shell scripts make diffing and grepping LZMA compressed
files easy. The scripts were adapted from gzip and bzip2.
When aiming for the highest compression ratio, LZMA2 encoder uses
a lot of CPU time and may use, depending on the settings, even
hundreds of megabytes of RAM. However, in fast modes, LZMA2 encoder
competes with bzip2 in compression speed, RAM usage, and compression
ratio.
LZMA2 is reasonably fast to decompress. It is a little slower than
gzip, but a lot faster than bzip2. Being fast to decompress means
that the .xz format is especially nice when the same file will be
decompressed very many times (usually on different computers), which
is the case e.g. when distributing software packages. In such
situations, it's not too bad if the compression takes some time,
since that needs to be done only once to benefit many people.
With some file types, combining (or "chaining") LZMA2 with an
additional filter can improve compression ratio. A filter chain may
contain up to four filters, although usually only one two is used.
For example, putting a BCJ (Branch/Call/Jump) filter before LZMA2
in the filter chain can improve compression ratio of executable files.
Since the .xz format allows adding new filter IDs, it is possible that
some day there will be a filter that is, for example, much faster to
compress than LZMA2 (but probably with worse compression ratio).
Similarly, it is possible that some day there is a filter that will
compress better than LZMA2.
XZ Utils doesn't support multithreaded compression or decompression
yet. It has been planned though and taken into account when designing
the .xz file format.
Supported platforms
1. Documentation
----------------
LZMA Utils are developed on GNU+Linux, but they should work at
least on *BSDs and Solaris. They probably work on some other
POSIX-like operating systems too.
1.1. Overall documentation
If you use GCC to compile LZMA Utils, you need at least version
3.x.x. GCC version 2.xx.x doesn't support some C99 features used
in LZMA Utils source code, thus GCC 2 won't compile LZMA Utils.
README This file
If you have written patches to make LZMA Utils to work on previously
unsupported platform, please send the patches to me! I will consider
including them to the official version. It's nice to minimize the
need of third-party patching.
INSTALL.generic Generic install instructions for those not familiar
with packages using GNU Autotools
INSTALL Installation instructions specific to XZ Utils
PACKAGERS Information to packagers of XZ Utils
One exception: Don't request or send patches to change the whole
source package to C89. I find C99 substantially nicer to write and
maintain. However, the public library headers must be in C89 to
avoid frustrating those who maintain programs, which are strictly
in C89 or C++.
COPYING XZ Utils copyright and license information
COPYING.GPLv2 GNU General Public License version 2
COPYING.GPLv3 GNU General Public License version 3
COPYING.LGPLv2.1 GNU Lesser General Public License version 2.1
AUTHORS The main authors of XZ Utils
THANKS Incomplete list of people who have helped making
this software
NEWS User-visible changes between XZ Utils releases
ChangeLog Detailed list of changes (commit log)
Note that only some of the above files are included in binary
packages.
configure options
1.2. Documentation for command line tools
If you are not familiar with `configure' scripts, read the file
INSTALL first.
In most cases, the default --enable/--disable/--with/--without options
are what you want. Don't touch them if you are unsure.
--disable-encoder
Do not compile the encoder component of liblzma. This
implies --disable-match-finders. If you need only
the decoder, you can decrease the library size
dramatically with this option.
The default is to build the encoder.
--disable-decoder
Do not compile the decoder component of liblzma.
The default is to build the decoder.
--enable-filters=
liblzma supports several filters. See liblzma-intro.txt
for a little more information about these.
The default is to build all the filters.
--enable-match-finders=
liblzma includes two categories of match finders:
hash chains and binary trees. Hash chains (hc3 and hc4)
are quite fast but they don't provide the best compression
ratio. Binary trees (bt2, bt3 and bt4) give excellent
compression ratio, but they are slower and need more
memory than hash chains.
You need to enable at least one match finder to build the
LZMA filter encoder. Usually hash chains are used only in
the fast mode, while binary trees are used to when the best
compression ratio is wanted.
The default is to build all the match finders.
--enable-checks=
liblzma support multiple integrity checks. CRC32 is
mandatory, and cannot be omitted. See liblzma-intro.txt
for more information about usage of the integrity checks.
--disable-assembler
liblzma includes some assembler optimizations. Currently
there is only assembler code for CRC32 and CRC64 for
32-bit x86.
All the assembler code in liblzma is position-independent
code, which is suitable for use in shared libraries and
position-independent executables.
--enable-small
Omits precomputed tables. This makes liblzma a few KiB
smaller. Startup time increases, because the tables need
to be computed first.
--enable-debug
This enables the assert() macro and possibly some other
run-time consistency checks. It slows down things somewhat,
so you normally don't want to have this enabled.
--enable-werror
Makes all compiler warnings an error, that abort the
compilation. This may help catching bugs, and should work
on most systems. This has no effect on the resulting
binaries.
The command line tools are documented as man pages. In source code
releases (and possibly also in some binary packages), the man pages
are also provided in plain text (ASCII only) and PDF formats in the
directory "doc/man" to make the man pages more accessible to those
whose operating system doesn't provide an easy way to view man pages.
Static vs. dynamic linking of the command line tools
1.3. Documentation for liblzma
By default, the command line tools are linked statically against
liblzma. There a are a few reasons:
The liblzma API headers include short docs about each function
and data type as Doxygen tags. These docs should be quite OK as
a quick reference.
- The executable(s) can be in /bin while the shared liblzma can still
be in /usr/lib (if the distro uses such file system hierachy).
I have planned to write a bunch of very well documented example
programs, which (due to comments) should work as a tutorial to
various features of liblzma. No such example programs have been
written yet.
- It's easier to copy the executables to other systems, since they
depend only on libc.
For now, if you have never used liblzma, libbzip2, or zlib, I
recommend learning *basics* of zlib API. Once you know that, it
should be easier to learn liblzma.
- It's slightly faster on some architectures like x86.
http://zlib.net/manual.html
http://zlib.net/zlib_how.html
If you don't like this, you can get the command line tools linked
against the shared liblzma by specifying --disable-static to configure.
This disables building static liblzma completely.
2. Version numbering
--------------------
The version number format of XZ Utils is X.Y.ZS:
- X is the major version. When this is incremented, the library
API and ABI break.
- Y is the minor version. It is incremented when new features are
added without breaking existing API or ABI. Even Y indicates
stable release and odd Y indicates unstable (alpha or beta
version).
- Z is the revision. This has different meaning for stable and
unstable releases:
* Stable: Z is incremented when bugs get fixed without adding
any new features.
* Unstable: Z is just a counter. API or ABI of features added
in earlier unstable releases having the same X.Y may break.
- S indicates stability of the release. It is missing from the
stable releases where Y is an even number. When Y is odd, S
is either "alpha" or "beta" to make it very clear that such
versions are not stable releases. The same X.Y.Z combination is
not used for more than one stability level i.e. after X.Y.Zalpha,
the next version can be X.Y.(Z+1)beta but not X.Y.Zbeta.
3. Reporting bugs
-----------------
Naturally it is easiest for me if you already know what causes the
unexpected behavior. Even better if you have a patch to propose.
However, quite often the reason for unexpected behavior is unknown,
so here are a few things to do before sending a bug report:
1. Try to create a small example how to reprocude the issue.
2. Compile XZ Utils with debugging code using configure switches
--enable-debug and, if possible, --disable-shared. If you are
using GCC, use CFLAGS='-O0 -ggdb3'. Don't strip the resulting
binaries.
3. Turn on core dumps. The exact command depends on your shell;
for example in GNU bash it is done with "ulimit -c unlimited",
and in tcsh with "limit coredumpsize unlimited".
4. Try to reproduce the suspected bug. If you get "assertion failed"
message, be sure to include the complete message in your bug
report. If the application leaves a coredump, get a backtrace
using gdb:
$ gdb /path/to/app-binary # Load the app to the debugger.
(gdb) core core # Open the coredump.
(gdb) bt # Print the backtrace. Copy & paste to bug report.
(gdb) quit # Quit gdb.
Report your bug via email or IRC (see Contact information below).
Don't send core dump files or any executables. If you have a small
example file(s) (total size less than 256 KiB), please include
it/them as an attachment. If you have bigger test files, put them
online somewhere and include an URL to the file(s) in the bug report.
Always include the exact version number of XZ Utils in the bug report.
If you are using a snapshot from the git repository, use "git describe"
to get the exact snapshot version. If you are using XZ Utils shipped
in an operating system distribution, mention the distribution name,
distribution version, and exact xz package version; if you cannot
repeat the bug with the code compiled from unpatched source code,
you probably need to report a bug to your distribution's bug tracking
system.
4. Other implementations of the .xz format
------------------------------------------
7-Zip and the p7zip port of 7-Zip support the .xz format starting
from the version 9.00alpha.
http://7-zip.org/
http://p7zip.sourceforge.net/
XZ Embedded is a limited implementation written for use in the Linux
kernel, but it is also suitable for other embedded use.
http://tukaani.org/xz/embedded.html
5. Contact information
----------------------
If you have questions, bug reports, patches etc. related to XZ Utils,
contact Lasse Collin <lasse.collin@tukaani.org> (in Finnish or English).
tukaani.org uses greylisting to reduce spam, thus when you send your
first email, it may get delayed by a few hours. In addition to that,
I'm sometimes slow at replying. If you haven't got a reply within two
weeks, assume that your email has got lost and resend it or use IRC.
You can find me also from #tukaani on Freenode; my nick is Larhzu.
The channel tends to be pretty quiet, so just ask your question and
someone may wake up.

40
THANKS
View File

@@ -1,23 +1,47 @@
Thanks
------
======
Some people have helped more, some less, some don't even know they have
been helpful, but nevertheless everyone's help has been important. :-)
In alphabetical order:
Some people have helped more, some less, but nevertheless everyone's help
has been important. :-) In alphabetical order:
- Mark Adler
- H. Peter Anvin
- Nelson H. F. Beebe
- Anders F. Björklund
- Emmanuel Blot
- David Burklund
- Andrew Dudman
- İsmail Dönmez
- Jean-loup Gailly
- Mike Frysinger
- Per Øyvind Karlsen
- Ville Koskinen
- Stephan Kulow
- Peter Lawler
- Hin-Tak Leung
- Andraž 'ruskie' Levstik
- Jim Meyering
- Hongbo Ni
- Jonathan Nieder
- Igor Pavlov
- Mikko Pouru
- Bernhard Reutner-Fischer
- Christian von Roques
- Alexandre Sauvé
- Julian Seward
- Andreas Schwab
- Dan Shechter
- Jonathan Stott
- Paul Townsend
- Mohammed Adnène Trojette
- Patrick J. Volkerding
- Bert Wesarg
- Ralf Wildenhues
- Charles Wilson
- Lars Wirzenius
- Pilorz Wojciech
- Andreas Zieringer
Also thanks to all the people who have participated the Tukaani project
and others who I have forgot.
Also thanks to all the people who have participated in the Tukaani project.
I have probably forgot to add some names to the above list. Sorry about
that and thanks for your help.

123
TODO
View File

@@ -1,109 +1,56 @@
LZMA Utils TODO List
--------------------
XZ Utils To-Do List
===================
Major missing features
Known bugs
----------
Memory limits in the command line tool apply only to compression.
The test suite is too incomplete.
Threading support in the lzma command line tool is still primitive.
It cannot split a file in pieces yet.
If the memor usage limit is less than about 13 MiB, xz is unable to
automatically scale down the compression settings enough even though
it would be possible by switching from BT2/BT3/BT4 match finder to
HC3/HC4.
The --list mode isn't implemented in the command line tool.
The code to detect number of CPU cores doesn't count hyperthreading
as multiple cores. In context of xz, it probably should.
Hyperthreading is good at least with p7zip.
Handling of Multi-Block Stream information should be separated
from Stream encoder and decoder. Those would be useful to implement
multi-threaded coding in applications.
Buffer to buffer coding is not implemented in liblzma. Probably
a naive version should be written first, which would simply wrap
things around lzma_stream. Later, there should be separate buffer
coding functions, that are slightly faster (less memcpy()) and
have smaller memory usage than the functions using lzma_stream.
libzfile is not implemented.
LZMA filter doesn't support predefined history buffer.
XZ Utils compress some files significantly worse than LZMA Utils.
This is due to faster compression presets used by XZ Utils, and
can be worked around by using "xz --extreme". However, the presets
need some tweaking and maybe this issue can be minimized without
making the typical case too much slower.
Security
Missing features
----------------
Search for bugs, especially security related issues. Security is
important in every piece of code in LZMA Utils, but it is extremely
important in the decoder part of liblzma.
"xz --list"
Subblock: If there is LZMA as a Subfilter but without EOPM, can it
trigger infinite loop when Subblock's "Unset Subfilter" flag is hit?
xz could create sparse files when decompressing. (Some prototyping
has been done.)
Similarly, can LZ decoder get stuck in infinite loop if the next
filter in the chain returns LZMA_STREAM_END but the decoded data
doesn't allow finishing the LZ decoding?
xz doesn't support copying extended attributes, access control
lists etc. from source to target file.
Multithreaded compression
Reliability
Multithreaded decompression
Create a test suite to be run with "make check".
Buffer-to-buffer coding could use less RAM (especially when
decompressing LZMA1 or LZMA2).
Should we use strlimit() and getrlimit() for memory usage limitting?
Performance
Benchmark the CRC code on non-x86 CPUs. Won't have huge effect on
overall speed, but it would still be nice to know what algorithm
variant is the best on different CPUs.
Third party support
Add support for LZMA to various applications. This naturally requires
cooperating with the authors of the specific applications.
* GNU grep and GNU diffutils: BSD grep already uses zlib directly
instead of ugly shell scripts. It would be nice to get similar
feature into relevant GNU tools. With libzfile, multiple
compression formats would be easy to support.
* kioslave for KDE
* Magic for the `file' command
* GNU Midnight Commander
* GNU Texinfo
* The `man' command
* Package managers
Test the patches already written. The patches should be sent to
upstream developers _once_ LZMA Utils APIs are stable enough (so
people don't need to fix those patches all the time).
Mandriva has quite a few patches. Some of them are OK, some need
adapting for new LZMA Utils.
I/O library is not implemented. It will possibly be named libzzf.
Documentation
-------------
Revise the man page of lzma command line tool.
Some tutorial is needed for liblzma. I have planned to write some
extremely well commented example programs, which would work as
a tutorial. I suppose the Doxygen tags are quite OK as a quick
reference once one is familiar with the liblzma API.
If the Doxygen docs aren't enough, write good Texinfo manual for
liblzma. It's been a long time I've even tried to build the Doxygen
docs, so they may look quite bad at the moment.
Document LZMA as an algorithm. It would be great to have detailed
description of the algorithm in English. Many people think, that
reading the source code is not the optimal way to learn how LZMA
works.
Other
Some things return LZMA_PROG_ERROR with invalid options, some
LZMA_HEADER_ERROR. These must be checked carefully and made so
that LZMA_HEADER_ERROR is used only when the given option could
make sense in future version of libzma.
lzma_restrict vs. restrict
Usage of LZMA_RUN vs. LZMA_FINISH with Metadata coders.
Port the Deflate implementation from 7-Zip into liblzma. 7-Zip's
Deflate compresses better than zlib, gzip or Info-ZIP. I don't
know if Deflate will be included in .lzma format (probably not),
but it's still useful once we also add support for .gz file format.
Document the LZMA1 and LZMA2 algorithms.

View File

@@ -1,38 +1,22 @@
#!/bin/sh
###############################################################################
#
# Author: Lasse Collin
#
# This file has been put into the public domain.
# You can do whatever you want with this file.
#
###############################################################################
# The result of using "autoreconf -fi" should be identical to using this
# script. I'm leaving this script here just in case someone finds it useful.
set -e -x
# autooint copies all kinds of crap even though we have told in
# configure.ac that we don't want the intl directory. It is able
# to omit the intl directory but still copies the m4 files needed
# only by the stuff in the non-existing intl directory.
autopoint -f
rm -f \
codeset.m4 \
glibc2.m4 \
glibc21.m4 \
intdiv0.m4 \
intl.m4 \
intldir.m4 \
intmax.m4 \
inttypes-pri.m4 \
inttypes_h.m4 \
lcmessage.m4 \
lock.m4 \
longdouble.m4 \
longlong.m4 \
printf-posix.m4 \
size_max.m4 \
stdint_h.m4 \
uintmax_t.m4 \
ulonglong.m4 \
visibility.m4 \
wchar_t.m4 \
wint_t.m4 \
xsize.m4
libtoolize -c -f || glibtoolize -c -f
aclocal -I m4
autoconf
autoheader
automake -acf --foreign
${AUTOPOINT:-autopoint} -f
${LIBTOOLIZE:-libtoolize} -c -f || glibtoolize -c -f
${ACLOCAL:-aclocal} -I m4
${AUTOCONF:-autoconf}
${AUTOHEADER:-autoheader}
${AUTOMAKE:-automake} -acf --foreign

File diff suppressed because it is too large Load Diff

30
debug/Makefile.am Normal file
View File

@@ -0,0 +1,30 @@
##
## Author: Lasse Collin
##
## This file has been put into the public domain.
## You can do whatever you want with this file.
##
noinst_PROGRAMS = \
repeat \
sync_flush \
full_flush \
memusage \
crc32 \
known_sizes \
hex2bin
AM_CPPFLAGS = \
-I$(top_srcdir)/src/common \
-I$(top_srcdir)/src/liblzma/api \
$(STATIC_CPPFLAGS)
AM_LDFLAGS = $(STATIC_LDFLAGS)
LDADD = $(top_builddir)/src/liblzma/liblzma.la
if COND_GNULIB
LDADD += $(top_builddir)/lib/libgnu.a
endif
LDADD += $(LTLIBINTL)

17
debug/README Normal file
View File

@@ -0,0 +1,17 @@
Debug tools
-----------
This directory contains a few tiny programs that may be helpful when
debugging LZMA Utils.
These tools are not meant to be installed. Often one needs to edit
the source code a little to make the programs do the wanted things.
If you don't know how these programs could help you, it is likely
that they really are useless to you.
These aren't intended to be used as example programs. They take some
shortcuts here and there, which correct programs should not do. Many
possible errors (especially I/O errors) are ignored. Don't report
bugs or send patches to fix this kind of bugs.

38
debug/crc32.c Normal file
View File

@@ -0,0 +1,38 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file crc32.c
/// \brief Primitive CRC32 calculation tool
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "sysdefs.h"
#include <stdio.h>
int
main(void)
{
uint32_t crc = 0;
do {
uint8_t buf[BUFSIZ];
const size_t size = fread(buf, 1, sizeof(buf), stdin);
crc = lzma_crc32(buf, size, crc);
} while (!ferror(stdin) && !feof(stdin));
//printf("%08" PRIX32 "\n", crc);
// I want it little endian so it's easy to work with hex editor.
printf("%02" PRIX32 " ", crc & 0xFF);
printf("%02" PRIX32 " ", (crc >> 8) & 0xFF);
printf("%02" PRIX32 " ", (crc >> 16) & 0xFF);
printf("%02" PRIX32 " ", crc >> 24);
printf("\n");
return 0;
}

102
debug/full_flush.c Normal file
View File

@@ -0,0 +1,102 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file full_flush.c
/// \brief Encode files using LZMA_FULL_FLUSH
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "sysdefs.h"
#include "lzma.h"
#include <stdio.h>
static lzma_stream strm = LZMA_STREAM_INIT;
static FILE *file_in;
static void
encode(size_t size, lzma_action action)
{
static const size_t CHUNK = 64;
uint8_t in[CHUNK];
uint8_t out[CHUNK];
lzma_ret ret;
do {
if (strm.avail_in == 0 && size > 0) {
const size_t amount = MIN(size, CHUNK);
strm.avail_in = fread(in, 1, amount, file_in);
strm.next_in = in;
size -= amount; // Intentionally not using avail_in.
}
strm.next_out = out;
strm.avail_out = CHUNK;
ret = lzma_code(&strm, size == 0 ? action : LZMA_RUN);
if (ret != LZMA_OK && ret != LZMA_STREAM_END) {
fprintf(stderr, "%s:%u: %s: ret == %d\n",
__FILE__, __LINE__, __func__, ret);
exit(1);
}
fwrite(out, 1, CHUNK - strm.avail_out, stdout);
} while (size > 0 || strm.avail_out == 0);
if ((action == LZMA_RUN && ret != LZMA_OK)
|| (action != LZMA_RUN && ret != LZMA_STREAM_END)) {
fprintf(stderr, "%s:%u: %s: ret == %d\n",
__FILE__, __LINE__, __func__, ret);
exit(1);
}
}
int
main(int argc, char **argv)
{
file_in = argc > 1 ? fopen(argv[1], "rb") : stdin;
// Config
lzma_options_lzma opt_lzma;
if (lzma_lzma_preset(&opt_lzma, 1)) {
fprintf(stderr, "preset failed\n");
exit(1);
}
lzma_filter filters[LZMA_FILTERS_MAX + 1];
filters[0].id = LZMA_FILTER_LZMA2;
filters[0].options = &opt_lzma;
filters[1].id = LZMA_VLI_UNKNOWN;
// Init
if (lzma_stream_encoder(&strm, filters, LZMA_CHECK_CRC32) != LZMA_OK) {
fprintf(stderr, "init failed\n");
exit(1);
}
// if (lzma_easy_encoder(&strm, 1)) {
// fprintf(stderr, "init failed\n");
// exit(1);
// }
// Encoding
encode(0, LZMA_FULL_FLUSH);
encode(6, LZMA_FULL_FLUSH);
encode(0, LZMA_FULL_FLUSH);
encode(7, LZMA_FULL_FLUSH);
encode(0, LZMA_FULL_FLUSH);
encode(0, LZMA_FINISH);
// Clean up
lzma_end(&strm);
return 0;
}

53
debug/hex2bin.c Normal file
View File

@@ -0,0 +1,53 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file hex2bin.c
/// \brief Converts hexadecimal input strings to binary
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "sysdefs.h"
#include <stdio.h>
#include <ctype.h>
static int
getbin(int x)
{
if (x >= '0' && x <= '9')
return x - '0';
if (x >= 'A' && x <= 'F')
return x - 'A' + 10;
return x - 'a' + 10;
}
int
main(void)
{
while (true) {
int byte = getchar();
if (byte == EOF)
return 0;
if (!isxdigit(byte))
continue;
const int digit = getchar();
if (digit == EOF || !isxdigit(digit)) {
fprintf(stderr, "Invalid input\n");
return 1;
}
byte = (getbin(byte) << 4) | getbin(digit);
if (putchar(byte) == EOF) {
perror(NULL);
return 1;
}
}
}

129
debug/known_sizes.c Normal file
View File

@@ -0,0 +1,129 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file known_sizes.c
/// \brief Encodes .lzma Stream with sizes known in Block Header
///
/// The input file is encoded in RAM, and the known Compressed Size
/// and/or Uncompressed Size values are stored in the Block Header.
/// As of writing there's no such Stream encoder in liblzma.
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "sysdefs.h"
#include "lzma.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/unistd.h>
#include <stdio.h>
// Support file sizes up to 1 MiB. We use this for output space too, so files
// close to 1 MiB had better compress at least a little or we have a buffer
// overflow.
#define BUFFER_SIZE (1U << 20)
int
main(void)
{
// Allocate the buffers.
uint8_t *in = malloc(BUFFER_SIZE);
uint8_t *out = malloc(BUFFER_SIZE);
if (in == NULL || out == NULL)
return 1;
// Fill the input buffer.
const size_t in_size = fread(in, 1, BUFFER_SIZE, stdin);
// Filter setup
lzma_options_lzma opt_lzma;
if (lzma_lzma_preset(&opt_lzma, 1))
return 1;
lzma_filter filters[] = {
{
.id = LZMA_FILTER_LZMA2,
.options = &opt_lzma
},
{
.id = LZMA_VLI_UNKNOWN
}
};
lzma_block block = {
.check = LZMA_CHECK_CRC32,
.compressed_size = BUFFER_SIZE, // Worst case reserve
.uncompressed_size = in_size,
.filters = filters,
};
lzma_stream strm = LZMA_STREAM_INIT;
if (lzma_block_encoder(&strm, &block) != LZMA_OK)
return 1;
// Reserve space for Stream Header and Block Header. We need to
// calculate the size of the Block Header first.
if (lzma_block_header_size(&block) != LZMA_OK)
return 1;
size_t out_size = LZMA_STREAM_HEADER_SIZE + block.header_size;
strm.next_in = in;
strm.avail_in = in_size;
strm.next_out = out + out_size;
strm.avail_out = BUFFER_SIZE - out_size;
if (lzma_code(&strm, LZMA_FINISH) != LZMA_STREAM_END)
return 1;
out_size += strm.total_out;
if (lzma_block_header_encode(&block, out + LZMA_STREAM_HEADER_SIZE)
!= LZMA_OK)
return 1;
lzma_index *idx = lzma_index_init(NULL, NULL);
if (idx == NULL)
return 1;
if (lzma_index_append(idx, NULL, block.header_size + strm.total_out,
strm.total_in) != LZMA_OK)
return 1;
if (lzma_index_encoder(&strm, idx) != LZMA_OK)
return 1;
if (lzma_code(&strm, LZMA_RUN) != LZMA_STREAM_END)
return 1;
out_size += strm.total_out;
lzma_end(&strm);
lzma_index_end(idx, NULL);
// Encode the Stream Header and Stream Footer. backwards_size is
// needed only for the Stream Footer.
lzma_stream_flags sf = {
.backward_size = strm.total_out,
.check = block.check,
};
if (lzma_stream_header_encode(&sf, out) != LZMA_OK)
return 1;
if (lzma_stream_footer_encode(&sf, out + out_size) != LZMA_OK)
return 1;
out_size += LZMA_STREAM_HEADER_SIZE;
// Write out the file.
fwrite(out, 1, out_size, stdout);
return 0;
}

49
debug/memusage.c Normal file
View File

@@ -0,0 +1,49 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file memusage.c
/// \brief Calculates memory usage using lzma_memory_usage()
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "sysdefs.h"
#include "lzma.h"
#include <stdio.h>
int
main(void)
{
lzma_options_lzma lzma = {
.dict_size = (1U << 30) + (1U << 29),
.lc = 3,
.lp = 0,
.pb = 2,
.preset_dict = NULL,
.preset_dict_size = 0,
.mode = LZMA_MODE_NORMAL,
.nice_len = 48,
.mf = LZMA_MF_BT4,
.depth = 0,
};
/*
lzma_options_filter filters[] = {
{ LZMA_FILTER_LZMA1,
(lzma_options_lzma *)&lzma_preset_lzma[6 - 1] },
{ UINT64_MAX, NULL }
};
*/
lzma_filter filters[] = {
{ LZMA_FILTER_LZMA1, &lzma },
{ UINT64_MAX, NULL }
};
printf("Encoder: %10" PRIu64 " B\n", lzma_memusage_encoder(filters));
printf("Decoder: %10" PRIu64 " B\n", lzma_memusage_decoder(filters));
return 0;
}

36
debug/repeat.c Normal file
View File

@@ -0,0 +1,36 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file repeat.c
/// \brief Repeats given string given times
///
/// This program can be useful when debugging run-length encoder in
/// the Subblock filter, especially the condition when repeat count
/// doesn't fit into 28-bit integer.
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "sysdefs.h"
#include <stdio.h>
int
main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: %s COUNT STRING\n", argv[0]);
exit(1);
}
unsigned long long count = strtoull(argv[1], NULL, 10);
const size_t size = strlen(argv[2]);
while (count-- != 0)
fwrite(argv[2], 1, size, stdout);
return !!(ferror(stdout) || fclose(stdout));
}

133
debug/sync_flush.c Normal file
View File

@@ -0,0 +1,133 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file sync_flush.c
/// \brief Encode files using LZMA_SYNC_FLUSH
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "sysdefs.h"
#include "lzma.h"
#include <stdio.h>
static lzma_stream strm = LZMA_STREAM_INIT;
static FILE *file_in;
static void
encode(size_t size, lzma_action action)
{
static const size_t CHUNK = 64;
uint8_t in[CHUNK];
uint8_t out[CHUNK];
lzma_ret ret;
do {
if (strm.avail_in == 0 && size > 0) {
const size_t amount = MIN(size, CHUNK);
strm.avail_in = fread(in, 1, amount, file_in);
strm.next_in = in;
size -= amount; // Intentionally not using avail_in.
}
strm.next_out = out;
strm.avail_out = CHUNK;
ret = lzma_code(&strm, size == 0 ? action : LZMA_RUN);
if (ret != LZMA_OK && ret != LZMA_STREAM_END) {
fprintf(stderr, "%s:%u: %s: ret == %d\n",
__FILE__, __LINE__, __func__, ret);
exit(1);
}
fwrite(out, 1, CHUNK - strm.avail_out, stdout);
} while (size > 0 || strm.avail_out == 0);
if ((action == LZMA_RUN && ret != LZMA_OK)
|| (action != LZMA_RUN && ret != LZMA_STREAM_END)) {
fprintf(stderr, "%s:%u: %s: ret == %d\n",
__FILE__, __LINE__, __func__, ret);
exit(1);
}
}
int
main(int argc, char **argv)
{
file_in = argc > 1 ? fopen(argv[1], "rb") : stdin;
// Config
lzma_options_lzma opt_lzma = {
.dict_size = 1U << 16,
.lc = LZMA_LC_DEFAULT,
.lp = LZMA_LP_DEFAULT,
.pb = LZMA_PB_DEFAULT,
.preset_dict = NULL,
.persistent = true,
.mode = LZMA_MODE_NORMAL,
.nice_len = 32,
.mf = LZMA_MF_HC3,
.depth = 0,
};
lzma_options_delta opt_delta = {
.dist = 16
};
lzma_options_subblock opt_subblock = {
.allow_subfilters = true,
.alignment = 8, // LZMA_SUBBLOCK_ALIGNMENT_DEFAULT,
.subblock_data_size = LZMA_SUBBLOCK_DATA_SIZE_DEFAULT,
.rle = 1, // LZMA_SUBBLOCK_RLE_OFF,
.subfilter_mode = LZMA_SUBFILTER_SET,
};
opt_subblock.subfilter_options.id = LZMA_FILTER_LZMA1;
opt_subblock.subfilter_options.options = &opt_lzma;
opt_subblock.subfilter_options.id = LZMA_FILTER_DELTA;
opt_subblock.subfilter_options.options = &opt_delta;
lzma_filter filters[LZMA_FILTERS_MAX + 1];
filters[0].id = LZMA_FILTER_LZMA2;
filters[0].options = &opt_lzma;
filters[1].id = LZMA_VLI_UNKNOWN;
// Init
if (lzma_stream_encoder(&strm, filters, LZMA_CHECK_CRC32) != LZMA_OK) {
fprintf(stderr, "init failed\n");
exit(1);
}
// Encoding
encode(0, LZMA_SYNC_FLUSH);
encode(6, LZMA_SYNC_FLUSH);
encode(0, LZMA_SYNC_FLUSH);
encode(7, LZMA_SYNC_FLUSH);
encode(0, LZMA_SYNC_FLUSH);
encode(0, LZMA_FINISH);
/*
encode(53, LZMA_SYNC_FLUSH);
// opt_lzma.literal_context_bits = 2;
// opt_lzma.literal_pos_bits = 1;
// opt_lzma.pos_bits = 0;
encode(404, LZMA_FINISH);
*/
// Clean up
lzma_end(&strm);
return 0;
// Prevent useless warnings so we don't need to have special CFLAGS
// to disable -Werror.
(void)opt_lzma;
(void)opt_subblock;
(void)opt_delta;
}

View File

@@ -1,46 +0,0 @@
Reporting bugs
--------------
Naturally it is easiest for me if you already know what causes the
unexpected behavior. Even better if you have a patch to propose.
However, quite often the reason for unexpected behavior is unknown,
so below are a few things what to do before sending a bug report.
In case of a crash (usually segmentation violation):
1. Try to create a small example how to reprocude the issue.
2. If you are writing an application using liblzma or libzfile,
double check that you are using the libraries correctly (for
example, that you didn't forget to call lzma_init()). If it is
the command line tool included in LZMA Utils that is crashing,
ignore this step.
3. Compile LZMA Utils with debugging code using configure switch
`--enable-debug'. If you are using GCC as the compiler, use
CFLAGS='-O0 -ggdb'. Don't strip the resulting binaries.
4. Turn on core dumps. The exact command depends on your shell;
for example in GNU bash it is done with `ulimit -c unlimited',
and in tcsh with `limit coredumpsize unlimited'.
5. Try to reproduce the suspected bug. If you get `assertion failed'
message, be sure to include the complete message in your bug
report. If the application leaves a coredump, get a backtrace
using gdb:
$ gdb /path/to/app-binary # Loads the app to the debugger.
(gdb) core core # Opens the coredump.
(gdb) bt # Prints the backtrace. Copy & paste to bug report.
(gdb) quit # Quits gdb.
Send your bug report to Lasse Collin <lasse.collin@tukaani.org>. Don't
send the core dump file or the actual executables. If you have a small
example file(s) (total size less than 100 KiB), please include it/them
as an attachment.
Do NOT complain about problems with LZMA Utils to Igor Pavlov.
Although the code of LZMA Utils is derived from his code, there are
a lot of changes, which may have introduced bugs not present in
the original version.

View File

@@ -1,193 +1,97 @@
LZMA Utils FAQ
--------------
XZ Utils FAQ
============
Copyright (C) 2007 Lasse Collin
Q: What do the letters XZ mean?
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.
A: Nothing. They are just two letters, which come from the file format
suffix .xz. The .xz suffix was selected, because it seemed to be
pretty much unused. It is no deeper meaning.
Q: What are LZMA, LZMA Utils, lzma, .lzma, liblzma, LZMA SDK, LZMA_Alone,
7-Zip and p7zip?
Q: What are LZMA and LZMA2?
A: LZMA stands for Lempel-Ziv-Markov chain-Algorithm. LZMA is the name
of the compression algorithm designed by Igor Pavlov. He is the author
of 7-Zip, which is a great LGPL'd compression tool for Microsoft
Windows operating systems. In addition to 7-Zip itself, also LZMA SDK
is available on the website of 7-Zip. LZMA SDK contains LZMA
implementations in C++, Java and C#. The C++ version is the original
implementation which is used also in 7-Zip itself.
A: LZMA stands for Lempel-Ziv-Markov chain-Algorithm. It is the name
of the compression algorithm designed by Igor Pavlov for 7-Zip.
LZMA is based on LZ77 and range encoding.
Excluding the unrar plugin, 7-Zip is free software (free as in
freedom). Thanks to this, it was possible to port it to POSIX
platforms. The port was done and is maintained by myspace (TODO:
myspace's real name?). p7zip is a port of 7-Zip's command line version;
p7zip doesn't include the 7-Zip's GUI.
In POSIX world, users are used to gzip and bzip2 command line tools.
Developers know APIs of zlib and libbzip2. LZMA Utils try to ease
adoption of LZMA on free operating systems by providing a compression
library and a set of command line tools. The library is called liblzma.
It provides a zlib-like API making it easy to adapt LZMA compression in
existing applications. The main command line tool is known as lzma,
whose command line syntax is very similar to that of gzip and bzip2.
The original command line tool from LZMA SDK (lzma.exe) was found from
a directory called LZMA_Alone in the LZMA SDK. It used a simple header
format in .lzma files. This format was also used by LZMA Utils up to
and including 4.32.x. In LZMA Utils documentation, LZMA_Alone refers
to both the file format and the command line tool from LZMA SDK.
Because of various limitations of the LZMA_Alone file format, a new
file format was developed. Extending some existing format such as .gz
used by gzip was considered, but these formats were found to be too
limited. The filename suffix for the new .lzma format is `.lzma'. The
same suffix is also used for files in the LZMA_Alone format. To make
the transition to the new format as transparent as possible, LZMA Utils
support both the new and old formats transparently.
7-Zip and LZMA SDK: <http://7-zip.org/>
p7zip: <http://p7zip.sourceforge.net/>
LZMA Utils: <http://tukaani.org/lzma/>
LZMA2 is an updated version of the original LZMA to fix a couple of
practical issues. In context of XZ Utils, LZMA is called LZMA1 to
emphasize that LZMA is not the same thing as LZMA2. LZMA2 is the
primary compression algorithm in the .xz file format.
Q: What LZMA implementations there are available?
Q: There are many LZMA related projects. How does XZ Utils relate to them?
A: LZMA SDK contains implementations in C++, Java and C#. The C++ version
is the original implementation which is part of 7-Zip. LZMA SDK
contains also a small LZMA decoder in C.
A: 7-Zip and LZMA SDK are the original projects. LZMA SDK is roughly
a subset of the 7-Zip source tree.
A port of LZMA SDK to Pascal was made by Alan Birtles
<http://www.birtles.org.uk/programming/>. It should work with
multiple Pascal programming language implementations.
p7zip is 7-Zip's command line tools ported to POSIX-like systems.
LZMA Utils includes liblzma, which is directly based on LZMA SDK.
liblzma is written in C (C99, not C89). In contrast to C++ callback
API used by LZMA SDK, liblzma uses zlib-like stateful C API. I do not
want to comment whether both/former/latter/neither API(s) are good or
bad. The only reason to implement a zlib-like API was, that many
developers are already familiar with zlib, and very many applications
already use zlib. Having a similar API makes it easier to include LZMA
support in existing applications.
LZMA Utils provide a gzip-like lzma tool for POSIX-like systems.
LZMA Utils are based on LZMA SDK. XZ Utils are the successor to
LZMA Utils.
See also <http://en.wikipedia.org/wiki/LZMA#External_links>.
There are several other projects using LZMA. Most are more or less
based on LZMA SDK.
Q: Which file formats are supported by LZMA Utils?
Q: Do XZ Utils support the .7z format?
A: Even when the raw LZMA stream is always the same, it can be wrapped
in different container formats. The preferred format is the new .lzma
format. It has magic bytes (the first six bytes: 0xFF 'L' 'Z' 'M'
'A' 0x00). The format supports chaining up to seven filters filters,
splitting data to multiple blocks for easier multi-threading and rough
random-access reading. The file integrity is verified using CRC32,
CRC64, or SHA256, and by verifying the uncompressed size of the file.
LZMA SDK includes a tool called LZMA_Alone. It supports uses a
primitive header which includes only the mandatory stream information
required by the LZMA decoder. This format can be both read and
written by liblzma and the command line tool (use --format=alone to
create such files).
.7z is the native archive format used by 7-Zip. This format is not
supported by liblzma, and probably will never be supported. You
should use e.g. p7zip to extract .7z files.
It is possible to implement custom file formats by using raw filter
mode in liblzma. In this mode the application needs to store the filter
properties and provide them to liblzma before starting to uncompress
the data.
A: No. Use 7-Zip (Windows) or p7zip (POSIX-like systems) to handle .7z
files.
Q: How can I identify files containing LZMA compressed data?
Q: I have many .tar.7z files. Can I convert them to .tar.xz without
spending hours recompressing the data?
A: The preferred filename suffix for .lzma files is `.lzma'. `.tar.lzma'
may be abbreviated to `.tlz'. The same suffixes are used for files in
LZMA_Alone format. In practice this should be no problem since tools
included in LZMA Utils support both formats transparently.
Checking the magic bytes is easy way to detect files in the new .lzma
format (the first six bytes: 0xFF 'L' 'Z' 'M' 'A' 0x00). The "file"
command version FIXME contains magic strings for this format.
The old LZMA_Alone format has no magic bytes. Its header cannot contain
arbitrary bytes, thus it is possible to make a guess. Unfortunately the
guessing is usually too hard to be reliable, so don't try it unless you
are desperate.
A: In the "extra" directory, there is a script named 7z2lzma.bash which
is able to convert some .7z files to the .lzma format (not .xz). It
needs the 7za (or 7z) command from p7zip. The script may silently
produce corrupt output if certain assumptions are not met, so
decompress the resulting .lzma file and compare it against the
original before deleting the original file!
Q: Does the lzma command line tool support sparse files?
Q: I have many .lzma files. Can I quickly convert them to the .xz format?
A: Sparse files can (of course) be compressed like normal files, but
uncompression will not restore sparseness of the file. Use an archiver
tool to take care of sparseness before compressing the data with lzma.
A: For now, no. Since XZ Utils supports the .lzma format, it's usually
not too bad to keep the old files in the old format. If you want to
do the conversion anyway, you need to decompress the .lzma files and
then recompress to the .xz format.
The reason for this is that archiver tools handle files, while
compression tools handle streams or buffers. Being a sparse file is
a property of the file on the disk, not a property of the stream or
buffer.
Technically, there is a way to make the conversion relatively fast
(roughly twice the time that normal decompression takes). Writing
such a tool would take quite a bit time though, and would probably
be useful to only a few people. If you really want such a conversion
tool, contact Lasse Collin and offer some money.
Q: Can I recover parts of a broken LZMA file (e.g. corrupted CD-R)?
Q: Can I recover parts of a broken .xz file (e.g. corrupted CD-R)?
A: With LZMA_Alone and single-block .lzma files, you can uncompress the
file until you hit the first broken byte. The data after the broken
position is lost. LZMA relies on the uncompression history, and if
bytes are missing in the middle of the file, it is impossible to
reliably continue after the broken section.
With multi-block .lzma files it may be possible to locale the next
block in the file and continue decoding there. A limited recovery
tool for this kind of situations is planned.
A: It may be possible if the file consists of multiple blocks, which
typically is not the case if the file was created in single-threaded
mode. There is no recovery program yet.
Q: Is LZMA patented?
Q: Is (some part of) XZ Utils patented?
A: No, the authors are not aware of any patents that could affect LZMA.
However, due to nature of software patents, the authors cannot
guarantee, that LZMA isn't affected by any third party patent.
A: Lasse Collin is not aware of any patents that could affect XZ Utils.
However, due to nature of software patents, it's not possible to
guarantee that XZ Utils isn't affected by any third party patent(s).
Q: Where can I find documentation about how LZMA works as an algorithm?
Q: Where can I find documentation about the file format and algorithms?
A: Read the source code, Luke. There is no documentation about LZMA
internals. It is possible that Igor Pavlov is the only person on
the Earth that completely knows and understands the algorithm.
A: The .xz format is documented in xz-file-format.txt. It is a container
format only, and doesn't include descriptions of any non-trivial
filters.
You could begin by downloading LZMA SDK, and start reading from
the LZMA decoder to get some idea about the bitstream format.
Before you begin, you should know the basics of LZ77 and
range coding algorithms. LZMA is based on LZ77, but LZMA is
*a lot* more complex. Range coding is used to compress the
final bitstream like Huffman coding is used in Deflate.
Q: What are filters?
A: In context of .lzma files, a filter means an implementation of a
compression algorithm. The primary filter is LZMA, which is why
the names of the tools contain the letters LZMA.
liblzma and the new .lzma format support also other filters than LZMA.
There are different types of filters, which are suitable for different
types of data. Thus, to select the optimal filter and settings, the
type of the input data being compressed needs to be known.
Some filters are most useful when combined with another filter like
LZMA. These filters increase redundancy in the data, without changing
the size of the data, by taking advantage of properties specific to
the data being compressed.
So far, all the filters are always reversible. That is, no matter what
data you pass to a filter encoder, it can be always defiltered back to
the original form. Because of this, it is safe to compress for example
a software package that contains other file types than executables
using a filter specific to the architechture of the package being
compressed.
The old LZMA_Alone format supports only the LZMA filter.
Documenting LZMA and LZMA2 is planned, but for now, there is no other
documentation that the source code. Before you begin, you should know
the basics of LZ77 and range coding algorithms. LZMA is based on LZ77,
but LZMA is *a lot* more complex. Range coding is used to compress
the final bitstream like Huffman coding is used in Deflate.
Q: I cannot find BCJ and BCJ2 filters. Don't they exist in liblzma?
@@ -196,52 +100,23 @@ A: BCJ filter is called "x86" in liblzma. BCJ2 is not included,
because it requires using more than one encoded output stream.
Q: Can I use LZMA in proprietary, non-free applications?
Q: How do I build a program that needs liblzmadec (lzmadec.h)?
A: liblzma is under the GNU LGPL version 2.1 or (at your opinion) any
later version. To summarise (*NOTE* This summary is not legally
binding, that is, it doesn't give you any extra permissions compared
to the LGPL. Read the GNU LGPL carefully for the exact license
conditions.):
* All the changes made into the library itself must be published
under the same license.
* End users must be able to replace the used liblzma. Easiest way
to assure this is to link dynamically against liblzma so users
can replace the shared library file if they want.
* You must make it clear to your users, that your application uses
liblzma, and that liblzma is free software under the GNU LGPL.
A copy of GNU LGPL must be included.
LZMA SDK contains a special exception which allows linking *unmodified*
code statically with a non-free application. This exception does *not*
apply to liblzma.
As an alternative, you can support the development of LZMA and 7-Zip
by buying a proprietary license from Igor Pavlov. See homepage of
LZMA SDK <http://7-zip.org/sdk.html> for more information. Note that
having a proprietary license from Igor Pavlov doesn't allow you to use
liblzma in a way that contradicts with the GNU LGPL, because liblzma
contains code that is not copyrighted by Igor Pavlov. Please contact
both Lasse Collin and Igor Pavlov if the license conditions of liblzma
are not suitable for you.
A: liblzmadec is part of LZMA Utils. XZ Utils has liblzma, but no
liblzmadec. The code using liblzmadec should be ported to use
liblzma instead. If you cannot or don't want to do that, download
LZMA Utils from <http://tukaani.org/lzma/>.
Q: I would like to help. What can I do?
Q: The default build of liblzma is too big. How can I make it smaller?
A: See the TODO file. Please contact Lasse Collin before starting to do
anything, because it is possible that someone else is already working
on the same thing.
A: Give --enable-small to the configure script. Use also appropriate
--enable or --disable options to include only those filter encoders
and decoders and integrity checks that you actually need. Use
CFLAGS=-Os (with GCC) or equivalent to tell your compiler to optimize
for size. See INSTALL for information about configure options.
Q: How can I contact the authors?
A: Lasse Collin is the maintainer of LZMA Utils. You can contact him
either via IRC (Larhzu on #tukaani at Freenode or IRCnet). Email
should work too, <lasse.collin@tukaani.org>.
Igor Pavlov is the father of LZMA. He is the author of 7-Zip
and LZMA SDK. <http://7-zip.org/>
NOTE: Please don't bother Igor Pavlov with questions specific
to LZMA Utils.
If the result is still too big, take a look at XZ Embedded. It is
a separate project, which provides a limited but signinificantly
smaller XZ decoder implementation than XZ Utils.

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
LZMA Utils history
------------------
History of LZMA Utils and XZ Utils
==================================
Tukaani distribution
@@ -15,10 +15,10 @@ Tukaani distribution
which is an abbreviation of .tar.gz. A logical naming for LZMA
compressed packages was .tlz, being an abbreviation of .tar.lzma.
At the end of the year 2007, there's no distribution under the Tukaani
project anymore. Development of LZMA Utils still continues. Still,
there are .tlz packages around, because at least Vector Linux (a
Slackware based distribution) uses LZMA for its packages.
At the end of the year 2007, there was no distribution under the
Tukaani project anymore, but development of LZMA Utils was kept going.
Still, there were .tlz packages around, because at least Vector Linux
(a Slackware based distribution) used LZMA for its packages.
First versions of the modified pkgtools used the LZMA_Alone tool from
Igor Pavlov's LZMA SDK as is. It was fine, because users wouldn't need
@@ -59,8 +59,8 @@ Second generation
command line tool, but they had completely different command line
interface. The file format was still the same.
Lasse wrote liblzmadec, which was a small decoder-only library based on
the C code found from LZMA SDK. liblzmadec had API similar to zlib,
Lasse wrote liblzmadec, which was a small decoder-only library based
on the C code found from LZMA SDK. liblzmadec had API similar to zlib,
although there were some significant differences, which made it
non-trivial to use it in some applications designed for zlib and
libbzip2.
@@ -77,8 +77,8 @@ Second generation
but appeared to work well enough, so some people started using it too.
Because the development of the third generation of LZMA Utils was
delayed considerably (roughly two years), the 4.32.x branch had to be
kept maintained. It got some bug fixes now and then, and finally it was
delayed considerably (3-4 years), the 4.32.x branch had to be kept
maintained. It got some bug fixes now and then, and finally it was
decided to call it stable, although most of the missing features were
never added.
@@ -90,51 +90,60 @@ File format problems
features. The two biggest problems for non-embedded use were lack of
magic bytes and integrity check.
Igor and Lasse started developing a new file format with some help from
Ville Koskinen, Mark Adler and Mikko Pouru. Designing the new format
took quite a long time. It was mostly because Lasse was quite slow at
getting things done due to personal reasons.
Igor and Lasse started developing a new file format with some help
from Ville Koskinen. Also Mark Adler, Mikko Pouru, H. Peter Anvin,
and Lars Wirzenius helped with some minor things at some point of the
development. Designing the new format took quite a long time (actually,
too long time would be more appropriate expression). It was mostly
because Lasse was quite slow at getting things done due to personal
reasons.
Near the end of the year 2007 the new format was practically finished.
Compared to LZMA_Alone format and the .gz format used by gzip, the new
.lzma format is quite complex as a whole. This means that tools having
*full* support for the new format would be larger and more complex than
the tools supporting only the old LZMA_Alone format.
Originally the new format was supposed to use the same .lzma suffix
that was already used by the old file format. Switching to the new
format wouldn't have caused much trouble when the old format wasn't
used by many people. But since the development of the new format took
so long time, the old format got quite popular, and it was decided
that the new file format must use a different suffix.
For the situations where the full support for the .lzma format wouldn't
be required (embedded systems, operating system kernels), the new
format has a well-defined subset, which is easy to support with small
amount of code. It wouldn't be as small as an implementation using the
LZMA_Alone format, but the difference shouldn't be significant.
It was decided to use .xz as the suffix of the new file format. The
first stable .xz file format specification was finally released in
December 2008. In addition to fixing the most obvious problems of
the old .lzma format, the .xz format added some new features like
support for multiple filters (compression algorithms), filter chaining
(like piping on the command line), and limited random-access reading.
The new .lzma format allows dividing the data in multiple independent
blocks, which can be compressed and uncompressed independenly. This
makes multi-threading possible with algorithms that aren't inherently
parallel (such as LZMA). There's also a central index of the sizes of
the blocks, which makes it possible to do limited random-access reading
with granularity of the block size.
The new .lzma format uses the same filename suffix that was used for
LZMA_Alone files. The advantage is that users using the new tools won't
notice the change to the new format. The disadvantage is that the old
tools won't work with the new files.
Currently the primary compression algorithm used in .xz is LZMA2.
It is an extension on top of the original LZMA to fix some practical
problems: LZMA2 adds support for flushing the encoder, uncompressed
chunks, eases stateful decoder implementations, and improves support
for multithreading. Since LZMA2 is better than the original LZMA, the
original LZMA is not supported in .xz.
Third generation
Transition to XZ Utils
LZMA Utils 4.42.0alphas drop the rest of the C++ LZMA SDK. The LZMA and
other included filters (algorithm implementations) are still directly
based on LZMA SDK, but ported to C.
The early versions of XZ Utils were called LZMA Utils. The first
releases were 4.42.0alphas. They dropped the rest of the C++ LZMA SDK.
The code was still directly based on LZMA SDK but ported to C and
converted from callback API to stateful API. Later, Igor Pavlov made
C version of the LZMA encoder too; these ports from C++ to C were
independent in LZMA SDK and LZMA Utils.
liblzma is now the core of LZMA Utils. It has zlib-like API, which
doesn't suffer from the problems of the API of liblzmadec. liblzma
supports not only LZMA, but several other filters, which together
can improve compression ratio even further with certain file types.
The core of the new LZMA Utils was liblzma, a compression library with
zlib-like API. liblzma supported both the old and new file format. The
gzip-like lzma command line tool was rewritten to use liblzma.
The lzma and lzmadec command line tools have been rewritten. They uses
liblzma to do the actual compressing or uncompressing.
The new LZMA Utils code base was renamed to XZ Utils when the name
of the new file format had been decided. The liblzma compression
library retained its name though, because changing it would have
caused unnecessary breakage in applications already using the early
liblzma snapshots.
The development of LZMA Utils 4.42.x is still in alpha stage. Several
features are still missing or don't fully work yet. Documentation is
also very minimal.
The xz command line tool can emulate the gzip-like lzma tool by
creating appropriate symlinks (e.g. lzma -> xz). Thus, practically
all scripts using the lzma tool from LZMA Utils will work as is with
XZ Utils (and will keep using the old .lzma format). Still, the .lzma
format is more or less deprecated. XZ Utils will keep supporting it,
but new applications should use the .xz format, and migrating old
applications to .xz is often a good idea too.

View File

@@ -1,324 +0,0 @@
Advanced features of liblzma
----------------------------
0. Introduction
Most developers need only the basic features of liblzma. These
features allow single-threaded encoding and decoding of .lzma files
in streamed mode.
In some cases developers want more. The .lzma file format is
designed to allow multi-threaded encoding and decoding and limited
random-access reading. These features are possible in non-streamed
mode and limitedly also in streamed mode.
To take advange of these features, the application needs a custom
.lzma file format handler. liblzma provides a set of tools to ease
this task, but it's still quite a bit of work to get a good custom
.lzma handler done.
1. Where to begin
Start by reading the .lzma file format specification. Understanding
the basics of the .lzma file structure is required to implement a
custom .lzma file handler and to understand the rest of this document.
2. The basic components
2.1. Stream Header and tail
Stream Header begins the .lzma Stream and Stream tail ends it. Stream
Header is defined in the file format specification, but Stream tail
isn't (thus I write "tail" with a lower-case letter). Stream tail is
simply the Stream Flags and the Footer Magic Bytes fields together.
It was done this way in liblzma, because the Block coders take care
of the rest of the stuff in the Stream Footer.
For now, the size of Stream Header is fixed to 11 bytes. The header
<lzma/stream_flags.h> defines LZMA_STREAM_HEADER_SIZE, which you
should use instead of a hardcoded number. Similarly, Stream tail
is fixed to 3 bytes, and there is a constant LZMA_STREAM_TAIL_SIZE.
It is possible, that a future version of the .lzma format will have
variable-sized Stream Header and tail. As of writing, this seems so
unlikely though, that it was considered simplest to just use a
constant instead of providing a functions to get and store the sizes
of the Stream Header and tail.
2.x. Stream tail
For now, the size of Stream tail is fixed to 3 bytes. The header
<lzma/stream_flags.h> defines LZMA_STREAM_TAIL_SIZE, which you
should use instead of a hardcoded number.
3. Keeping track of size information
The lzma_info_* functions found from <lzma/info.h> should ease the
task of keeping track of sizes of the Blocks and also the Stream
as a whole. Using these functions is strongly recommended, because
there are surprisingly many situations where an error can occur,
and these functions check for possible errors every time some new
information becomes available.
If you find lzma_info_* functions lacking something that you would
find useful, please contact the author.
3.1. Start offset of the Stream
If you are storing the .lzma Stream inside anothe file format, or
for some other reason are placing the .lzma Stream to somewhere
else than to the beginning of the file, you should tell the starting
offset of the Stream using lzma_info_start_offset_set().
The start offset of the Stream is used for two distinct purporses.
First, knowing the start offset of the Stream allows
lzma_info_alignment_get() to correctly calculate the alignment of
every Block. This information is given to the Block encoder, which
will calculate the size of Header Padding so that Compressed Data
is alignment at an optimal offset.
Another use for start offset of the Stream is in random-access
reading. If you set the start offset of the Stream, lzma_info_locate()
will be able to calculate the offset relative to the beginning of the
file containing the Stream (instead of offset relative to the
beginning of the Stream).
3.2. Size of Stream Header
While the size of Stream Header is constant (11 bytes) in the current
version of the .lzma file format, this may change in future.
3.3. Size of Header Metadata Block
This information is needed when doing random-access reading, and
to verify the value of this field stored in Footer Metadata Block.
3.4. Total Size of the Data Blocks
3.5. Uncompressed Size of Data Blocks
3.6. Index
x. Alignment
There are a few slightly different types of alignment issues when
working with .lzma files.
The .lzma format doesn't strictly require any kind of alignment.
However, if the encoder carefully optimizes the alignment in all
situations, it can improve compression ratio, speed of the encoder
and decoder, and slightly help if the files get damaged and need
recovery.
Alignment has the most significant effect compression ratio FIXME
x.1. Compression ratio
Some filters take advantage of the alignment of the input data.
To get the best compression ratio, make sure that you feed these
filters correctly aligned data.
Some filters (e.g. LZMA) don't necessarily mind too much if the
input doesn't match the preferred alignment. With these filters
the penalty in compression ratio depends on the specific type of
data being compressed.
Other filters (e.g. PowerPC executable filter) won't work at all
with data that is improperly aligned. While the data can still
be de-filtered back to its original form, the benefit of the
filtering (better compression ratio) is completely lost, because
these filters expect certain patterns at properly aligned offsets.
The compression ratio may even worse with incorrectly aligned input
than without the filter.
x.1.1. Inter-filter alignment
When there are multiple filters chained, checking the alignment can
be useful not only with the input of the first filter and output of
the last filter, but also between the filters.
Inter-filter alignment important especially with the Subblock filter.
x.1.2. Further compression with external tools
This is relatively rare situation in practice, but still worth
understanding.
Let's say that there are several SPARC executables, which are each
filtered to separate .lzma files using only the SPARC filter. If
Uncompressed Size is written to the Block Header, the size of Block
Header may vary between the .lzma files. If no Padding is used in
the Block Header to correct the alignment, the starting offset of
the Compressed Data field will be differently aligned in different
.lzma files.
All these .lzma files are archived into a single .tar archive. Due
to nature of the .tar format, every file is aligned inside the
archive to an offset that is a multiple of 512 bytes.
The .tar archive is compressed into a new .lzma file using the LZMA
filter with options, that prefer input alignment of four bytes. Now
if the independent .lzma files don't have the same alignment of
the Compressed Data fields, the LZMA filter will be unable to take
advantage of the input alignment between the files in the .tar
archive, which reduces compression ratio.
Thus, even if you have only single Block per file, it can be good for
compression ratio to align the Compressed Data to optimal offset.
x.2. Speed
Most modern computers are faster when multi-byte data is located
at aligned offsets in RAM. Proper alignment of the Compressed Data
fields can slightly increase the speed of some filters.
x.3. Recovery
Aligning every Block Header to start at an offset with big enough
alignment may ease or at least speed up recovery of broken files.
y. Typical usage cases
y.x. Parsing the Stream backwards
You may need to parse the Stream backwards if you need to get
information such as the sizes of the Stream, Index, or Extra.
The basic procedure to do this follows.
Locate the end of the Stream. If the Stream is stored as is in a
standalone .lzma file, simply seek to the end of the file and start
reading backwards using appropriate buffer size. The file format
specification allows arbitrary amount of Footer Padding (zero or more
NUL bytes), which you skip before trying to decode the Stream tail.
Once you have located the end of the Stream (a non-NULL byte), make
sure you have at least the last LZMA_STREAM_TAIL_SIZE bytes of the
Stream in a buffer. If there isn't enough bytes left from the file,
the file is too small to contain a valid Stream. Decode the Stream
tail using lzma_stream_tail_decoder(). Store the offset of the first
byte of the Stream tail; you will need it later.
You may now want to do some internal verifications e.g. if the Check
type is supported by the liblzma build you are using.
Decode the Backward Size field with lzma_vli_reverse_decode(). The
field is at maximum of LZMA_VLI_BYTES_MAX bytes long. Check that
Backward Size is not zero. Store the offset of the first byte of
the Backward Size; you will need it later.
Now you know the Total Size of the last Block of the Stream. It's the
value of Backward Size plus the size of the Backward Size field. Note
that you cannot use lzma_vli_size() to calculate the size since there
might be padding; you need to use the real observed size of the
Backward Size field.
At this point, the operation continues differently for Single-Block
and Multi-Block Streams.
y.x.1. Single-Block Stream
There might be Uncompressed Size field present in the Stream Footer.
You cannot know it for sure unless you have already parsed the Block
Header earlier. For security reasons, you probably want to try to
decode the Uncompressed Size field, but you must not indicate any
error if decoding fails. Later you can give the decoded Uncompressed
Size to Block decoder if Uncopmressed Size isn't otherwise known;
this prevents it from producing too much output in case of (possibly
intentionally) corrupt file.
Calculate the the start offset of the Stream:
backward_offset - backward_size - LZMA_STREAM_HEADER_SIZE
backward_offset is the offset of the first byte of the Backward Size
field. Remember to check for integer overflows, which can occur with
invalid input files.
Seek to the beginning of the Stream. Decode the Stream Header using
lzma_stream_header_decoder(). Verify that the decoded Stream Flags
match the values found from Stream tail. You can use the
lzma_stream_flags_is_equal() macro for this.
Decode the Block Header. Verify that it isn't a Metadata Block, since
Single-Block Streams cannot have Metadata. If Uncompressed Size is
present in the Block Header, the value you tried to decode from the
Stream Footer must be ignored, since Uncompressed Size wasn't actually
present there. If Block Header doesn't have Uncompressed Size, and
decoding the Uncompressed Size field from the Stream Footer failed,
the file is corrupt.
If you were only looking for the Uncompressed Size of the Stream,
you now got that information, and you can stop processing the Stream.
To decode the Block, the same instructions apply as described in
FIXME. However, because you have some extra known information decoded
from the Stream Footer, you should give this information to the Block
decoder so that it can verify it while decoding:
- If Uncompressed Size is not present in the Block Header, set
lzma_options_block.uncompressed_size to the value you decoded
from the Stream Footer.
- Always set lzma_options_block.total_size to backward_size +
size_of_backward_size (you calculated this sum earlier already).
y.x.2. Multi-Block Stream
Calculate the start offset of the Footer Metadata Block:
backward_offset - backward_size
backward_offset is the offset of the first byte of the Backward Size
field. Remember to check for integer overflows, which can occur with
broken input files.
Decode the Block Header. Verify that it is a Metadata Block. Set
lzma_options_block.total_size to backward_size + size_of_backward_size
(you calculated this sum earlier already). Then decode the Footer
Metadata Block.
Store the decoded Footer Metadata to lzma_info structure using
lzma_info_set_metadata(). Set also the offset of the Backward Size
field using lzma_info_size_set(). Then you can get the start offset
of the Stream using lzma_info_size_get(). Note that any of these steps
may fail so don't omit error checking.
Seek to the beginning of the Stream. Decode the Stream Header using
lzma_stream_header_decoder(). Verify that the decoded Stream Flags
match the values found from Stream tail. You can use the
lzma_stream_flags_is_equal() macro for this.
If you were only looking for the Uncompressed Size of the Stream,
it's possible that you already have it now. If Uncompressed Size (or
whatever information you were looking for) isn't available yet,
continue by decoding also the Header Metadata Block. (If some
information is missing, the Header Metadata Block has to be present.)
Decoding the Data Blocks goes the same way as described in FIXME.
y.x.3. Variations
If you know the offset of the beginning of the Stream, you may want
to parse the Stream Header before parsing the Stream tail.

View File

@@ -1,112 +0,0 @@
Hacking liblzma
---------------
0. Preface
This document gives some overall information about the internals of
liblzma, which should make it easier to start reading and modifying
the code.
1. Programming language
liblzma was written in C99. If you use GCC, this means that you need
at least GCC 3.x.x. GCC 2 isn't and won't be supported.
Some GCC-specific extensions are used *conditionally*. They aren't
required to build a full-featured library. Don't make the code rely
on any non-standard compiler extensions or even C99 features that
aren't portable between almost-C99 compatible compilers (for example
non-static inlines).
The public API headers are in C89. This is to avoid frustrating those
who maintain programs, which are strictly in C89 or C++.
An assumption about sizeof(size_t) is made. If this assumption is
wrong, some porting is probably needed:
sizeof(uint32_t) <= sizeof(size_t) <= sizeof(uint64_t)
2. Internal vs. external API
Input Output
v Application ^
| liblzma public API |
| Stream coder |
| Block coder |
| Filter coder |
| ... |
v Filter coder ^
Application
`-- liblzma public API
`-- Stream coder
|-- Stream info handler
|-- Stream Header coder
|-- Block Header coder
| `-- Filter Flags coder
|-- Metadata coder
| `-- Block coder
| `-- Filter 0
| `-- Filter 1
| ...
|-- Data Block coder
| `-- Filter 0
| `-- Filter 1
| ...
`-- Stream tail coder
x. Designing new filters
All filters must be designed so that the decoder cannot consume
arbitrary amount input without producing any decoded output. Failing
to follow this rule makes liblzma vulnerable to DoS attacks if
untrusted files are decoded (usually they are untrusted).
An example should clarify the reason behind this requirement: There
are two filters in the chain. The decoder of the first filter produces
huge amount of output (many gigabytes or more) with a few bytes of
input, which gets passed to the decoder of the second filter. If the
data passed to the second filter is interpreted as something that
produces no output (e.g. padding), the filter chain as a whole
produces no output and consumes no input for a long period of time.
The above problem was present in the first versions of the Subblock
filter. A tiny .lzma file could have taken several years to decode
while it wouldn't produce any output at all. The problem was fixed
by adding limits for number of consecutive Padding bytes, and requiring
that some decoded output must be produced between Set Subfilter and
Unset Subfilter.
x. Implementing new filters
If the filter supports embedding End of Payload Marker, make sure that
when your filter detects End of Payload Marker,
- the usage of End of Payload Marker is actually allowed (i.e. End
of Input isn't used); and
- it also checks that there is no more input coming from the next
filter in the chain.
The second requirement is slightly tricky. It's possible that the next
filter hasn't returned LZMA_STREAM_END yet. It may even need a few
bytes more input before it will do so. You need to give it as much
input as it needs, and verify that it doesn't produce any output.
Don't call the next filter in the chain after it has returned
LZMA_STREAM_END (except in encoder if action == LZMA_SYNC_FLUSH).
It will result undefined behavior.
Be pedantic. If the input data isn't exactly valid, reject it.
At the moment, liblzma isn't modular. You will need to edit several
files in src/liblzma/common to include support for a new filter. grep
for LZMA_FILTER_LZMA to locate the files needing changes.

View File

@@ -1,188 +0,0 @@
Introduction to liblzma
-----------------------
Writing applications to work with liblzma
liblzma API is split in several subheaders to improve readability and
maintainance. The subheaders must not be #included directly; simply
use `#include <lzma.h>' instead.
Those who have used zlib should find liblzma's API easy to use.
To developers who haven't used zlib before, I recommend learning
zlib first, because zlib has excellent documentation.
While the API is similar to that of zlib, there are some major
differences, which are summarized below.
For basic stream encoding, zlib has three functions (deflateInit(),
deflate(), and deflateEnd()). Similarly, there are three functions
for stream decoding (inflateInit(), inflate(), and inflateEnd()).
liblzma has only single coding and ending function. Thus, to
encode one may use, for example, lzma_stream_encoder_single(),
lzma_code(), and lzma_end(). Simlarly for decoding, one may
use lzma_auto_decoder(), lzma_code(), and lzma_end().
zlib has deflateReset() and inflateReset() to reset the stream
structure without reallocating all the memory. In liblzma, all
coder initialization functions are like zlib's reset functions:
the first-time initializations are done with the same functions
as the reinitializations (resetting).
To make all this work, liblzma needs to know when lzma_stream
doesn't already point to an allocated and initialized coder.
This is achieved by initializing lzma_stream structure with
LZMA_STREAM_INIT (static initialization) or LZMA_STREAM_INIT_VAR
(for exampple when new lzma_stream has been allocated with malloc()).
This initialization should be done exactly once per lzma_stream
structure to avoid leaking memory. Calling lzma_end() will leave
lzma_stream into a state comparable to the state achieved with
LZMA_STREAM_INIT and LZMA_STREAM_INIT_VAR.
Example probably clarifies a lot. With zlib, compression goes
roughly like this:
z_stream strm;
deflateInit(&strm, level);
deflate(&strm, Z_RUN);
deflate(&strm, Z_RUN);
...
deflate(&strm, Z_FINISH);
deflateEnd(&strm) or deflateReset(&strm)
With liblzma, it's slightly different:
lzma_stream strm = LZMA_STREAM_INIT;
lzma_stream_encoder_single(&strm, &options);
lzma_code(&strm, LZMA_RUN);
lzma_code(&strm, LZMA_RUN);
...
lzma_code(&strm, LZMA_FINISH);
lzma_end(&strm) or reinitialize for new coding work
Reinitialization in the last step can be any function that can
initialize lzma_stream; it doesn't need to be the same function
that was used for the previous initialization. If it is the same
function, liblzma will usually be able to re-use most of the
existing memory allocations (depends on how much the initialization
options change). If you reinitialize with different function,
liblzma will automatically free the memory of the previous coder.
File formats
liblzma supports multiple container formats for the compressed data.
Different initialization functions initialize the lzma_stream to
process different container formats. See the details from the public
header files.
The following functions are the most commonly used:
- lzma_stream_encoder_single(): Encodes Single-Block Stream; this
the recommended format for most purporses.
- lzma_alone_encoder(): Useful if you need to encode into the
legacy LZMA_Alone format.
- lzma_auto_decoder(): Decoder that automatically detects the
file format; recommended when you decode compressed files on
disk, because this way compatibility with the legacy LZMA_Alone
format is transparent.
- lzma_stream_decoder(): Decoder for Single- and Multi-Block
Streams; this is good if you want to accept only .lzma Streams.
Filters
liblzma supports multiple filters (algorithm implementations). The new
.lzma format supports filter-chain having up to seven filters. In the
filter chain, the output of one filter is input of the next filter in
the chain. The legacy LZMA_Alone format supports only one filter, and
that must always be LZMA.
General-purporse compression:
LZMA The main algorithm of liblzma (surprise!)
Branch/Call/Jump filters for executables:
x86 This filter is known as BCJ in 7-Zip
IA64 IA-64 (Itanium)
PowerPC Big endian PowerPC
ARM
ARM-Thumb
SPARC
Other filters:
Copy Dummy filter that simply copies all the data
from input to output.
Subblock Multi-purporse filter, that can
- embed End of Payload Marker if the previous
filter in the chain doesn't support it; and
- apply Subfilters, which filter only part
of the same compressed Block in the Stream.
Branch/Call/Jump filters never change the size of the data. They
should usually be used as a pre-filter for some compression filter
like LZMA.
Integrity checks
The .lzma Stream format uses CRC32 as the integrity check for
different file format headers. It is possible to omit CRC32 from
the Block Headers, but not from Stream Header. This is the reason
why CRC32 code cannot be disabled when building liblzma (in addition,
the LZMA encoder uses CRC32 for hashing, so that's another reason).
The integrity check of the actual data is calculated from the
uncompressed data. This check can be CRC32, CRC64, or SHA256.
It can also be omitted completely, although that usually is not
a good thing to do. There are free IDs left, so support for new
checks algorithms can be added later.
API and ABI stability
The API and ABI of liblzma isn't stable yet, although no huge
changes should happen. One potential place for change is the
lzma_options_subblock structure.
In the 4.42.0alpha phase, the shared library version number won't
be updated even if ABI breaks. I don't want to track the ABI changes
yet. Just rebuild everything when you upgrade liblzma until we get
to the beta stage.
Size of the library
While liblzma isn't huge, it is quite far from the smallest possible
LZMA implementation: full liblzma binary (with support for all
filters and other features) is way over 100 KiB, but the plain raw
LZMA decoder is only 5-10 KiB.
To decrease the size of the library, you can omit parts of the library
by passing certain options to the `configure' script. Disabling
everything but the decoders of the require filters will usually give
you a small enough library, but if you need a decoder for example
embedded in the operating system kernel, the code from liblzma probably
isn't suitable as is.
If you need a minimal implementation supporting .lzma Streams, you
may need to do partial rewrite. liblzma uses stateful API like zlib.
That increases the size of the library. Using callback API or even
simpler buffer-to-buffer API would allow smaller implementation.
LZMA SDK contains smaller LZMA decoder written in ANSI-C than
liblzma, so you may want to take a look at that code. However,
it doesn't (at least not yet) support the new .lzma Stream format.
Documentation
There's no other documentation than the public headers and this
text yet. Real docs will be written some day, I hope.

View File

@@ -1,219 +0,0 @@
Using liblzma securely
----------------------
0. Introduction
This document discusses how to use liblzma securely. There are issues
that don't apply to zlib or libbzip2, so reading this document is
strongly recommended even for those who are very familiar with zlib
or libbzip2.
While making liblzma itself as secure as possible is essential, it's
out of scope of this document.
1. Memory usage
The memory usage of liblzma varies a lot.
1.1. Problem sources
1.1.1. Block coder
The memory requirements of Block encoder depend on the used filters
and their settings. The memory requirements of the Block decoder
depend on the which filters and with which filter settings the Block
was encoded. Usually the memory requirements of a decoder are equal
or less than the requirements of the encoder with the same settings.
While the typical memory requirements to decode a Block is from a few
hundred kilobytes to tens of megabytes, a maliciously constructed
files can require a lot more RAM to decode. With the current filters,
the maximum amount is about 7 GiB. If you use multi-threaded decoding,
every Block can require this amount of RAM, thus a four-threaded
decoder could suddenly try to allocate 28 GiB of RAM.
If you don't limit the maximum memory usage in any way, and there are
no resource limits set on the operating system side, one malicious
input file can run the system out of memory, or at least make it swap
badly for a long time. This is exceptionally bad on servers e.g.
email server doing virus scanning on incoming messages.
1.1.2. Metadata decoder
Multi-Block .lzma files contain at least one Metadata Block.
Externally the Metadata Blocks are similar to Data Blocks, so all
the issues mentioned about memory usage of Data Blocks applies to
Metadata Blocks too.
The uncompressed content of Metadata Blocks contain information about
the Stream as a whole, and optionally some Extra Records. The
information about the Stream is kept in liblzma's internal data
structures in RAM. Extra Records can contain arbitrary data. They are
not interpreted by liblzma, but liblzma will provide them to the
application in uninterpreted form if the application wishes so.
Usually the Uncompressed Size of a Metadata Block is small. Even on
extreme cases, it shouldn't be much bigger than a few megabytes. Once
the Metadata has been parsed into native data structures in liblzma,
it usually takes a little more memory than in the encoded form. For
all normal files, this is no problem, since the resulting memory usage
won't be too much.
The problem is that a maliciously constructed Metadata Block can
contain huge amount of "information", which liblzma will try to store
in its internal data structures. This may cause liblzma to allocate
all the available RAM unless some kind of resource usage limits are
applied.
Note that the Extra Records in Metadata are always parsed but, but
memory is allocated for them only if the application has requested
liblzma to provide the Extra Records to the application.
1.2. Solutions
If you need to decode files from untrusted sources (most people do),
you must limit the memory usage to avoid denial of service (DoS)
conditions caused by malicious input files.
The first step is to find out how much memory you are allowed consume
at maximum. This may be a hardcoded constant or derived from the
available RAM; whatever is appropriate in the application.
The simplest solution is to use setrlimit() if the kernel supports
RLIMIT_AS, which limits the memory usage of the whole process.
For more portable and fine-grained limitting, you can use
memory limitter functions found from <lzma/memlimit.h>.
1.2.1. Encoder
lzma_memory_usage() will give you a rough estimate about the memory
usage of the given filter chain. To dramatically simplify the internal
implementation, this function doesn't take into account all the small
helper data structures needed in various places; only the structures
with significant memory usage are taken into account. Still, the
accuracy of this function should be well within a mebibyte.
The Subblock filter is a special case. If a Subfilter has been
specified, it isn't taken into account when lzma_memory_usage()
calculates the memory usage. You need to calculate the memory usage
of the Subfilter separately.
Keeping track of Blocks in a Multi-Block Stream takes a few dozen
bytes of RAM per Block (size of the lzma_index structure plus overhead
of malloc()). It isn't a good idea to put tens of thousands of Blocks
into a Stream unless you have a very good reason to do so (compressed
dictionary could be an example of such situation).
Also keep the number and sizes of Extra Records sane. If you produce
the list of Extra Records automatically from some untrusted source,
you should not only validate the content of these Records, but also
their memory usage.
1.2.2. Decoder
A single-threaded decoder should simply use a memory limitter and
indicate an error if it runs out of memory.
Memory-limitting with multi-threaded decoding is tricky. The simple
solution is to divide the maximum allowed memory usage with the
maximum allowed threads, and give each Block decoder their own
independent lzma_memory_limitter. The drawback is that if one Block
needs notably more RAM than any other Block, the decoder will run out
of memory when in reality there would be plenty of free RAM.
An attractive alternative would be using shared lzma_memory_limitter.
Depending on the application and the expected type of input, this may
either be the best solution or a source of hard-to-repeat problems.
Consider the following requirements:
- You use at maximum of n threads.
- x(i) is the decoder memory requirements of the Block number i
in an expected input Stream.
- The memory limitter is set to higher value than the sum of n
highest values x(i).
(If you are better at explaining the above conditions, please
contribute your improved version.)
If the above conditions aren't met, it is possible that the decoding
will fail unpredictably. That is, on the same machine using the same
settings, the decoding may sometimes succeed and sometimes fail. This
is because sometimes threads may run so that the Blocks with highest
memory usage are tried to be decoded at the same time.
Most .lzma files have all the Blocks encoded with identical settings,
or at least the memory usage won't vary dramatically. That's why most
multi-threaded decoders probably want to use the simple "separate
lzma_memory_limitter for each thread" solution, possibly fallbacking
to single-threaded mode in case the per-thread memory limits aren't
enough in multi-threaded mode.
FIXME: Memory usage of Stream info.
[
]
2. Huge uncompressed output
2.1. Data Blocks
Decoding a tiny .lzma file can produce huge amount of uncompressed
output. There is an example file of 45 bytes, which decodes to 64 PiB
(that's 2^56 bytes). Uncompressing such a file to disk is likely to
fill even a bigger disk array. If the data is written to a pipe, it
may not fill the disk, but would still take very long time to finish.
To avoid denial of service conditions caused by huge amount of
uncompressed output, applications using liblzma should use some method
to limit the amount of output produced. The exact method depends on
the application.
All valid .lzma Streams make it possible to find out the uncompressed
size of the Stream without actually uncompressing the data. This
information is available in at least one of the Metadata Blocks.
Once the uncompressed size is parsed, the decoder can verify that
it doesn't exceed certain limits (e.g. available disk space).
When the uncompressed size is known, the decoder can actively keep
track of the amount of output produced so far, and that it doesn't
exceed the known uncompressed size. If it does exceed, the file is
known to be corrupt and an error should be indicated without
continuing to decode the rest of the file.
Unfortunately, finding the uncompressed size beforehand is often
possible only in non-streamed mode, because the needed information
could be in the Footer Metdata Block, which (obviously) is at the
end of the Stream. In purely streamed mode decoding, one may need to
use some rough arbitrary limits to prevent the problems described in
the beginning of this section.
2.2. Metadata
Metadata is stored in Metadata Blocks, which are very similar to
Data Blocks. Thus, the uncompressed size can be huge just like with
Data Blocks. The difference is, that the contents of Metadata Blocks
aren't given to the application as is, but parsed by liblzma. Still,
reading through a huge Metadata can take very long time, effectively
creating a denial of service like piping decoded a Data Block to
another process would do.
At first it would seem that using a memory limitter would prevent
this issue as a side effect. But it does so only if the application
requests liblzma to allocate the Extra Records and provide them to
the application. If Extra Records aren't requested, they aren't
allocated either. Still, the Extra Records are being read through
to validate that the Metadata is in proper format.
The solution is to limit the Uncompressed Size of a Metadata Block
to some relatively large value. This will make liblzma to give an
error when the given limit is reached.

166
doc/lzma-file-format.txt Normal file
View File

@@ -0,0 +1,166 @@
The .lzma File Format
=====================
0. Preface
0.1. Notices and Acknowledgements
0.2. Changes
1. File Format
1.1. Header
1.1.1. Properties
1.1.2. Dictionary Size
1.1.3. Uncompressed Size
1.2. LZMA Compressed Data
2. References
0. Preface
This document describes the .lzma file format, which is
sometimes also called LZMA_Alone format. It is a legacy file
format, which is being or has been replaced by the .xz format.
The MIME type of the .lzma format is `application/x-lzma'.
The most commonly used software to handle .lzma files are
LZMA SDK, LZMA Utils, 7-Zip, and XZ Utils. This document
describes some of the differences between these implementations
and gives hints what subset of the .lzma format is the most
portable.
0.1. Notices and Acknowledgements
This file format was designed by Igor Pavlov for use in
LZMA SDK. This document was written by Lasse Collin
<lasse.collin@tukaani.org> using the documentation found
from the LZMA SDK.
This document has been put into the public domain.
0.2. Changes
Last modified: 2009-05-01 11:15+0300
1. File Format
+-+-+-+-+-+-+-+-+-+-+-+-+-+==========================+
| Header | LZMA Compressed Data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+==========================+
The .lzma format file consist of 13-byte Header followed by
the LZMA Compressed Data.
Unlike the .gz, .bz2, and .xz formats, it is not possible to
concatenate multiple .lzma files as is and expect the
decompression tool to decode the resulting file as if it were
a single .lzma file.
For example, the command line tools from LZMA Utils and
LZMA SDK silently ignore all the data after the first .lzma
stream. In contrast, the command line tool from XZ Utils
considers the .lzma file to be corrupt if there is data after
the first .lzma stream.
1.1. Header
+------------+----+----+----+----+--+--+--+--+--+--+--+--+
| Properties | Dictionary Size | Uncompressed Size |
+------------+----+----+----+----+--+--+--+--+--+--+--+--+
1.1.1. Properties
The Properties field contains three properties. An abbreviation
is given in parentheses, followed by the value range of the
property. The field consists of
1) the number of literal context bits (lc, [0, 8]);
2) the number of literal position bits (lp, [0, 4]); and
3) the number of position bits (pb, [0, 4]).
The properties are encoded using the following formula:
Properties = (pb * 5 + lp) * 9 + lc
The following C code illustrates a straightforward way to
decode the Properties field:
uint8_t lc, lp, pb;
uint8_t prop = get_lzma_properties();
if (prop > (4 * 5 + 4) * 9 + 8)
return LZMA_PROPERTIES_ERROR;
pb = prop / (9 * 5);
prop -= pb * 9 * 5;
lp = prop / 9;
lc = prop - lp * 9;
XZ Utils has an additional requirement: lc + lp <= 4. Files
which don't follow this requirement cannot be decompressed
with XZ Utils. Usually this isn't a problem since the most
common lc/lp/pb values are 3/0/2. It is the only lc/lp/pb
combination that the files created by LZMA Utils can have,
but LZMA Utils can decompress files with any lc/lp/pb.
1.1.2. Dictionary Size
Dictionary Size is stored as an unsigned 32-bit little endian
integer. Any 32-bit value is possible, but for maximum
portability, only sizes of 2^n and 2^n + 2^(n-1) should be
used.
LZMA Utils creates only files with dictionary size 2^n,
16 <= n <= 25. LZMA Utils can decompress files with any
dictionary size.
XZ Utils creates and decompresses .lzma files only with
dictionary sizes 2^n and 2^n + 2^(n-1). If some other
dictionary size is specified when compressing, the value
stored in the Dictionary Size field is a rounded up, but the
specified value is still used in the actual compression code.
1.1.3. Uncompressed Size
Uncompressed Size is stored as unsigned 64-bit little endian
integer. A special value of 0xFFFF_FFFF_FFFF_FFFF indicates
that Uncompressed Size is unknown. End of Payload Marker (*)
is used if and only if Uncompressed Size is unknown.
XZ Utils rejects files whose Uncompressed Size field specifies
a known size that is 256 GiB or more. This is to reject false
positives when trying to guess if the input file is in the
.lzma format. When Uncompressed Size is unknown, there is no
limit for the uncompressed size of the file.
(*) Some tools use the term End of Stream (EOS) marker
instead of End of Payload Marker.
1.2. LZMA Compressed Data
Detailed description of the format of this field is out of
scope of this document.
2. References
LZMA SDK - The original LZMA implementation
http://7-zip.org/sdk.html
7-Zip
http://7-zip.org/
LZMA Utils - LZMA adapted to POSIX-like systems
http://tukaani.org/lzma/
XZ Utils - The next generation of LZMA Utils
http://tukaani.org/xz/
The .xz file format - The successor of the the .lzma format
http://tukaani.org/xz/xz-file-format.txt

View File

@@ -1,107 +0,0 @@
Introduction to the lzma command line tool
------------------------------------------
Overview
The lzma command line tool is similar to gzip and bzip2, but for
compressing and uncompressing .lzma files.
Supported file formats
By default, the tool creates files in the new .lzma format. This can
be overriden with --format=FMT command line option. Use --format=alone
to create files in the old LZMA_Alone format.
By default, the tool uncompresses both the new .lzma format and
LZMA_Alone format. This is to make it transparent to switch from
the old LZMA_Alone format to the new .lzma format. Since both
formats use the same filename suffix, average user should never
notice which format was used.
Differences to gzip and bzip2
Standard input and output
Both gzip and bzip2 refuse to write compressed data to a terminal and
read compressed data from a terminal. With gzip (but not with bzip2),
this can be overriden with the `--force' option. lzma follows the
behavior of gzip here.
Usage of LZMA_OPT environment variable
gzip and bzip2 read GZIP and BZIP2 environment variables at startup.
These variables may contain extra command line options.
gzip and bzip2 allow passing not only options, but also end-of-options
indicator (`--') and filenames via the environment variable. No quoting
is supported with the filenames.
Here are examples with gzip. bzip2 behaves identically.
bash$ echo asdf > 'foo bar'
bash$ GZIP='"foo bar"' gzip
gzip: "foo: No such file or directory
gzip: bar": No such file or directory
bash$ GZIP=-- gzip --help
gzip: --help: No such file or directory
lzma silently ignores all non-option arguments given via the
environment variable LZMA_OPT. Like on the command line, everything
after `--' is taken as non-options, and thus ignored in LZMA_OPT.
bash$ LZMA_OPT='--help' lzma --version # Displays help
bash$ LZMA_OPT='-- --help' lzma --version # Displays version
Filter chain presets
Like in gzip and bzip2, lzma supports numbered presets from 1 to 9
where 1 is the fastest and 9 the best compression. 1 and 2 are for
fast compressing with small memory usage, 3 to 6 for good compression
ratio with medium memory usage, and 7 to 9 for excellent compression
ratio with higher memory requirements. The default is 7 if memory
usage limit allows.
In future, there will probably be an option like --preset=NAME, which
will contain more special presets for specific file types.
It's also possible that there will be some heuristics to select good
filters. For example, the tool could detect when a .tar archive is
being compressed, and enable x86 filter only for those files in the
.tar archive that are ELF or PE executables for x86.
Specifying custom filter chains
Custom filter chains are specified by using long options with the name
of the filters in correct order. For example, to pass the input data to
the x86 filter and the output of that to the LZMA filter, the following
command will do:
lzma --x86 --lzma filename
Some filters accept options, which are specified as a comma-separated
list of key=value pairs:
lzma --delta=distance=4 --lzma=dict=4Mi,lc=8,lp=2 filename
Memory usage control
By default, the command line tool limits memory usage to 1/3 of the
available physical RAM. If no preset or custom filter chain has been
given, the default preset will be used. If the memory limit is too
low for the default preset, the tool will silently switch to lower
preset.
When a preset or a custom filter chain has been specified and the
memory limit is too low, an error message is displayed and no files
are processed.
If the decoder hits the memory usage limit, an error is displayed and
no more files are processed.

1150
doc/xz-file-format.txt Normal file

File diff suppressed because it is too large Load Diff

255
dos/Makefile Normal file
View File

@@ -0,0 +1,255 @@
###############################################################################
#
# Makefile to build XZ Utils using DJGPP
#
# Make flags to alter compilation:
#
# DEBUG=1 Enable assertions. Don't use this for production builds!
# You may also want to set CFLAGS="-g -O0" to disable
# optimizations.
#
# The usual CPPFLAGS and CFLAGS are supported too.
#
###############################################################################
#
# Author: Lasse Collin
#
# This file has been put into the public domain.
# You can do whatever you want with this file.
#
###############################################################################
CC = gcc
AR = ar
STRIP = strip
SED = sed
RM = rm -f
CFLAGS = -g -Wextra -Wfatal-errors -Wall -march=i386 -mtune=i686 -O2
# NOTE: -fgnu89-inline is needed on DJGPP 2.04 beta and GCC 4.3.2
# because time.h uses GNU-style "extern inline".
ALL_CFLAGS = -std=gnu99 -fgnu89-inline
ALL_CPPFLAGS = \
-I. \
-I../lib \
-I../src/common \
-I../src/liblzma/api \
-I../src/liblzma/common \
-I../src/liblzma/check \
-I../src/liblzma/rangecoder \
-I../src/liblzma/lz \
-I../src/liblzma/lzma \
-I../src/liblzma/delta \
-I../src/liblzma/simple \
-I../src/liblzma/subblock
ALL_CPPFLAGS += -DHAVE_CONFIG_H
ifdef DEBUG
STRIP := rem Skipping strip
else
ALL_CPPFLAGS += -DNDEBUG
endif
ALL_CPPFLAGS += $(CPPFLAGS)
ALL_CFLAGS += $(CFLAGS)
################
# Common rules #
################
.PHONY: all clean
all: liblzma.a getopt.a xzdec.exe lzmadec.exe xz.exe
clean: liblzma-clean getopt-clean xzdec-clean xz-clean
#############
# liblzma.a #
#############
LIBLZMA_SRCS_C = \
../src/liblzma/common/alone_decoder.c \
../src/liblzma/common/alone_encoder.c \
../src/liblzma/common/auto_decoder.c \
../src/liblzma/common/block_buffer_decoder.c \
../src/liblzma/common/block_buffer_encoder.c \
../src/liblzma/common/block_decoder.c \
../src/liblzma/common/block_encoder.c \
../src/liblzma/common/block_header_decoder.c \
../src/liblzma/common/block_header_encoder.c \
../src/liblzma/common/block_util.c \
../src/liblzma/common/common.c \
../src/liblzma/common/easy_buffer_encoder.c \
../src/liblzma/common/easy_decoder_memusage.c \
../src/liblzma/common/easy_encoder.c \
../src/liblzma/common/easy_encoder_memusage.c \
../src/liblzma/common/easy_preset.c \
../src/liblzma/common/filter_common.c \
../src/liblzma/common/filter_decoder.c \
../src/liblzma/common/filter_encoder.c \
../src/liblzma/common/filter_flags_decoder.c \
../src/liblzma/common/filter_flags_encoder.c \
../src/liblzma/common/index.c \
../src/liblzma/common/index_decoder.c \
../src/liblzma/common/index_encoder.c \
../src/liblzma/common/index_hash.c \
../src/liblzma/common/stream_buffer_decoder.c \
../src/liblzma/common/stream_buffer_encoder.c \
../src/liblzma/common/stream_decoder.c \
../src/liblzma/common/stream_encoder.c \
../src/liblzma/common/stream_flags_common.c \
../src/liblzma/common/stream_flags_decoder.c \
../src/liblzma/common/stream_flags_encoder.c \
../src/liblzma/common/vli_decoder.c \
../src/liblzma/common/vli_encoder.c \
../src/liblzma/common/vli_size.c \
../src/liblzma/check/check.c \
../src/liblzma/check/crc32_table.c \
../src/liblzma/check/crc64_table.c \
../src/liblzma/check/sha256.c \
../src/liblzma/rangecoder/price_table.c \
../src/liblzma/lz/lz_decoder.c \
../src/liblzma/lz/lz_encoder.c \
../src/liblzma/lz/lz_encoder_mf.c \
../src/liblzma/lzma/fastpos_table.c \
../src/liblzma/lzma/lzma2_decoder.c \
../src/liblzma/lzma/lzma2_encoder.c \
../src/liblzma/lzma/lzma_decoder.c \
../src/liblzma/lzma/lzma_encoder.c \
../src/liblzma/lzma/lzma_encoder_optimum_fast.c \
../src/liblzma/lzma/lzma_encoder_optimum_normal.c \
../src/liblzma/lzma/lzma_encoder_presets.c \
../src/liblzma/delta/delta_common.c \
../src/liblzma/delta/delta_decoder.c \
../src/liblzma/delta/delta_encoder.c \
../src/liblzma/simple/arm.c \
../src/liblzma/simple/armthumb.c \
../src/liblzma/simple/ia64.c \
../src/liblzma/simple/powerpc.c \
../src/liblzma/simple/simple_coder.c \
../src/liblzma/simple/simple_decoder.c \
../src/liblzma/simple/simple_encoder.c \
../src/liblzma/simple/sparc.c \
../src/liblzma/simple/x86.c
LIBLZMA_SRCS_ASM = \
../src/liblzma/check/crc32_x86.S \
../src/liblzma/check/crc64_x86.S
LIBLZMA_OBJS_C = $(LIBLZMA_SRCS_C:.c=.o)
LIBLZMA_OBJS_ASM = $(LIBLZMA_SRCS_ASM:.S=.o)
LIBLZMA_OBJS = $(LIBLZMA_OBJS_C) $(LIBLZMA_OBJS_ASM)
$(LIBLZMA_OBJS_C): %.o: %.c
$(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -c -o $@ $<
$(LIBLZMA_OBJS_ASM): %.o: %.S
$(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -c -o $@ $<
liblzma.a: $(LIBLZMA_OBJS)
$(RM) $@
$(AR) rcs $@ $(LIBLZMA_OBJS)
$(STRIP) --strip-unneeded $@
# Avoid too long command lines.
.PHONY: liblzma-clean $(LIBLZMA_OBJS:.o=-clean)
liblzma-clean: $(LIBLZMA_OBJS:.o=-clean)
-$(RM) liblzma.a
$(LIBLZMA_OBJS:.o=-clean):
-$(RM) $(@:-clean=.o)
###############
# getopt_long #
###############
GETOPT_SRCS = \
../lib/getopt.c \
../lib/getopt1.c
GETOPT_OBJS = $(GETOPT_SRCS:.c=.o)
GETOPT_H = ../lib/getopt.h
$(GETOPT_H): %.h: %.in.h
$(SED) "" $< > $@
$(GETOPT_OBJS): %.o: %.c $(GETOPT_H)
$(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -c -o $@ $<
getopt.a: $(GETOPT_OBJS)
$(RM) $@
$(AR) rcs $@ $(GETOPT_OBJS)
$(STRIP) --strip-unneeded $@
getopt-clean:
$(RM) $(GETOPT_H) $(GETOPT_OBJS) getopt.a
###########################
# xzdec.exe & lzmadec.exe #
###########################
XZDEC_SRCS = ../src/xzdec/xzdec.c
xzdec.exe: getopt.a liblzma.a $(XZDEC_SRCS)
$(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) $(XZDEC_SRCS) -o $@ getopt.a liblzma.a
$(STRIP) --strip-all $@
exe2coff $@
$(RM) $@
copy /b $(DJGPP:DJGPP.ENV=BIN\CWSDSTUB.EXE) + $(@:.exe=) $@
$(RM) $(@:.exe=)
lzmadec.exe: getopt.a liblzma.a $(XZDEC_SRCS)
$(CC) $(ALL_CPPFLAGS) -DLZMADEC $(ALL_CFLAGS) $(XZDEC_SRCS) -o $@ getopt.a liblzma.a
$(STRIP) --strip-all $@
exe2coff $@
$(RM) $@
copy /b $(DJGPP:DJGPP.ENV=BIN\CWSDSTUB.EXE) + $(@:.exe=) $@
$(RM) $(@:.exe=)
.PHONY: xzdec-clean
xzdec-clean:
-$(RM) xzdec.exe lzmadec.exe xzdec lzmadec
##########
# xz.exe #
##########
XZ_SRCS = \
../src/xz/args.c \
../src/xz/coder.c \
../src/xz/file_io.c \
../src/xz/hardware.c \
../src/xz/main.c \
../src/xz/message.c \
../src/xz/options.c \
../src/xz/signals.c \
../src/xz/suffix.c \
../src/xz/util.c
XZ_OBJS = $(XZ_SRCS:.c=.o)
$(XZ_OBJS): %.o: %.c
$(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -c -o $@ $<
xz.exe: getopt.a liblzma.a $(XZ_OBJS)
$(CC) $(ALL_CFLAGS) $(XZ_OBJS) -o $@ getopt.a liblzma.a
$(STRIP) --strip-all $@
exe2coff $@
$(RM) $@
copy /b $(DJGPP:DJGPP.ENV=BIN\CWSDSTUB.EXE) + $(@:.exe=) $@
$(RM) $(@:.exe=)
# Avoid too long command lines.
.PHONY: xz-clean $(XZ_OBJS:.o=-clean)
xz-clean: $(XZ_OBJS:.o=-clean)
-$(RM) xz.exe xz
$(XZ_OBJS:.o=-clean):
-$(RM) $(@:-clean=.o)

113
dos/README Normal file
View File

@@ -0,0 +1,113 @@
XZ Utils on DOS
===============
Introduction
This document explains how to build XZ Utils for DOS using DJGPP.
The resulting binaries should run at least on various DOS versions
and under Windows 95/98/98SE/ME, which cannot run the Windows version
of XZ Utils.
This is currently experimental and has got very little testing.
Getting and Installing DJGPP
You may use <http://www.delorie.com/djgpp/zip-picker.html> to help
deciding what to download, but as of writing (2009-02-13) that may
not be the most convenient way taking into account what components
are actually required to build XZ Utils. However, using the
zip-picker can still be worth doing to get nice short summary of
installation instructions (they can be found from readme.1st too).
For more manual method, first select a mirror from
<http://www.delorie.com/djgpp/getting.html>. You need
the following files:
unzip32.exe
beta/v2/djdev204.zip
v2gnu/bnu219b.zip
v2gnu/gcc432b.zip
v2gnu/mak3791b.zip
v2gnu/sed415b.zip
v2misc/csdpmi5b.zip
If newer versions are available, probably you should try them first.
Note that djdev203.zip is too old to build XZ Utils; you need at
least djdev204.zip. Also note that you want csdpmi5b.zip even if you
run under Windows or DOSEMU, because the XZ Utils Makefile will embed
cwsdstub.exe to the resulting binaries.
See the instructions in readme.1st found from djdev204.zip. Here's
a short summary, but you should still read readme.1st.
C:\> mkdir DJGPP
C:\> cd DJGPP
C:\DJGPP> c:\download\unzip32 c:\download\djdev204.zip
C:\DJGPP> c:\download\unzip32 c:\download\bnu219b.zip
C:\DJGPP> c:\download\unzip32 c:\download\gcc432b.zip
C:\DJGPP> c:\download\unzip32 c:\download\mak3791b.zip
C:\DJGPP> c:\download\unzip32 c:\download\sed415b.zip
C:\DJGPP> c:\download\unzip32 c:\download\csdpmi5b.zip
C:\DJGPP> set PATH=C:\DJGPP\BIN;%PATH%
C:\DJGPP> set DJGPP=C:\DJGPP\DJGPP.ENV
You may want to add the last two lines into AUTOEXEC.BAT or have,
for example, DJGPP.BAT which you can run before using DJGPP.
Make sure you use completely upper case path in the DJGPP environment
variable. This is not required by DJGPP, but the XZ Utils Makefile is
a bit stupid and expects that everything in DJGPP environment variable
is uppercase.
Building
Just run "make" in this directory (the directory containing this
README). You should get liblzma.a, xz.exe, xzdec.exe, and
lzmadec.exe. Of these, probably xz.exe is the only interesting one.
Note: You need to have an environment that supports long filenames.
Once you have built XZ Utils, the resulting binaries can be run
without long filename support.
Additional Make Flags and Targets
You may want to try some additional optimizations, which may or
may not make the code faster (and may or may not hit possible
compiler bugs more easily):
make CFLAGS="-O3 -fomit-frame-pointer -funroll-loops"
If you want to enable assertions (the assert() macro), use DEBUG=1.
You may want to disable optimizations too if you plan to actually
debug the code. Never use DEBUG=1 for production builds!
make DEBUG=1 CFLAGS="-g -O0"
Bugs
"make clean" may remove src/xz/hardware.c when it tries to remove
src/xz/hardware-fixed.c. This is probably a bug somewhere in the
DOS environment I use. Maybe it tries truncated 8.3 name first and
since that gives a name of an existing file, it doesn't look for
long filename.
"xz -fc /dev/tty" hangs at least in DOSEMU and cannot be interrupted
by pressing C-c. Maybe xz should never accept non-regular files on
DOS even when --force is used.
Using different memory usage limit for encoding and decoding doesn't
make sense under pure DOS. Maybe it is still OK when running under
Windows.
The progress indicator of "xz -v" doesn't get updated when running
under Dosbox, but it works in DOSEMU. I currently (2009-02-13) don't
know if it works in other environments.
Report bugs to <lasse.collin@tukaani.org> (in English or Finnish).

150
dos/config.h Normal file
View File

@@ -0,0 +1,150 @@
/* Define to 1 if using x86 assembler optimizations. */
#define HAVE_ASM_X86 1
/* Define to 1 if crc32 integrity check is enabled. */
#define HAVE_CHECK_CRC32 1
/* Define to 1 if crc64 integrity check is enabled. */
#define HAVE_CHECK_CRC64 1
/* Define to 1 if sha256 integrity check is enabled. */
#define HAVE_CHECK_SHA256 1
/* Define to 1 if decoder components are enabled. */
#define HAVE_DECODER 1
/* Define to 1 if arm decoder is enabled. */
#define HAVE_DECODER_ARM 1
/* Define to 1 if armthumb decoder is enabled. */
#define HAVE_DECODER_ARMTHUMB 1
/* Define to 1 if delta decoder is enabled. */
#define HAVE_DECODER_DELTA 1
/* Define to 1 if ia64 decoder is enabled. */
#define HAVE_DECODER_IA64 1
/* Define to 1 if lzma1 decoder is enabled. */
#define HAVE_DECODER_LZMA1 1
/* Define to 1 if lzma2 decoder is enabled. */
#define HAVE_DECODER_LZMA2 1
/* Define to 1 if powerpc decoder is enabled. */
#define HAVE_DECODER_POWERPC 1
/* Define to 1 if sparc decoder is enabled. */
#define HAVE_DECODER_SPARC 1
/* Define to 1 if subblock decoder is enabled. */
/* #undef HAVE_DECODER_SUBBLOCK */
/* Define to 1 if x86 decoder is enabled. */
#define HAVE_DECODER_X86 1
/* Define to 1 if encoder components are enabled. */
#define HAVE_ENCODER 1
/* Define to 1 if arm encoder is enabled. */
#define HAVE_ENCODER_ARM 1
/* Define to 1 if armthumb encoder is enabled. */
#define HAVE_ENCODER_ARMTHUMB 1
/* Define to 1 if delta encoder is enabled. */
#define HAVE_ENCODER_DELTA 1
/* Define to 1 if ia64 encoder is enabled. */
#define HAVE_ENCODER_IA64 1
/* Define to 1 if lzma1 encoder is enabled. */
#define HAVE_ENCODER_LZMA1 1
/* Define to 1 if lzma2 encoder is enabled. */
#define HAVE_ENCODER_LZMA2 1
/* Define to 1 if powerpc encoder is enabled. */
#define HAVE_ENCODER_POWERPC 1
/* Define to 1 if sparc encoder is enabled. */
#define HAVE_ENCODER_SPARC 1
/* Define to 1 if subblock encoder is enabled. */
/* #undef HAVE_ENCODER_SUBBLOCK */
/* Define to 1 if x86 encoder is enabled. */
#define HAVE_ENCODER_X86 1
/* Define to 1 if the system supports fast unaligned memory access. */
#define HAVE_FAST_UNALIGNED_ACCESS 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 to enable bt2 match finder. */
#define HAVE_MF_BT2 1
/* Define to 1 to enable bt3 match finder. */
#define HAVE_MF_BT3 1
/* Define to 1 to enable bt4 match finder. */
#define HAVE_MF_BT4 1
/* Define to 1 to enable hc3 match finder. */
#define HAVE_MF_HC3 1
/* Define to 1 to enable hc4 match finder. */
#define HAVE_MF_HC4 1
/* Define to 1 if optimizing for size. */
/* #undef HAVE_SMALL */
/* Define to 1 if stdbool.h conforms to C99. */
#define HAVE_STDBOOL_H 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if the system has the type `uintptr_t'. */
#define HAVE_UINTPTR_T 1
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define to 1 if you have the `utimes' function. */
#define HAVE_UTIMES 1
/* Define to 1 or 0, depending whether the compiler supports simple visibility
declarations. */
#define HAVE_VISIBILITY 0
/* Define to 1 if the system has the type `_Bool'. */
#define HAVE__BOOL 1
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "lasse.collin@tukaani.org"
/* Define to the full name of this package. */
#define PACKAGE_NAME "XZ Utils"
/* The size of `size_t', as computed by sizeof. */
#define SIZEOF_SIZE_T 4
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1

115
extra/7z2lzma/7z2lzma.bash Executable file
View File

@@ -0,0 +1,115 @@
#!/bin/bash
#
#############################################################################
#
# 7z2lzma.bash is very primitive .7z to .lzma converter. The input file must
# have exactly one LZMA compressed stream, which has been created with the
# default lc, lp, and pb values. The CRC32 in the .7z archive is not checked,
# and the script may seem to succeed while it actually created a corrupt .lzma
# file. You should always try uncompressing both the original .7z and the
# created .lzma and compare that the output is identical.
#
# This script requires basic GNU tools and 7z or 7za tool from p7zip.
#
# Last modified: 2009-01-15 14:25+0200
#
#############################################################################
#
# Author: Lasse Collin <lasse.collin@tukaani.org>
#
# This file has been put into the public domain.
# You can do whatever you want with this file.
#
#############################################################################
# You can use 7z or 7za, both will work.
SEVENZIP=7za
if [ $# != 2 -o -z "$1" -o -z "$2" ]; then
echo "Usage: $0 input.7z output.lzma"
exit 1
fi
# Converts an integer variable to little endian binary integer.
int2bin()
{
local LEN=$1
local NUM=$2
local HEX=(0 1 2 3 4 5 6 7 8 9 A B C D E F)
local I
for ((I=0; I < "$LEN"; ++I)); do
printf "\\x${HEX[(NUM >> 4) & 0x0F]}${HEX[NUM & 0x0F]}"
NUM=$((NUM >> 8))
done
}
# Make sure we get possible errors from pipes.
set -o pipefail
# Get information about the input file. At least older 7z and 7za versions
# may return with zero exit status even when an error occurred, so check
# if the output has any lines beginning with "Error".
INFO=$("$SEVENZIP" l -slt "$1")
if [ $? != 0 ] || printf '%s\n' "$INFO" | grep -q ^Error; then
printf '%s\n' "$INFO"
exit 1
fi
# Check if the input file has more than one compressed block.
if printf '%s\n' "$INFO" | grep -q '^Block = 1'; then
echo "Cannot convert, because the input file has more than"
echo "one compressed block."
exit 1
fi
# Get copmressed, uncompressed, and dictionary size.
CSIZE=$(printf '%s\n' "$INFO" | sed -rn 's|^Packed Size = ([0-9]+$)|\1|p')
USIZE=$(printf '%s\n' "$INFO" | sed -rn 's|^Size = ([0-9]+$)|\1|p')
DICT=$(printf '%s\n' "$INFO" | sed -rn 's|^Method = LZMA:([0-9]+[bkm]?)$|\1|p')
if [ -z "$CSIZE" -o -z "$USIZE" -o -z "$DICT" ]; then
echo "Parsing output of $SEVENZIP failed. Maybe the file uses some"
echo "other compression method than plain LZMA."
exit 1
fi
# The following assumes that the default lc, lp, and pb settings were used.
# Otherwise the output will be corrupt.
printf '\x5D' > "$2"
# Dictionary size can be either was power of two, bytes, kibibytes, or
# mebibytes. We need to convert it to bytes.
case $DICT in
*b)
DICT=${DICT%b}
;;
*k)
DICT=${DICT%k}
DICT=$((DICT << 10))
;;
*m)
DICT=${DICT%m}
DICT=$((DICT << 20))
;;
*)
DICT=$((1 << DICT))
;;
esac
int2bin 4 "$DICT" >> "$2"
# Uncompressed size
int2bin 8 "$USIZE" >> "$2"
# Copy the actual compressed data. Using multiple dd commands to avoid
# copying large amount of data with one-byte block size, which would be
# annoyingly slow.
BS=8192
BIGSIZE=$((CSIZE / BS))
CSIZE=$((CSIZE % BS))
{
dd of=/dev/null bs=32 count=1 \
&& dd bs="$BS" count="$BIGSIZE" \
&& dd bs=1 count="$CSIZE"
} < "$1" >> "$2"
exit $?

View File

@@ -64,11 +64,11 @@ int main(int argc, char *argv[]) {
ret = fread(buf, BUFSIZE, 1, stdin);
if (ret != 1)
break;
/* Scan for signature. */
for (i = 0; i<BUFSIZE-23; i++) {
if (find_lzma_header(buf+i) && numlzma-- <= 0) {
fwrite(buf+i, (BUFSIZE-i), 1, stdout);
fwrite(buf+i, (BUFSIZE-i), 1, stdout);
for (;;) {
int ch;
ch = getchar();
@@ -76,7 +76,6 @@ int main(int argc, char *argv[]) {
exit(0);
putchar(ch);
}
}
}
blocks++;

View File

@@ -1,40 +1,32 @@
##
## Copyright (C) 2004-2007 Free Software Foundation, Inc.
## Copyright (C) 2007 Lasse Collin
## Copyright (C) 2004-2007 Free Software Foundation, Inc.
##
## 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.
##
## Not using gnulib-tool, at least for now. Less mess this way.
## Not using gnulib-tool, at least for now. It is likely that we won't
## need anything else from Gnulib than getopt_long().
## We need two builds of libgnu: one with NLS and one without.
## This is because lzma uses NLS but lzmadec doesn't, while
## both need GNU getopt_long().
noinst_LIBRARIES = libgnu.a libgnu_nls.a
noinst_LIBRARIES = libgnu.a
libgnu_a_SOURCES =
libgnu_a_DEPENDENCIES = $(LIBOBJS)
libgnu_a_LIBADD = $(LIBOBJS)
libgnu_a_CPPFLAGS = -DDISABLE_NLS=1
libgnu_nls_a_SOURCES =
libgnu_nls_a_DEPENDENCIES = $(LIBOBJS)
libgnu_nls_a_LIBADD = $(LIBOBJS)
EXTRA_DIST = gettext.h getopt_.h getopt.c getopt1.c getopt_int.h
EXTRA_DIST = getopt.in.h getopt.c getopt1.c getopt_int.h
BUILT_SOURCES = $(GETOPT_H)
MOSTLYCLEANFILES = getopt.h getopt.h-t
getopt.h: getopt_.h
getopt.h: getopt.in.h
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
cat $(srcdir)/getopt_.h; \
cat $(srcdir)/getopt.in.h; \
} > $@-t
mv -f $@-t $@

View File

@@ -7,16 +7,16 @@
This file is part of the GNU C Library.
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, or (at your option)
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1, 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.
GNU Lesser General Public License for more details.
You should have received a copy of the GNU General Public License along
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
@@ -35,12 +35,18 @@
# include <unixlib.h>
#endif
/* Completely disable NLS for getopt. We won't include translations for it
anyway. If the system lacks getopt_long, missing translations probably
aren't a problem. */
/*
#ifdef _LIBC
# include <libintl.h>
#else
# include "gettext.h"
# define _(msgid) gettext (msgid)
#endif
*/
#define _(msgid) (msgid)
#if defined _LIBC && defined USE_IN_LIBIO
# include <wchar.h>

View File

@@ -4,16 +4,16 @@
This file is part of the GNU C Library.
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, or (at your option)
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1, 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.
GNU Lesser General Public License for more details.
You should have received a copy of the GNU General Public License along
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */

View File

@@ -4,16 +4,16 @@
This file is part of the GNU C Library.
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, or (at your option)
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1, 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.
GNU Lesser General Public License for more details.
You should have received a copy of the GNU General Public License along
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */

View File

@@ -1,240 +0,0 @@
/* Convenience header for conditional use of GNU <libintl.h>.
Copyright (C) 1995-1998, 2000-2002, 2004-2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published
by the Free Software Foundation; either version 2, 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA. */
#ifndef _LIBGETTEXT_H
#define _LIBGETTEXT_H 1
/* NLS can be disabled through the configure --disable-nls option.
*
* Extra hack in LZMA Utils: if DISABLE_NLS is defined, NLS is disabled
* even if ENABLE_NLS is true. See Makefile.am for more information.
*/
#if ENABLE_NLS && !defined(DISABLE_NLS)
/* Get declarations of GNU message catalog functions. */
# include <libintl.h>
/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
the gettext() and ngettext() macros. This is an alternative to calling
textdomain(), and is useful for libraries. */
# ifdef DEFAULT_TEXT_DOMAIN
# undef gettext
# define gettext(Msgid) \
dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
# undef ngettext
# define ngettext(Msgid1, Msgid2, N) \
dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
# endif
#else
/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
chokes if dcgettext is defined as a macro. So include it now, to make
later inclusions of <locale.h> a NOP. We don't include <libintl.h>
as well because people using "gettext.h" will not include <libintl.h>,
and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
is OK. */
#if defined(__sun)
# include <locale.h>
#endif
/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
<libintl.h>, which chokes if dcgettext is defined as a macro. So include
it now, to make later inclusions of <libintl.h> a NOP. */
#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
# include <cstdlib>
# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H
# include <libintl.h>
# endif
#endif
/* Disabled NLS.
The casts to 'const char *' serve the purpose of producing warnings
for invalid uses of the value returned from these functions.
On pre-ANSI systems without 'const', the config.h file is supposed to
contain "#define const". */
# define gettext(Msgid) ((const char *) (Msgid))
# define dgettext(Domainname, Msgid) ((const char *) (Msgid))
# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
# define ngettext(Msgid1, Msgid2, N) \
((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
# define dngettext(Domainname, Msgid1, Msgid2, N) \
((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
# define textdomain(Domainname) ((const char *) (Domainname))
# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname))
# define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset))
#endif
/* A pseudo function call that serves as a marker for the automated
extraction of messages, but does not call gettext(). The run-time
translation is done at a different place in the code.
The argument, String, should be a literal string. Concatenated strings
and other string expressions won't work.
The macro's expansion is not parenthesized, so that it is suitable as
initializer for static 'char[]' or 'const char[]' variables. */
#define gettext_noop(String) String
/* The separator between msgctxt and msgid in a .mo file. */
#define GETTEXT_CONTEXT_GLUE "\004"
/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be
short and rarely need to change.
The letter 'p' stands for 'particular' or 'special'. */
#ifdef DEFAULT_TEXT_DOMAIN
# define pgettext(Msgctxt, Msgid) \
pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
#else
# define pgettext(Msgctxt, Msgid) \
pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
#endif
#define dpgettext(Domainname, Msgctxt, Msgid) \
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
#ifdef DEFAULT_TEXT_DOMAIN
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
#else
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
#endif
#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
static inline const char *
pgettext_aux (const char *domain,
const char *msg_ctxt_id, const char *msgid,
int category)
{
const char *translation = dcgettext (domain, msg_ctxt_id, category);
if (translation == msg_ctxt_id)
return msgid;
else
return translation;
}
static inline const char *
npgettext_aux (const char *domain,
const char *msg_ctxt_id, const char *msgid,
const char *msgid_plural, unsigned long int n,
int category)
{
const char *translation =
dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
if (translation == msg_ctxt_id || translation == msgid_plural)
return (n == 1 ? msgid : msgid_plural);
else
return translation;
}
/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID
can be arbitrary expressions. But for string literals these macros are
less efficient than those above. */
#include <string.h>
#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
#include <stdlib.h>
#endif
#define pgettext_expr(Msgctxt, Msgid) \
dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
static inline const char *
dcpgettext_expr (const char *domain,
const char *msgctxt, const char *msgid,
int category)
{
size_t msgctxt_len = strlen (msgctxt) + 1;
size_t msgid_len = strlen (msgid) + 1;
const char *translation;
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
char msg_ctxt_id[msgctxt_len + msgid_len];
#else
char buf[1024];
char *msg_ctxt_id =
(msgctxt_len + msgid_len <= sizeof (buf)
? buf
: (char *) malloc (msgctxt_len + msgid_len));
if (msg_ctxt_id != NULL)
#endif
{
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
msg_ctxt_id[msgctxt_len - 1] = '\004';
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
translation = dcgettext (domain, msg_ctxt_id, category);
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
if (msg_ctxt_id != buf)
free (msg_ctxt_id);
#endif
if (translation != msg_ctxt_id)
return translation;
}
return msgid;
}
#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
static inline const char *
dcnpgettext_expr (const char *domain,
const char *msgctxt, const char *msgid,
const char *msgid_plural, unsigned long int n,
int category)
{
size_t msgctxt_len = strlen (msgctxt) + 1;
size_t msgid_len = strlen (msgid) + 1;
const char *translation;
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
char msg_ctxt_id[msgctxt_len + msgid_len];
#else
char buf[1024];
char *msg_ctxt_id =
(msgctxt_len + msgid_len <= sizeof (buf)
? buf
: (char *) malloc (msgctxt_len + msgid_len));
if (msg_ctxt_id != NULL)
#endif
{
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
msg_ctxt_id[msgctxt_len - 1] = '\004';
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
if (msg_ctxt_id != buf)
free (msg_ctxt_id);
#endif
if (!(translation == msg_ctxt_id || translation == msgid_plural))
return translation;
}
return (n == 1 ? msgid : msgid_plural);
}
#endif /* _LIBGETTEXT_H */

35
m4/.gitignore vendored Normal file
View File

@@ -0,0 +1,35 @@
codeset.m4
gettext.m4
glibc2.m4
glibc21.m4
iconv.m4
intdiv0.m4
intl.m4
intldir.m4
intmax.m4
inttypes-pri.m4
inttypes_h.m4
lcmessage.m4
lib-ld.m4
lib-link.m4
lib-prefix.m4
libtool.m4
lock.m4
longdouble.m4
longlong.m4
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
nls.m4
po.m4
printf-posix.m4
progtest.m4
size_max.m4
stdint_h.m4
uintmax_t.m4
ulonglong.m4
visibility.m4
wchar_t.m4
wint_t.m4
xsize.m4

View File

@@ -1,5 +1,5 @@
# getopt.m4 serial 13
dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
# getopt.m4 serial 14 (modified version)
dnl Copyright (C) 2002-2006, 2008 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
@@ -13,7 +13,6 @@ AC_DEFUN([gl_GETOPT_SUBSTITUTE],
AC_LIBOBJ([getopt])
AC_LIBOBJ([getopt1])
gl_GETOPT_SUBSTITUTE_HEADER
gl_PREREQ_GETOPT
])
AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER],
@@ -32,40 +31,35 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
fi
if test -z "$GETOPT_H"; then
AC_CHECK_FUNCS([getopt_long_only], [], [GETOPT_H=getopt.h])
AC_CHECK_FUNCS([getopt_long], [], [GETOPT_H=getopt.h])
fi
dnl BSD getopt_long uses an incompatible method to reset option processing,
dnl and (as of 2004-10-15) mishandles optional option-arguments.
dnl BSD getopt_long uses a way to reset option processing, that is different
dnl from GNU and Solaris (which copied the GNU behavior). We support both
dnl GNU and BSD style resetting of getopt_long(), so there's no need to use
dnl GNU getopt_long() on BSD due to different resetting style.
dnl
dnl With getopt_long(), some BSD versions have a bug in handling optional
dnl arguments. This bug appears only if the environment variable
dnl POSIXLY_CORRECT has been set, so it shouldn't be too bad in most
dnl cases; probably most don't have that variable set. But if we actually
dnl hit this bug, it is a real problem due to our heavy use of optional
dnl arguments.
dnl
dnl According to CVS logs, the bug was introduced in OpenBSD in 2003-09-22
dnl and copied to FreeBSD in 2004-02-24. It was fixed in both in 2006-09-22,
dnl so the affected versions shouldn't be popular anymore anyway. NetBSD
dnl never had this bug. TODO: What about Darwin and others?
if test -z "$GETOPT_H"; then
AC_CHECK_DECL([optreset], [GETOPT_H=getopt.h], [], [#include <getopt.h>])
AC_CHECK_DECL([optreset],
[AC_DEFINE([HAVE_OPTRESET], 1,
[Define to 1 if getopt.h declares extern int optreset.])],
[], [#include <getopt.h>])
fi
dnl Solaris 10 getopt doesn't handle `+' as a leading character in an
dnl option string (as of 2005-05-05).
if test -z "$GETOPT_H"; then
AC_CACHE_CHECK([for working GNU getopt function], [gl_cv_func_gnu_getopt],
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM([#include <getopt.h>],
[[
char *myargv[3];
myargv[0] = "conftest";
myargv[1] = "-+";
myargv[2] = 0;
return getopt (2, myargv, "+a") != '?';
]])],
[gl_cv_func_gnu_getopt=yes],
[gl_cv_func_gnu_getopt=no],
[dnl cross compiling - pessimistically guess based on decls
dnl Solaris 10 getopt doesn't handle `+' as a leading character in an
dnl option string (as of 2005-05-05).
AC_CHECK_DECL([getopt_clip],
[gl_cv_func_gnu_getopt=no], [gl_cv_func_gnu_getopt=yes],
[#include <getopt.h>])])])
if test "$gl_cv_func_gnu_getopt" = "no"; then
GETOPT_H=getopt.h
fi
fi
dnl option string (as of 2005-05-05). We don't use that feature, so this
dnl is not a problem for us. Thus, the respective test was removed here.
])
AC_DEFUN([gl_GETOPT_IFELSE],
@@ -75,9 +69,3 @@ AC_DEFUN([gl_GETOPT_IFELSE],
])
AC_DEFUN([gl_GETOPT], [gl_GETOPT_IFELSE([gl_GETOPT_SUBSTITUTE])])
# Prerequisites of lib/getopt*.
AC_DEFUN([gl_PREREQ_GETOPT],
[
AC_CHECK_DECLS_ONCE([getenv])
])

57
m4/lc_cpucores.m4 Normal file
View File

@@ -0,0 +1,57 @@
dnl ###########################################################################
dnl
dnl lc_CPUCORES - Check how to find out the number of online CPU cores
dnl
dnl Check how to find out the number of available CPU cores in the system.
dnl sysconf(_SC_NPROCESSORS_ONLN) works on most systems, except that BSDs
dnl use sysctl().
dnl
dnl ###########################################################################
dnl
dnl Author: Lasse Collin
dnl
dnl This file has been put into the public domain.
dnl You can do whatever you want with this file.
dnl
dnl ###########################################################################
AC_DEFUN([lc_CPUCORES], [
AC_MSG_CHECKING([how to detect the number of available CPU cores])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include <unistd.h>
int
main(void)
{
long i;
i = sysconf(_SC_NPROCESSORS_ONLN);
return 0;
}
]])], [
AC_DEFINE([HAVE_CPUCORES_SYSCONF], [1],
[Define to 1 if the number of available CPU cores can be
detected with sysconf(_SC_NPROCESSORS_ONLN).])
AC_MSG_RESULT([sysconf])
], [
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include <sys/types.h>
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
#include <sys/sysctl.h>
int
main(void)
{
int name[2] = { CTL_HW, HW_NCPU };
int cpus;
size_t cpus_size = sizeof(cpus);
sysctl(name, 2, &cpus, &cpus_size, NULL, NULL);
return 0;
}
]])], [
AC_DEFINE([HAVE_CPUCORES_SYSCTL], [1],
[Define to 1 if the number of available CPU cores can be
detected with sysctl().])
AC_MSG_RESULT([sysctl])
], [
AC_MSG_RESULT([unknown])
])])
])dnl lc_CPUCORES

84
m4/lc_physmem.m4 Normal file
View File

@@ -0,0 +1,84 @@
dnl ###########################################################################
dnl
dnl lc_PHYSMEM - Check how to find out the amount of physical memory
dnl
dnl - sysconf() gives all the needed info on GNU+Linux and Solaris.
dnl - BSDs use sysctl().
dnl - sysinfo() works on Linux/dietlibc and probably on other Linux systems
dnl whose libc may lack sysconf().
dnl
dnl ###########################################################################
dnl
dnl Author: Lasse Collin
dnl
dnl This file has been put into the public domain.
dnl You can do whatever you want with this file.
dnl
dnl ###########################################################################
AC_DEFUN([lc_PHYSMEM], [
AC_MSG_CHECKING([how to detect the amount of physical memory])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include <unistd.h>
int
main(void)
{
long i;
i = sysconf(_SC_PAGESIZE);
i = sysconf(_SC_PHYS_PAGES);
return 0;
}
]])], [
AC_DEFINE([HAVE_PHYSMEM_SYSCONF], [1],
[Define to 1 if the amount of physical memory can be detected
with sysconf(_SC_PAGESIZE) and sysconf(_SC_PHYS_PAGES).])
AC_MSG_RESULT([sysconf])
], [
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include <sys/types.h>
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
#include <sys/sysctl.h>
int
main(void)
{
int name[2] = { CTL_HW, HW_PHYSMEM };
unsigned long mem;
size_t mem_ptr_size = sizeof(mem);
sysctl(name, 2, &mem, &mem_ptr_size, NULL, NULL);
return 0;
}
]])], [
AC_DEFINE([HAVE_PHYSMEM_SYSCTL], [1],
[Define to 1 if the amount of physical memory can be detected
with sysctl().])
AC_MSG_RESULT([sysctl])
], [
dnl sysinfo() is Linux-specific. Some non-Linux systems have
dnl incompatible sysinfo() so we must check $host_os.
case $host_os in
linux*)
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include <sys/sysinfo.h>
int
main(void)
{
struct sysinfo si;
sysinfo(&si);
return 0;
}
]])], [
AC_DEFINE([HAVE_PHYSMEM_SYSINFO], [1],
[Define to 1 if the amount of physical memory
can be detected with Linux sysinfo().])
AC_MSG_RESULT([sysinfo])
], [
AC_MSG_RESULT([unknown])
])
;;
*)
AC_MSG_RESULT([unknown])
;;
esac
])])
])dnl lc_PHYSMEM

63
m4/posix-shell.m4 Normal file
View File

@@ -0,0 +1,63 @@
# Find a POSIX-conforming shell.
# Copyright (C) 2007-2008 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# Written by Paul Eggert.
# If a POSIX-conforming shell can be found, set POSIX_SHELL and
# PREFERABLY_POSIX_SHELL to it. If not, set POSIX_SHELL to the
# empty string and PREFERABLY_POSIX_SHELL to '/bin/sh'.
AC_DEFUN([gl_POSIX_SHELL],
[
AC_CACHE_CHECK([for a shell that conforms to POSIX], [gl_cv_posix_shell],
[gl_test_posix_shell_script='
func_return () {
(exit [$]1)
}
func_success () {
func_return 0
}
func_failure () {
func_return 1
}
func_ret_success () {
return 0
}
func_ret_failure () {
return 1
}
subshell_umask_sanity () {
(umask 22; (umask 0); test $(umask) -eq 22)
}
test "[$](echo foo)" = foo &&
func_success &&
! func_failure &&
func_ret_success &&
! func_ret_failure &&
(set x && func_ret_success y && test x = "[$]1") &&
subshell_umask_sanity
'
for gl_cv_posix_shell in \
"$CONFIG_SHELL" "$SHELL" /bin/sh /bin/bash /bin/ksh /bin/sh5 no; do
case $gl_cv_posix_shell in
/*)
"$gl_cv_posix_shell" -c "$gl_test_posix_shell_script" 2>/dev/null \
&& break;;
esac
done])
if test "$gl_cv_posix_shell" != no; then
POSIX_SHELL=$gl_cv_posix_shell
PREFERABLY_POSIX_SHELL=$POSIX_SHELL
else
POSIX_SHELL=
PREFERABLY_POSIX_SHELL=/bin/sh
fi
AC_SUBST([POSIX_SHELL])
AC_SUBST([PREFERABLY_POSIX_SHELL])
])

15
po/.gitignore vendored Normal file
View File

@@ -0,0 +1,15 @@
boldquot.sed
en@boldquot.header
en@quot.header
insert-header.sin
Makefile
Makefile.in
Makefile.in.in
Makevars.template
POTFILES
quot.sed
remove-potcdate.sed
remove-potcdate.sin
Rules-quot
stamp-po
xz.pot

View File

@@ -1 +0,0 @@
fi

View File

@@ -1,13 +1,10 @@
# List of source files which contain translatable strings.
src/lzma/help.c
src/lzma/alloc.c
src/lzma/args.c
src/lzma/error.c
src/lzma/io.c
src/lzma/list.c
src/lzma/main.c
src/lzma/options.c
src/lzma/process.c
src/lzma/suffix.c
src/lzma/util.c
lib/getopt.c
src/xz/args.c
src/xz/coder.c
src/xz/file_io.c
src/xz/hardware.c
src/xz/main.c
src/xz/message.c
src/xz/options.c
src/xz/suffix.c
src/xz/util.c

446
po/fi.po
View File

@@ -1,446 +0,0 @@
# translation of fi.po to Finnish
# This file is put in the public domain.
#
msgid ""
msgstr ""
"Project-Id-Version: fi\n"
"Report-Msgid-Bugs-To: lasse.collin@tukaani.org\n"
"POT-Creation-Date: 2007-12-10 14:34+0200\n"
"PO-Revision-Date: 2007-08-09 22:14+0300\n"
"Last-Translator: Lasse Collin <lasse.collin@tukaani.org>\n"
"Language-Team: Finnish\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: src/lzma/help.c:28
#, c-format
msgid "Try `%s --help' for more information."
msgstr "Lisätietoja saa komennolla \"%s --help\"."
#: src/lzma/help.c:36
#, c-format
msgid ""
"Usage: %s [OPTION]... [FILE]...\n"
"Compress or decompress FILEs in the .lzma format.\n"
"\n"
msgstr ""
"Käyttö: %s [VALITSIN]... [TIEDOSTO]...\n"
"Pakkaa tai purkaa .lzma-muotoiset TIEDOSTOt\n"
"\n"
#: src/lzma/help.c:40
msgid "Mandatory arguments to long options are mandatory for short options too.\n"
msgstr "Pitkien valitsinten pakolliset argumentit ovat pakollisia myös lyhyille.\n"
#: src/lzma/help.c:44
msgid ""
" Operation mode:\n"
"\n"
" -z, --compress force compression\n"
" -d, --decompress force decompression\n"
" -t, --test test compressed file integrity\n"
" -l, --list list block sizes, total sizes, and possible metadata\n"
msgstr ""
#: src/lzma/help.c:53
msgid ""
" Operation modifiers:\n"
"\n"
" -k, --keep keep (don't delete) input files\n"
" -f, --force force overwrite of output file and (de)compress links\n"
" -c, --stdout write to standard output and don't delete input files\n"
" -S, --suffix=.SUF use suffix `.SUF' on compressed files instead of `.lzma'\n"
" -F, --format=FMT file format to encode or decode; possible values are\n"
" `auto', `native', `single', `multi', and `alone'\n"
" --files=[FILE] read filenames to process from FILE; if FILE is\n"
" omitted, filenames are read from the standard input;\n"
" filenames must be terminated with the newline character\n"
" --files0=[FILE] like --files but use the nul byte as terminator\n"
msgstr ""
#: src/lzma/help.c:68
msgid ""
" Compression presets and basic compression options:\n"
"\n"
" -1 .. -2 fast compression\n"
" -3 .. -6 good compression\n"
" -7 .. -9 excellent compression, but needs a lot of memory;\n"
" default is -7 if memory limit allows\n"
"\n"
" -C, --check=CHECK integrity check type: `crc32', `crc64' (default),\n"
" or `sha256'\n"
msgstr ""
#: src/lzma/help.c:80
msgid ""
" Custom filter chain for compression (alternative for using presets):\n"
"\n"
" --lzma=[OPTS] LZMA filter; OPTS is a comma-separated list of zero or\n"
" more of the following options (valid values; default):\n"
" dict=NUM dictionary size in bytes (1 - 1Gi; 8Mi)\n"
" lc=NUM number of literal context bits (0-8; 3)\n"
" lp=NUM number of literal position bits (0-4; 0)\n"
" pb=NUM number of position bits (0-4; 2)\n"
" mode=MODE compression mode (`fast' or `best'; `best')\n"
" fb=NUM number of fast bytes (5-273; 128)\n"
" mf=NAME match finder (hc3, hc4, bt2, bt3, bt4; bt4)\n"
" mfc=NUM match finder cycles; 0=automatic (default)\n"
"\n"
" --x86 x86 filter (sometimes called BCJ filter)\n"
" --powerpc PowerPC (big endian) filter\n"
" --ia64 IA64 (Itanium) filter\n"
" --arm ARM filter\n"
" --armthumb ARM-Thumb filter\n"
" --sparc SPARC filter\n"
"\n"
" --copy No filtering (useful only when specified alone)\n"
" --subblock=[OPTS] Subblock filter; valid OPTS (valid values; default):\n"
" size=NUM number of bytes of data per subblock\n"
" (1 - 256Mi; 4Ki)\n"
" rle=NUM run-length encoder chunk size (0-256; 0)\n"
msgstr ""
#: src/lzma/help.c:120
msgid ""
" Resource usage options:\n"
"\n"
" -M, --memory=NUM use roughly NUM bytes of memory at maximum\n"
" -T, --threads=NUM use at maximum of NUM (de)compression threads\n"
msgstr ""
#: src/lzma/help.c:129
msgid ""
" Other options:\n"
"\n"
" -q, --quiet suppress warnings; specify twice to suppress errors too\n"
" -v, --verbose be verbose; specify twice for even more verbose\n"
"\n"
" -h, --help display this help and exit\n"
" -V, --version display version and license information and exit\n"
msgstr ""
#: src/lzma/help.c:137
msgid "With no FILE, or when FILE is -, read standard input.\n"
msgstr "Jos TIEDOSTOa ei ole annettu, tai se on \"-\", luetaan vakiosyötettä.\n"
#: src/lzma/help.c:143
msgid "On this system and configuration, the tool will use"
msgstr "Tässä järjestelmässä näillä asetuksilla, tämä työkalu käyttää"
#: src/lzma/help.c:144
#, c-format
msgid " * roughly %zu MiB of memory at maximum; and\n"
msgstr " * korkeintaan %zu MiB keskusmuistia (suurpiirteinen rajoitus); ja\n"
#: src/lzma/help.c:147
msgid ""
" * at maximum of one thread for (de)compression.\n"
"\n"
msgstr ""
" * korkeintaan yhtä säiettä pakkaukseen tai purkuun.\n"
"\n"
#: src/lzma/help.c:151
#, c-format
msgid "Report bugs to <%s> (in English or Finnish).\n"
msgstr ""
"Lähetä raportit ohjelmistovioista (englanniksi tai suomeksi)\n"
"osoitteeseen <%s>.\n"
#: src/lzma/args.c:128
msgid "Maximum number of filters is seven"
msgstr "Suotimia voi olla korkeintaan seitsemän"
#: src/lzma/args.c:193
#, c-format
msgid "%s: Invalid filename suffix"
msgstr "%s: Virheellinen tiedostonimen pääte"
#: src/lzma/args.c:327
#, c-format
msgid "%s: Unknown file format type"
msgstr "%s: Tuntematon tiedostomuodon tyyppi"
#: src/lzma/args.c:353
#, c-format
msgid "%s: Unknown integrity check type"
msgstr "%s: Tuntematon eheystarkisteen tyyppi"
#: src/lzma/args.c:371
msgid "Only one file can be specified with `--files'or `--files0'."
msgstr ""
#: src/lzma/args.c:421
msgid "The environment variable LZMA_OPT contains too many arguments"
msgstr "Ympäristömuuttuja LZMA_OPT sisältää liian monta argumenttia"
#: src/lzma/args.c:485
msgid "Memory usage limit is too small for any internal filter preset"
msgstr ""
#: src/lzma/args.c:500
msgid "Memory usage limit is too small for the given filter setup"
msgstr "Muistinkäyttörajoitus on liian pieni annetuille suodinasetusille"
#: src/lzma/error.c:35
msgid "Operation successful"
msgstr ""
#: src/lzma/error.c:38
msgid "Operation finished successfully"
msgstr ""
#: src/lzma/error.c:41 src/lzma/error.c:153
msgid "Internal error (bug)"
msgstr "Sisäinen virhe (bugi)"
#: src/lzma/error.c:44
msgid "Compressed data is corrupt"
msgstr "Pakattu data on korruptoitunut"
#: src/lzma/error.c:50
msgid "Unexpected end of input"
msgstr ""
#: src/lzma/error.c:53
msgid "Unsupported options"
msgstr ""
#: src/lzma/error.c:56
msgid "Unsupported integrity check type"
msgstr ""
#: src/lzma/error.c:87 src/lzma/error.c:93
#, c-format
msgid "Writing to standard output failed: %s"
msgstr ""
#: src/lzma/io.c:81
#, c-format
msgid "Cannot get file descriptor of the current directory: %s"
msgstr ""
#: src/lzma/io.c:123 src/lzma/util.c:127
#, c-format
msgid "%s: Invalid filename"
msgstr "%s: Virheellinen tiedostonimi"
#: src/lzma/io.c:130 src/lzma/io.c:233
#, c-format
msgid "Cannot change directory: %s"
msgstr "Hakemiston vaihtaminen epäonnistui: %s"
#: src/lzma/io.c:135
#, c-format
msgid "%s: File seems to be moved, not removing"
msgstr "%s: Tiedosto näyttää olevan siirretty, ei poisteta"
#: src/lzma/io.c:141
#, c-format
msgid "%s: Cannot remove: %s"
msgstr ""
#: src/lzma/io.c:164
#, c-format
msgid "%s: Cannot set the file owner: %s"
msgstr "%s: Tiedoston omistajuuden asetus epäonnistui: %s"
#: src/lzma/io.c:170
#, c-format
msgid "%s: Cannot set the file group: %s"
msgstr "%s: Tiedoston ryhmän asetus epäonnistui: %s"
#: src/lzma/io.c:189
#, c-format
msgid "%s: Cannot set the file permissions: %s"
msgstr "%s: Tiedoston oikeuksien asetus epäonnistui: %s"
#: src/lzma/io.c:252
#, c-format
msgid "%s: Cannot open the directory containing the file: %s"
msgstr ""
#: src/lzma/io.c:313
#, c-format
msgid "%s: Is a symbolic link, skipping"
msgstr "%s: Symbolinen linkki, ohitetaan"
#: src/lzma/io.c:330
#, c-format
msgid "%s: Is a directory, skipping"
msgstr "%s: Hakemisto, ohitetaan"
#: src/lzma/io.c:337 src/lzma/list.c:445
#, c-format
msgid "%s: Not a regular file, skipping"
msgstr "%s: Ei ole tavallinen tiedosto, ohitetaan"
#: src/lzma/io.c:348
#, c-format
msgid "%s: File has setuid or setgid bit set, skipping"
msgstr "%s: Tiedostolla on setuid- tai setgid-bitti asetettuna, ohitetaan"
#: src/lzma/io.c:355
#, c-format
msgid "%s: File has sticky bit set, skipping"
msgstr "%s: Tiedostolla on sticky-bitti asetettuna, ohitetaan"
#: src/lzma/io.c:362
#, c-format
msgid "%s: Input file has more than one hard link, skipping"
msgstr "%s: Tiedostoon viittaa useampi kuin yksi linkki, ohitetaan"
#: src/lzma/io.c:390 src/lzma/io.c:468
#, c-format
msgid "%s: Closing the file failed: %s"
msgstr "%s: Tiedoston sulkeminen epäonnistui: %s"
#: src/lzma/io.c:611
#, c-format
msgid "%s: Read error: %s"
msgstr "%s: Lukeminen epäonnistui: %s"
#: src/lzma/io.c:654
#, c-format
msgid "%s: Write error: %s"
msgstr "%s: Kirjoitus epäonnistui: %s"
#: src/lzma/list.c:451
#, c-format
msgid "%s: File is empty"
msgstr ""
#: src/lzma/main.c:57
msgid "Cannot establish signal handlers"
msgstr "Signaalikäsittelijöiden asetus epäonnistui"
#: src/lzma/main.c:75
msgid "Compressed data not read from a terminal."
msgstr "Pakattua dataa ei lueta päätteeltä."
#: src/lzma/main.c:77 src/lzma/main.c:92
msgid "Use `--force' to force decompression."
msgstr "Käytä valitsinta \"--force\" pakottaaksesi purun."
#: src/lzma/main.c:90
msgid "Compressed data not written to a terminal."
msgstr "Pakattua dataa ei kirjoiteta päätteelle."
#: src/lzma/main.c:117
#, fuzzy, c-format
msgid "%s: Error reading filenames: %s"
msgstr "%s: Tiedoston sulkeminen epäonnistui: %s"
#: src/lzma/main.c:122
#, c-format
msgid "%s: Unexpected end of input when reading filenames"
msgstr ""
#: src/lzma/main.c:212
msgid "Cannot read data from standard input when reading filenames from standard input"
msgstr "Dataa ei voida lukea oletussyötteestä, kun tiedostonimiä luetaan oletussyötteestä"
#: src/lzma/options.c:83
#, c-format
msgid "%s: Options must be `name=value' pairs separated with commas"
msgstr "%s: Asetusten tulee olla \"nimi=arvo\"-pareja, jotka on eroteltu pilkuilla"
#: src/lzma/options.c:111
#, c-format
msgid "%s: Invalid option value"
msgstr "%s: Virheellinen asetuksen arvo"
#: src/lzma/options.c:124
#, c-format
msgid "%s: Invalid option name"
msgstr "%s: Virheellinen asetuksen nimi"
#: src/lzma/process.c:142
#, c-format
msgid "Cannot create a thread: %s"
msgstr "Säikeen luonti epäonnistui: %s"
#: src/lzma/suffix.c:85
#, c-format
msgid "%s: Filename has an unknown suffix, skipping"
msgstr "%s: Tiedostonimellä on tuntematon pääte, ohitetaan"
#: src/lzma/suffix.c:114
#, c-format
msgid "%s: File already has `%s' suffix, skipping"
msgstr "%s: Tiedostolla on jo \"%s\"-pääte, ohitetaan"
#: src/lzma/util.c:44
#, c-format
msgid "%s: Value is not a non-negative decimal integer"
msgstr ""
#: src/lzma/util.c:84
#, c-format
msgid "%s: Invalid multiplier suffix. Valid suffixes:"
msgstr ""
#: src/lzma/util.c:105
#, c-format
msgid "Value of the option `%s' must be in the range [%llu, %llu]"
msgstr "Asetuksen \"%s\" arvon tulee olla välillä [%llu, %llu]"
#: src/lzma/util.c:177
msgid "Empty filename, skipping"
msgstr "Tyhjä tiedostonimi, ohitetaan"
#: lib/getopt.c:531 lib/getopt.c:547
#, c-format
msgid "%s: option `%s' is ambiguous\n"
msgstr ""
#: lib/getopt.c:580 lib/getopt.c:584
#, c-format
msgid "%s: option `--%s' doesn't allow an argument\n"
msgstr ""
#: lib/getopt.c:593 lib/getopt.c:598
#, c-format
msgid "%s: option `%c%s' doesn't allow an argument\n"
msgstr ""
#: lib/getopt.c:641 lib/getopt.c:660 lib/getopt.c:976 lib/getopt.c:995
#, c-format
msgid "%s: option `%s' requires an argument\n"
msgstr ""
#: lib/getopt.c:698 lib/getopt.c:701
#, c-format
msgid "%s: unrecognized option `--%s'\n"
msgstr ""
#: lib/getopt.c:709 lib/getopt.c:712
#, c-format
msgid "%s: unrecognized option `%c%s'\n"
msgstr ""
#: lib/getopt.c:764 lib/getopt.c:767
#, c-format
msgid "%s: illegal option -- %c\n"
msgstr ""
#: lib/getopt.c:773 lib/getopt.c:776
#, c-format
msgid "%s: invalid option -- %c\n"
msgstr "%s: virheellinen valitsin -- %c\n"
#: lib/getopt.c:828 lib/getopt.c:844 lib/getopt.c:1048 lib/getopt.c:1066
#, c-format
msgid "%s: option requires an argument -- %c\n"
msgstr ""
#: lib/getopt.c:897 lib/getopt.c:913
#, c-format
msgid "%s: option `-W %s' is ambiguous\n"
msgstr ""
#: lib/getopt.c:937 lib/getopt.c:955
#, c-format
msgid "%s: option `-W %s' doesn't allow an argument\n"
msgstr ""

View File

@@ -1,16 +1,9 @@
##
## Copyright (C) 2007 Lasse Collin
## Author: Lasse Collin
##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public
## License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
##
## 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
## Lesser General Public License for more details.
## This file has been put into the public domain.
## You can do whatever you want with this file.
##
SUBDIRS = liblzma lzma lzmadec scripts
SUBDIRS = liblzma xz xzdec lzmainfo scripts
EXTRA_DIST = common

View File

@@ -1,34 +1,43 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file check_byteswap.h
/// \brief Byteswapping needed by the checks
/// \file bswap.h
/// \brief Byte swapping
//
// This code has been put into the public domain.
// Author: Lasse Collin
//
// 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 file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef LZMA_CHECK_BYTESWAP_H
#define LZMA_CHECK_BYTESWAP_H
#ifndef LZMA_BSWAP_H
#define LZMA_BSWAP_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
// NOTE: We assume that config.h is already #included.
// At least glibc has byteswap.h which contains inline assembly code for
// byteswapping. Some systems have byteswap.h but lack one or more of the
// bswap_xx macros/functions, which is why we check them separately even
// if byteswap.h is available.
// byteswap.h is a GNU extension. It contains inline assembly versions
// for byteswapping. When byteswap.h is not available, we use generic code.
#ifdef HAVE_BYTESWAP_H
# include <byteswap.h>
#else
#endif
#ifndef HAVE_BSWAP_16
# define bswap_16(num) \
(((num) << 8) | ((num) >> 8))
#endif
#ifndef HAVE_BSWAP_32
# define bswap_32(num) \
( (((num) << 24) ) \
| (((num) << 8) & UINT32_C(0x00FF0000)) \
| (((num) >> 8) & UINT32_C(0x0000FF00)) \
| (((num) >> 24) ) )
#endif
#ifndef HAVE_BSWAP_64
# define bswap_64(num) \
( (((num) << 56) ) \
| (((num) << 40) & UINT64_C(0x00FF000000000000)) \

View File

@@ -0,0 +1,53 @@
/*
* Author: Lasse Collin
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/
#include <winresrc.h>
#include "config.h"
#define LZMA_H_INTERNAL
#define LZMA_H_INTERNAL_RC
#include "lzma/version.h"
#ifndef MY_BUILD
# define MY_BUILD 0
#endif
#define MY_VERSION LZMA_VERSION_MAJOR,LZMA_VERSION_MINOR,LZMA_VERSION_PATCH,MY_BUILD
#define MY_FILENAME MY_NAME MY_SUFFIX
#define MY_COMPANY "Lasse Collin and Igor Pavlov"
#define MY_COPYRIGHT "Public Domain by " MY_COMPANY
#define MY_COMMENTS "http://tukaani.org/xz/"
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
VS_VERSION_INFO VERSIONINFO
FILEVERSION MY_VERSION
PRODUCTVERSION MY_VERSION
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEFLAGS 0
FILEOS VOS_NT_WINDOWS32
FILETYPE MY_TYPE
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", MY_COMMENTS
VALUE "CompanyName", MY_COMPANY
VALUE "FileDescription", MY_DESC
VALUE "FileVersion", LZMA_VERSION_STRING
VALUE "InternalName", MY_NAME
VALUE "LegalCopyright", MY_COPYRIGHT
VALUE "OriginalFilename", MY_FILENAME
VALUE "ProductName", PACKAGE_NAME
VALUE "ProductVersion", LZMA_VERSION_STRING
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END

51
src/common/cpucores.h Normal file
View File

@@ -0,0 +1,51 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file cpucores.h
/// \brief Get the number of online CPU cores
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef CPUCORES_H
#define CPUCORES_H
#if defined(HAVE_CPUCORES_SYSCONF)
# include <unistd.h>
#elif defined(HAVE_CPUCORES_SYSCTL)
# ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
# endif
# ifdef HAVE_SYS_SYSCTL_H
# include <sys/sysctl.h>
# endif
#endif
static inline uint32_t
cpucores(void)
{
uint32_t ret = 0;
#if defined(HAVE_CPUCORES_SYSCONF)
const long cpus = sysconf(_SC_NPROCESSORS_ONLN);
if (cpus > 0)
ret = (uint32_t)(cpus);
#elif defined(HAVE_CPUCORES_SYSCTL)
int name[2] = { CTL_HW, HW_NCPU };
int cpus;
size_t cpus_size = sizeof(cpus);
if (!sysctl(name, &cpus, &cpus_size, NULL, NULL)
&& cpus_size == sizeof(cpus) && cpus > 0)
ret = (uint32_t)(cpus);
#endif
return ret;
}
#endif

170
src/common/integer.h Normal file
View File

@@ -0,0 +1,170 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file integer.h
/// \brief Reading and writing integers from and to buffers
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef LZMA_INTEGER_H
#define LZMA_INTEGER_H
// On big endian, we need byte swapping. These macros may be used outside
// this file, so don't put these inside HAVE_FAST_UNALIGNED_ACCESS.
#ifdef WORDS_BIGENDIAN
# include "bswap.h"
# define integer_le_16(n) bswap_16(n)
# define integer_le_32(n) bswap_32(n)
# define integer_le_64(n) bswap_64(n)
#else
# define integer_le_16(n) (n)
# define integer_le_32(n) (n)
# define integer_le_64(n) (n)
#endif
// I'm aware of AC_CHECK_ALIGNED_ACCESS_REQUIRED from Autoconf archive, but
// it's not useful here. We don't care if unaligned access is supported,
// we care if it is fast. Some systems can emulate unaligned access in
// software, which is horribly slow; we want to use byte-by-byte access on
// such systems but the Autoconf test would detect such a system as
// supporting unaligned access.
//
// NOTE: HAVE_FAST_UNALIGNED_ACCESS indicates only support for 16-bit and
// 32-bit integer loads and stores. 64-bit integers may or may not work.
// That's why 64-bit functions are commented out.
//
// TODO: Big endian PowerPC supports byte swapping load and store instructions
// that also allow unaligned access. Inline assembler could be OK for that.
//
// Performance of these functions isn't that important until LZMA3, but it
// doesn't hurt to have these ready already.
#ifdef HAVE_FAST_UNALIGNED_ACCESS
static inline uint16_t
integer_read_16(const uint8_t buf[static 2])
{
uint16_t ret = *(const uint16_t *)(buf);
return integer_le_16(ret);
}
static inline uint32_t
integer_read_32(const uint8_t buf[static 4])
{
uint32_t ret = *(const uint32_t *)(buf);
return integer_le_32(ret);
}
/*
static inline uint64_t
integer_read_64(const uint8_t buf[static 8])
{
uint64_t ret = *(const uint64_t *)(buf);
return integer_le_64(ret);
}
*/
static inline void
integer_write_16(uint8_t buf[static 2], uint16_t num)
{
*(uint16_t *)(buf) = integer_le_16(num);
}
static inline void
integer_write_32(uint8_t buf[static 4], uint32_t num)
{
*(uint32_t *)(buf) = integer_le_32(num);
}
/*
static inline void
integer_write_64(uint8_t buf[static 8], uint64_t num)
{
*(uint64_t *)(buf) = integer_le_64(num);
}
*/
#else
static inline uint16_t
integer_read_16(const uint8_t buf[static 2])
{
uint16_t ret = buf[0] | (buf[1] << 8);
return ret;
}
static inline uint32_t
integer_read_32(const uint8_t buf[static 4])
{
uint32_t ret = buf[0];
ret |= (uint32_t)(buf[1]) << 8;
ret |= (uint32_t)(buf[2]) << 16;
ret |= (uint32_t)(buf[3]) << 24;
return ret;
}
/*
static inline uint64_t
integer_read_64(const uint8_t buf[static 8])
{
uint64_t ret = buf[0];
ret |= (uint64_t)(buf[1]) << 8;
ret |= (uint64_t)(buf[2]) << 16;
ret |= (uint64_t)(buf[3]) << 24;
ret |= (uint64_t)(buf[4]) << 32;
ret |= (uint64_t)(buf[5]) << 40;
ret |= (uint64_t)(buf[6]) << 48;
ret |= (uint64_t)(buf[7]) << 56;
return ret;
}
*/
static inline void
integer_write_16(uint8_t buf[static 2], uint16_t num)
{
buf[0] = (uint8_t)(num);
buf[1] = (uint8_t)(num >> 8);
}
static inline void
integer_write_32(uint8_t buf[static 4], uint32_t num)
{
buf[0] = (uint8_t)(num);
buf[1] = (uint8_t)(num >> 8);
buf[2] = (uint8_t)(num >> 16);
buf[3] = (uint8_t)(num >> 24);
}
/*
static inline void
integer_write_64(uint8_t buf[static 8], uint64_t num)
{
buf[0] = (uint8_t)(num);
buf[1] = (uint8_t)(num >> 8);
buf[2] = (uint8_t)(num >> 16);
buf[3] = (uint8_t)(num >> 24);
buf[4] = (uint8_t)(num >> 32);
buf[5] = (uint8_t)(num >> 40);
buf[6] = (uint8_t)(num >> 48);
buf[7] = (uint8_t)(num >> 56);
}
*/
#endif
#endif

42
src/common/mythread.h Normal file
View File

@@ -0,0 +1,42 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file mythread.h
/// \brief Wrappers for threads
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "sysdefs.h"
#ifdef HAVE_PTHREAD
# include <pthread.h>
# define mythread_once(func) \
do { \
static pthread_once_t once_ = PTHREAD_ONCE_INIT; \
pthread_once(&once_, &func); \
} while (0)
# define mythread_sigmask(how, set, oset) \
pthread_sigmask(how, set, oset)
#else
# define mythread_once(func) \
do { \
static bool once_ = false; \
if (!once_) { \
func(); \
once_ = true; \
} \
} while (0)
# define mythread_sigmask(how, set, oset) \
sigprocmask(how, set, oset)
#endif

View File

@@ -3,11 +3,10 @@
/// \file open_stdxxx.h
/// \brief Make sure that file descriptors 0, 1, and 2 are open
//
// This code has been put into the public domain.
// Author: Lasse Collin
//
// 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 file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////

View File

@@ -3,35 +3,41 @@
/// \file physmem.h
/// \brief Get the amount of physical memory
//
// This code has been put into the public domain.
// Author: Lasse Collin
//
// 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 file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef PHYSMEM_H
#define PHYSMEM_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
// Test for Windows first, because we want to use Windows-specific code
// on Cygwin, which also has memory information available via sysconf(), but
// on Cygwin 1.5 and older it gives wrong results (from our point of view).
#if defined(_WIN32) || defined(__CYGWIN__)
# ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0500
# endif
# include <windows.h>
#include <sys/types.h>
#include <inttypes.h>
#elif defined(HAVE_PHYSMEM_SYSCONF)
# include <unistd.h>
#ifdef HAVE_LIMITS_H
# include <limits.h>
#endif
#if defined(HAVE_PHYSMEM_SYSCTL) || defined(HAVE_NCPU_SYSCTL)
#elif defined(HAVE_PHYSMEM_SYSCTL)
# ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
# endif
# ifdef HAVE_SYS_SYSCTL_H
# include <sys/sysctl.h>
# endif
#elif defined(HAVE_PHYSMEM_SYSINFO)
# include <sys/sysinfo.h>
#elif defined(__DJGPP__)
# include <dpmi.h>
#endif
@@ -44,7 +50,36 @@ physmem(void)
{
uint64_t ret = 0;
#if defined(HAVE_PHYSMEM_SYSCONF)
#if defined(_WIN32) || defined(__CYGWIN__)
if ((GetVersion() & 0xFF) >= 5) {
// Windows 2000 and later have GlobalMemoryStatusEx() which
// supports reporting values greater than 4 GiB. To keep the
// code working also on older Windows versions, use
// GlobalMemoryStatusEx() conditionally.
HMODULE kernel32 = GetModuleHandle("kernel32.dll");
if (kernel32 != NULL) {
BOOL (WINAPI *gmse)(LPMEMORYSTATUSEX) = GetProcAddress(
kernel32, "GlobalMemoryStatusEx");
if (gmse != NULL) {
MEMORYSTATUSEX meminfo;
meminfo.dwLength = sizeof(meminfo);
if (gmse(&meminfo))
ret = meminfo.ullTotalPhys;
}
}
}
if (ret == 0) {
// GlobalMemoryStatus() is supported by Windows 95 and later,
// so it is fine to link against it unconditionally. Note that
// GlobalMemoryStatus() has no return value.
MEMORYSTATUS meminfo;
meminfo.dwLength = sizeof(meminfo);
GlobalMemoryStatus(&meminfo);
ret = meminfo.dwTotalPhys;
}
#elif defined(HAVE_PHYSMEM_SYSCONF)
const long pagesize = sysconf(_SC_PAGESIZE);
const long pages = sysconf(_SC_PHYS_PAGES);
if (pagesize != -1 || pages != -1)
@@ -56,19 +91,41 @@ physmem(void)
ret = (uint64_t)(pagesize) * (uint64_t)(pages);
#elif defined(HAVE_PHYSMEM_SYSCTL)
int name[2] = { CTL_HW, HW_PHYSMEM };
unsigned long mem;
size_t mem_ptr_size = sizeof(mem);
if (!sysctl(name, 2, &mem, &mem_ptr_size, NULL, NULL)) {
// Some systems use unsigned int as the "return value".
// This makes a difference on 64-bit boxes.
if (mem_ptr_size != sizeof(mem)) {
if (mem_ptr_size == sizeof(unsigned int))
ret = *(unsigned int *)(&mem);
} else {
ret = mem;
}
int name[2] = {
CTL_HW,
#ifdef HW_PHYSMEM64
HW_PHYSMEM64
#else
HW_PHYSMEM
#endif
};
union {
uint32_t u32;
uint64_t u64;
} mem;
size_t mem_ptr_size = sizeof(mem.u64);
if (!sysctl(name, 2, &mem.u64, &mem_ptr_size, NULL, NULL)) {
// IIRC, 64-bit "return value" is possible on some 64-bit
// BSD systems even with HW_PHYSMEM (instead of HW_PHYSMEM64),
// so support both.
if (mem_ptr_size == sizeof(mem.u64))
ret = mem.u64;
else if (mem_ptr_size == sizeof(mem.u32))
ret = mem.u32;
}
#elif defined(HAVE_PHYSMEM_SYSINFO)
struct sysinfo si;
if (sysinfo(&si) == 0)
ret = (uint64_t)(si.totalram) * si.mem_unit;
#elif defined(__DJGPP__)
__dpmi_free_mem_info meminfo;
if (__dpmi_get_free_memory_information(&meminfo) == 0
&& meminfo.total_number_of_physical_pages
!= (unsigned long)(-1))
ret = (uint64_t)(meminfo.total_number_of_physical_pages)
* 4096;
#endif
return ret;

View File

@@ -6,17 +6,10 @@
/// This file is used also by the lzma command line tool, that's why this
/// file is separate from common.h.
//
// Copyright (C) 2007 Lasse Collin
// Author: Lasse Collin
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// 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
// Lesser General Public License for more details.
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
@@ -31,10 +24,98 @@
# include <config.h>
#endif
#include "lzma.h"
// size_t and NULL
#include <stddef.h>
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
// C99 says that inttypes.h always includes stdint.h, but some systems
// don't do that, and require including stdint.h separately.
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
// Some pre-C99 systems have SIZE_MAX in limits.h instead of stdint.h. The
// limits are also used to figure out some macros missing from pre-C99 systems.
#ifdef HAVE_LIMITS_H
# include <limits.h>
#endif
// Be more compatible with systems that have non-conforming inttypes.h.
// We assume that int is 32-bit and that long is either 32-bit or 64-bit.
// Full Autoconf test could be more correct, but this should work well enough.
// Note that this duplicates some code from lzma.h, but this is better since
// we can work without inttypes.h thanks to Autoconf tests.
#ifndef UINT32_C
# if UINT_MAX != 4294967295U
# error UINT32_C is not defined and unsiged int is not 32-bit.
# endif
# define UINT32_C(n) n ## U
#endif
#ifndef UINT32_MAX
# define UINT32_MAX UINT32_C(4294967295)
#endif
#ifndef PRIu32
# define PRIu32 "u"
#endif
#ifndef PRIX32
# define PRIX32 "X"
#endif
#if ULONG_MAX == 4294967295UL
# ifndef UINT64_C
# define UINT64_C(n) n ## ULL
# endif
# ifndef PRIu64
# define PRIu64 "llu"
# endif
# ifndef PRIX64
# define PRIX64 "llX"
# endif
#else
# ifndef UINT64_C
# define UINT64_C(n) n ## UL
# endif
# ifndef PRIu64
# define PRIu64 "lu"
# endif
# ifndef PRIX64
# define PRIX64 "lX"
# endif
#endif
#ifndef UINT64_MAX
# define UINT64_MAX UINT64_C(18446744073709551615)
#endif
// The code currently assumes that size_t is either 32-bit or 64-bit.
#ifndef SIZE_MAX
# if SIZEOF_SIZE_T == 4
# define SIZE_MAX UINT32_MAX
# elif SIZEOF_SIZE_T == 8
# define SIZE_MAX UINT64_MAX
# else
# error sizeof(size_t) is not 32-bit or 64-bit
# endif
#endif
#if SIZE_MAX != UINT32_MAX && SIZE_MAX != UINT64_MAX
# error sizeof(size_t) is not 32-bit or 64-bit
#endif
#include <stdlib.h>
#include <assert.h>
// Pre-C99 systems lack stdbool.h. All the code in LZMA Utils must be written
// so that it works with fake bool type, for example:
//
// bool foo = (flags & 0x100) != 0;
// bool bar = !!(flags & 0x100);
//
// This works with the real C99 bool but breaks with fake bool:
//
// bool baz = (flags & 0x100);
//
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#else
@@ -47,17 +128,8 @@ typedef unsigned char _Bool;
# define __bool_true_false_are_defined 1
#endif
#ifdef HAVE_ASSERT_H
# include <assert.h>
#else
# ifdef NDEBUG
# define assert(x)
# else
// TODO: Pretty bad assert() macro.
# define assert(x) (!(x) && abort())
# endif
#endif
// string.h should be enough but let's include strings.h and memory.h too if
// they exists, since that shouldn't do any harm, but may improve portability.
#ifdef HAVE_STRING_H
# include <string.h>
#endif
@@ -75,19 +147,12 @@ typedef unsigned char _Bool;
// Macros //
////////////
#ifndef HAVE_MEMCPY
# define memcpy(dest, src, n) bcopy(src, dest, n)
#if defined(_WIN32) || defined(__MSDOS__) || defined(__OS2__)
# define DOSLIKE 1
#endif
#ifndef HAVE_MEMMOVE
# define memmove(dest, src, n) bcopy(src, dest, n)
#endif
#ifdef HAVE_MEMSET
# define memzero(s, n) memset(s, 0, n)
#else
# define memzero(s, n) bzero(s, n)
#endif
#undef memzero
#define memzero(s, n) memset(s, 0, n)
#ifndef MIN
# define MIN(x, y) ((x) < (y) ? (x) : (y))
@@ -97,4 +162,8 @@ typedef unsigned char _Bool;
# define MAX(x, y) ((x) > (y) ? (x) : (y))
#endif
#ifndef ARRAY_SIZE
# define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
#endif
#endif

View File

@@ -1,47 +1,94 @@
##
## Copyright (C) 2007 Lasse Collin
## Author: Lasse Collin
##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public
## License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
##
## 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
## Lesser General Public License for more details.
## This file has been put into the public domain.
## You can do whatever you want with this file.
##
SUBDIRS = api common check
SUBDIRS = api
EXTRA_DIST =
CLEANFILES =
doc_DATA =
lib_LTLIBRARIES = liblzma.la
liblzma_la_SOURCES =
liblzma_la_LDFLAGS = -version-info 0:0:0
liblzma_la_CPPFLAGS = \
-I$(top_srcdir)/src/liblzma/api \
-I$(top_srcdir)/src/liblzma/common \
-I$(top_srcdir)/src/liblzma/check \
-I$(top_srcdir)/src/liblzma/lz \
-I$(top_srcdir)/src/liblzma/rangecoder \
-I$(top_srcdir)/src/liblzma/lzma \
-I$(top_srcdir)/src/liblzma/subblock \
-I$(top_srcdir)/src/liblzma/delta \
-I$(top_srcdir)/src/liblzma/simple \
-I$(top_srcdir)/src/common
liblzma_la_LDFLAGS = -no-undefined -version-info 0:0:0
liblzma_la_LIBADD = \
common/libcommon.la \
check/libcheck.la
include $(srcdir)/common/Makefile.inc
include $(srcdir)/check/Makefile.inc
if COND_FILTER_LZMA
SUBDIRS += lz lzma rangecoder
liblzma_la_LIBADD += \
lz/liblz.la \
lzma/liblzma4.la \
rangecoder/librangecoder.la
if COND_FILTER_LZ
include $(srcdir)/lz/Makefile.inc
endif
if COND_FILTER_LZMA1
include $(srcdir)/lzma/Makefile.inc
include $(srcdir)/rangecoder/Makefile.inc
endif
if COND_FILTER_SUBBLOCK
SUBDIRS += subblock
liblzma_la_LIBADD += subblock/libsubblock.la
include $(srcdir)/subblock/Makefile.inc
endif
if COND_MAIN_SIMPLE
SUBDIRS += simple
liblzma_la_LIBADD += simple/libsimple.la
if COND_FILTER_DELTA
include $(srcdir)/delta/Makefile.inc
endif
if COND_FILTER_SIMPLE
include $(srcdir)/simple/Makefile.inc
endif
## Windows-specific stuff
# Windows resource compiler support. libtool knows what to do with .rc
# files, but Automake (<= 1.11 at least) doesn't know.
#
# We want the resource file only in shared liblzma. To avoid linking it into
# static liblzma, we overwrite the static object file with an object file
# compiled from empty input. Note that GNU-specific features are OK here,
# because on Windows we are compiled with the GNU toolchain.
.rc.lo:
$(LIBTOOL) --mode=compile $(RC) $(DEFS) $(DEFAULT_INCLUDES) \
$(INCLUDES) $(liblzma_la_CPPFLAGS) $(CPPFLAGS) $(RCFLAGS) \
-i $< -o $@
echo > empty.c
$(COMPILE) -c empty.c -o $(*D)/$(*F).o
# Remove ordinals from the generated .def file. People must link by name,
# not by ordinal, because no one is going to track the ordinal numbers.
liblzma.def: liblzma.la liblzma.def.in
sed 's/ \+@ *[0-9]\+//' liblzma.def.in > liblzma.def
# Creating liblzma.def.in is a side effect of linking the library.
liblzma.def.in: liblzma.la
if COND_W32
CLEANFILES += liblzma.def liblzma.def.in empty.c
liblzma_la_SOURCES += liblzma_w32res.rc
liblzma_la_LDFLAGS += -Xlinker --output-def -Xlinker liblzma.def.in
## liblzma.def.in is created only when building shared liblzma, so don't
## try to create liblzma.def when not building shared liblzma.
if COND_SHARED
doc_DATA += liblzma.def
endif
endif
## pkg-config
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = lzma.pc
EXTRA_DIST = lzma.pc.in
pkgconfig_DATA = liblzma.pc
EXTRA_DIST += liblzma.pc.in

View File

@@ -1,38 +1,22 @@
##
## Copyright (C) 2007 Lasse Collin
## Author: Lasse Collin
##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public
## License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
##
## 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
## Lesser General Public License for more details.
## This file has been put into the public domain.
## You can do whatever you want with this file.
##
nobase_include_HEADERS = \
lzma.h \
lzma/alignment.h \
lzma/alone.h \
lzma/auto.h \
lzma/base.h \
lzma/bcj.h \
lzma/block.h \
lzma/check.h \
lzma/copy.h \
lzma/container.h \
lzma/delta.h \
lzma/extra.h \
lzma/filter.h \
lzma/index.h \
lzma/info.h \
lzma/init.h \
lzma/index_hash.h \
lzma/lzma.h \
lzma/memlimit.h \
lzma/metadata.h \
lzma/raw.h \
lzma/simple.h \
lzma/stream.h \
lzma/stream_flags.h \
lzma/subblock.h \
lzma/version.h \

View File

@@ -1,67 +1,277 @@
/**
* \file lzma.h
* \brief The public API of liblzma
* \file api/lzma.h
* \brief The public API of liblzma data compression library
*
* liblzma is a LZMA compression library with a zlib-like API.
* liblzma is based on LZMA SDK found from http://7-zip.org/sdk.html.
* liblzma is a public domain general-purpose data compression library with
* a zlib-like API. The native file format is .xz, but also the old .lzma
* format and raw (no headers) streams are supported. Multiple compression
* algorithms (filters) are supported. Currently LZMA2 is the primary filter.
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
* liblzma is part of XZ Utils <http://tukaani.org/xz/>. XZ Utils includes
* a gzip-like command line tool named xz and some other tools. XZ Utils
* is developed and maintained by Lasse Collin.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* Major parts of liblzma are based on Igor Pavlov's public domain LZMA SDK
* <http://7-zip.org/sdk.html>.
*
* 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
* Lesser General Public License for more details.
* The SHA-256 implementation is based on the public domain code found from
* 7-Zip <http://7-zip.org/>, which has a modified version of the public
* domain SHA-256 code found from Crypto++ <http://www.cryptopp.com/>.
* The SHA-256 code in Crypto++ was written by Kevin Springle and Wei Dai.
*/
/*
* Author: Lasse Collin
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/
#ifndef LZMA_H
#define LZMA_H
/********************
* External headers *
********************/
/*****************************
* Required standard headers *
*****************************/
/* size_t */
#include <sys/types.h>
/*
* liblzma API headers need some standard types and macros. To allow
* including lzma.h without requiring the application to include other
* headers first, lzma.h includes the required standard headers unless
* they already seem to be included already or if LZMA_MANUAL_HEADERS
* has been defined.
*
* Here's what types and macros are needed and from which headers:
* - stddef.h: size_t, NULL
* - stdint.h: uint8_t, uint32_t, uint64_t, UINT32_C(n), uint64_C(n),
* UINT32_MAX, UINT64_MAX
*
* However, inttypes.h is a little more portable than stdint.h, although
* inttypes.h declares some unneeded things compared to plain stdint.h.
*
* The hacks below aren't perfect, specifically they assume that inttypes.h
* exists and that it typedefs at least uint8_t, uint32_t, and uint64_t,
* and that, in case of incomplete inttypes.h, unsigned int is 32-bit.
* If the application already takes care of setting up all the types and
* macros properly (for example by using gnulib's stdint.h or inttypes.h),
* we try to detect that the macros are already defined and don't include
* inttypes.h here again. However, you may define LZMA_MANUAL_HEADERS to
* force this file to never include any system headers.
*
* Some could argue that liblzma API should provide all the required types,
* for example lzma_uint64, LZMA_UINT64_C(n), and LZMA_UINT64_MAX. This was
* seen unnecessary mess, since most systems already provide all the necessary
* types and macros in the standard headers.
*
* Note that liblzma API still has lzma_bool, because using stdbool.h would
* break C89 and C++ programs on many systems. sizeof(bool) in C99 isn't
* necessarily the same as sizeof(bool) in C++.
*/
/* NULL */
#include <stddef.h>
#ifndef LZMA_MANUAL_HEADERS
/*
* I suppose this works portably also in C++. Note that in C++,
* we need to get size_t into the global namespace.
*/
# include <stddef.h>
/* uint8_t, uint32_t, uint64_t, UINT32_C, UINT64_C, UINT64_MAX. */
#include <inttypes.h>
/*
* Skip inttypes.h if we already have all the required macros. If we
* have the macros, we assume that we have the matching typedefs too.
*/
# if !defined(UINT32_C) || !defined(UINT64_C) \
|| !defined(UINT32_MAX) || !defined(UINT64_MAX)
/*
* MSVC has no C99 support, and thus it cannot be used to
* compile liblzma. The liblzma API has to still be usable
* from MSVC, so we need to define the required standard
* integer types here.
*/
# if defined(_WIN32) && defined(_MSC_VER)
typedef unsigned __int8 uint8_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
# else
/* Use the standard inttypes.h. */
# ifdef __cplusplus
/*
* C99 sections 7.18.2 and 7.18.4 specify that
* in C++ implementations define the limit
* and constant macros only if specifically
* requested. Note that if you want the
* format macros (PRIu64 etc.) too, you need
* to define __STDC_FORMAT_MACROS before
* including lzma.h, since re-including
* inttypes.h with __STDC_FORMAT_MACROS
* defined doesn't necessarily work.
*/
# ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS 1
# endif
# ifndef __STDC_CONSTANT_MACROS
# define __STDC_CONSTANT_MACROS 1
# endif
# endif
# include <inttypes.h>
# endif
/*
* Some old systems have only the typedefs in inttypes.h, and
* lack all the macros. For those systems, we need a few more
* hacks. We assume that unsigned int is 32-bit and unsigned
* long is either 32-bit or 64-bit. If these hacks aren't
* enough, the application has to setup the types manually
* before including lzma.h.
*/
# ifndef UINT32_C
# if defined(_WIN32) && defined(_MSC_VER)
# define UINT32_C(n) n ## UI32
# else
# define UINT32_C(n) n ## U
# endif
# endif
# ifndef UINT64_C
# if defined(_WIN32) && defined(_MSC_VER)
# define UINT64_C(n) n ## UI64
# else
/* Get ULONG_MAX. */
# include <limits.h>
# if ULONG_MAX == 4294967295UL
# define UINT64_C(n) n ## ULL
# else
# define UINT64_C(n) n ## UL
# endif
# endif
# endif
# ifndef UINT32_MAX
# define UINT32_MAX (UINT32_C(4294967295))
# endif
# ifndef UINT64_MAX
# define UINT64_MAX (UINT64_C(18446744073709551615))
# endif
# endif
#endif /* ifdef LZMA_MANUAL_HEADERS */
/******************
* GCC extensions *
* LZMA_API macro *
******************/
/*
* GCC extensions are used conditionally in the public API. It doesn't
* Some systems require (or at least recommend) that the functions and
* function pointers are declared specially in the headers. LZMA_API_IMPORT
* is for importing symbols and LZMA_API_CALL is to specify calling
* convention.
*
* By default it is assumed that the application will link dynamically
* against liblzma. #define LZMA_API_STATIC in your application if you
* want to link against static liblzma. If you don't care about portability
* to operating systems like Windows, or at least don't care about linking
* against static liblzma on them, don't worry about LZMA_API_STATIC. That
* is, most developers will never need to use LZMA_API_STATIC.
*
* Cygwin is a special case on Windows. We rely on GCC doing the right thing
* and thus don't use dllimport and don't specify the calling convention.
*/
#ifndef LZMA_API_IMPORT
# if !defined(LZMA_API_STATIC) && defined(_WIN32) && !defined(__CYGWIN__)
# define LZMA_API_IMPORT __declspec(dllimport)
# else
# define LZMA_API_IMPORT
# endif
#endif
#ifndef LZMA_API_CALL
# if defined(_WIN32) && !defined(__CYGWIN__)
# define LZMA_API_CALL __cdecl
# else
# define LZMA_API_CALL
# endif
#endif
#ifndef LZMA_API
# define LZMA_API(type) LZMA_API_IMPORT type LZMA_API_CALL
#endif
/***********
* nothrow *
***********/
/*
* None of the functions in liblzma may throw an exception. Even
* the functions that use callback functions won't throw exceptions,
* because liblzma would break if a callback function threw an exception.
*/
#ifndef lzma_nothrow
# if defined(__cplusplus)
# define lzma_nothrow throw()
# elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
# define lzma_nothrow __attribute__((__nothrow__))
# else
# define lzma_nothrow
# endif
#endif
/********************
* GNU C extensions *
********************/
/*
* GNU C extensions are used conditionally in the public API. It doesn't
* break anything if these are sometimes enabled and sometimes not, only
* affects warnings and optimizations.
*/
#if defined(__GNUC__) && __GNUC__ >= 3
#if __GNUC__ >= 3
# ifndef lzma_attribute
# define lzma_attribute(attr) __attribute__(attr)
# endif
# ifndef lzma_restrict
# define lzma_restrict __restrict__
# endif
/* warn_unused_result was added in GCC 3.4. */
# ifndef lzma_attr_warn_unused_result
# if __GNUC__ == 3 && __GNUC_MINOR__ < 4
# define lzma_attr_warn_unused_result
# endif
# endif
#else
# ifndef lzma_attribute
# define lzma_attribute(attr)
# endif
# ifndef lzma_restrict
# define lzma_restrict
# if __STDC_VERSION__ >= 199901L
# define lzma_restrict restrict
# else
# define lzma_restrict
# endif
# endif
#endif
#ifndef lzma_attr_pure
# define lzma_attr_pure lzma_attribute((__pure__))
#endif
#ifndef lzma_attr_const
# define lzma_attr_const lzma_attribute((__const__))
#endif
#ifndef lzma_attr_warn_unused_result
# define lzma_attr_warn_unused_result \
lzma_attribute((__warn_unused_result__))
#endif
/**************
* Subheaders *
**************/
@@ -77,37 +287,26 @@ extern "C" {
#define LZMA_H_INTERNAL 1
/* Basic features */
#include "lzma/init.h"
#include "lzma/version.h"
#include "lzma/base.h"
#include "lzma/vli.h"
#include "lzma/filter.h"
#include "lzma/check.h"
/* Filters */
#include "lzma/copy.h"
#include "lzma/filter.h"
#include "lzma/subblock.h"
#include "lzma/simple.h"
#include "lzma/bcj.h"
#include "lzma/delta.h"
#include "lzma/lzma.h"
/* Container formats and Metadata */
#include "lzma/block.h"
#include "lzma/index.h"
#include "lzma/extra.h"
#include "lzma/metadata.h"
#include "lzma/stream.h"
#include "lzma/alone.h"
#include "lzma/raw.h"
#include "lzma/auto.h"
/* Container formats */
#include "lzma/container.h"
/* Advanced features */
#include "lzma/info.h"
#include "lzma/alignment.h"
#include "lzma/stream_flags.h"
#include "lzma/memlimit.h"
/* Version number */
#include "lzma/version.h"
#include "lzma/block.h"
#include "lzma/index.h"
#include "lzma/index_hash.h"
/*
* All subheaders included. Undefine LZMA_H_INTERNAL to prevent applications

View File

@@ -1,60 +0,0 @@
/**
* \file lzma/alignment.h
* \brief Calculating input and output alignment of filter chains
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*/
#ifndef LZMA_H_INTERNAL
# error Never include this file directly. Use <lzma.h> instead.
#endif
/**
* \brief Calculates the preferred alignment of the input data
*
* FIXME desc
*/
extern uint32_t lzma_alignment_input(
const lzma_options_filter *filters, uint32_t guess);
/**
* \brief Calculates the alignment of the encoded output
*
* Knowing the alignment of the output data is useful e.g. in the Block
* encoder which tries to align the Compressed Data field optimally.
*
* \param filters Pointer to lzma_options_filter array, whose last
* member must have .id = LZMA_VLI_VALUE_UNKNOWN.
* \param guess The value to return if the alignment of the output
* is the same as the alignment of the input data.
* If you want to always detect this special case,
* this guess to zero; this function never returns
* zero unless guess is zero.
*
* \return In most cases, a small positive integer is returned;
* for optimal use, the encoded output of this filter
* chain should start at on offset that is a multiple of
* the returned integer value.
*
* If the alignment of the output is the same as the input
* data (which this function cannot know), \a guess is
* returned.
*
* If an error occurs (that is, unknown Filter IDs or filter
* options), UINT32_MAX is returned.
*/
extern uint32_t lzma_alignment_output(
const lzma_options_filter *filters, uint32_t guess);

View File

@@ -1,82 +0,0 @@
/**
* \file lzma/alone.h
* \brief Handling of the legacy LZMA_Alone format
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*/
#ifndef LZMA_H_INTERNAL
# error Never include this file directly. Use <lzma.h> instead.
#endif
/**
* \brief Options for files in the LZMA_Alone format
*/
typedef struct {
/**
* \brief Uncompressed Size and usage of End of Payload Marker
*
* In contrast to .lzma Blocks, LZMA_Alone format cannot have both
* uncompressed size field in the header and end of payload marker.
* If you don't know the uncompressed size beforehand, set it to
* LZMA_VLI_VALUE_UNKNOWN and liblzma will embed end of payload
* marker.
*/
lzma_vli uncompressed_size;
/**
* \brief LZMA options
*
* The LZMA_Alone format supports only one filter: the LZMA filter.
*
* \note There exists also an undocumented variant of the
* LZMA_Alone format, which uses the x86 filter in
* addition to LZMA. This format was never supported
* by LZMA Utils and is not supported by liblzma either.
*/
lzma_options_lzma lzma;
} lzma_options_alone;
/**
* \brief Initializes LZMA_Alone encoder
*
* LZMA_Alone files have the suffix .lzma like the .lzma Stream files.
* LZMA_Alone format supports only one filter, the LZMA filter. There is
* no support for integrity checks like CRC32.
*
* Use this format if and only if you need to create files readable by
* legacy LZMA tools.
*
* LZMA_Alone encoder doesn't support LZMA_SYNC_FLUSH or LZMA_FULL_FLUSH.
*
* \return - LZMA_OK
* - LZMA_MEM_ERROR
* - LZMA_PROG_ERROR
*/
extern lzma_ret lzma_alone_encoder(
lzma_stream *strm, const lzma_options_alone *options);
/**
* \brief Initializes decoder for LZMA_Alone file
*
* The LZMA_Alone decoder supports LZMA_SYNC_FLUSH.
*
* \return - LZMA_OK
* - LZMA_MEM_ERROR
*/
extern lzma_ret lzma_alone_decoder(lzma_stream *strm);

View File

@@ -1,41 +0,0 @@
/**
* \file lzma/auto.h
* \brief Decoder with automatic file format detection
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*/
#ifndef LZMA_H_INTERNAL
# error Never include this file directly. Use <lzma.h> instead.
#endif
/**
* \brief Decode .lzma Streams and LZMA_Alone files with autodetection
*
* Autodetects between the .lzma Stream and LZMA_Alone formats, and
* calls lzma_stream_decoder_init() or lzma_alone_decoder_init() once
* the type of the file has been detected.
*
* \param strm Pointer to propertily prepared lzma_stream
* \param header Pointer to hold a pointer to Extra Records read
* from the Header Metadata Block. Use NULL if
* you don't care about Extra Records.
* \param footer Same as header, but for Footer Metadata Block.
*
* \return - LZMA_OK: Initialization was successful.
* - LZMA_MEM_ERROR: Cannot allocate memory.
*/
extern lzma_ret lzma_auto_decoder(lzma_stream *strm,
lzma_extra **header, lzma_extra **footer);

View File

@@ -1,19 +1,15 @@
/**
* \file lzma/base.h
* \brief Data types and functions used in many places of the public API
* \brief Data types and functions used in many places in liblzma API
*/
/*
* Author: Lasse Collin
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
* This file has been put into the public domain.
* You can do whatever you want with this file.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
* See ../lzma.h for information about liblzma as a whole.
*/
#ifndef LZMA_H_INTERNAL
@@ -33,28 +29,193 @@
typedef unsigned char lzma_bool;
/**
* \brief Type of reserved enumeration variable in structures
*
* To avoid breaking library ABI when new features are added, several
* structures contain extra variables that may be used in future. Since
* sizeof(enum) can be different than sizeof(int), and sizeof(enum) may
* even vary depending on the range of enumeration constants, we specify
* a separate type to be used for reserved enumeration variables. All
* enumeration constants in liblzma API will be non-negative and less
* than 128, which should guarantee that the ABI won't break even when
* new constants are added to existing enumerations.
*/
typedef enum {
LZMA_RESERVED_ENUM = 0
} lzma_reserved_enum;
/**
* \brief Return values used by several functions in liblzma
*
* Check the descriptions of specific functions to find out which return
* values they can return and the exact meanings of the values in every
* situation. The descriptions given here are only suggestive.
* values they can return. With some functions the return values may have
* more specific meanings than described here; those differences are
* described per-function basis.
*/
typedef enum {
LZMA_OK = 0,
LZMA_OK = 0,
/**<
* \brief Operation completed successfully
*/
LZMA_STREAM_END = 1,
LZMA_STREAM_END = 1,
/**<
* \brief End of stream was reached
*
* The application should pick the last remaining output
* bytes from strm->next_out.
* In encoder, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, or
* LZMA_FINISH was finished. In decoder, this indicates
* that all the data was successfully decoded.
*
* In all cases, when LZMA_STREAM_END is returned, the last
* output bytes should be picked from strm->next_out.
*/
LZMA_PROG_ERROR = -2,
LZMA_NO_CHECK = 2,
/**<
* \brief Input stream has no integrity check
*
* This return value can be returned only if the
* LZMA_TELL_NO_CHECK flag was used when initializing
* the decoder. LZMA_NO_CHECK is just a warning, and
* the decoding can be continued normally.
*
* It is possible to call lzma_get_check() immediatelly after
* lzma_code has returned LZMA_NO_CHECK. The result will
* naturally be LZMA_CHECK_NONE, but the possibility to call
* lzma_get_check() may be convenient in some applications.
*/
LZMA_UNSUPPORTED_CHECK = 3,
/**<
* \brief Cannot calculate the integrity check
*
* The usage of this return value is different in encoders
* and decoders.
*
* Encoders can return this value only from the initialization
* function. If initialization fails with this value, the
* encoding cannot be done, because there's no way to produce
* output with the correct integrity check.
*
* Decoders can return this value only from lzma_code() and
* only if the LZMA_TELL_UNSUPPORTED_CHECK flag was used when
* initializing the decoder. The decoding can still be
* continued normally even if the check type is unsupported,
* but naturally the check will not be validated, and possible
* errors may go undetected.
*
* With decoder, it is possible to call lzma_get_check()
* immediatelly after lzma_code() has returned
* LZMA_UNSUPPORTED_CHECK. This way it is possible to find
* out what the unsupported Check ID was.
*/
LZMA_GET_CHECK = 4,
/**<
* \brief Integrity check type is now available
*
* This value can be returned only by the lzma_code() function
* and only if the decoder was initialized with the
* LZMA_TELL_ANY_CHECK flag. LZMA_GET_CHECK tells the
* application that it may now call lzma_get_check() to find
* out the Check ID. This can be used, for example, to
* implement a decoder that accepts only files that have
* strong enough integrity check.
*/
LZMA_MEM_ERROR = 5,
/**<
* \brief Cannot allocate memory
*
* Memory allocation failed, or the size of the allocation
* would be greater than SIZE_MAX.
*
* Due to internal implementation reasons, the coding cannot
* be continued even if more memory were made available after
* LZMA_MEM_ERROR.
*/
LZMA_MEMLIMIT_ERROR = 6,
/**
* \brief Memory usage limit was reached
*
* Decoder would need more memory than allowed by the
* specified memory usage limit. To continue decoding,
* the memory usage limit has to be increased with
* lzma_memlimit_set().
*/
LZMA_FORMAT_ERROR = 7,
/**<
* \brief File format not recognized
*
* The decoder did not recognize the input as supported file
* format. This error can occur, for example, when trying to
* decode .lzma format file with lzma_stream_decoder,
* because lzma_stream_decoder accepts only the .xz format.
*/
LZMA_OPTIONS_ERROR = 8,
/**<
* \brief Invalid or unsupported options
*
* Invalid or unsupported options, for example
* - unsupported filter(s) or filter options; or
* - reserved bits set in headers (decoder only).
*
* Rebuilding liblzma with more features enabled, or
* upgrading to a newer version of liblzma may help.
*/
LZMA_DATA_ERROR = 9,
/**<
* \brief Data is corrupt
*
* The usage of this return value is different in encoders
* and decoders. In both encoder and decoder, the coding
* cannot continue after this error.
*
* Encoders return this if size limits of the target file
* format would be exceeded. These limits are huge, thus
* getting this error from an encoder is mostly theoretical.
* For example, the maximum compressed and uncompressed
* size of a .xz Stream is roughly 8 EiB (2^63 bytes).
*
* Decoders return this error if the input data is corrupt.
* This can mean, for example, invalid CRC32 in headers
* or invalid check of uncompressed data.
*/
LZMA_BUF_ERROR = 10,
/**<
* \brief No progress is possible
*
* This error code is returned when the coder cannot consume
* any new input and produce any new output. The most common
* reason for this error is that the input stream being
* decoded is truncated or corrupt.
*
* This error is not fatal. Coding can be continued normally
* by providing more input and/or more output space, if
* possible.
*
* Typically the first call to lzma_code() that can do no
* progress returns LZMA_OK instead of LZMA_BUF_ERROR. Only
* the second consecutive call doing no progress will return
* LZMA_BUF_ERROR. This is intentional.
*
* With zlib, Z_BUF_ERROR may be returned even if the
* application is doing nothing wrong, so apps will need
* to handle Z_BUF_ERROR specially. The above hack
* guarantees that liblzma never returns LZMA_BUF_ERROR
* to properly written applications unless the input file
* is truncated or corrupt. This should simplify the
* applications a little.
*/
LZMA_PROG_ERROR = 11,
/**<
* \brief Programming error
*
@@ -73,70 +234,24 @@ typedef enum {
* can be a sign of a bug in liblzma. See the documentation
* how to report bugs.
*/
LZMA_DATA_ERROR = -3,
/**<
* \brief Data is corrupt
*
* - Encoder: The input size doesn't match the uncompressed
* size given to lzma_*_encoder_init().
* - Decoder: The input is corrupt. This includes corrupted
* header, corrupted compressed data, and unmatching
* integrity Check.
*
* \todo What can be done if encoder returns this?
* Probably can continue by fixing the input
* amount, but make sure.
*/
LZMA_MEM_ERROR = -4,
/**<
* \brief Cannot allocate memory
*
* Memory allocation failed.
*/
LZMA_BUF_ERROR = -5,
/**<
* \brief No progress is possible
*
* This may happen when avail_in or avail_out is zero.
*
* \note This error is not fatal. Coding can continue
* normally once the reason for this error has
* been fixed.
*/
LZMA_HEADER_ERROR = -6,
/**<
* \brief Invalid or unsupported header
*
* Invalid or unsupported options, for example
* - unsupported filter(s) or filter options; or
* - reserved bits set in headers (decoder only).
*
* Rebuilding liblzma with more features enabled, or
* upgrading to a newer version of liblzma may help.
*/
LZMA_UNSUPPORTED_CHECK = -7,
/**<
* \brief Check type is unknown
*
* The type of Check is not supported, and thus the Check
* cannot be calculated. In the encoder, this is an error.
* In the decoder, this is only a warning and decoding can
* still proceed normally (but the Check is ignored).
*/
} lzma_ret;
/**
* \brief The `action' argument for lzma_code()
*
* After the first use of LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, or LZMA_FINISH,
* the same `action' must is used until lzma_code() returns LZMA_STREAM_END.
* Also, the amount of input (that is, strm->avail_in) must not be modified
* by the application until lzma_code() returns LZMA_STREAM_END. Changing the
* `action' or modifying the amount of input will make lzma_code() return
* LZMA_PROG_ERROR.
*/
typedef enum {
LZMA_RUN = 0,
/**<
* \brief Continue coding
*
* Encoder: Encode as much input as possible. Some internal
* buffering will probably be done (depends on the filter
* chain in use), which causes latency: the input used won't
@@ -144,55 +259,65 @@ typedef enum {
* lzma_code() call.
*
* Decoder: Decode as much input as possible and produce as
* much output as possible. This action provides best
* throughput, but may introduce latency, because the
* decoder may decode more data into its internal buffers
* than that fits into next_out.
* much output as possible.
*/
LZMA_SYNC_FLUSH = 1,
/**<
* Encoder: Makes all the data given to liblzma via next_in
* available in next_out without resetting the filters. Call
* lzma_code() with LZMA_SYNC_FLUSH until it returns
* LZMA_STREAM_END. Then continue encoding normally.
* \brief Make all the input available at output
*
* \note Synchronous flushing is supported only by
* some filters. Some filters support it only
* partially.
* Normally the encoder introduces some latency.
* LZMA_SYNC_FLUSH forces all the buffered data to be
* available at output without resetting the internal
* state of the encoder. This way it is possible to use
* compressed stream for example for communication over
* network.
*
* Decoder: Asks the decoder to decode only as much as is
* needed to fill next_out. This decreases latency with some
* filters, but is likely to decrease also throughput. It is
* a good idea to use this flag only when it is likely that
* you don't need more output soon.
* Only some filters support LZMA_SYNC_FLUSH. Trying to use
* LZMA_SYNC_FLUSH with filters that don't support it will
* make lzma_code() return LZMA_OPTIONS_ERROR. For example,
* LZMA1 doesn't support LZMA_SYNC_FLUSH but LZMA2 does.
*
* \note With decoder, this is not comparable to
* zlib's Z_SYNC_FLUSH.
* Using LZMA_SYNC_FLUSH very often can dramatically reduce
* the compression ratio. With some filters (for example,
* LZMA2), finetuning the compression options may help
* mitigate this problem significantly.
*
* Decoders don't support LZMA_SYNC_FLUSH.
*/
LZMA_FULL_FLUSH = 2,
/**<
* Finishes encoding of the current Data Block. All the input
* data going to the current Data Block must have been given
* \brief Make all the input available at output
*
* Finish encoding of the current Block. All the input
* data going to the current Block must have been given
* to the encoder (the last bytes can still be pending in
* next_in). Call lzma_code() with LZMA_FULL_FLUSH until
* it returns LZMA_STREAM_END. Then continue normally with
* LZMA_RUN or finish the Stream with LZMA_FINISH.
*
* This action is supported only by Multi-Block Stream
* encoder. If there is no unfinished Data Block, no empty
* Data Block is created.
* This action is currently supported only by Stream encoder
* and easy encoder (which uses Stream encoder). If there is
* no unfinished Block, no empty Block is created.
*/
LZMA_FINISH = 3
/**<
* Finishes the encoding operation. All the input data must
* \brief Finish the coding operation
*
* Finishes the coding operation. All the input data must
* have been given to the encoder (the last bytes can still
* be pending in next_in). Call lzma_code() with LZMA_FINISH
* until it returns LZMA_STREAM_END.
* until it returns LZMA_STREAM_END. Once LZMA_FINISH has
* been used, the amount of input must no longer be changed
* by the application.
*
* This action is not supported by decoders.
* When decoding, using LZMA_FINISH is optional unless the
* LZMA_CONCATENATED flag was used when the decoder was
* initialized. When LZMA_CONCATENATED was not used, the only
* effect of LZMA_FINISH is that the amount of input must not
* be changed just like in the encoder.
*/
} lzma_action;
@@ -201,8 +326,11 @@ typedef enum {
* \brief Custom functions for memory handling
*
* A pointer to lzma_allocator may be passed via lzma_stream structure
* to liblzma. The library will use these functions for memory handling
* instead of the default malloc() and free().
* to liblzma, and some advanced functions take a pointer to lzma_allocator
* as a separate function argument. The library will use the functions
* specified in lzma_allocator for memory handling instead of the default
* malloc() and free(). C++ users should note that the custom memory
* handling functions must not throw exceptions.
*
* liblzma doesn't make an internal copy of lzma_allocator. Thus, it is
* OK to change these function pointers in the middle of the coding
@@ -212,50 +340,54 @@ typedef enum {
*/
typedef struct {
/**
* \brief Pointer to custom memory allocation function
*
* Set this to point to your custom memory allocation function.
* It can be useful for example if you want to limit how much
* memory liblzma is allowed to use: for this, you may use
* a pointer to lzma_memory_alloc().
* \brief Pointer to a custom memory allocation function
*
* If you don't want a custom allocator, but still want
* custom free(), set this to NULL and liblzma will use
* the standard malloc().
*
* \param opaque lzma_allocator.opaque (see below)
* \param nmemb Number of elements like in calloc().
* liblzma will always set nmemb to 1.
* This argument exists only for
* \param nmemb Number of elements like in calloc(). liblzma
* will always set nmemb to 1, so it is safe to
* ignore nmemb in a custom allocator if you like.
* The nmemb argument exists only for
* compatibility with zlib and libbzip2.
* \param size Size of an element in bytes.
* liblzma never sets this to zero.
*
* \return Pointer to the beginning of a memory block of
* size nmemb * size, or NULL if allocation fails
* `size' bytes, or NULL if allocation fails
* for some reason. When allocation fails, functions
* of liblzma return LZMA_MEM_ERROR.
*
* The allocator should not waste time zeroing the allocated buffers.
* This is not only about speed, but also memory usage, since the
* operating system kernel doesn't necessarily allocate the requested
* memory in physical memory until it is actually used. With small
* input files, liblzma may actually need only a fraction of the
* memory that it requested for allocation.
*
* \note LZMA_MEM_ERROR is also used when the size of the
* allocation would be greater than SIZE_MAX. Thus,
* don't assume that the custom allocator must have
* returned NULL if some function from liblzma
* returns LZMA_MEM_ERROR.
*/
void *(*alloc)(void *opaque, size_t nmemb, size_t size);
void *(LZMA_API_CALL *alloc)(void *opaque, size_t nmemb, size_t size);
/**
* \brief Pointer to custom memory freeing function
*
* Set this to point to your custom memory freeing function.
* If lzma_memory_alloc() is used as allocator, this should
* be set to lzma_memory_free().
* \brief Pointer to a custom memory freeing function
*
* If you don't want a custom freeing function, but still
* want a custom allocator, set this to NULL and liblzma
* will use the standard free().
*
* \param opaque lzma_allocator.opaque (see below)
* \param ptr Pointer returned by
* lzma_allocator.alloc(), or when it
* is set to NULL, a pointer returned
* \param ptr Pointer returned by lzma_allocator.alloc(),
* or when it is set to NULL, a pointer returned
* by the standard malloc().
*/
void (*free)(void *opaque, void *ptr);
void (LZMA_API_CALL *free)(void *opaque, void *ptr);
/**
* \brief Pointer passed to .alloc() and .free()
@@ -264,11 +396,7 @@ typedef struct {
* and lzma_allocator.free(). This intended to ease implementing
* custom memory allocation functions for use with liblzma.
*
* When using lzma_memory_alloc() and lzma_memory_free(), opaque
* must point to lzma_memory_limitter structure allocated and
* initialized with lzma_memory_limitter_create().
*
* If you don't need this, you should set it to NULL.
* If you don't need this, you should set this to NULL.
*/
void *opaque;
@@ -287,35 +415,43 @@ typedef struct lzma_internal_s lzma_internal;
* \brief Passing data to and from liblzma
*
* The lzma_stream structure is used for
* - passing pointers to input and output buffers to liblzma;
* - defining custom memory hander functions; and
* - holding a pointer to coder-specific internal data structures.
* - passing pointers to input and output buffers to liblzma;
* - defining custom memory hander functions; and
* - holding a pointer to coder-specific internal data structures.
*
* Before calling any of the lzma_*_init() functions the first time,
* the application must reset lzma_stream to LZMA_STREAM_INIT. The
* lzma_*_init() function will verify the options, allocate internal
* data structures and store pointer to them into `internal'. Finally
* total_in and total_out are reset to zero. In contrast to zlib,
* next_in and avail_in are ignored by the initialization functions.
* Typical usage:
*
* The actual coding is done with the lzma_code() function. Application
* must update next_in, avail_in, next_out, and avail_out between
* calls to lzma_decode() just like with zlib.
* - After allocating lzma_stream (on stack or with malloc()), it must be
* initialized to LZMA_STREAM_INIT (see LZMA_STREAM_INIT for details).
*
* In contrast to zlib, even the decoder requires that there always
* is at least one byte space in next_out; if avail_out == 0,
* LZMA_BUF_ERROR is returned immediatelly. This shouldn't be a problem
* for most applications that already use zlib, but it's still worth
* checking your application.
* - Initialize a coder to the lzma_stream, for example by using
* lzma_easy_encoder() or lzma_auto_decoder(). Some notes:
* - In contrast to zlib, strm->next_in and strm->next_out are
* ignored by all initialization functions, thus it is safe
* to not initialize them yet.
* - The initialization functions always set strm->total_in and
* strm->total_out to zero.
* - If the initialization function fails, no memory is left allocated
* that would require freeing with lzma_end() even if some memory was
* associated with the lzma_stream structure when the initialization
* function was called.
*
* Application may modify values of total_in and total_out as it wants.
* - Use lzma_code() to do the actual work.
*
* - Once the coding has been finished, the existing lzma_stream can be
* reused. It is OK to reuse lzma_stream with different initialization
* function without calling lzma_end() first. Old allocations are
* automatically freed.
*
* - Finally, use lzma_end() to free the allocated memory. lzma_end() never
* frees the lzma_stream structure itself.
*
* Application may modify the values of total_in and total_out as it wants.
* They are updated by liblzma to match the amount of data read and
* written, but liblzma doesn't use the values internally.
*
* Application must not touch the `internal' pointer.
* written, but aren't used for anything else.
*/
typedef struct {
uint8_t *next_in; /**< Pointer to the next input byte. */
const uint8_t *next_in; /**< Pointer to the next input byte. */
size_t avail_in; /**< Number of available input bytes in next_in. */
uint64_t total_in; /**< Total number of bytes read by liblzma. */
@@ -324,14 +460,29 @@ typedef struct {
uint64_t total_out; /**< Total number of bytes written by liblzma. */
/**
* Custom memory allocation functions. Set to NULL to use
* \brief Custom memory allocation functions
*
* In most cases this is NULL which makes liblzma use
* the standard malloc() and free().
*/
lzma_allocator *allocator;
/** Internal state is not visible to outsiders. */
/** Internal state is not visible to applications. */
lzma_internal *internal;
/*
* Reserved space to allow possible future extensions without
* breaking the ABI. Excluding the initialization of this structure,
* you should not touch these, because the names of these variables
* may change.
*/
void *reserved_ptr1;
void *reserved_ptr2;
uint64_t reserved_int1;
uint64_t reserved_int2;
lzma_reserved_enum reserved_enum1;
lzma_reserved_enum reserved_enum2;
} lzma_stream;
@@ -343,68 +494,103 @@ typedef struct {
* has been allocated yet:
*
* lzma_stream strm = LZMA_STREAM_INIT;
*
* If you need to initialize a dynamically allocated lzma_stream, you can use
* memset(strm_pointer, 0, sizeof(lzma_stream)). Strictly speaking, this
* violates the C standard since NULL may have different internal
* representation than zero, but it should be portable enough in practice.
* Anyway, for maximum portability, you can use something like this:
*
* lzma_stream tmp = LZMA_STREAM_INIT;
* *strm = tmp;
*/
#define LZMA_STREAM_INIT { NULL, 0, 0, NULL, 0, 0, NULL, NULL }
#define LZMA_STREAM_INIT \
{ NULL, 0, 0, NULL, 0, 0, NULL, NULL, \
NULL, NULL, 0, 0, LZMA_RESERVED_ENUM, LZMA_RESERVED_ENUM }
/**
* \brief Initialization for lzma_stream
*
* This is like LZMA_STREAM_INIT, but this can be used when the lzma_stream
* has already been allocated:
*
* lzma_stream *strm = malloc(sizeof(lzma_stream));
* if (strm == NULL)
* return LZMA_MEM_ERROR;
* *strm = LZMA_STREAM_INIT_VAR;
*/
extern const lzma_stream LZMA_STREAM_INIT_VAR;
/**
* \brief Encodes or decodes data
* \brief Encode or decode data
*
* Once the lzma_stream has been successfully initialized (e.g. with
* lzma_stream_encoder_single()), the actual encoding or decoding is
* done using this function.
* lzma_stream_encoder()), the actual encoding or decoding is done
* using this function. The application has to update strm->next_in,
* strm->avail_in, strm->next_out, and strm->avail_out to pass input
* to and get output from liblzma.
*
* \return Some coders may have more exact meaning for different return
* values, which are mentioned separately in the description of
* the initialization functions. Here are the typical meanings:
* - LZMA_OK: So far all good.
* - LZMA_STREAM_END:
* - Encoder: LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, or
* LZMA_FINISH completed.
* - Decoder: End of uncompressed data was reached.
* - LZMA_BUF_ERROR: Unable to progress. Provide more input or
* output space, and call this function again. This cannot
* occur if both avail_in and avail_out were non-zero (or
* there's a bug in liblzma).
* - LZMA_MEM_ERROR: Unable to allocate memory. Due to lazy
* programming, the coding cannot continue even if the
* application could free more memory. The next call must
* be lzma_end() or some initialization function.
* - LZMA_DATA_ERROR:
* - Encoder: Filter(s) cannot process the given data.
* - Decoder: Compressed data is corrupt.
* - LZMA_HEADER_ERROR: Unsupported options. Rebuilding liblzma
* with more features enabled or upgrading to a newer version
* may help, although usually this is a sign of invalid options
* (encoder) or corrupted input data (decoder).
* - LZMA_PROG_ERROR: Invalid arguments or the internal state
* of the coder is corrupt.
* See the description of the coder-specific initialization function to find
* out what `action' values are supported by the coder.
*/
extern lzma_ret lzma_code(lzma_stream *strm, lzma_action action);
extern LZMA_API(lzma_ret) lzma_code(lzma_stream *strm, lzma_action action)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Frees memory allocated for the coder data structures
* \brief Free memory allocated for the coder data structures
*
* \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
*
* After lzma_end(strm), strm->internal is guaranteed to be NULL. No other
* members of the lzma_stream structure are touched.
*
* \note zlib indicates an error if application end()s unfinished
* stream. liblzma doesn't do this, and assumes that
* stream structure. liblzma doesn't do this, and assumes that
* application knows what it is doing.
*/
extern void lzma_end(lzma_stream *strm);
extern LZMA_API(void) lzma_end(lzma_stream *strm) lzma_nothrow;
/**
* \brief Get the memory usage of decoder filter chain
*
* This function is currently supported only when *strm has been initialized
* with a function that takes a memlimit argument. With other functions, you
* should use e.g. lzma_raw_encoder_memusage() or lzma_raw_decoder_memusage()
* to estimate the memory requirements.
*
* This function is useful e.g. after LZMA_MEMLIMIT_ERROR to find out how big
* the memory usage limit should have been to decode the input. Note that
* this may give misleading information if decoding .xz Streams that have
* multiple Blocks, because each Block can have different memory requirements.
*
* \return Rough estimate of how much memory is currently allocated
* for the filter decoders. If no filter chain is currently
* allocated, some non-zero value is still returned, which is
* less than or equal to what any filter chain would indicate
* as its memory requirement.
*
* If this function isn't supported by *strm or some other error
* occurs, zero is returned.
*/
extern LZMA_API(uint64_t) lzma_memusage(const lzma_stream *strm)
lzma_nothrow lzma_attr_pure;
/**
* \brief Get the current memory usage limit
*
* This function is supported only when *strm has been initialized with
* a function that takes a memlimit argument.
*
* \return On success, the current memory usage limit is returned
* (always non-zero). On error, zero is returned.
*/
extern LZMA_API(uint64_t) lzma_memlimit_get(const lzma_stream *strm)
lzma_nothrow lzma_attr_pure;
/**
* \brief Set the memory usage limit
*
* This function is supported only when *strm has been initialized with
* a function that takes a memlimit argument.
*
* \return - LZMA_OK: New memory usage limit successfully set.
* - LZMA_MEMLIMIT_ERROR: The new limit is too small.
* The limit was not changed.
* - LZMA_PROG_ERROR: Invalid arguments, e.g. *strm doesn't
* support memory usage limit or memlimit was zero.
*/
extern LZMA_API(lzma_ret) lzma_memlimit_set(
lzma_stream *strm, uint64_t memlimit) lzma_nothrow;

View File

@@ -1,19 +1,15 @@
/**
* \file lzma/simple.h
* \brief So called "simple" filters
* \file lzma/bcj.h
* \brief Branch/Call/Jump conversion filters
*/
/*
* Author: Lasse Collin
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
* This file has been put into the public domain.
* You can do whatever you want with this file.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
* See ../lzma.h for information about liblzma as a whole.
*/
#ifndef LZMA_H_INTERNAL
@@ -21,11 +17,11 @@
#endif
/* Filter IDs for lzma_options_filter.id */
/* Filter IDs for lzma_filter.id */
#define LZMA_FILTER_X86 LZMA_VLI_C(0x04)
/**<
* BCJ (Branch, Call, Jump) filter for x86 binaries
* Filter for x86 binaries
*/
#define LZMA_FILTER_POWERPC LZMA_VLI_C(0x05)
@@ -55,19 +51,28 @@
/**
* \brief Options for so called "simple" filters
* \brief Options for BCJ filters
*
* The simple filters never change the size of the data. Specifying options
* for them is optional: if pointer to options is NULL, default values are
* used. You probably never need to specify these options, so just set the
* options pointer to NULL and be happy.
* The BCJ filters never change the size of the data. Specifying options
* for them is optional: if pointer to options is NULL, default value is
* used. You probably never need to specify options to BCJ filters, so just
* set the options pointer to NULL and be happy.
*
* If options with non-default values have been specified when encoding,
* the same options must also be specified when decoding.
*
* \note At the moment, none of the BCJ filters support
* LZMA_SYNC_FLUSH. If LZMA_SYNC_FLUSH is specified,
* LZMA_OPTIONS_ERROR will be returned. If there is need,
* partial support for LZMA_SYNC_FLUSH can be added in future.
* Partial means that flushing would be possible only at
* offsets that are multiple of 2, 4, or 16 depending on
* the filter, except x86 which cannot be made to support
* LZMA_SYNC_FLUSH predictably.
*/
typedef struct {
/**
* \brief Start offset for branch conversions
* \brief Start offset for conversions
*
* This setting is useful only when the same filter is used
* _separately_ for multiple sections of the same executable file,
@@ -77,9 +82,9 @@ typedef struct {
* of the cross-section branch/call/jump instructions will use the
* same absolute addresses as in the first section.
*
* When the pointer to options is NULL, the default value is used.
* The default value is zero.
* When the pointer to options is NULL, the default value (zero)
* is used.
*/
uint32_t start_offset;
} lzma_options_simple;
} lzma_options_bcj;

View File

@@ -1,19 +1,15 @@
/**
* \file lzma/block.h
* \brief .lzma Block handling
* \brief .xz Block handling
*/
/*
* Author: Lasse Collin
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
* This file has been put into the public domain.
* You can do whatever you want with this file.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
* See ../lzma.h for information about liblzma as a whole.
*/
#ifndef LZMA_H_INTERNAL
@@ -22,10 +18,10 @@
/**
* \brief Options for the Block Header encoder and decoder
* \brief Options for the Block and Block Header encoders and decoders
*
* Different things use different parts of this structure. Some read
* some members, other functions write, and some do both. Only the
* Different Block handling functions use different parts of this structure.
* Some read some members, other functions write, and some do both. Only the
* members listed for reading need to be initialized when the specified
* functions are called. The members marked for writing will be assigned
* new values at some point either by calling the given function or by
@@ -33,377 +29,506 @@
*/
typedef struct {
/**
* \brief Type of integrity Check
* \brief Block format version
*
* The type of the integrity Check is not stored into the Block
* Header, thus its value must be provided also when decoding.
* To prevent API and ABI breakages if new features are needed in
* Block, a version number is used to indicate which fields in this
* structure are in use. For now, version must always be zero.
* With non-zero version, most Block related functions will return
* LZMA_OPTIONS_ERROR.
*
* Read by:
* - lzma_block_encoder()
* - lzma_block_decoder()
*/
lzma_check_type check;
/**
* \brief Precense of CRC32 of the Block Header
*
* Set this to true if CRC32 of the Block Header should be
* calculated and stored in the Block Header.
*
* There is no way to autodetect if CRC32 is present in the Block
* Header, thus this information must be provided also when decoding.
* The decoding functions will always set this to the lowest value
* that supports all the features indicated by the Block Header field.
* The application must check that the version number set by the
* decoding functions is supported by the application. Otherwise it
* is possible that the application will decode the Block incorrectly.
*
* Read by:
* - lzma_block_header_size()
* - lzma_block_header_encoder()
* - lzma_block_header_decoder()
*/
lzma_bool has_crc32;
/**
* \brief Usage of End of Payload Marker
*
* If this is true, End of Payload Marker is used even if
* Uncompressed Size is known.
*
* Read by:
* - lzma_block_header_encoder()
* - lzma_block_header_encode()
* - lzma_block_compressed_size()
* - lzma_block_unpadded_size()
* - lzma_block_total_size()
* - lzma_block_encoder()
* - lzma_block_decoder()
* - lzma_block_buffer_encode()
* - lzma_block_buffer_decode()
*
* Written by:
* - lzma_block_header_decoder()
* - lzma_block_header_decode()
*/
lzma_bool has_eopm;
uint32_t version;
/**
* \brief True if the Block is a Metadata Block
* \brief Size of the Block Header field
*
* If this is true, the Metadata bit will be set in the Block Header.
* It is up to the application to store correctly formatted data
* into Metadata Block.
* This is always a multiple of four.
*
* Read by:
* - lzma_block_header_encoder()
* - lzma_block_header_encode()
* - lzma_block_header_decode()
* - lzma_block_compressed_size()
* - lzma_block_unpadded_size()
* - lzma_block_total_size()
* - lzma_block_decoder()
* - lzma_block_buffer_decode()
*
* Written by:
* - lzma_block_header_decoder()
* - lzma_block_header_size()
* - lzma_block_buffer_encode()
*/
lzma_bool is_metadata;
uint32_t header_size;
# define LZMA_BLOCK_HEADER_SIZE_MIN 8
# define LZMA_BLOCK_HEADER_SIZE_MAX 1024
/**
* \brief True if Uncompressed Size is in Block Footer
* \brief Type of integrity Check
*
* The Check ID is not stored into the Block Header, thus its value
* must be provided also when decoding.
*
* Read by:
* - lzma_block_header_encode()
* - lzma_block_header_decode()
* - lzma_block_compressed_size()
* - lzma_block_unpadded_size()
* - lzma_block_total_size()
* - lzma_block_encoder()
* - lzma_block_decoder()
* - lzma_block_buffer_encode()
* - lzma_block_buffer_decode()
*/
lzma_bool has_uncompressed_size_in_footer;
/**
* \brief True if Backward Size is in Block Footer
*
* Read by:
* - lzma_block_encoder()
* - lzma_block_decoder()
*/
lzma_bool has_backward_size;
/**
* \brief True if Block coder should take care of Padding
*
* In liblzma, Stream decoder sets this to true when decoding
* Header Metadata Block or Data Blocks from Multi-Block Stream,
* and to false when decoding Single-Block Stream or Footer
* Metadata Block from a Multi-Block Stream.
*
* Read by:
* - lzma_block_encoder()
* - lzma_block_decoder()
*/
lzma_bool handle_padding;
lzma_check check;
/**
* \brief Size of the Compressed Data in bytes
*
* Usually you don't know this value when encoding in streamed mode.
* In non-streamed mode you can reserve space for this field when
* encoding the Block Header the first time, and then re-encode the
* Block Header and copy it over the original one after the encoding
* of the Block has been finished.
* Encoding: If this is not LZMA_VLI_UNKNOWN, Block Header encoder
* will store this value to the Block Header. Block encoder doesn't
* care about this value, but will set it once the encoding has been
* finished.
*
* Decoding: If this is not LZMA_VLI_UNKNOWN, Block decoder will
* verify that the size of the Compressed Data field matches
* compressed_size.
*
* Usually you don't know this value when encoding in streamed mode,
* and thus cannot write this field into the Block Header.
*
* In non-streamed mode you can reserve space for this field before
* encoding the actual Block. After encoding the data, finish the
* Block by encoding the Block Header. Steps in detail:
*
* - Set compressed_size to some big enough value. If you don't know
* better, use LZMA_VLI_MAX, but remember that bigger values take
* more space in Block Header.
*
* - Call lzma_block_header_size() to see how much space you need to
* reserve for the Block Header.
*
* - Encode the Block using lzma_block_encoder() and lzma_code().
* It sets compressed_size to the correct value.
*
* - Use lzma_block_header_encode() to encode the Block Header.
* Because space was reserved in the first step, you don't need
* to call lzma_block_header_size() anymore, because due to
* reserving, header_size has to be big enough. If it is "too big",
* lzma_block_header_encode() will add enough Header Padding to
* make Block Header to match the size specified by header_size.
*
* Read by:
* - lzma_block_header_size()
* - lzma_block_header_encoder()
* - lzma_block_encoder()
* - lzma_block_header_encode()
* - lzma_block_compressed_size()
* - lzma_block_unpadded_size()
* - lzma_block_total_size()
* - lzma_block_decoder()
* - lzma_block_buffer_decode()
*
* Written by:
* - lzma_block_header_decoder()
* - lzma_block_header_decode()
* - lzma_block_compressed_size()
* - lzma_block_encoder()
* - lzma_block_decoder()
* - lzma_block_buffer_encode()
* - lzma_block_buffer_decode()
*/
lzma_vli compressed_size;
/**
* \brief Uncompressed Size in bytes
*
* Encoder: If this value is not LZMA_VLI_VALUE_UNKNOWN, it is stored
* to the Uncompressed Size field in the Block Header. The real
* uncompressed size of the data being compressed must match
* the Uncompressed Size or LZMA_HEADER_ERROR is returned.
* This is handled very similarly to compressed_size above.
*
* If Uncompressed Size is unknown, End of Payload Marker must
* be used. If uncompressed_size == LZMA_VLI_VALUE_UNKNOWN and
* has_eopm == 0, LZMA_HEADER_ERROR will be returned.
*
* Decoder: If this value is not LZMA_VLI_VALUE_UNKNOWN, it is
* compared to the real Uncompressed Size. If they do not match,
* LZMA_HEADER_ERROR is returned.
* uncompressed_size is needed by fewer functions than
* compressed_size. This is because uncompressed_size isn't
* needed to validate that Block stays within proper limits.
*
* Read by:
* - lzma_block_header_size()
* - lzma_block_header_encoder()
* - lzma_block_encoder()
* - lzma_block_header_encode()
* - lzma_block_decoder()
* - lzma_block_buffer_decode()
*
* Written by:
* - lzma_block_header_decoder()
* - lzma_block_header_decode()
* - lzma_block_encoder()
* - lzma_block_decoder()
* - lzma_block_buffer_encode()
* - lzma_block_buffer_decode()
*/
lzma_vli uncompressed_size;
/**
* \brief Number of bytes to reserve for Compressed Size
*
* This is useful if you want to be able to store the Compressed Size
* to the Block Header, but you don't know it when starting to encode.
* Setting this to non-zero value at maximum of LZMA_VLI_BYTES_MAX,
* the Block Header encoder will force the Compressed Size field to
* occupy specified number of bytes. You can later rewrite the Block
* Header to contain correct information by using otherwise identical
* lzma_options_block structure except the correct compressed_size.
*
* Read by:
* - lzma_block_header_size()
* - lzma_block_header_encoder()
*
* Written by:
* - lzma_block_header_decoder()
*/
uint32_t compressed_reserve;
/**
* \brief Number of bytes to reserve for Uncompressed Size
*
* See the description of compressed_size above.
*
* Read by:
* - lzma_block_header_size()
* - lzma_block_header_encoder()
*
* Written by:
* - lzma_block_header_decoder()
*/
uint32_t uncompressed_reserve;
/**
* \brief Total Size of the Block in bytes
*
* This is useful in the decoder, which can verify the Total Size
* if it is known from Index.
*
* Read by:
* - lzma_block_encoder()
* - lzma_block_decoder()
*
* Written by:
* - lzma_block_encoder()
* - lzma_block_decoder()
*/
lzma_vli total_size;
/**
* \brief Upper limit of Total Size
*
* Read by:
* - lzma_block_encoder()
* - lzma_block_decoder()
*/
lzma_vli total_limit;
/**
* \brief Upper limit of Uncompressed Size
*
* Read by:
* - lzma_block_encoder()
* - lzma_block_decoder()
*/
lzma_vli uncompressed_limit;
/**
* \brief Array of filters
*
* There can be at maximum of seven filters. The end of the array
* is marked with .id = LZMA_VLI_VALUE_UNKNOWN. Minimum number of
* filters is zero; in that case, an implicit Copy filter is used.
* There can be 1-4 filters. The end of the array is marked with
* .id = LZMA_VLI_UNKNOWN.
*
* Read by:
* - lzma_block_header_size()
* - lzma_block_header_encoder()
* - lzma_block_header_encode()
* - lzma_block_encoder()
* - lzma_block_decoder()
* - lzma_block_buffer_encode()
* - lzma_block_buffer_decode()
*
* Written by:
* - lzma_block_header_decoder(): Note that this does NOT free()
* the old filter options structures. If decoding fails, the
* caller must take care of freeing the options structures
* that may have been allocated and decoded before the error
* occurred.
* - lzma_block_header_decode(): Note that this does NOT free()
* the old filter options structures. All unused filters[] will
* have .id == LZMA_VLI_UNKNOWN and .options == NULL. If
* decoding fails, all filters[] are guaranteed to be
* LZMA_VLI_UNKNOWN and NULL.
*
* \note Because of the array is terminated with
* .id = LZMA_VLI_UNKNOWN, the actual array must
* have LZMA_FILTERS_MAX + 1 members or the Block
* Header decoder will overflow the buffer.
*/
lzma_options_filter filters[8];
lzma_filter *filters;
/**
* \brief Size of the Padding field
* \brief Raw value stored in the Check field
*
* The Padding field exist to allow aligning the Compressed Data field
* optimally in the Block. See lzma_options_stream.alignment in
* stream.h for more information.
* After successful coding, the first lzma_check_size(check) bytes
* of this array contain the raw value stored in the Check field.
*
* If you want the Block Header encoder to automatically calculate
* optimal size for the Padding field by looking at the information
* in filters[], set this to LZMA_BLOCK_HEADER_PADDING_AUTO. In that
* case, you must also set the aligmnet variable to tell the the
* encoder the aligmnet of the beginning of the Block Header.
* Note that CRC32 and CRC64 are stored in little endian byte order.
* Take it into account if you display the Check values to the user.
*
* The decoder never sets this to LZMA_BLOCK_HEADER_PADDING_AUTO.
*
* Read by:
* - lzma_block_header_size()
* - lzma_block_header_encoder(): Note that this doesn't
* accept LZMA_BLOCK_HEADER_PADDING_AUTO.
*
* Written by (these never set padding to
* LZMA_BLOCK_HEADER_PADDING_AUTO):
* - lzma_block_header_size()
* - lzma_block_header_decoder()
*/
int32_t padding;
# define LZMA_BLOCK_HEADER_PADDING_AUTO (-1)
# define LZMA_BLOCK_HEADER_PADDING_MIN 0
# define LZMA_BLOCK_HEADER_PADDING_MAX 31
/**
* \brief Alignment of the beginning of the Block Header
*
* This variable is read only if padding has been set to
* LZMA_BLOCK_HEADER_PADDING_AUTO.
*
* Read by:
* - lzma_block_header_size()
* - lzma_block_header_encoder()
*/
uint32_t alignment;
/**
* \brief Size of the Block Header
*
* Read by:
* Written by:
* - lzma_block_encoder()
* - lzma_block_decoder()
*
* Written by:
* - lzma_block_header_size()
* - lzma_block_header_decoder()
* - lzma_block_buffer_encode()
* - lzma_block_buffer_decode()
*/
uint32_t header_size;
uint8_t raw_check[LZMA_CHECK_SIZE_MAX];
} lzma_options_block;
/*
* Reserved space to allow possible future extensions without
* breaking the ABI. You should not touch these, because the names
* of these variables may change. These are and will never be used
* with the currently supported options, so it is safe to leave these
* uninitialized.
*/
void *reserved_ptr1;
void *reserved_ptr2;
void *reserved_ptr3;
uint32_t reserved_int1;
uint32_t reserved_int2;
lzma_vli reserved_int3;
lzma_vli reserved_int4;
lzma_vli reserved_int5;
lzma_vli reserved_int6;
lzma_vli reserved_int7;
lzma_vli reserved_int8;
lzma_reserved_enum reserved_enum1;
lzma_reserved_enum reserved_enum2;
lzma_reserved_enum reserved_enum3;
lzma_reserved_enum reserved_enum4;
lzma_bool reserved_bool1;
lzma_bool reserved_bool2;
lzma_bool reserved_bool3;
lzma_bool reserved_bool4;
lzma_bool reserved_bool5;
lzma_bool reserved_bool6;
lzma_bool reserved_bool7;
lzma_bool reserved_bool8;
} lzma_block;
/**
* \brief Calculates the size of Header Padding and Block Header
* \brief Decode the Block Header Size field
*
* To decode Block Header using lzma_block_header_decode(), the size of the
* Block Header has to be known and stored into lzma_block.header_size.
* The size can be calculated from the first byte of a Block using this macro.
* Note that if the first byte is 0x00, it indicates beginning of Index; use
* this macro only when the byte is not 0x00.
*
* There is no encoding macro, because Block Header encoder is enough for that.
*/
#define lzma_block_header_size_decode(b) (((uint32_t)(b) + 1) * 4)
/**
* \brief Calculate Block Header Size
*
* Calculate the minimum size needed for the Block Header field using the
* settings specified in the lzma_block structure. Note that it is OK to
* increase the calculated header_size value as long as it is a multiple of
* four and doesn't exceed LZMA_BLOCK_HEADER_SIZE_MAX. Increasing header_size
* just means that lzma_block_header_encode() will add Header Padding.
*
* \return - LZMA_OK: Size calculated successfully and stored to
* options->header_size.
* - LZMA_HEADER_ERROR: Unsupported filters or filter options.
* - LZMA_PROG_ERROR: Invalid options
* block->header_size.
* - LZMA_OPTIONS_ERROR: Unsupported version, filters or
* filter options.
* - LZMA_PROG_ERROR: Invalid values like compressed_size == 0.
*
* \note This doesn't check that all the options are valid i.e. this
* may return LZMA_OK even if lzma_block_header_encode() or
* lzma_block_encoder() would fail.
* lzma_block_encoder() would fail. If you want to validate the
* filter chain, consider using lzma_memlimit_encoder() which as
* a side-effect validates the filter chain.
*/
extern lzma_ret lzma_block_header_size(lzma_options_block *options);
extern LZMA_API(lzma_ret) lzma_block_header_size(lzma_block *block)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Encodes Block Header
* \brief Encode Block Header
*
* Encoding of the Block options is done with a single call instead of
* first initializing and then doing the actual work with lzma_code().
* The caller must have calculated the size of the Block Header already with
* lzma_block_header_size(). If a value larger than the one calculated by
* lzma_block_header_size() is used, the Block Header will be padded to the
* specified size.
*
* \param out Beginning of the output buffer. This must be
* at least options->header_size bytes.
* \param options Block options to be encoded.
* at least block->header_size bytes.
* \param block Block options to be encoded.
*
* \return - LZMA_OK: Encoding was successful. options->header_size
* \return - LZMA_OK: Encoding was successful. block->header_size
* bytes were written to output buffer.
* - LZMA_HEADER_ERROR: Invalid or unsupported options.
* - LZMA_PROG_ERROR
* - LZMA_OPTIONS_ERROR: Invalid or unsupported options.
* - LZMA_PROG_ERROR: Invalid arguments, for example
* block->header_size is invalid or block->filters is NULL.
*/
extern lzma_ret lzma_block_header_encode(
uint8_t *out, const lzma_options_block *options);
extern LZMA_API(lzma_ret) lzma_block_header_encode(
const lzma_block *block, uint8_t *out)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Initializes Block Header decoder
* \brief Decode Block Header
*
* Because the results of this decoder are placed into *options,
* strm->next_in, strm->avail_in, and strm->total_in are not used.
* The size of the Block Header must have already been decoded with
* lzma_block_header_size_decode() macro and stored to block->header_size.
* block->filters must have been allocated, but not necessarily initialized.
* Possible existing filter options are _not_ freed.
*
* The only valid `action' with lzma_code() is LZMA_RUN.
* \param block Destination for block options with header_size
* properly initialized.
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() (and also free()
* if an error occurs).
* \param in Beginning of the input buffer. This must be
* at least block->header_size bytes.
*
* \return - LZMA_OK: Encoding was successful. options->header_size
* bytes were written to output buffer.
* - LZMA_HEADER_ERROR: Invalid or unsupported options.
* - LZMA_PROG_ERROR
* \return - LZMA_OK: Decoding was successful. block->header_size
* bytes were read from the input buffer.
* - LZMA_OPTIONS_ERROR: The Block Header specifies some
* unsupported options such as unsupported filters.
* - LZMA_DATA_ERROR: Block Header is corrupt, for example,
* the CRC32 doesn't match.
* - LZMA_PROG_ERROR: Invalid arguments, for example
* block->header_size is invalid or block->filters is NULL.
*/
extern lzma_ret lzma_block_header_decoder(
lzma_stream *strm, lzma_options_block *options);
extern LZMA_API(lzma_ret) lzma_block_header_decode(lzma_block *block,
lzma_allocator *allocator, const uint8_t *in)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Initializes .lzma Block encoder
* \brief Validate and set Compressed Size according to Unpadded Size
*
* This function is required for multi-thread encoding. It may also be
* useful when implementing custom file formats.
* Block Header stores Compressed Size, but Index has Unpadded Size. If the
* application has already parsed the Index and is now decoding Blocks,
* it can calculate Compressed Size from Unpadded Size. This function does
* exactly that with error checking:
*
* - Compressed Size calculated from Unpadded Size must be positive integer,
* that is, Unpadded Size must be big enough that after Block Header and
* Check fields there's still at least one byte for Compressed Size.
*
* - If Compressed Size was present in Block Header, the new value
* calculated from Unpadded Size is compared against the value
* from Block Header.
*
* \note This function must be called _after_ decoding the Block Header
* field so that it can properly validate Compressed Size if it
* was present in Block Header.
*
* \return - LZMA_OK: block->compressed_size was set successfully.
* - LZMA_DATA_ERROR: unpadded_size is too small compared to
* block->header_size and lzma_check_size(block->check).
* - LZMA_PROG_ERROR: Some values are invalid. For example,
* block->header_size must be a multiple of four and
* between 8 and 1024 inclusive.
*/
extern LZMA_API(lzma_ret) lzma_block_compressed_size(
lzma_block *block, lzma_vli unpadded_size)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Calculate Unpadded Size
*
* The Index field stores Unpadded Size and Uncompressed Size. The latter
* can be taken directly from the lzma_block structure after coding a Block,
* but Unpadded Size needs to be calculated from Block Header Size,
* Compressed Size, and size of the Check field. This is where this function
* is needed.
*
* \return Unpadded Size on success, or zero on error.
*/
extern LZMA_API(lzma_vli) lzma_block_unpadded_size(const lzma_block *block)
lzma_nothrow lzma_attr_pure;
/**
* \brief Calculate the total encoded size of a Block
*
* This is equivalent to lzma_block_unpadded_size() except that the returned
* value includes the size of the Block Padding field.
*
* \return On success, total encoded size of the Block. On error,
* zero is returned.
*/
extern LZMA_API(lzma_vli) lzma_block_total_size(const lzma_block *block)
lzma_nothrow lzma_attr_pure;
/**
* \brief Initialize .xz Block encoder
*
* Valid actions for lzma_code() are LZMA_RUN, LZMA_SYNC_FLUSH (only if the
* filter chain supports it), and LZMA_FINISH.
*
* \return - LZMA_OK: All good, continue with lzma_code().
* - LZMA_MEM_ERROR
* - LZMA_HEADER_ERROR
* - LZMA_DATA_ERROR: Limits (total_limit and uncompressed_limit)
* have been reached already.
* - LZMA_UNSUPPORTED_CHECK: options->check specfies a Check
* - LZMA_OPTIONS_ERROR
* - LZMA_UNSUPPORTED_CHECK: block->check specfies a Check ID
* that is not supported by this buid of liblzma. Initializing
* the encoder failed.
* - LZMA_PROG_ERROR
*
* lzma_code() can return FIXME
*/
extern lzma_ret lzma_block_encoder(
lzma_stream *strm, lzma_options_block *options);
extern LZMA_API(lzma_ret) lzma_block_encoder(
lzma_stream *strm, lzma_block *block)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Initializes decoder for .lzma Block
* \brief Initialize .xz Block decoder
*
* Valid actions for lzma_code() are LZMA_RUN and LZMA_FINISH. Using
* LZMA_FINISH is not required. It is supported only for convenience.
*
* \return - LZMA_OK: All good, continue with lzma_code().
* - LZMA_UNSUPPORTED_CHECK: Initialization was successful, but
* the given Check type is not supported, thus Check will be
* the given Check ID is not supported, thus Check will be
* ignored.
* - LZMA_PROG_ERROR
* - LZMA_MEM_ERROR
*/
extern lzma_ret lzma_block_decoder(
lzma_stream *strm, lzma_options_block *options);
extern LZMA_API(lzma_ret) lzma_block_decoder(
lzma_stream *strm, lzma_block *block)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Calculate maximum output size for single-call Block encoding
*
* This is equivalent to lzma_stream_buffer_bound() but for .xz Blocks.
* See the documentation of lzma_stream_buffer_bound().
*/
extern LZMA_API(size_t) lzma_block_buffer_bound(size_t uncompressed_size)
lzma_nothrow;
/**
* \brief Single-call .xz Block encoder
*
* In contrast to the multi-call encoder initialized with
* lzma_block_encoder(), this function encodes also the Block Header. This
* is required to make it possible to write appropriate Block Header also
* in case the data isn't compressible, and different filter chain has to be
* used to encode the data in uncompressed form using uncompressed chunks
* of the LZMA2 filter.
*
* When the data isn't compressible, header_size, compressed_size, and
* uncompressed_size are set just like when the data was compressible, but
* it is possible that header_size is too small to hold the filter chain
* specified in block->filters, because that isn't necessarily the filter
* chain that was actually used to encode the data. lzma_block_unpadded_size()
* still works normally, because it doesn't read the filters array.
*
* \param block Block options: block->version, block->check,
* and block->filters must have been initialized.
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
* \param in Beginning of the input buffer
* \param in_size Size of the input buffer
* \param out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos].
* *out_pos is updated only if encoding succeeds.
* \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size].
*
* \return - LZMA_OK: Encoding was successful.
* - LZMA_BUF_ERROR: Not enough output buffer space.
* - LZMA_OPTIONS_ERROR
* - LZMA_MEM_ERROR
* - LZMA_DATA_ERROR
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_block_buffer_encode(
lzma_block *block, lzma_allocator *allocator,
const uint8_t *in, size_t in_size,
uint8_t *out, size_t *out_pos, size_t out_size)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Single-call .xz Block decoder
*
* This is single-call equivalent of lzma_block_decoder(), and requires that
* the caller has already decoded Block Header and checked its memory usage.
*
* \param block Block options just like with lzma_block_decoder().
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
* \param in Beginning of the input buffer
* \param in_pos The next byte will be read from in[*in_pos].
* *in_pos is updated only if decoding succeeds.
* \param in_size Size of the input buffer; the first byte that
* won't be read is in[in_size].
* \param out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos].
* *out_pos is updated only if encoding succeeds.
* \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size].
*
* \return - LZMA_OK: Decoding was successful.
* - LZMA_OPTIONS_ERROR
* - LZMA_DATA_ERROR
* - LZMA_MEM_ERROR
* - LZMA_BUF_ERROR: Output buffer was too small.
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_block_buffer_decode(
lzma_block *block, lzma_allocator *allocator,
const uint8_t *in, size_t *in_pos, size_t in_size,
uint8_t *out, size_t *out_pos, size_t out_size)
lzma_nothrow;

View File

@@ -1,19 +1,15 @@
/**
* \file lzma/check.h
* \brief Integrity checks
*/
/*
* Author: Lasse Collin
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
* This file has been put into the public domain.
* You can do whatever you want with this file.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
* See ../lzma.h for information about liblzma as a whole.
*/
#ifndef LZMA_H_INTERNAL
@@ -22,11 +18,11 @@
/**
* \brief Type of the Check
* \brief Type of the integrity check (Check ID)
*
* The .lzma format supports multiple types of Checks that are calculated
* from the uncompressed data (unless it is empty; then it's calculated
* from Block Header).
* The .xz format supports multiple types of checks that are calculated
* from the uncompressed data. They vary in both speed and ability to
* detect errors.
*/
typedef enum {
LZMA_CHECK_NONE = 0,
@@ -43,86 +39,112 @@ typedef enum {
* Size of the Check field: 4 bytes
*/
LZMA_CHECK_CRC64 = 3,
LZMA_CHECK_CRC64 = 4,
/**<
* CRC64 using the polynomial from the ECMA-182 standard
*
* Size of the Check field: 8 bytes
*/
LZMA_CHECK_SHA256 = 5
LZMA_CHECK_SHA256 = 10
/**<
* SHA-256
*
* Size of the Check field: 32 bytes
*/
} lzma_check_type;
} lzma_check;
/**
* \brief Maximum valid Check ID
*
* The .lzma file format specification specifies eight Check IDs (0-7). Some
* of them are only reserved i.e. no actual Check algorithm has been assigned.
* Still liblzma accepts any of these eight IDs for future compatibility
* when decoding files. If a valid but unsupported Check ID is detected,
* liblzma indicates a warning with LZMA_UNSUPPORTED_CHECK.
*
* FIXME bad desc
* The .xz file format specification specifies 16 Check IDs (0-15). Some
* of them are only reserved, that is, no actual Check algorithm has been
* assigned. When decoding, liblzma still accepts unknown Check IDs for
* future compatibility. If a valid but unsupported Check ID is detected,
* liblzma can indicate a warning; see the flags LZMA_TELL_NO_CHECK,
* LZMA_TELL_UNSUPPORTED_CHECK, and LZMA_TELL_ANY_CHECK in container.h.
*/
#define LZMA_CHECK_ID_MAX 7
#define LZMA_CHECK_ID_MAX 15
/**
* \brief Check IDs supported by this liblzma build
* \brief Test if the given Check ID is supported
*
* If lzma_available_checks[n] is true, the Check ID n is supported by this
* liblzma build. You can assume that LZMA_CHECK_NONE and LZMA_CHECK_CRC32
* are always available.
* Return true if the given Check ID is supported by this liblzma build.
* Otherwise false is returned. It is safe to call this with a value that
* is not in the range [0, 15]; in that case the return value is always false.
*
* You can assume that LZMA_CHECK_NONE and LZMA_CHECK_CRC32 are always
* supported (even if liblzma is built with limited features).
*/
extern const lzma_bool lzma_available_checks[LZMA_CHECK_ID_MAX + 1];
extern LZMA_API(lzma_bool) lzma_check_is_supported(lzma_check check)
lzma_nothrow lzma_attr_const;
/**
* \brief Size of the Check field with different Check IDs
* \brief Get the size of the Check field with the given Check ID
*
* Although not all Check IDs have a check algorithm associated, the size of
* every Check is already frozen. This array contains the size (in bytes) of
* the Check field with specified Check ID. The values are taken from the
* section 2.2.2 of the .lzma file format specification:
* { 0, 4, 4, 8, 16, 32, 32, 64 }
* every Check is already frozen. This function returns the size (in bytes) of
* the Check field with the specified Check ID. The values are:
* { 0, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 32, 64, 64, 64 }
*
* If the argument is not in the range [0, 15], UINT32_MAX is returned.
*/
extern const uint32_t lzma_check_sizes[LZMA_CHECK_ID_MAX + 1];
extern LZMA_API(uint32_t) lzma_check_size(lzma_check check)
lzma_nothrow lzma_attr_const;
/**
* \brief Maximum size of a Check field
*/
#define LZMA_CHECK_SIZE_MAX 64
/**
* \brief Calculate CRC32
*
* Calculates CRC32 using the polynomial from the IEEE 802.3 standard.
* Calculate CRC32 using the polynomial from the IEEE 802.3 standard.
*
* \param buf Pointer to the input buffer
* \param size Size of the input buffer
* \param crc Previously returned CRC value. This is used to
* calculate the CRC of a big buffer in smaller chunks.
* Set to zero when there is no previous value.
* Set to zero when starting a new calculation.
*
* \return Updated CRC value, which can be passed to this function
* again to continue CRC calculation.
*/
extern uint32_t lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc);
extern LZMA_API(uint32_t) lzma_crc32(
const uint8_t *buf, size_t size, uint32_t crc)
lzma_nothrow lzma_attr_pure;
/**
* \brief Calculate CRC64
*
* Calculates CRC64 using the polynomial from the ECMA-182 standard.
* Calculate CRC64 using the polynomial from the ECMA-182 standard.
*
* This function is used similarly to lzma_crc32(). See its documentation.
*/
extern uint64_t lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc);
extern LZMA_API(uint64_t) lzma_crc64(
const uint8_t *buf, size_t size, uint64_t crc)
lzma_nothrow lzma_attr_pure;
/*
* SHA256 functions are currently not exported to public API.
* Contact the author if you think it should be.
* SHA-256 functions are currently not exported to public API.
* Contact Lasse Collin if you think it should be.
*/
/**
* \brief Get the type of the integrity check
*
* This function can be called only immediatelly after lzma_code() has
* returned LZMA_NO_CHECK, LZMA_UNSUPPORTED_CHECK, or LZMA_GET_CHECK.
* Calling this function in any other situation has undefined behavior.
*/
extern LZMA_API(lzma_check) lzma_get_check(const lzma_stream *strm)
lzma_nothrow;

View File

@@ -0,0 +1,404 @@
/**
* \file lzma/container.h
* \brief File formats
*/
/*
* Author: Lasse Collin
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*
* See ../lzma.h for information about liblzma as a whole.
*/
#ifndef LZMA_H_INTERNAL
# error Never include this file directly. Use <lzma.h> instead.
#endif
/************
* Encoding *
************/
/**
* \brief Default compression preset
*
* It's not straightforward to recommend a default preset, because in some
* cases keeping the resource usage relatively low is more important that
* getting the maximum compression ratio.
*/
#define LZMA_PRESET_DEFAULT UINT32_C(6)
/**
* \brief Mask for preset level
*
* This is useful only if you need to extract the level from the preset
* variable. That should be rare.
*/
#define LZMA_PRESET_LEVEL_MASK UINT32_C(0x1F)
/*
* Preset flags
*
* Currently only one flag is defined.
*/
/**
* \brief Extreme compression preset
*
* This flag modifies the preset to make the encoding significantly slower
* while improving the compression ratio only marginally. This is useful
* when you don't mind wasting time to get as small result as possible.
*
* This flag doesn't affect the memory usage requirements of the decoder (at
* least not significantly). The memory usage of the encoder may be increased
* a little but only at the lowest preset levels (0-2).
*/
#define LZMA_PRESET_EXTREME (UINT32_C(1) << 31)
/**
* \brief Calculate rough memory usage of easy encoder
*
* This function is a wrapper for lzma_raw_encoder_memusage().
*
* \param preset Compression preset (level and possible flags)
*/
extern LZMA_API(uint64_t) lzma_easy_encoder_memusage(uint32_t preset)
lzma_nothrow lzma_attr_pure;
/**
* \brief Calculate rough decoder memory usage of a preset
*
* This function is a wrapper for lzma_raw_decoder_memusage().
*
* \param preset Compression preset (level and possible flags)
*/
extern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset)
lzma_nothrow lzma_attr_pure;
/**
* \brief Initialize .xz Stream encoder using a preset number
*
* This function is intended for those who just want to use the basic features
* if liblzma (that is, most developers out there).
*
* \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
* \param preset Compression preset to use. A preset consist of level
* number and zero or more flags. Usually flags aren't
* used, so preset is simply a number [0, 9] which match
* the options -0 .. -9 of the xz command line tool.
* Additional flags can be be set using bitwise-or with
* the preset level number, e.g. 6 | LZMA_PRESET_EXTREME.
* \param check Integrity check type to use. See check.h for available
* checks. If you are unsure, use LZMA_CHECK_CRC32.
*
* \return - LZMA_OK: Initialization succeeded. Use lzma_code() to
* encode your data.
* - LZMA_MEM_ERROR: Memory allocation failed.
* - LZMA_OPTIONS_ERROR: The given compression level is not
* supported by this build of liblzma.
* - LZMA_UNSUPPORTED_CHECK: The given check type is not
* supported by this liblzma build.
* - LZMA_PROG_ERROR: One or more of the parameters have values
* that will never be valid. For example, strm == NULL.
*
* If initialization fails (return value is not LZMA_OK), all the memory
* allocated for *strm by liblzma is always freed. Thus, there is no need
* to call lzma_end() after failed initialization.
*
* If initialization succeeds, use lzma_code() to do the actual encoding.
* Valid values for `action' (the second argument of lzma_code()) are
* LZMA_RUN, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, and LZMA_FINISH. In future,
* there may be compression levels or flags that don't support LZMA_SYNC_FLUSH.
*/
extern LZMA_API(lzma_ret) lzma_easy_encoder(
lzma_stream *strm, uint32_t preset, lzma_check check)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Single-call .xz Stream encoding using a preset number
*
* The maximum required output buffer size can be calculated with
* lzma_stream_buffer_bound().
*
* \param preset Compression preset to use. See the description
* in lzma_easy_encoder().
* \param check Type of the integrity check to calculate from
* uncompressed data.
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
* \param in Beginning of the input buffer
* \param in_size Size of the input buffer
* \param out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos].
* *out_pos is updated only if encoding succeeds.
* \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size].
*
* \return - LZMA_OK: Encoding was successful.
* - LZMA_BUF_ERROR: Not enough output buffer space.
* - LZMA_OPTIONS_ERROR
* - LZMA_MEM_ERROR
* - LZMA_DATA_ERROR
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_easy_buffer_encode(
uint32_t preset, lzma_check check,
lzma_allocator *allocator, const uint8_t *in, size_t in_size,
uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow;
/**
* \brief Initialize .xz Stream encoder using a custom filter chain
*
* \param strm Pointer to properly prepared lzma_stream
* \param filters Array of filters. This must be terminated with
* filters[n].id = LZMA_VLI_UNKNOWN. See filter.h for
* more information.
* \param check Type of the integrity check to calculate from
* uncompressed data.
*
* \return - LZMA_OK: Initialization was successful.
* - LZMA_MEM_ERROR
* - LZMA_OPTIONS_ERROR
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_stream_encoder(lzma_stream *strm,
const lzma_filter *filters, lzma_check check)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Initialize .lzma encoder (legacy file format)
*
* The .lzma format is sometimes called the LZMA_Alone format, which is the
* reason for the name of this function. The .lzma format supports only the
* LZMA1 filter. There is no support for integrity checks like CRC32.
*
* Use this function if and only if you need to create files readable by
* legacy LZMA tools such as LZMA Utils 4.32.x. Moving to the .xz format
* is strongly recommended.
*
* The valid action values for lzma_code() are LZMA_RUN and LZMA_FINISH.
* No kind of flushing is supported, because the file format doesn't make
* it possible.
*
* \return - LZMA_OK
* - LZMA_MEM_ERROR
* - LZMA_OPTIONS_ERROR
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_alone_encoder(
lzma_stream *strm, const lzma_options_lzma *options)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Calculate output buffer size for single-call Stream encoder
*
* When trying to compress uncompressible data, the encoded size will be
* slightly bigger than the input data. This function calculates how much
* output buffer space is required to be sure that lzma_stream_buffer_encode()
* doesn't return LZMA_BUF_ERROR.
*
* The calculated value is not exact, but it is guaranteed to be big enough.
* The actual maximum output space required may be slightly smaller (up to
* about 100 bytes). This should not be a problem in practice.
*
* If the calculated maximum size doesn't fit into size_t or would make the
* Stream grow past LZMA_VLI_MAX (which should never happen in practice),
* zero is returned to indicate the error.
*
* \note The limit calculated by this function applies only to
* single-call encoding. Multi-call encoding may (and probably
* will) have larger maximum expansion when encoding
* uncompressible data. Currently there is no function to
* calculate the maximum expansion of multi-call encoding.
*/
extern LZMA_API(size_t) lzma_stream_buffer_bound(size_t uncompressed_size)
lzma_nothrow;
/**
* \brief Single-call .xz Stream encoder
*
* \param filters Array of filters. This must be terminated with
* filters[n].id = LZMA_VLI_UNKNOWN. See filter.h
* for more information.
* \param check Type of the integrity check to calculate from
* uncompressed data.
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
* \param in Beginning of the input buffer
* \param in_size Size of the input buffer
* \param out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos].
* *out_pos is updated only if encoding succeeds.
* \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size].
*
* \return - LZMA_OK: Encoding was successful.
* - LZMA_BUF_ERROR: Not enough output buffer space.
* - LZMA_OPTIONS_ERROR
* - LZMA_MEM_ERROR
* - LZMA_DATA_ERROR
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_stream_buffer_encode(
lzma_filter *filters, lzma_check check,
lzma_allocator *allocator, const uint8_t *in, size_t in_size,
uint8_t *out, size_t *out_pos, size_t out_size)
lzma_nothrow lzma_attr_warn_unused_result;
/************
* Decoding *
************/
/**
* This flag makes lzma_code() return LZMA_NO_CHECK if the input stream
* being decoded has no integrity check. Note that when used with
* lzma_auto_decoder(), all .lzma files will trigger LZMA_NO_CHECK
* if LZMA_TELL_NO_CHECK is used.
*/
#define LZMA_TELL_NO_CHECK UINT32_C(0x01)
/**
* This flag makes lzma_code() return LZMA_UNSUPPORTED_CHECK if the input
* stream has an integrity check, but the type of the integrity check is not
* supported by this liblzma version or build. Such files can still be
* decoded, but the integrity check cannot be verified.
*/
#define LZMA_TELL_UNSUPPORTED_CHECK UINT32_C(0x02)
/**
* This flag makes lzma_code() return LZMA_GET_CHECK as soon as the type
* of the integrity check is known. The type can then be got with
* lzma_get_check().
*/
#define LZMA_TELL_ANY_CHECK UINT32_C(0x04)
/**
* This flag enables decoding of concatenated files with file formats that
* allow concatenating compressed files as is. From the formats currently
* supported by liblzma, only the .xz format allows concatenated files.
* Concatenated files are not allowed with the legacy .lzma format.
*
* This flag also affects the usage of the `action' argument for lzma_code().
* When LZMA_CONCATENATED is used, lzma_code() won't return LZMA_STREAM_END
* unless LZMA_FINISH is used as `action'. Thus, the application has to set
* LZMA_FINISH in the same way as it does when encoding.
*
* If LZMA_CONCATENATED is not used, the decoders still accept LZMA_FINISH
* as `action' for lzma_code(), but the usage of LZMA_FINISH isn't required.
*/
#define LZMA_CONCATENATED UINT32_C(0x08)
/**
* \brief Initialize .xz Stream decoder
*
* \param strm Pointer to properly prepared lzma_stream
* \param memlimit Rough memory usage limit as bytes
* \param flags Bitwise-or of zero or more of the decoder flags:
* LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,
* LZMA_TELL_ANY_CHECK, LZMA_CONCATENATED
*
* \return - LZMA_OK: Initialization was successful.
* - LZMA_MEM_ERROR: Cannot allocate memory.
* - LZMA_OPTIONS_ERROR: Unsupported flags
*/
extern LZMA_API(lzma_ret) lzma_stream_decoder(
lzma_stream *strm, uint64_t memlimit, uint32_t flags)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Decode .xz Streams and .lzma files with autodetection
*
* This decoder autodetects between the .xz and .lzma file formats, and
* calls lzma_stream_decoder() or lzma_alone_decoder() once the type
* of the input file has been detected.
*
* \param strm Pointer to properly prepared lzma_stream
* \param memlimit Rough memory usage limit as bytes
* \param flags Bitwise-or of flags, or zero for no flags.
*
* \return - LZMA_OK: Initialization was successful.
* - LZMA_MEM_ERROR: Cannot allocate memory.
* - LZMA_OPTIONS_ERROR: Unsupported flags
*/
extern LZMA_API(lzma_ret) lzma_auto_decoder(
lzma_stream *strm, uint64_t memlimit, uint32_t flags)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Initialize .lzma decoder (legacy file format)
*
* Valid `action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.
* There is no need to use LZMA_FINISH, but allowing it may simplify
* certain types of applications.
*
* \return - LZMA_OK
* - LZMA_MEM_ERROR
*/
extern LZMA_API(lzma_ret) lzma_alone_decoder(
lzma_stream *strm, uint64_t memlimit)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Single-call .xz Stream decoder
*
* \param memlimit Pointer to how much memory the decoder is allowed
* to allocate. The value pointed by this pointer is
* modified if and only if LZMA_MEMLIMIT_ERROR is
* returned.
* \param flags Bitwise-or of zero or more of the decoder flags:
* LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,
* LZMA_CONCATENATED. Note that LZMA_TELL_ANY_CHECK
* is not allowed and will return LZMA_PROG_ERROR.
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
* \param in Beginning of the input buffer
* \param in_pos The next byte will be read from in[*in_pos].
* *in_pos is updated only if decoding succeeds.
* \param in_size Size of the input buffer; the first byte that
* won't be read is in[in_size].
* \param out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos].
* *out_pos is updated only if encoding succeeds.
* \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size].
*
* \return - LZMA_OK: Decoding was successful.
* - LZMA_FORMAT_ERROR
* - LZMA_OPTIONS_ERROR
* - LZMA_DATA_ERROR
* - LZMA_NO_CHECK: This can be returned only if using
* the LZMA_TELL_NO_CHECK flag.
* - LZMA_UNSUPPORTED_CHECK: This can be returned only if using
* the LZMA_TELL_UNSUPPORTED_CHECK flag.
* - LZMA_MEM_ERROR
* - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached.
* The minimum required memlimit value was stored to *memlimit.
* - LZMA_BUF_ERROR: Output buffer was too small.
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_stream_buffer_decode(
uint64_t *memlimit, uint32_t flags, lzma_allocator *allocator,
const uint8_t *in, size_t *in_pos, size_t in_size,
uint8_t *out, size_t *out_pos, size_t out_size)
lzma_nothrow lzma_attr_warn_unused_result;

View File

@@ -1,29 +0,0 @@
/**
* \file lzma/copy.h
* \brief Copy filter
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*/
#ifndef LZMA_H_INTERNAL
# error Never include this file directly. Use <lzma.h> instead.
#endif
/**
* \brief Filter ID
*
* Filter ID of the Copy filter. This is used as lzma_options_filter.id.
*/
#define LZMA_FILTER_COPY LZMA_VLI_C(0x00)

View File

@@ -1,19 +1,15 @@
/**
* \file lzma/delta.h
* \brief Delta filter
*/
/*
* Author: Lasse Collin
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
* This file has been put into the public domain.
* You can do whatever you want with this file.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
* See ../lzma.h for information about liblzma as a whole.
*/
#ifndef LZMA_H_INTERNAL
@@ -24,9 +20,21 @@
/**
* \brief Filter ID
*
* Filter ID of the Delta filter. This is used as lzma_options_filter.id.
* Filter ID of the Delta filter. This is used as lzma_filter.id.
*/
#define LZMA_FILTER_DELTA LZMA_VLI_C(0x20)
#define LZMA_FILTER_DELTA LZMA_VLI_C(0x03)
/**
* \brief Type of the delta calculation
*
* Currently only byte-wise delta is supported. Other possible types could
* be, for example, delta of 16/32/64-bit little/big endian integers, but
* these are not currently planned since byte-wise delta is almost as good.
*/
typedef enum {
LZMA_DELTA_TYPE_BYTE
} lzma_delta_type;
/**
@@ -35,15 +43,35 @@
* These options are needed by both encoder and decoder.
*/
typedef struct {
/** For now, this must always be LZMA_DELTA_TYPE_BYTE. */
lzma_delta_type type;
/**
* \brief Delta distance as bytes
* \brief Delta distance
*
* With the only currently supported type, LZMA_DELTA_TYPE_BYTE,
* the distance is as bytes.
*
* Examples:
* - 16-bit stereo audio: distance = 4 bytes
* - 24-bit RGB image data: distance = 3 bytes
*/
uint32_t distance;
# define LZMA_DELTA_DISTANCE_MIN 1
# define LZMA_DELTA_DISTANCE_MAX 256
uint32_t dist;
# define LZMA_DELTA_DIST_MIN 1
# define LZMA_DELTA_DIST_MAX 256
/*
* Reserved space to allow possible future extensions without
* breaking the ABI. You should not touch these, because the names
* of these variables may change. These are and will never be used
* when type is LZMA_DELTA_TYPE_BYTE, so it is safe to leave these
* uninitialized.
*/
uint32_t reserved_int1;
uint32_t reserved_int2;
uint32_t reserved_int3;
uint32_t reserved_int4;
void *reserved_ptr1;
void *reserved_ptr2;
} lzma_options_delta;

View File

@@ -1,114 +0,0 @@
/**
* \file lzma/extra.h
* \brief Handling of Extra Records in Metadata
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*/
#ifndef LZMA_H_INTERNAL
# error Never include this file directly. Use <lzma.h> instead.
#endif
/*
* Extra Record IDs
*
* See the .lzma file format specification for description what each
* Extra Record type exactly means.
*
* If you ever need to update .lzma files with Extra Records, note that
* the Record IDs are divided in two categories:
* - Safe-to-Copy Records may be preserved as is when the
* Stream is modified in ways that don't change the actual
* uncompressed data. Examples of such operatings include
* recompressing and adding, modifying, or deleting unrelated
* Extra Records.
* - Unsafe-to-Copy Records should be removed (and possibly
* recreated) when any kind of changes are made to the Stream.
*/
#define LZMA_EXTRA_PADDING 0x00
#define LZMA_EXTRA_OPENPGP 0x01
#define LZMA_EXTRA_FILTERS 0x02
#define LZMA_EXTRA_COMMENT 0x03
#define LZMA_EXTRA_CHECKS 0x04
#define LZMA_EXTRA_FILENAME 0x05
#define LZMA_EXTRA_MTIME 0x07
#define LZMA_EXTRA_MTIME_HR 0x09
#define LZMA_EXTRA_MIME_TYPE 0x0B
#define LZMA_EXTRA_HOMEPAGE 0x0D
/**
* \brief Extra Records
*
* The .lzma format provides a way to store custom information along
* the actual compressed content. Information about these Records
* are passed to and from liblzma via this linked list.
*/
typedef struct lzma_extra_s lzma_extra;
struct lzma_extra_s {
/**
* \brief Pointer to the next Extra Record
*
* This is NULL on the last Extra Record.
*/
lzma_extra *next;
/**
* \brief Record ID
*
* Extra Record IDs are divided in three categories:
* - Zero is a special case used for padding. It doesn't have
* Size of Data fields.
* - Odd IDs (1, 3, 5, ...) are Safe-to-Copy IDs.
* These can be preserved as is if the Stream is
* modified in a way that doesn't alter the actual
* uncompressed content.
* - Even IDs (2, 4, 6, ...) are Unsafe-to-Copy IDs.
* If the .lzma Stream is modified in any way,
* the Extra Records having a sensitive ID should
* be removed or updated accordingly.
*
* Refer to the .lzma file format specification for
* the up to date list of Extra Record IDs.
*/
lzma_vli id;
/**
* \brief Size of the Record data
*
* In case of strings, this should not include the
* trailing '\0'.
*/
size_t size;
/**
* \brief Record data
*
* Record data is often a string in UTF-8 encoding,
* but it can be arbitrary binary data. In case of
* strings, the trailing '\0' is usually not stored
* in the .lzma file.
*
* To ease working with Extra Records containing strings,
* liblzma always adds '\0' to the end of data even when
* it wasn't present in the .lzma file. This '\0' is not
* counted in the size of the data.
*/
uint8_t *data;
};
extern void lzma_extra_free(lzma_extra *extra, lzma_allocator *allocator);

View File

@@ -1,19 +1,15 @@
/**
* \file lzma/filter.h
* \brief Common filter related types
*/
/*
* Author: Lasse Collin
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
* This file has been put into the public domain.
* You can do whatever you want with this file.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
* See ../lzma.h for information about liblzma as a whole.
*/
#ifndef LZMA_H_INTERNAL
@@ -21,19 +17,39 @@
#endif
/**
* \brief Maximum number of filters in a chain
*
* A filter chain can have 1-4 filters, of which three are allowed to change
* the size of the data. Usually only one or two filters are needed.
*/
#define LZMA_FILTERS_MAX 4
/**
* \brief Filter options
*
* This structure is used to pass Filter ID and a pointer filter's options
* to liblzma.
* This structure is used to pass Filter ID and a pointer filter's
* options to liblzma. A few functions work with a single lzma_filter
* structure, while most functions expect a filter chain.
*
* A filter chain is indicated with an array of lzma_filter structures.
* The array is terminated with .id = LZMA_VLI_UNKNOWN. Thus, the filter
* array must have LZMA_FILTERS_MAX + 1 elements (that is, five) to
* be able to hold any arbitrary filter chain. This is important when
* using lzma_block_header_decode() from block.h, because too small
* array would make liblzma write past the end of the filters array.
*/
typedef struct {
/**
* \brief Filter ID
*
* Use constants whose name begin with `LZMA_FILTER_' to specify
* different filters. In an array of lzma_option_filter structures,
* use LZMA_VLI_VALUE_UNKNOWN to indicate end of filters.
* different filters. In an array of lzma_filter structures, use
* LZMA_VLI_UNKNOWN to indicate end of filters.
*
* \note This is not an enum, because on some systems enums
* cannot be 64-bit.
*/
lzma_vli id;
@@ -41,7 +57,7 @@ typedef struct {
* \brief Pointer to filter-specific options structure
*
* If the filter doesn't need options, set this to NULL. If id is
* set to LZMA_VLI_VALUE_UNKNOWN, options is ignored, and thus
* set to LZMA_VLI_UNKNOWN, options is ignored, and thus
* doesn't need be initialized.
*
* Some filters support changing the options in the middle of
@@ -51,116 +67,294 @@ typedef struct {
*/
void *options;
} lzma_options_filter;
} lzma_filter;
/**
* \brief Filters available for encoding
* \brief Test if the given Filter ID is supported for encoding
*
* Pointer to an array containing the list of available Filter IDs that
* can be used for encoding. The last element is LZMA_VLI_VALUE_UNKNOWN.
* Return true if the give Filter ID is supported for encoding by this
* liblzma build. Otherwise false is returned.
*
* If lzma_available_filter_encoders[0] == LZMA_VLI_VALUE_UNKNOWN, the
* encoder components haven't been built at all. This means that the
* encoding-specific functions are probably missing from the library
* API/ABI completely.
* There is no way to list which filters are available in this particular
* liblzma version and build. It would be useless, because the application
* couldn't know what kind of options the filter would need.
*/
extern const lzma_vli *const lzma_available_filter_encoders;
extern LZMA_API(lzma_bool) lzma_filter_encoder_is_supported(lzma_vli id)
lzma_nothrow lzma_attr_const;
/**
* \brief Filters available for decoding
* \brief Test if the given Filter ID is supported for decoding
*
* Pointer to an array containing the list of available Filter IDs that
* can be used for decoding. The last element is LZMA_VLI_VALUE_UNKNOWN.
*
* If lzma_available_filter_decoders[0] == LZMA_VLI_VALUE_UNKNOWN, the
* decoder components haven't been built at all. This means that the
* decoding-specific functions are probably missing from the library
* API/ABI completely.
* Return true if the give Filter ID is supported for decoding by this
* liblzma build. Otherwise false is returned.
*/
extern const lzma_vli *const lzma_available_filter_decoders;
extern LZMA_API(lzma_bool) lzma_filter_decoder_is_supported(lzma_vli id)
lzma_nothrow lzma_attr_const;
/**
* \brief Calculate rough memory requirements for given filter chain
* \brief Calculate rough memory requirements for raw encoder
*
* Because the calculation is rough, this function can be used to calculate
* the memory requirements for Block and Stream encoders too.
*
* \param filters Array of filters terminated with
* .id == LZMA_VLI_VALUE_UNKNOWN.
* \param is_encoder Set to true when calculating memory requirements
* of an encoder; false for decoder.
* .id == LZMA_VLI_UNKNOWN.
*
* \return Number of mebibytes (MiB i.e. 2^20) required for the given
* encoder or decoder filter chain.
*
* \note If calculating memory requirements of encoder, lzma_init() or
* lzma_init_encoder() must have been called earlier. Similarly,
* if calculating memory requirements of decoder, lzma_init() or
* lzma_init_decoder() must have been called earlier.
* \return Rough number of bytes of memory required for the given
* filter chain when encoding.
*/
extern uint32_t lzma_memory_usage(
const lzma_options_filter *filters, lzma_bool is_encoder);
extern LZMA_API(uint64_t) lzma_raw_encoder_memusage(const lzma_filter *filters)
lzma_nothrow lzma_attr_pure;
/**
* \brief Calculates encoded size of a Filter Flags field
* \brief Calculate rough memory requirements for raw decoder
*
* Because the calculation is rough, this function can be used to calculate
* the memory requirements for Block and Stream decoders too.
*
* \param filters Array of filters terminated with
* .id == LZMA_VLI_UNKNOWN.
*
* \return Rough number of bytes of memory required for the given
* filter chain when decoding.
*/
extern LZMA_API(uint64_t) lzma_raw_decoder_memusage(const lzma_filter *filters)
lzma_nothrow lzma_attr_pure;
/**
* \brief Initialize raw encoder
*
* This function may be useful when implementing custom file formats.
*
* \param strm Pointer to properly prepared lzma_stream
* \param filters Array of lzma_filter structures. The end of the
* array must be marked with .id = LZMA_VLI_UNKNOWN.
*
* The `action' with lzma_code() can be LZMA_RUN, LZMA_SYNC_FLUSH (if the
* filter chain supports it), or LZMA_FINISH.
*
* \return - LZMA_OK
* - LZMA_MEM_ERROR
* - LZMA_OPTIONS_ERROR
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_raw_encoder(
lzma_stream *strm, const lzma_filter *filters)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Initialize raw decoder
*
* The initialization of raw decoder goes similarly to raw encoder.
*
* The `action' with lzma_code() can be LZMA_RUN or LZMA_FINISH. Using
* LZMA_FINISH is not required, it is supported just for convenience.
*
* \return - LZMA_OK
* - LZMA_MEM_ERROR
* - LZMA_OPTIONS_ERROR
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_raw_decoder(
lzma_stream *strm, const lzma_filter *filters)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Single-call raw encoder
*
* \param filters Array of lzma_filter structures. The end of the
* array must be marked with .id = LZMA_VLI_UNKNOWN.
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
* \param in Beginning of the input buffer
* \param in_size Size of the input buffer
* \param out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos].
* *out_pos is updated only if encoding succeeds.
* \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size].
*
* \return - LZMA_OK: Encoding was successful.
* - LZMA_BUF_ERROR: Not enough output buffer space.
* - LZMA_OPTIONS_ERROR
* - LZMA_MEM_ERROR
* - LZMA_DATA_ERROR
* - LZMA_PROG_ERROR
*
* \note There is no function to calculate how big output buffer
* would surely be big enough. (lzma_stream_buffer_bound()
* works only for lzma_stream_buffer_encode().)
*/
extern LZMA_API(lzma_ret) lzma_raw_buffer_encode(
const lzma_filter *filters, lzma_allocator *allocator,
const uint8_t *in, size_t in_size, uint8_t *out,
size_t *out_pos, size_t out_size) lzma_nothrow;
/**
* \brief Single-call raw decoder
*
* \param filters Array of lzma_filter structures. The end of the
* array must be marked with .id = LZMA_VLI_UNKNOWN.
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
* \param in Beginning of the input buffer
* \param in_pos The next byte will be read from in[*in_pos].
* *in_pos is updated only if decoding succeeds.
* \param in_size Size of the input buffer; the first byte that
* won't be read is in[in_size].
* \param out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos].
* *out_pos is updated only if encoding succeeds.
* \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size].
*/
extern LZMA_API(lzma_ret) lzma_raw_buffer_decode(
const lzma_filter *filters, lzma_allocator *allocator,
const uint8_t *in, size_t *in_pos, size_t in_size,
uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow;
/**
* \brief Get the size of the Filter Properties field
*
* This function may be useful when implementing custom file formats
* using the raw encoder and decoder.
*
* \param size Pointer to uint32_t to hold the size of the properties
* \param filter Filter ID and options (the size of the propeties may
* vary depending on the options)
*
* \return - LZMA_OK
* - LZMA_OPTIONS_ERROR
* - LZMA_PROG_ERROR
*
* \note This function validates the Filter ID, but does not
* necessarily validate the options. Thus, it is possible
* that this returns LZMA_OK while the following call to
* lzma_properties_encode() returns LZMA_OPTIONS_ERROR.
*/
extern LZMA_API(lzma_ret) lzma_properties_size(
uint32_t *size, const lzma_filter *filter) lzma_nothrow;
/**
* \brief Encode the Filter Properties field
*
* \param filter Filter ID and options
* \param props Buffer to hold the encoded options. The size of
* buffer must have been already determined with
* lzma_properties_size().
*
* \return - LZMA_OK
* - LZMA_OPTIONS_ERROR
* - LZMA_PROG_ERROR
*
* \note Even this function won't validate more options than actually
* necessary. Thus, it is possible that encoding the properties
* succeeds but using the same options to initialize the encoder
* will fail.
*
* \note It is OK to skip calling this function if
* lzma_properties_size() indicated that the size
* of the Filter Properties field is zero.
*/
extern LZMA_API(lzma_ret) lzma_properties_encode(
const lzma_filter *filter, uint8_t *props) lzma_nothrow;
/**
* \brief Decode the Filter Properties field
*
* \param filter filter->id must have been set to the correct
* Filter ID. filter->options doesn't need to be
* initialized (it's not freed by this function). The
* decoded options will be stored to filter->options.
* filter->options is set to NULL if there are no
* properties or if an error occurs.
* \param allocator Custom memory allocator used to allocate the
* options. Set to NULL to use the default malloc(),
* and in case of an error, also free().
* \param props Input buffer containing the properties.
* \param props_size Size of the properties. This must be the exact
* size; giving too much or too little input will
* return LZMA_OPTIONS_ERROR.
*
* \return - LZMA_OK
* - LZMA_OPTIONS_ERROR
* - LZMA_MEM_ERROR
*/
extern LZMA_API(lzma_ret) lzma_properties_decode(
lzma_filter *filter, lzma_allocator *allocator,
const uint8_t *props, size_t props_size) lzma_nothrow;
/**
* \brief Calculate encoded size of a Filter Flags field
*
* Knowing the size of Filter Flags is useful to know when allocating
* memory to hold the encoded Filter Flags.
*
* \param size Pointer to integer to hold the calculated size
* \param options Filter ID and associated options whose encoded
* \param filters Filter ID and associated options whose encoded
* size is to be calculted
*
* \return - LZMA_OK: *size set successfully. Note that this doesn't
* guarantee that options->options is valid, thus
* guarantee that filters->options is valid, thus
* lzma_filter_flags_encode() may still fail.
* - LZMA_HEADER_ERROR: Unknown Filter ID or unsupported options.
* - LZMA_OPTIONS_ERROR: Unknown Filter ID or unsupported options.
* - LZMA_PROG_ERROR: Invalid options
*
* \note If you need to calculate size of List of Filter Flags,
* you need to loop over every lzma_options_filter entry.
* you need to loop over every lzma_filter entry.
*/
extern lzma_ret lzma_filter_flags_size(
uint32_t *size, const lzma_options_filter *options);
extern LZMA_API(lzma_ret) lzma_filter_flags_size(
uint32_t *size, const lzma_filter *filters)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Encodes Filter Flags into given buffer
* \brief Encode Filter Flags into given buffer
*
* In contrast to some functions, this doesn't allocate the needed buffer.
* This is due to how this function is used internally by liblzma.
*
* \param filters Filter ID and options to be encoded
* \param out Beginning of the output buffer
* \param out_pos out[*out_pos] is the next write position. This
* is updated by the encoder.
* \param out_size out[out_size] is the first byte to not write.
* \param options Filter options to be encoded
*
* \return - LZMA_OK: Encoding was successful.
* - LZMA_HEADER_ERROR: Invalid or unsupported options.
* - LZMA_OPTIONS_ERROR: Invalid or unsupported options.
* - LZMA_PROG_ERROR: Invalid options or not enough output
* buffer space (you should have checked it with
* lzma_filter_flags_size()).
*/
extern lzma_ret lzma_filter_flags_encode(uint8_t *out, size_t *out_pos,
size_t out_size, const lzma_options_filter *options);
extern LZMA_API(lzma_ret) lzma_filter_flags_encode(const lzma_filter *filters,
uint8_t *out, size_t *out_pos, size_t out_size)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Initializes Filter Flags decoder
* \brief Decode Filter Flags from given buffer
*
* The decoded result is stored into *options. options->options is
* The decoded result is stored into *filters. filters->options is
* initialized but the old value is NOT free()d.
*
* Because the results of this decoder are placed into *options,
* strm->next_in, strm->avail_in, and strm->total_in are not used
* when calling lzma_code(). The only valid action for lzma_code()
* is LZMA_RUN
*
* \return - LZMA_OK
* - LZMA_OPTIONS_ERROR
* - LZMA_MEM_ERROR
* - LZMA_PROG_ERROR
*/
extern lzma_ret lzma_filter_flags_decoder(
lzma_stream *strm, lzma_options_filter *options);
extern LZMA_API(lzma_ret) lzma_filter_flags_decode(
lzma_filter *filters, lzma_allocator *allocator,
const uint8_t *in, size_t *in_pos, size_t in_size)
lzma_nothrow lzma_attr_warn_unused_result;

View File

@@ -1,19 +1,15 @@
/**
* \file lzma/index.h
* \brief Handling of Index lists
* \brief Handling of .xz Index lists
*/
/*
* Author: Lasse Collin
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
* This file has been put into the public domain.
* You can do whatever you want with this file.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
* See ../lzma.h for information about liblzma as a whole.
*/
#ifndef LZMA_H_INTERNAL
@@ -22,63 +18,386 @@
/**
* \brief
*
* FIXME desc
* \brief Opaque data type to hold the Index
*/
typedef struct lzma_index_s lzma_index;
struct lzma_index_s {
/**
* \brief Index Record and its location
*/
typedef struct {
/**
* \brief Total Size of the Block
* \brief Total encoded size of a Block including Block Padding
*
* This includes Block Header, Compressed Data, and Block Footer.
* This value is useful if you need to know the actual size of the
* Block that the Block decoder will read.
*/
lzma_vli total_size;
/**
* \brief Uncompressed Size of the Block
* \brief Encoded size of a Block excluding Block Padding
*
* This value is stored in the Index. When doing random-access
* reading, you should give this value to the Block decoder along
* with uncompressed_size.
*/
lzma_vli unpadded_size;
/**
* \brief Uncompressed Size of a Block
*/
lzma_vli uncompressed_size;
/**
* \brief Pointer to the next Index Record
* \brief Compressed offset in the Stream(s)
*
* This is NULL on the last Index Record.
* This is the offset of the first byte of the Block, that is,
* where you need to seek to decode the Block. The offset
* is relative to the beginning of the Stream, or if there are
* multiple Indexes combined, relative to the beginning of the
* first Stream.
*/
lzma_index *next;
};
lzma_vli stream_offset;
/**
* \brief Uncompressed offset
*
* When doing random-access reading, it is possible that the target
* offset is not exactly at Block boundary. One will need to compare
* the target offset against uncompressed_offset, and possibly decode
* and throw away some amount of data before reaching the target
* offset.
*/
lzma_vli uncompressed_offset;
} lzma_index_record;
/**
* \brief Duplicates an Index list
* \brief Calculate memory usage for Index with given number of Records
*
* \return A copy of the Index list, or NULL if memory allocation
* failed or the original Index was empty.
*/
extern lzma_index *lzma_index_dup(
const lzma_index *index, lzma_allocator *allocator);
/**
* \brief Frees an Index list
* On disk, the size of the Index field depends on both the number of Records
* stored and how big values the Records store (due to variable-length integer
* encoding). When the Index is kept in lzma_index structure, the memory usage
* depends only on the number of Records stored in the Index. The size in RAM
* is almost always a lot bigger than in encoded form on disk.
*
* All Index Recors in the list are freed. This function is convenient when
* getting rid of lzma_metadata structures containing an Index.
*/
extern void lzma_index_free(lzma_index *index, lzma_allocator *allocator);
/**
* \brief Calculates information about the Index
* This function calculates an approximate amount of memory needed hold the
* given number of Records in lzma_index structure. This value may vary
* between liblzma versions if the internal implementation is modified.
*
* \return LZMA_OK on success, LZMA_PROG_ERROR on error. FIXME
* If you want to know how much memory an existing lzma_index structure is
* using, use lzma_index_memusage(lzma_index_count(i)).
*/
extern lzma_ret lzma_index_count(const lzma_index *index, size_t *count,
lzma_vli *lzma_restrict total_size,
lzma_vli *lzma_restrict uncompressed_size);
extern LZMA_API(uint64_t) lzma_index_memusage(lzma_vli record_count)
lzma_nothrow;
/**
* \brief Compares if two Index lists are identical
* \brief Allocate and initialize a new lzma_index structure
*
* If i is NULL, a new lzma_index structure is allocated, initialized,
* and a pointer to it returned. If allocation fails, NULL is returned.
*
* If i is non-NULL, it is reinitialized and the same pointer returned.
* In this case, return value cannot be NULL or a different pointer than
* the i that was given as an argument.
*/
extern lzma_bool lzma_index_is_equal(const lzma_index *a, const lzma_index *b);
extern LZMA_API(lzma_index *) lzma_index_init(
lzma_index *i, lzma_allocator *allocator) lzma_nothrow;
/**
* \brief Deallocate the Index
*
* If i is NULL, this does nothing.
*/
extern LZMA_API(void) lzma_index_end(lzma_index *i, lzma_allocator *allocator)
lzma_nothrow;
/**
* \brief Add a new Record to an Index
*
* \param i Pointer to a lzma_index structure
* \param allocator Pointer to lzma_allocator, or NULL to
* use malloc()
* \param unpadded_size Unpadded Size of a Block. This can be
* calculated with lzma_block_unpadded_size()
* after encoding or decoding the Block.
* \param uncompressed_size Uncompressed Size of a Block. This can be
* taken directly from lzma_block structure
* after encoding or decoding the Block.
*
* Appending a new Record does not affect the read position.
*
* \return - LZMA_OK
* - LZMA_MEM_ERROR
* - LZMA_DATA_ERROR: Compressed or uncompressed size of the
* Stream or size of the Index field would grow too big.
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_index_append(
lzma_index *i, lzma_allocator *allocator,
lzma_vli unpadded_size, lzma_vli uncompressed_size)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Get the number of Records
*/
extern LZMA_API(lzma_vli) lzma_index_count(const lzma_index *i)
lzma_nothrow lzma_attr_pure;
/**
* \brief Get the size of the Index field as bytes
*
* This is needed to verify the Backward Size field in the Stream Footer.
*/
extern LZMA_API(lzma_vli) lzma_index_size(const lzma_index *i)
lzma_nothrow lzma_attr_pure;
/**
* \brief Get the total size of the Blocks
*
* This doesn't include the Stream Header, Stream Footer, Stream Padding,
* or Index fields.
*/
extern LZMA_API(lzma_vli) lzma_index_total_size(const lzma_index *i)
lzma_nothrow lzma_attr_pure;
/**
* \brief Get the total size of the Stream
*
* If multiple Indexes have been combined, this works as if the Blocks
* were in a single Stream.
*/
extern LZMA_API(lzma_vli) lzma_index_stream_size(const lzma_index *i)
lzma_nothrow lzma_attr_pure;
/**
* \brief Get the total size of the file
*
* When no Indexes have been combined with lzma_index_cat(), this function is
* identical to lzma_index_stream_size(). If multiple Indexes have been
* combined, this includes also the headers of each separate Stream and the
* possible Stream Padding fields.
*/
extern LZMA_API(lzma_vli) lzma_index_file_size(const lzma_index *i)
lzma_nothrow lzma_attr_pure;
/**
* \brief Get the uncompressed size of the Stream
*/
extern LZMA_API(lzma_vli) lzma_index_uncompressed_size(const lzma_index *i)
lzma_nothrow lzma_attr_pure;
/**
* \brief Get the next Record from the Index
*/
extern LZMA_API(lzma_bool) lzma_index_read(
lzma_index *i, lzma_index_record *record)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Rewind the Index
*
* Rewind the Index so that next call to lzma_index_read() will return the
* first Record.
*/
extern LZMA_API(void) lzma_index_rewind(lzma_index *i) lzma_nothrow;
/**
* \brief Locate a Record
*
* When the Index is available, it is possible to do random-access reading
* with granularity of Block size.
*
* \param i Pointer to lzma_index structure
* \param record Pointer to a structure to hold the search results
* \param target Uncompressed target offset which the caller would
* like to locate from the Stream
*
* If the target is smaller than the uncompressed size of the Stream (can be
* checked with lzma_index_uncompressed_size()):
* - Information about the Record containing the requested uncompressed
* offset is stored into *record.
* - Read offset will be adjusted so that calling lzma_index_read() can be
* used to read subsequent Records.
* - This function returns false.
*
* If target is greater than the uncompressed size of the Stream, *record
* and the read position are not modified, and this function returns true.
*/
extern LZMA_API(lzma_bool) lzma_index_locate(
lzma_index *i, lzma_index_record *record, lzma_vli target)
lzma_nothrow;
/**
* \brief Concatenate Indexes of two Streams
*
* Concatenating Indexes is useful when doing random-access reading in
* multi-Stream .xz file, or when combining multiple Streams into single
* Stream.
*
* \param dest Destination Index after which src is appended
* \param src Source Index. If this function succeeds, the
* memory allocated for src is freed or moved to
* be part of dest.
* \param allocator Custom memory allocator; can be NULL to use
* malloc() and free().
* \param padding Size of the Stream Padding field between Streams.
* This must be a multiple of four.
*
* \return - LZMA_OK: Indexes concatenated successfully. src is now
* a dangling pointer.
* - LZMA_DATA_ERROR: *dest would grow too big.
* - LZMA_MEM_ERROR
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_index_cat(lzma_index *lzma_restrict dest,
lzma_index *lzma_restrict src,
lzma_allocator *allocator, lzma_vli padding)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Duplicate an Index list
*
* Makes an identical copy of the Index. Also the read position is copied.
*
* \return A copy of the Index, or NULL if memory allocation failed.
*/
extern LZMA_API(lzma_index *) lzma_index_dup(
const lzma_index *i, lzma_allocator *allocator)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Compare if two Index lists are identical
*
* Read positions are not compared.
*
* \return True if *a and *b are equal, false otherwise.
*/
extern LZMA_API(lzma_bool) lzma_index_equal(
const lzma_index *a, const lzma_index *b)
lzma_nothrow lzma_attr_pure;
/**
* \brief Initialize .xz Index encoder
*
* \param strm Pointer to properly prepared lzma_stream
* \param i Pointer to lzma_index which should be encoded.
* The read position will be at the end of the Index
* after lzma_code() has returned LZMA_STREAM_END.
*
* The only valid action value for lzma_code() is LZMA_RUN.
*
* \return - LZMA_OK: Initialization succeeded, continue with lzma_code().
* - LZMA_MEM_ERROR
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_index_encoder(lzma_stream *strm, lzma_index *i)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Initialize .xz Index decoder
*
* \param strm Pointer to properly prepared lzma_stream
* \param i Pointer to a pointer that will be made to point
* to the final decoded Index once lzma_code() has
* returned LZMA_STREAM_END. That is,
* lzma_index_decoder() always takes care of
* allocating a new lzma_index structure, and *i
* doesn't need to be initialized by the caller.
* \param memlimit How much memory the resulting Index is allowed
* to require.
*
* The only valid action value for lzma_code() is LZMA_RUN.
*
* \return - LZMA_OK: Initialization succeeded, continue with lzma_code().
* - LZMA_MEM_ERROR
* - LZMA_MEMLIMIT_ERROR
* - LZMA_PROG_ERROR
*
* \note The memory usage limit is checked early in the decoding
* (within the first dozen input bytes or so). The actual memory
* is allocated later in smaller pieces. If the memory usage
* limit is modified with lzma_memlimit_set() after a part
* of the Index has already been decoded, the new limit may
* get ignored.
*/
extern LZMA_API(lzma_ret) lzma_index_decoder(
lzma_stream *strm, lzma_index **i, uint64_t memlimit)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Single-call .xz Index encoder
*
* \param i Index to be encoded. The read position will be at
* the end of the Index if encoding succeeds, or at
* unspecified position in case an error occurs.
* \param out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos].
* *out_pos is updated only if encoding succeeds.
* \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size].
*
* \return - LZMA_OK: Encoding was successful.
* - LZMA_BUF_ERROR: Output buffer is too small. Use
* lzma_index_size() to find out how much output
* space is needed.
* - LZMA_PROG_ERROR
*
* \note This function doesn't take allocator argument since all
* the internal data is allocated on stack.
*/
extern LZMA_API(lzma_ret) lzma_index_buffer_encode(lzma_index *i,
uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow;
/**
* \brief Single-call .xz Index decoder
*
* \param i Pointer to a pointer that will be made to point
* to the final decoded Index if decoding is
* successful. That is, lzma_index_buffer_decode()
* always takes care of allocating a new
* lzma_index structure, and *i doesn't need to be
* initialized by the caller.
* \param memlimit Pointer to how much memory the resulting Index
* is allowed to require. The value pointed by
* this pointer is modified if and only if
* LZMA_MEMLIMIT_ERROR is returned.
* \param allocator Pointer to lzma_allocator, or NULL to use malloc()
* \param in Beginning of the input buffer
* \param in_pos The next byte will be read from in[*in_pos].
* *in_pos is updated only if decoding succeeds.
* \param in_size Size of the input buffer; the first byte that
* won't be read is in[in_size].
*
* \return - LZMA_OK: Decoding was successful.
* - LZMA_MEM_ERROR
* - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached.
* The minimum required memlimit value was stored to *memlimit.
* - LZMA_DATA_ERROR
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_index_buffer_decode(lzma_index **i,
uint64_t *memlimit, lzma_allocator *allocator,
const uint8_t *in, size_t *in_pos, size_t in_size)
lzma_nothrow;

View File

@@ -0,0 +1,107 @@
/**
* \file lzma/index_hash.h
* \brief Validates Index by using a hash function
*
* Hashing makes it possible to use constant amount of memory to validate
* Index of arbitrary size.
*/
/*
* Author: Lasse Collin
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*
* See ../lzma.h for information about liblzma as a whole.
*/
#ifndef LZMA_H_INTERNAL
# error Never include this file directly. Use <lzma.h> instead.
#endif
/**
* \brief Opaque data type to hold the Index hash
*/
typedef struct lzma_index_hash_s lzma_index_hash;
/**
* \brief Allocate and initialize a new lzma_index_hash structure
*
* If index_hash is NULL, a new lzma_index_hash structure is allocated,
* initialized, and a pointer to it returned. If allocation fails, NULL
* is returned.
*
* If index_hash is non-NULL, it is reinitialized and the same pointer
* returned. In this case, return value cannot be NULL or a different
* pointer than the index_hash that was given as an argument.
*/
extern LZMA_API(lzma_index_hash *) lzma_index_hash_init(
lzma_index_hash *index_hash, lzma_allocator *allocator)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Deallocate lzma_index_hash structure
*/
extern LZMA_API(void) lzma_index_hash_end(
lzma_index_hash *index_hash, lzma_allocator *allocator)
lzma_nothrow;
/**
* \brief Add a new Record to an Index hash
*
* \param index Pointer to a lzma_index_hash structure
* \param unpadded_size Unpadded Size of a Block
* \param uncompressed_size Uncompressed Size of a Block
*
* \return - LZMA_OK
* - LZMA_DATA_ERROR: Compressed or uncompressed size of the
* Stream or size of the Index field would grow too big.
* - LZMA_PROG_ERROR: Invalid arguments or this function is being
* used when lzma_index_hash_decode() has already been used.
*/
extern LZMA_API(lzma_ret) lzma_index_hash_append(lzma_index_hash *index_hash,
lzma_vli unpadded_size, lzma_vli uncompressed_size)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Decode and validate the Index field
*
* After telling the sizes of all Blocks with lzma_index_hash_append(),
* the actual Index field is decoded with this function. Specifically,
* once decoding of the Index field has been started, no more Records
* can be added using lzma_index_hash_append().
*
* This function doesn't use lzma_stream structure to pass the input data.
* Instead, the input buffer is specified using three arguments. This is
* because it matches better the internal APIs of liblzma.
*
* \param index_hash Pointer to a lzma_index_hash structure
* \param in Pointer to the beginning of the input buffer
* \param in_pos in[*in_pos] is the next byte to process
* \param in_size in[in_size] is the first byte not to process
*
* \return - LZMA_OK: So far good, but more input is needed.
* - LZMA_STREAM_END: Index decoded successfully and it matches
* the Records given with lzma_index_hash_append().
* - LZMA_DATA_ERROR: Index is corrupt or doesn't match the
* information given with lzma_index_hash_append().
* - LZMA_BUF_ERROR: Cannot progress because *in_pos >= in_size.
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_index_hash_decode(lzma_index_hash *index_hash,
const uint8_t *in, size_t *in_pos, size_t in_size)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Get the size of the Index field as bytes
*
* This is needed to verify the Backward Size field in the Stream Footer.
*/
extern LZMA_API(lzma_vli) lzma_index_hash_size(
const lzma_index_hash *index_hash)
lzma_nothrow lzma_attr_pure;

View File

@@ -1,315 +0,0 @@
/**
* \file lzma/info.h
* \brief Handling of Stream size information
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*/
#ifndef LZMA_H_INTERNAL
# error Never include this file directly. Use <lzma.h> instead.
#endif
/**********
* Basics *
**********/
/**
* \brief Opaque data type to hold the size information
*/
typedef struct lzma_info_s lzma_info;
typedef struct {
/**
* \brief Total Size of this Block
*
* This can be LZMA_VLI_VALUE_UNKNOWN.
*/
lzma_vli total_size;
/**
* \brief Uncompressed Size of this Block
*
* This can be LZMA_VLI_VALUE_UNKNOWN.
*/
lzma_vli uncompressed_size;
/**
* \brief Offset of the first byte of the Block
*
* In encoder, this is useful to find out the alignment of the Block.
*
* In decoder, this is useful when doing random-access reading
* with help from lzma_info_data_locate().
*/
lzma_vli stream_offset;
/**
* \brief Uncompressed offset of the Block
*
* Offset of the first uncompressed byte of the Block relative to
* all uncompressed data in the Block.
* FIXME desc
*/
lzma_vli uncompressed_offset;
/**
* \brief Pointers to internal data structures
*
* Applications must not touch these.
*/
void *internal[4];
} lzma_info_iter;
typedef enum {
LZMA_INFO_STREAM_START,
LZMA_INFO_HEADER_METADATA,
LZMA_INFO_TOTAL,
LZMA_INFO_UNCOMPRESSED,
LZMA_INFO_FOOTER_METADATA
} lzma_info_size;
/**
* \brief Allocates and initializes a new lzma_info structure
*
* If info is NULL, a new lzma_info structure is allocated, initialized, and
* a pointer to it returned. If allocation fails, NULL is returned.
*
* If info is non-NULL, it is reinitialized and the same pointer returned.
* (In this case, return value cannot be NULL or a different pointer than
* the info given as argument.)
*/
extern lzma_info *lzma_info_init(lzma_info *info, lzma_allocator *allocator);
/**
* \brief Resets lzma_info
*
* This is like calling lzma_info_end() and lzma_info_create(), but
* re-uses the existing base structure.
*/
extern void lzma_info_reset(
lzma_info *info, lzma_allocator *allocator);
/**
* \brief Frees memory allocated for a lzma_info structure
*/
extern void lzma_info_free(lzma_info *info, lzma_allocator *allocator);
/************************
* Setting known values *
************************/
/**
* \brief Set a known size value
*
* \param info Pointer returned by lzma_info_create()
* \param type Any value from lzma_info_size
* \param size Value to set or verify
*
* \return LZMA_OK on success, LZMA_DATA_ERROR if the size doesn't
* match the existing information, or LZMA_PROG_ERROR
* if type is invalid or size is not a valid VLI.
*/
extern lzma_ret lzma_info_size_set(
lzma_info *info, lzma_info_size type, lzma_vli size);
/**
* \brief Sets the Index
*
* The given lzma_index list is "absorbed" by this function. The application
* must not access it after this function call, even if this function returns
* an error.
*
* \note The given lzma_index will at some point get freed by the
* lzma_info_* functions. If you use a custom lzma_allocator,
* make sure that it can free the lzma_index.
*/
extern lzma_ret lzma_info_index_set(
lzma_info *info, lzma_allocator *allocator,
lzma_index *index, lzma_bool eat_index);
/**
* \brief Sets information from a known Metadata Block
*
* This is a shortcut for calling lzma_info_size_set() with different type
* arguments, lzma_info_index_set() with metadata->index.
*/
extern lzma_ret lzma_info_metadata_set(lzma_info *info,
lzma_allocator *allocator, lzma_metadata *metadata,
lzma_bool is_header_metadata, lzma_bool eat_index);
/***************
* Incremental *
***************/
/**
* \brief Prepares an iterator to be used with given lzma_info structure
*
*
*/
extern void lzma_info_iter_begin(lzma_info *info, lzma_info_iter *iter);
/**
* \brief Moves to the next Index Record
*
*
*/
extern lzma_ret lzma_info_iter_next(
lzma_info_iter *iter, lzma_allocator *allocator);
/**
* \brief Sets or verifies the sizes in the Index Record
*
* \param iter Pointer to iterator to be set or verified
* \param total_size
* Total Size in bytes or LZMA_VLI_VALUE_UNKNOWN
* \param uncompressed_size
* Uncompressed Size or LZMA_VLI_VALUE_UNKNOWN
*
* \return - LZMA_OK: All OK.
* - LZMA_DATA_ERROR: Given sizes don't match with the already
* known sizes.
* - LZMA_PROG_ERROR: Internal error, possibly integer
* overflow (e.g. the sum of all the known sizes is too big)
*/
extern lzma_ret lzma_info_iter_set(lzma_info_iter *iter,
lzma_vli total_size, lzma_vli uncompressed_size);
/**
* \brief Locates a Data Block
*
* \param iter Properly initialized iterator
* \param allocator Pointer to lzma_allocator or NULL
* \param uncompressed_offset
* Target offset to locate. The final offset
* will be equal or smaller than this.
* \param allow_alloc True if this function is allowed to call
* lzma_info_iter_next() to allocate a new Record
* if the requested offset reached end of Index
* Record list. Note that if Index has been marked
* final, lzma_info_iter_next() is never called.
*
* \return - LZMA_OK: All OK, *iter updated accordingly.
* - LZMA_DATA_ERROR: Trying to search past the end of the Index
* Record list, and allocating a new Record was not allowed
* either because allow_alloc was false or Index was final.
* - LZMA_PROG_ERROR: Internal error (probably integer
* overflow causing some lzma_vli getting too big).
*/
extern lzma_ret lzma_info_iter_locate(lzma_info_iter *iter,
lzma_allocator *allocator, lzma_vli uncompressed_offset,
lzma_bool allow_alloc);
/**
* \brief Finishes incrementally constructed Index
*
* This sets the known Total Size and Uncompressed of the Data Blocks
* based on the information collected from the Index Records, and marks
* the Index as final.
*/
extern lzma_ret lzma_info_index_finish(lzma_info *info);
/***************************
* Reading the information *
***************************/
/**
* \brief Gets a known size
*
*
*/
extern lzma_vli lzma_info_size_get(
const lzma_info *info, lzma_info_size type);
extern lzma_vli lzma_info_metadata_locate(
const lzma_info *info, lzma_bool is_header_metadata);
/**
* \brief Gets a pointer to the beginning of the Index list
*
* If detach is true, the Index will be detached from the lzma_info
* structure, and thus not be modified or freed by lzma_info_end().
*
* If detach is false, the application must not modify the Index in any way.
* Also, the Index list is guaranteed to be valid only till the next call
* to any lzma_info_* function.
*/
extern lzma_index *lzma_info_index_get(lzma_info *info, lzma_bool detach);
extern size_t lzma_info_index_count_get(const lzma_info *info);
extern uint32_t lzma_info_metadata_alignment_get(
const lzma_info *info, lzma_bool is_header_metadata);
/**
* \brief Locate a Block containing the given uncompressed offset
*
* This function is useful when you need to do random-access reading in
* a Multi-Block Stream.
*
* \param info Pointer to lzma_info that has at least one
* Index Record. The Index doesn't need to be finished.
* \param uncompressed_target
* Uncompressed target offset which the caller would
* like to locate from the Stream.
* \param stream_offset
* Starting offset (relative to the beginning the Stream)
* of the Block containing the requested location.
* \param uncompressed_offset
* The actual uncompressed offset of the beginning of
* the Block. uncompressed_offset <= uncompressed_target
* is always true; the application needs to uncompress
* uncompressed_target - uncompressed_offset bytes to
* reach the requested target offset.
* \param total_size
* Total Size of the Block. If the Index is incomplete,
* this may be LZMA_VLI_VALUE_UNKNOWN indicating unknown
* size.
* \param uncompressed_size
* Uncompressed Size of the Block. If the Index is
* incomplete, this may be LZMA_VLI_VALUE_UNKNOWN
* indicating unknown size. The application must pass
* this value to the Block decoder to verify FIXME
*
* \return
*
* \note This function is currently implemented as a linear search.
* If there are many Index Records, this can be really slow.
* This can be improved in newer liblzma versions if needed.
*/
extern lzma_bool lzma_info_data_locate(const lzma_info *info,
lzma_vli uncompressed_target,
lzma_vli *lzma_restrict stream_offset,
lzma_vli *lzma_restrict uncompressed_offset,
lzma_vli *lzma_restrict total_size,
lzma_vli *lzma_restrict uncompressed_size);

View File

@@ -1,85 +0,0 @@
/**
* \file lzma/init.h
* \brief Initializations
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*/
#ifndef LZMA_H_INTERNAL
# error Never include this file directly. Use <lzma.h> instead.
#endif
/**
* \brief Initialize all internal static variables
*
* Depending on the build options, liblzma may have some internal static
* variables, that must be initialized before using any other part of
* the library (*). It is recommended to do these initializations in the very
* beginning of the application by calling appropriate initialization function.
*
* (*) There are some exceptions to this rule. FIXME
*
* The initialization functions are not necessarily thread-safe, thus the
* required initializations must be done before creating any threads. (The
* rest of the functions of liblzma are thread-safe.) Calling the
* initialization functions multiple times does no harm, although it
* still shouldn't be done when there are multiple threads running.
*
* lzma_init() initializes all internal static variables by calling
* lzma_lzma_init_encoder() and lzma_init_decoder().
*
* If you need only encoder, decoder, or neither-encoder-nor-decoder
* functions, you may use other initialization functions, which initialize
* only a subset of liblzma's internal static variables. Using those
* functions have the following advantages:
* - When linking statically against liblzma, less useless functions will
* get linked into the binary. E.g. if you need only the decoder functions,
* using lzma_init_decoder() avoids linking bunch of encoder related code.
* - There is less things to initialize, making the initialization
* process slightly faster.
*/
extern void lzma_init(void);
/**
* \brief Initialize internal static variables needed by encoders
*
* If you need only the encoder functions, you may use this function to
* initialize only the things required by encoders.
*
* This function also calls lzma_init_check().
*/
extern void lzma_init_encoder(void);
/**
* \brief Initialize internal static variables needed by decoders
*
* If you need only the decoder functions, you may use this function to
* initialize only the things required by decoders.
*
* This function also calls lzma_init_check().
*/
extern void lzma_init_decoder(void);
/**
* \brief Initialize internal static variables needed by integrity checks
*
* Currently this initializes CRC32 and CRC64 lookup tables if precalculated
* tables haven't been built into the library. This function can be useful
* if the only thing you need from liblzma is the integrity check functions.
*/
extern void lzma_init_check(void);

View File

@@ -1,19 +1,15 @@
/**
* \file lzma/lzma.h
* \brief LZMA filter
* \brief LZMA1 and LZMA2 filters
*/
/*
* Author: Lasse Collin
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
* This file has been put into the public domain.
* You can do whatever you want with this file.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
* See ../lzma.h for information about liblzma as a whole.
*/
#ifndef LZMA_H_INTERNAL
@@ -22,45 +18,26 @@
/**
* \brief Filter ID
* \brief LZMA1 Filter ID
*
* Filter ID of the LZMA filter. This is used as lzma_options_filter.id.
* LZMA1 is the very same thing as what was called just LZMA in LZMA Utils,
* 7-Zip, and LZMA SDK. It's called LZMA1 here to prevent developers from
* accidentally using LZMA when they actually want LZMA2.
*
* LZMA1 shouldn't be used for new applications unless you _really_ know
* what you are doing. LZMA2 is almost always a better choice.
*/
#define LZMA_FILTER_LZMA LZMA_VLI_C(0x40)
#define LZMA_FILTER_LZMA1 LZMA_VLI_C(0x4000000000000001)
/**
* \brief LZMA compression modes
* \brief LZMA2 Filter ID
*
* Currently there are only two modes. Earlier LZMA SDKs had also third
* mode between fast and best.
* Usually you want this instead of LZMA1. Compared to LZMA1, LZMA2 adds
* support for LZMA_SYNC_FLUSH, uncompressed chunks (smaller expansion
* when trying to compress uncompressible data), possibility to change
* lc/lp/pb in the middle of encoding, and some other internal improvements.
*/
typedef enum {
LZMA_MODE_INVALID = -1,
/**<
* \brief Invalid mode
*
* Used as array terminator in lzma_available_modes.
*/
LZMA_MODE_FAST = 0,
/**<
* \brief Fast compression
*
* Fast mode is usually at its best when combined with
* a hash chain match finder.
*/
LZMA_MODE_BEST = 2
/**<
* \brief Best compression ratio
*
* This is usually notably slower than fast mode. Use this
* together with binary tree match finders to expose the
* full potential of the LZMA encoder.
*/
} lzma_mode;
#define LZMA_FILTER_LZMA2 LZMA_VLI_C(0x21)
/**
@@ -68,76 +45,135 @@ typedef enum {
*
* Match finder has major effect on both speed and compression ratio.
* Usually hash chains are faster than binary trees.
*
* The memory usage formulas are only rough estimates, which are closest to
* reality when dict_size is a power of two. The formulas are more complex
* in reality, and can also change a little between liblzma versions. Use
* lzma_memusage_encoder() to get more accurate estimate of memory usage.
*/
typedef enum {
LZMA_MF_INVALID = -1,
/**<
* \brief Invalid match finder ID
*
* Used as array terminator in lzma_available_match_finders.
*/
LZMA_MF_HC3 = 0x03,
/**<
* \brief Hash Chain with 3 bytes hashing
* \brief Hash Chain with 2- and 3-byte hashing
*
* \todo Memory requirements
* Minimum nice_len: 3
*
* \note It's possible that this match finder gets
* removed in future. The definition will stay
* in this header, but liblzma may return
* LZMA_HEADER_ERROR if it is specified (just
* like it would if the match finder had been
* disabled at compile time).
* Memory usage:
* - dict_size <= 16 MiB: dict_size * 7.5
* - dict_size > 16 MiB: dict_size * 5.5 + 64 MiB
*/
LZMA_MF_HC4 = 0x04,
/**<
* \brief Hash Chain with 4 bytes hashing
* \brief Hash Chain with 2-, 3-, and 4-byte hashing
*
* Memory requirements: 7.5 * dictionary_size + 4 MiB
* Minimum nice_len: 4
*
* \note It's possible that this match finder gets
* removed in future. The definition will stay
* in this header, but liblzma may return
* LZMA_HEADER_ERROR if it is specified (just
* like it would if the match finder had been
* disabled at compile time).
* Memory usage: dict_size * 7.5
*/
LZMA_MF_BT2 = 0x12,
/**<
* \brief Binary Tree with 2 bytes hashing
* \brief Binary Tree with 2-byte hashing
*
* Memory requirements: 9.5 * dictionary_size + 4 MiB
* Minimum nice_len: 2
*
* Memory usage: dict_size * 9.5
*/
LZMA_MF_BT3 = 0x13,
/**<
* \brief Binary Tree with 3 bytes hashing
* \brief Binary Tree with 2- and 3-byte hashing
*
* Memory requirements: 11.5 * dictionary_size + 4 MiB
* Minimum nice_len: 3
*
* Memory usage:
* - dict_size <= 16 MiB: dict_size * 11.5
* - dict_size > 16 MiB: dict_size * 9.5 + 64 MiB
*/
LZMA_MF_BT4 = 0x14
/**<
* \brief Binary Tree with 4 bytes hashing
* \brief Binary Tree with 2-, 3-, and 4-byte hashing
*
* Memory requirements: 11.5 * dictionary_size + 4 MiB
* Minimum nice_len: 4
*
* Memory usage: dict_size * 11.5
*/
} lzma_match_finder;
/**
* \brief Options specific to the LZMA method handler
* \brief Test if given match finder is supported
*
* Return true if the given match finder is supported by this liblzma build.
* Otherwise false is returned. It is safe to call this with a value that
* isn't listed in lzma_match_finder enumeration; the return value will be
* false.
*
* There is no way to list which match finders are available in this
* particular liblzma version and build. It would be useless, because
* a new match finder, which the application developer wasn't aware,
* could require giving additional options to the encoder that the older
* match finders don't need.
*/
extern LZMA_API(lzma_bool) lzma_mf_is_supported(lzma_match_finder match_finder)
lzma_nothrow lzma_attr_const;
/**
* \brief Compression modes
*
* This selects the function used to analyze the data produced by the match
* finder.
*/
typedef enum {
LZMA_MODE_FAST = 1,
/**<
* \brief Fast compression
*
* Fast mode is usually at its best when combined with
* a hash chain match finder.
*/
LZMA_MODE_NORMAL = 2
/**<
* \brief Normal compression
*
* This is usually notably slower than fast mode. Use this
* together with binary tree match finders to expose the
* full potential of the LZMA1 or LZMA2 encoder.
*/
} lzma_mode;
/**
* \brief Test if given compression mode is supported
*
* Return true if the given compression mode is supported by this liblzma
* build. Otherwise false is returned. It is safe to call this with a value
* that isn't listed in lzma_mode enumeration; the return value will be false.
*
* There is no way to list which modes are available in this particular
* liblzma version and build. It would be useless, because a new compression
* mode, which the application developer wasn't aware, could require giving
* additional options to the encoder that the older modes don't need.
*/
extern LZMA_API(lzma_bool) lzma_mode_is_supported(lzma_mode mode)
lzma_nothrow lzma_attr_const;
/**
* \brief Options specific to the LZMA1 and LZMA2 filters
*
* Since LZMA1 and LZMA2 share most of the code, it's simplest to share
* the options structure too. For encoding, all but the reserved variables
* need to be initialized unless specifically mentioned otherwise.
*
* For raw decoding, both LZMA1 and LZMA2 need dict_size, preset_dict, and
* preset_dict_size (if preset_dict != NULL). LZMA1 needs also lc, lp, and pb.
*/
typedef struct {
/**********************************
* LZMA encoding/decoding options *
**********************************/
/* These options are required in encoder and also with raw decoding. */
/**
* \brief Dictionary size in bytes
*
@@ -145,16 +181,68 @@ typedef struct {
* uncompressed data is kept in memory. One method to reduce size of
* the uncompressed data is to store distance-length pairs, which
* indicate what data to repeat from the dictionary buffer. Thus,
* the bigger the dictionary, the better compression ratio usually is.
* the bigger the dictionary, the better the compression ratio
* usually is.
*
* Raw decoding: Too big dictionary does no other harm than
* wasting memory. This value is ignored by lzma_raw_decode_buffer(),
* because it uses the target buffer as the dictionary.
* Maximum size of the dictionary depends on multiple things:
* - Memory usage limit
* - Available address space (not a problem on 64-bit systems)
* - Selected match finder (encoder only)
*
* Currently the maximum dictionary size for encoding is 1.5 GiB
* (i.e. (UINT32_C(1) << 30) + (UINT32_C(1) << 29)) even on 64-bit
* systems for certain match finder implementation reasons. In the
* future, there may be match finders that support bigger
* dictionaries.
*
* Decoder already supports dictionaries up to 4 GiB - 1 B (i.e.
* UINT32_MAX), so increasing the maximum dictionary size of the
* encoder won't cause problems for old decoders.
*
* Because extremely small dictionaries sizes would have unneeded
* overhead in the decoder, the minimum dictionary size is 4096 bytes.
*
* \note When decoding, too big dictionary does no other harm
* than wasting memory.
*/
uint32_t dictionary_size;
# define LZMA_DICTIONARY_SIZE_MIN 1
# define LZMA_DICTIONARY_SIZE_MAX (UINT32_C(1) << 30)
# define LZMA_DICTIONARY_SIZE_DEFAULT (UINT32_C(1) << 23)
uint32_t dict_size;
# define LZMA_DICT_SIZE_MIN UINT32_C(4096)
# define LZMA_DICT_SIZE_DEFAULT (UINT32_C(1) << 23)
/**
* \brief Pointer to an initial dictionary
*
* It is possible to initialize the LZ77 history window using
* a preset dictionary. It is useful when compressing many
* similar, relatively small chunks of data independently from
* each other. The preset dictionary should contain typical
* strings that occur in the files being compressed. The most
* probable strings should be near the end of the preset dictionary.
*
* This feature should be used only in special situations. For
* now, it works correctly only with raw encoding and decoding.
* Currently none of the container formats supported by
* liblzma allow preset dictionary when decoding, thus if
* you create a .xz or .lzma file with preset dictionary, it
* cannot be decoded with the regular decoder functions. In the
* future, the .xz format will likely get support for preset
* dictionary though.
*/
const uint8_t *preset_dict;
/**
* \brief Size of the preset dictionary
*
* Specifies the size of the preset dictionary. If the size is
* bigger than dict_size, only the last dict_size bytes are
* processed.
*
* This variable is read only when preset_dict is not NULL.
* If preset_dict is not NULL but preset_dict_size is zero,
* no preset dictionary is used (identical to only setting
* preset_dict to NULL).
*/
uint32_t preset_dict_size;
/**
* \brief Number of literal context bits
@@ -164,11 +252,21 @@ typedef struct {
* account when predicting the bits of the next literal.
*
* \todo Example
*
* There is a limit that applies to literal context bits and literal
* position bits together: lc + lp <= 4. Without this limit the
* decoding could become very slow, which could have security related
* results in some cases like email servers doing virus scanning.
* This limit also simplifies the internal implementation in liblzma.
*
* There may be LZMA1 streams that have lc + lp > 4 (maximum possible
* lc would be 8). It is not possible to decode such streams with
* liblzma.
*/
uint32_t literal_context_bits;
# define LZMA_LITERAL_CONTEXT_BITS_MIN 0
# define LZMA_LITERAL_CONTEXT_BITS_MAX 8
# define LZMA_LITERAL_CONTEXT_BITS_DEFAULT 3
uint32_t lc;
# define LZMA_LCLP_MIN 0
# define LZMA_LCLP_MAX 4
# define LZMA_LC_DEFAULT 3
/**
* \brief Number of literal position bits
@@ -180,10 +278,8 @@ typedef struct {
*
* \todo Example
*/
uint32_t literal_pos_bits;
# define LZMA_LITERAL_POS_BITS_MIN 0
# define LZMA_LITERAL_POS_BITS_MAX 4
# define LZMA_LITERAL_POS_BITS_DEFAULT 0
uint32_t lp;
# define LZMA_LP_DEFAULT 0
/**
* \brief Number of position bits
@@ -194,119 +290,121 @@ typedef struct {
* which a matching sequence is found from the dictionary and
* thus can be stored as distance-length pair.
*
* Example: If most of the matches occur at byte positions
* of 8 * n + 3, that is, 3, 11, 19, ... set pos_bits to 3,
* because 2**3 == 8.
* Example: If most of the matches occur at byte positions of
* 8 * n + 3, that is, 3, 11, 19, ... set pb to 3, because 2**3 == 8.
*/
uint32_t pos_bits;
# define LZMA_POS_BITS_MIN 0
# define LZMA_POS_BITS_MAX 4
# define LZMA_POS_BITS_DEFAULT 2
uint32_t pb;
# define LZMA_PB_MIN 0
# define LZMA_PB_MAX 4
# define LZMA_PB_DEFAULT 2
/**
* \brief Pointer to an initial dictionary
* \brief Indicate if the options structure is persistent
*
* It is possible to initialize the LZ77 history window using
* a preset dictionary. Here is a good quote from zlib's
* documentation; this applies to LZMA as is:
* If this is true, the application must keep this options structure
* available after the LZMA2 encoder has been initialized. With
* persistent structure it is possible to change some encoder options
* in the middle of the encoding process without resetting the encoder.
*
* "The dictionary should consist of strings (byte sequences) that
* are likely to be encountered later in the data to be compressed,
* with the most commonly used strings preferably put towards the
* end of the dictionary. Using a dictionary is most useful when
* the data to be compressed is short and can be predicted with
* good accuracy; the data can then be compressed better than
* with the default empty dictionary."
* (From deflateSetDictionary() in zlib.h of zlib version 1.2.3)
*
* This feature should be used only in special situations.
* It works correctly only with raw encoding and decoding.
* Currently none of the container formats supported by
* liblzma allow preset dictionary when decoding, thus if
* you create a .lzma file with preset dictionary, it cannot
* be decoded with the regular .lzma decoder functions.
*
* \todo This feature is not implemented yet.
* This option is used only by LZMA2. LZMA1 ignores this and it is
* safe to not initialize this when encoding with LZMA1.
*/
const uint8_t *preset_dictionary;
lzma_bool persistent;
/**
* \brief Size of the preset dictionary
*
* Specifies the size of the preset dictionary. If the size is
* bigger than dictionary_size, only the last dictionary_size
* bytes are processed.
*
* This variable is read only when preset_dictionary is not NULL.
*/
uint32_t preset_dictionary_size;
/******************************************
* LZMA options needed only when encoding *
******************************************/
/** LZMA compression mode */
/** Compression mode */
lzma_mode mode;
/**
* \brief Number of fast bytes
* \brief Nice length of a match
*
* Number of fast bytes determines how many bytes the encoder
* compares from the match candidates when looking for the best
* match. Bigger fast bytes value usually increase both compression
* ratio and time.
* This determines how many bytes the encoder compares from the match
* candidates when looking for the best match. Once a match of at
* least nice_len bytes long is found, the encoder stops looking for
* better condidates and encodes the match. (Naturally, if the found
* match is actually longer than nice_len, the actual length is
* encoded; it's not truncated to nice_len.)
*
* Bigger values usually increase the compression ratio and
* compression time. For most files, 32 to 128 is a good value,
* which gives very good compression ratio at good speed.
*
* The exact minimum value depends on the match finder. The maximum
* is 273, which is the maximum length of a match that LZMA1 and
* LZMA2 can encode.
*/
uint32_t fast_bytes;
# define LZMA_FAST_BYTES_MIN 5
# define LZMA_FAST_BYTES_MAX 273
# define LZMA_FAST_BYTES_DEFAULT 128
uint32_t nice_len;
/** Match finder ID */
lzma_match_finder match_finder;
lzma_match_finder mf;
/**
* \brief Match finder cycles
* \brief Maximum search depth in the match finder
*
* Higher values give slightly better compression ratio but
* decrease speed. Use special value 0 to let liblzma use
* match-finder-dependent default value.
* For every input byte, match finder searches through the hash chain
* or binary tree in a loop, each iteration going one step deeper in
* the chain or tree. The searching stops if
* - a match of at least nice_len bytes long is found;
* - all match candidates from the hash chain or binary tree have
* been checked; or
* - maximum search depth is reached.
*
* \todo Write much better description.
* Maximum search depth is needed to prevent the match finder from
* wasting too much time in case there are lots of short match
* candidates. On the other hand, stopping the search before all
* candidates have been checked can reduce compression ratio.
*
* Setting depth to zero tells liblzma to use an automatic default
* value, that depends on the selected match finder and nice_len.
* The default is in the range [10, 200] or so (it may vary between
* liblzma versions).
*
* Using a bigger depth value than the default can increase
* compression ratio in some cases. There is no strict maximum value,
* but high values (thousands or millions) should be used with care:
* the encoder could remain fast enough with typical input, but
* malicious input could cause the match finder to slow down
* dramatically, possibly creating a denial of service attack.
*/
uint32_t match_finder_cycles;
uint32_t depth;
/*
* Reserved space to allow possible future extensions without
* breaking the ABI. You should not touch these, because the names
* of these variables may change. These are and will never be used
* with the currently supported options, so it is safe to leave these
* uninitialized.
*/
void *reserved_ptr1;
void *reserved_ptr2;
uint32_t reserved_int1;
uint32_t reserved_int2;
uint32_t reserved_int3;
uint32_t reserved_int4;
uint32_t reserved_int5;
uint32_t reserved_int6;
uint32_t reserved_int7;
uint32_t reserved_int8;
lzma_reserved_enum reserved_enum1;
lzma_reserved_enum reserved_enum2;
lzma_reserved_enum reserved_enum3;
lzma_reserved_enum reserved_enum4;
} lzma_options_lzma;
/**
* \brief Available LZMA encoding modes
* \brief Set a compression preset to lzma_options_lzma structure
*
* Pointer to an array containing the list of available encoding modes.
*
* This variable is available only if LZMA encoder has been enabled.
*/
extern const lzma_mode *const lzma_available_modes;
/**
* \brief Available match finders
*
* Pointer to an array containing the list of available match finders.
* The last element is LZMA_MF_INVALID.
*
* This variable is available only if LZMA encoder has been enabled.
*/
extern const lzma_match_finder *const lzma_available_match_finders;
/**
* \brief Table of presets for the LZMA filter
*
* lzma_presets[0] is the fastest and lzma_preset_lzma[8] is the slowest.
* These presets match the switches -1 .. -9 of the lzma command line tool
* 0 is the fastest and 9 is the slowest. These match the switches -0 .. -9
* of the xz command line tool. In addition, it is possible to bitwise-or
* flags to the preset. Currently only LZMA_PRESET_EXTREME is supported.
* The flags are defined in container.h, because the flags are used also
* with lzma_easy_encoder().
*
* The preset values are subject to changes between liblzma versions.
*
* This variable is available only if LZMA encoder has been enabled.
* This function is available only if LZMA1 or LZMA2 encoder has been enabled
* when building liblzma.
*/
extern const lzma_options_lzma lzma_preset_lzma[9];
extern LZMA_API(lzma_bool) lzma_lzma_preset(
lzma_options_lzma *options, uint32_t preset) lzma_nothrow;

View File

@@ -1,157 +0,0 @@
/**
* \file lzma/memlimit.h
* \brief Memory usage limitter
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*/
#ifndef LZMA_H_INTERNAL
# error Never include this file directly. Use <lzma.h> instead.
#endif
/**
* \brief Opaque data type used with the memory usage limitting functions
*/
typedef struct lzma_memlimit_s lzma_memlimit;
/**
* \brief Allocates and initializes a new lzma_memlimit structure
*
* It is easy to make liblzma to use huge amounts of memory. This can
* be a problem especially with the decoder, since it a file requiring
* huge amounts of memory to uncompress could allow even a denial of
* service attack if the memory usage wasn't limited.
*
* liblzma provides a set of functions to control memory usage. Pointers
* to these functions can be used in lzma_allocator structure, which makes
* it easy to limit memory usage with liblzma.
*
* The memory limitter functions are not tied to limitting memory usage
* with liblzma itself. You can use them with anything you like.
*
* In multi-threaded applications, only one thread at once may use the same
* lzma_memlimit structure. If there is a need, this limitation may
* be removed in future versions without breaking the libary API/ABI.
*
* \param limit Initial memory usage limit in bytes
*
* \return Pointer to allocated and initialized lzma_memlimit
* structure. On error, NULL is returned. The reason behind
* an error is either that malloc() failed or that the given
* limit was so small that it didn't allow allocating even
* the lzma_memlimit structure itself.
*
* \note Excluding lzma_memlimit_usage(), the functions whose name begin
* lzma_memlimit_ can be used even if lzma_init() hasn't been
* called.
*/
extern lzma_memlimit *lzma_memlimit_create(size_t limit);
/**
* \brief Sets a new memory usage limit
*
* \param mem Pointer to a lzma_memlimit structure returned
* earlier by lzma_memry_limit_create().
* \param limit New memory usage limit
*
* The new usage limit may be smaller than the amount of memory currently
* allocated via *mem: New allocations will fail until enough memory has
* been freed or a new limit is set, but the existing allocatations will
* stay untouched.
*/
extern void lzma_memlimit_set(lzma_memlimit *mem, size_t limit);
/**
* \brief Gets the current memory usage limit
*/
extern size_t lzma_memlimit_get(const lzma_memlimit *mem);
/**
* \brief Gets the amount of currently allocated memory
*
* \note This value includes the sizes of some helper structures,
* thus it will always be larger than the total number of
* bytes allocated via lzma_memlimit_alloc().
*/
extern size_t lzma_memlimit_used(const lzma_memlimit *mem);
/**
* \brief Allocates memory with malloc() if memory limit allows
*
* \param mem Pointer to a lzma_memlimit structure returned
* earlier by lzma_memry_limit_create().
* \param nmemb Number of elements to allocate. While liblzma always
* sets this to one, this function still takes the
* value of nmemb into account to keep the function
* usable with zlib and libbzip2.
* \param size Size of an element.
*
* \return Pointer to memory allocated with malloc(nmemb * size),
* except if nmemb * size == 0 which returns malloc(1).
* On error, NULL is returned.
*
* \note This function assumes that nmemb * size is at maximum of
* SIZE_MAX. If it isn't, an overflow will occur resulting
* invalid amount of memory being allocated.
*/
extern void *lzma_memlimit_alloc(
lzma_memlimit *mem, size_t nmemb, size_t size);
/**
* \brief Removes the pointer from memory limitting list
*
* \param mem Pointer to a lzma_memlimit structure returned
* earlier by lzma_memry_limit_create().
* \param ptr Pointer returned earlier by lzma_memlimit_alloc().
*
* This function removes ptr from the internal list and decreases the
* counter of used memory accordingly. The ptr itself isn't freed. This is
* useful when Extra Records allocated by liblzma using lzma_memlimit
* are needed by the application and must not be freed when the
* lzma_memlimit structure is destroyed.
*
* It is OK to call this function with ptr that hasn't been allocated with
* lzma_memlimit_alloc(). In that case, this has no effect other than wasting
* a few CPU cycles.
*/
extern void lzma_memlimit_detach(lzma_memlimit *mem, void *ptr);
/**
* \brief Frees memory and updates the memory limit list
*
* This is like lzma_memlimit_detach() but also frees the given pointer.
*/
extern void lzma_memlimit_free(lzma_memlimit *mem, void *ptr);
/**
* \brief Frees the memory allocated for and by the memory usage limitter
*
* \param mem Pointer to memory limitter
* \param free_allocated If this is non-zero, all the memory allocated
* by lzma_memlimit_alloc() using *mem is also
* freed if it hasn't already been freed with
* lzma_memlimit_free(). Usually this should be
* set to true.
*/
extern void lzma_memlimit_end(
lzma_memlimit *mem, lzma_bool free_allocated);

View File

@@ -1,100 +0,0 @@
/**
* \file lzma/metadata.h
* \brief Metadata handling
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*/
#ifndef LZMA_H_INTERNAL
# error Never include this file directly. Use <lzma.h> instead.
#endif
/**
* \brief Information stored into a Metadata Block
*
* This structure holds all the information that can be stored to
* a Metadata Block.
*/
typedef struct {
/**
* \brief Size of Header Metadata Block
*/
lzma_vli header_metadata_size;
/**
* \brief Total Size of the Stream
*/
lzma_vli total_size;
/**
* \brief Uncompressed Size of the Stream
*/
lzma_vli uncompressed_size;
/**
* \brief Index of the Blocks stored in the Stream
*/
lzma_index *index;
/**
* \brief Extra information
*/
lzma_extra *extra;
} lzma_metadata;
/**
* \brief Calculate the encoded size of Metadata
*
* \return Uncompressed size of the Metadata in encoded form. This value
* may be passed to Block encoder as Uncompressed Size when using
* Metadata filter. On error, zero is returned.
*/
extern lzma_vli lzma_metadata_size(const lzma_metadata *metadata);
/**
* \brief Initializes Metadata encoder
*
* \param coder Pointer to a pointer to hold Metadata encoder's
* internal state. Original value is ignored, thus
* you don't need to initialize the pointer.
* \param allocator Custom memory allocator; usually NULL.
* \param metadata Pointer to Metadata to encoded
*
* \return - LZMA_OK: Initialization succeeded.
* - LZMA_MEM_ERROR: Cannot allocate memory for *coder.
*
* The initialization function makes internal copy of the *metadata structure.
* However, the linked lists metadata->index and metadata->extra are NOT
* copied. Thus, the application may destroy *metadata after initialization
* if it likes, but not Index or Extra.
*/
extern lzma_ret lzma_metadata_encoder(lzma_stream *strm,
lzma_options_block *options, const lzma_metadata *metadata);
/**
* \brief Initializes Metadata decoder
*
* \param want_extra If this is true, Extra Records will be stored
* to metadata->extra. If this is false, Extra
* Records will be parsed but not stored anywhere,
* metadata->extra will be set to NULL.
*/
extern lzma_ret lzma_metadata_decoder(
lzma_stream *strm, lzma_options_block *options,
lzma_metadata *metadata, lzma_bool want_extra);

View File

@@ -1,72 +0,0 @@
/**
* \file lzma/raw.h
* \brief Raw encoder and decoder
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*/
#ifndef LZMA_H_INTERNAL
# error Never include this file directly. Use <lzma.h> instead.
#endif
/**
* \brief Initializes raw encoder
*
* This function may be useful when implementing custom file formats.
*
* \param strm Pointer to properly prepared lzma_stream
* \param options Array of lzma_options_filter structures.
* The end of the array must be marked with
* .id = LZMA_VLI_VALUE_UNKNOWN. The minimum
* number of filters is zero; the maximum is
* determined by available memory.
* \param uncompressed_size
* Size of the uncompressed data. If it is unknown,
* use LZMA_VLI_VALUE_UNKNOWN. You need to give the
* same value to the raw decoder to decode the data.
* \param allow_implicit
* If true, an implicit Copy or Subblock filter should be
* automatically added when needed. If this is false and
* an implicit filter would be needed, LZMA_PROG_ERROR is
* returned.
*
* The `action' with lzma_code() can be LZMA_RUN, LZMA_SYNC_FLUSH (if the
* filter chain support it), or LZMA_FINISH.
*
* \return - LZMA_OK
* - LZMA_MEM_ERROR
* - LZMA_HEADER_ERROR
* - LZMA_PROG_ERROR
*/
extern lzma_ret lzma_raw_encoder(
lzma_stream *strm, const lzma_options_filter *options,
lzma_vli uncompressed_size, lzma_bool allow_implicit);
/**
* \brief Initializes raw decoder
*
* The initialization of raw decoder goes similarly to raw encoder.
*
* The `action' with lzma_code() can be LZMA_RUN or LZMA_SYNC_FLUSH.
*
* \return - LZMA_OK
* - LZMA_MEM_ERROR
* - LZMA_HEADER_ERROR
* - LZMA_PROG_ERROR
*/
extern lzma_ret lzma_raw_decoder(
lzma_stream *strm, const lzma_options_filter *options,
lzma_vli uncompressed_size, lzma_bool allow_implicit);

View File

@@ -1,178 +0,0 @@
/**
* \file lzma/stream.h
* \brief .lzma Stream handling
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*/
#ifndef LZMA_H_INTERNAL
# error Never include this file directly. Use <lzma.h> instead.
#endif
/**
* \brief Options for .lzma Stream encoder
*/
typedef struct {
/**
* \brief Type of integrity Check
*
* The type of the integrity Check is stored into Stream Header
* and Stream Footer. The same Check is used for all Blocks in
* the Stream.
*/
lzma_check_type check;
/**
* \brief Precense of CRC32 of the Block Header
*
* Set this to true if CRC32 of every Block Header should be
* calculated and stored in the Block Header. This is recommended.
*
* This setting is stored into Stream Header and Stream Footer.
*/
lzma_bool has_crc32;
/**
* \brief Uncompressed Size in bytes
*
* This is somewhat advanced feature. Most users want to set this to
* LZMA_VLI_VALUE_UNKNOWN to indicate unknown Uncompressed Size.
*
* If the Uncompressed Size of the Stream being encoded is known,
* it can be stored to the beginning of the Stream. The details
* differ for Single-Block and Multi-Block Streams:
* - With Single-Block Streams, the Uncompressed Size is stored to
* the Block Header and End of Payload Marker is omitted.
* - With Multi-Block Streams, the Uncompressed Size is stored to
* the Header Metadata Block. The Uncompressed Size of the Blocks
* will be unknown, because liblzma cannot predict how the
* application is going to split the data in Blocks.
*/
lzma_vli uncompressed_size;
/**
* \brief Alignment of the beginning of the Stream
*
* Certain filters handle data in bigger chunks than single bytes.
* This affects two things:
* - Performance: aligned memory access is usually faster.
* - Further compression ratio in custom file formats: if you
* encode multiple Blocks with some non-compression filter
* such as LZMA_FILTER_POWERPC, it is a good idea to keep
* the inter-Block alignment correct to maximize compression
* ratio when all these Blocks are finally compressed as a
* single step.
*
* Usually the Stream is stored into its own file, thus
* the alignment is usually zero.
*/
uint32_t alignment;
/**
* \brief Array of filters used to encode Data Blocks
*
* There can be at maximum of seven filters. The end of the array is
* marked with .id = LZMA_VLI_VALUE_UNKNOWN. (That's why the array
* has eight members.) Minimum number of filters is zero; in that
* case, an implicit Copy filter is used.
*/
lzma_options_filter filters[8];
/**
* \brief Array of filters used to encode Metadata Blocks
*
* This is like filters[] but for Metadata Blocks. If Metadata
* Blocks are compressed, they usually are compressed with
* settings that require only little memory to uncompress e.g.
* LZMA with 64 KiB dictionary.
*
* \todo Recommend a preset.
*
* When liblzma sees that the Metadata Block would be very small
* even in uncompressed form, it is not compressed no matter
* what filter have been set here. This is to avoid possibly
* increasing the size of the Metadata Block with bad compression,
* and to avoid useless overhead of filters in uncompression phase.
*/
lzma_options_filter metadata_filters[8];
/**
* \brief Extra information in the Header Metadata Block
*/
lzma_extra *header;
/**
* \brief Extra information in the Footer Metadata Block
*
* It is enough to set this pointer any time before calling
* lzma_code() with LZMA_FINISH as the second argument.
*/
lzma_extra *footer;
} lzma_options_stream;
/**
* \brief Initializes Single-Block .lzma Stream encoder
*
* This is the function that most developers are looking for. :-) It
* compresses using the specified options without storing any extra
* information.
*
* \todo Describe that is_metadata is ignored, maybe something else.
*/
extern lzma_ret lzma_stream_encoder_single(
lzma_stream *strm, const lzma_options_stream *options);
/**
* \brief Initializes Multi-Block .lzma Stream encoder
*
*/
extern lzma_ret lzma_stream_encoder_multi(
lzma_stream *strm, const lzma_options_stream *options);
/**
* \brief Initializes decoder for .lzma Stream
*
* \param strm Pointer to propertily prepared lzma_stream
* \param header Pointer to hold a pointer to Extra Records read
* from the Header Metadata Block. Use NULL if
* you don't care about Extra Records.
* \param footer Same as header, but for Footer Metadata Block.
*
* \return - LZMA_OK: Initialization was successful.
* - LZMA_MEM_ERROR: Cannot allocate memory.
*
* If header and/or footer are not NULL, *header and/or *footer will be
* initially set to NULL.
*
* The application can detect that Header Metadata Block has been completely
* parsed when the decoder procudes some output the first time. If *header
* is still NULL, there was no Extra field in the Header Metadata Block (or
* the whole Header Metadata Block wasn't present at all).
*
* The application can detect that Footer Metadata Block has been parsed
* completely when lzma_code() returns LZMA_STREAM_END. If *footer is still
* NULL, there was no Extra field in the Footer Metadata Block.
*
* \note If you use lzma_memory_limitter, the Extra Records will be
* allocated with it, and thus remain in the lzma_memory_limitter
* even after they get exported to the application via *header
* and *footer pointers.
*/
extern lzma_ret lzma_stream_decoder(lzma_stream *strm,
lzma_extra **header, lzma_extra **footer);

View File

@@ -1,19 +1,15 @@
/**
* \file lzma/stream_flags.h
* \brief .lzma Stream Header and Stream tail encoder and decoder
* \brief .xz Stream Header and Stream Footer encoder and decoder
*/
/*
* Author: Lasse Collin
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
* This file has been put into the public domain.
* You can do whatever you want with this file.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
* See ../lzma.h for information about liblzma as a whole.
*/
#ifndef LZMA_H_INTERNAL
@@ -22,121 +18,210 @@
/**
* \brief Size of Stream Header
* \brief Size of Stream Header and Stream Footer
*
* Magic Bytes (6) + Stream Flags (1) + CRC32 (4)
* Stream Header and Stream Footer have the same size and they are not
* going to change even if a newer version of the .xz file format is
* developed in future.
*/
#define LZMA_STREAM_HEADER_SIZE (6 + 1 + 4)
#define LZMA_STREAM_HEADER_SIZE 12
/**
* \brief Size of Stream tail
*
* Because Stream Footer already has a defined meaning in the file format
* specification, we use Stream tail to denote these two fields:
* Stream Flags (1) + Magic Bytes (2)
*/
#define LZMA_STREAM_TAIL_SIZE (1 + 2)
/**
* Options for encoding and decoding Stream Header and Stream tail
* \brief Options for encoding/decoding Stream Header and Stream Footer
*/
typedef struct {
/**
* Type of the Check calculated from uncompressed data
* \brief Stream Flags format version
*
* To prevent API and ABI breakages if new features are needed in
* Stream Header or Stream Footer, a version number is used to
* indicate which fields in this structure are in use. For now,
* version must always be zero. With non-zero version, the
* lzma_stream_header_encode() and lzma_stream_footer_encode()
* will return LZMA_OPTIONS_ERROR.
*
* lzma_stream_header_decode() and lzma_stream_footer_decode()
* will always set this to the lowest value that supports all the
* features indicated by the Stream Flags field. The application
* must check that the version number set by the decoding functions
* is supported by the application. Otherwise it is possible that
* the application will decode the Stream incorrectly.
*/
lzma_check_type check;
uint32_t version;
/**
* True if Block Headers have the CRC32 field. Note that the CRC32
* field is always present in the Stream Header.
* \brief Backward Size
*
* Backward Size must be a multiple of four bytes. In this Stream
* format version, Backward Size is the size of the Index field.
*
* Backward Size isn't actually part of the Stream Flags field, but
* it is convenient to include in this structure anyway. Backward
* Size is present only in the Stream Footer. There is no need to
* initialize backward_size when encoding Stream Header.
*
* lzma_stream_header_decode() always sets backward_size to
* LZMA_VLI_UNKNOWN so that it is convenient to use
* lzma_stream_flags_compare() when both Stream Header and Stream
* Footer have been decoded.
*/
lzma_bool has_crc32;
lzma_vli backward_size;
# define LZMA_BACKWARD_SIZE_MIN 4
# define LZMA_BACKWARD_SIZE_MAX (LZMA_VLI_C(1) << 34)
/**
* True if the Stream is a Multi-Block Stream.
* \brief Check ID
*
* This indicates the type of the integrity check calculated from
* uncompressed data.
*/
lzma_bool is_multi;
lzma_check check;
/*
* Reserved space to allow possible future extensions without
* breaking the ABI. You should not touch these, because the
* names of these variables may change.
*
* (We will never be able to use all of these since Stream Flags
* is just two bytes plus Backward Size of four bytes. But it's
* nice to have the proper types when they are needed.)
*/
lzma_reserved_enum reserved_enum1;
lzma_reserved_enum reserved_enum2;
lzma_reserved_enum reserved_enum3;
lzma_reserved_enum reserved_enum4;
lzma_reserved_enum reserved_enum5;
lzma_reserved_enum reserved_enum6;
lzma_bool reserved_bool1;
lzma_bool reserved_bool2;
lzma_bool reserved_bool3;
lzma_bool reserved_bool4;
lzma_bool reserved_bool5;
lzma_bool reserved_bool6;
lzma_bool reserved_bool7;
lzma_bool reserved_bool8;
uint32_t reserved_int1;
uint32_t reserved_int2;
uint32_t reserved_int3;
uint32_t reserved_int4;
} lzma_stream_flags;
#define lzma_stream_flags_is_equal(a, b) \
((a).check == (b).check \
&& (a).has_crc32 == (b).has_crc32 \
&& (a).is_multi == (b).is_multi)
/**
* \brief Encodes Stream Header
* \brief Encode Stream Header
*
* Encoding of the Stream Header is done with a single call instead of
* first initializing and then doing the actual work with lzma_code().
*
* \param out Beginning of the output buffer
* \param out_pos out[*out_pos] is the next write position. This
* is updated by the encoder.
* \param out_size out[out_size] is the first byte to not write.
* \param options Stream Header options to be encoded.
* options->backward_size is ignored and doesn't
* need to be initialized.
* \param out Beginning of the output buffer of
* LZMA_STREAM_HEADER_SIZE bytes.
*
* \return - LZMA_OK: Encoding was successful.
* - LZMA_OPTIONS_ERROR: options->version is not supported by
* this liblzma version.
* - LZMA_PROG_ERROR: Invalid options.
* - LZMA_BUF_ERROR: Not enough output buffer space.
*/
extern lzma_ret lzma_stream_header_encode(
uint8_t *out, const lzma_stream_flags *options);
extern LZMA_API(lzma_ret) lzma_stream_header_encode(
const lzma_stream_flags *options, uint8_t *out)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Encodes Stream tail
* \brief Encode Stream Footer
*
* \param options Stream Footer options to be encoded.
* \param out Beginning of the output buffer of
* LZMA_STREAM_HEADER_SIZE bytes.
*
* \return - LZMA_OK: Encoding was successful.
* - LZMA_OPTIONS_ERROR: options->version is not supported by
* this liblzma version.
* - LZMA_PROG_ERROR: Invalid options.
*/
extern LZMA_API(lzma_ret) lzma_stream_footer_encode(
const lzma_stream_flags *options, uint8_t *out)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Decode Stream Header
*
* \param footer Pointer to a pointer that will hold the
* allocated buffer. Caller must free it once
* it isn't needed anymore.
* \param footer_size Pointer to a variable that will the final size
* of the footer buffer.
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc().
* \param options Stream Header options to be encoded.
* \param in Beginning of the input buffer of
* LZMA_STREAM_HEADER_SIZE bytes.
*
* \return - LZMA_OK: Success; *header and *header_size set.
* - LZMA_PROG_ERROR: *options is invalid.
* - LZMA_MEM_ERROR: Cannot allocate memory.
* options->backward_size is always set to LZMA_VLI_UNKNOWN. This is to
* help comparing Stream Flags from Stream Header and Stream Footer with
* lzma_stream_flags_compare().
*
* \return - LZMA_OK: Decoding was successful.
* - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given
* buffer cannot be Stream Header.
* - LZMA_DATA_ERROR: CRC32 doesn't match, thus the header
* is corrupt.
* - LZMA_OPTIONS_ERROR: Unsupported options are present
* in the header.
*
* \note When decoding .xz files that contain multiple Streams, it may
* make sense to print "file format not recognized" only if
* decoding of the Stream Header of the _first_ Stream gives
* LZMA_FORMAT_ERROR. If non-first Stream Header gives
* LZMA_FORMAT_ERROR, the message used for LZMA_DATA_ERROR is
* probably more appropriate.
*
* For example, Stream decoder in liblzma uses LZMA_DATA_ERROR if
* LZMA_FORMAT_ERROR is returned by lzma_stream_header_decode()
* when decoding non-first Stream.
*/
extern lzma_ret lzma_stream_tail_encode(
uint8_t *out, const lzma_stream_flags *options);
extern LZMA_API(lzma_ret) lzma_stream_header_decode(
lzma_stream_flags *options, const uint8_t *in)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Initializes Stream Header decoder
* \brief Decode Stream Footer
*
* \param strm Pointer to lzma_stream used to pass input data
* \param options Target structure for parsed results
* \param options Stream Header options to be encoded.
* \param in Beginning of the input buffer of
* LZMA_STREAM_HEADER_SIZE bytes.
*
* \return - LZMA_OK: Successfully initialized
* - LZMA_MEM_ERROR: Cannot allocate memory
* \return - LZMA_OK: Decoding was successful.
* - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given
* buffer cannot be Stream Footer.
* - LZMA_DATA_ERROR: CRC32 doesn't match, thus the Stream Footer
* is corrupt.
* - LZMA_OPTIONS_ERROR: Unsupported options are present
* in Stream Footer.
*
* The actual decoding is done with lzma_code() and freed with lzma_end().
* \note If Stream Header was already decoded successfully, but
* decoding Stream Footer returns LZMA_FORMAT_ERROR, the
* application should probably report some other error message
* than "file format not recognized", since the file more likely
* is corrupt (possibly truncated). Stream decoder in liblzma
* uses LZMA_DATA_ERROR in this situation.
*/
extern lzma_ret lzma_stream_header_decoder(
lzma_stream *strm, lzma_stream_flags *options);
extern LZMA_API(lzma_ret) lzma_stream_footer_decode(
lzma_stream_flags *options, const uint8_t *in)
lzma_nothrow lzma_attr_warn_unused_result;
/**
* \brief Initializes Stream tail decoder
* \brief Compare two lzma_stream_flags structures
*
* \param strm Pointer to lzma_stream used to pass input data
* \param options Target structure for parsed results.
* \param decode_uncompressed_size
* Set to true if the first field to decode is
* Uncompressed Size. Set to false if the first
* field to decode is Backward Size.
* backward_size values are compared only if both are not
* LZMA_VLI_UNKNOWN.
*
* \return - LZMA_OK: Successfully initialized
* - LZMA_MEM_ERROR: Cannot allocate memory
*
* The actual decoding is done with lzma_code() and freed with lzma_end().
* \return - LZMA_OK: Both are equal. If either had backward_size set
* to LZMA_VLI_UNKNOWN, backward_size values were not
* compared or validated.
* - LZMA_DATA_ERROR: The structures differ.
* - LZMA_OPTIONS_ERROR: version in either structure is greater
* than the maximum supported version (currently zero).
* - LZMA_PROG_ERROR: Invalid value, e.g. invalid check or
* backward_size.
*/
extern lzma_ret lzma_stream_tail_decoder(
lzma_stream *strm, lzma_stream_flags *options);
extern LZMA_API(lzma_ret) lzma_stream_flags_compare(
const lzma_stream_flags *a, const lzma_stream_flags *b)
lzma_nothrow lzma_attr_pure;

View File

@@ -1,19 +1,15 @@
/**
* \file lzma/subblock.h
* \brief Subblock filter
*/
/*
* Author: Lasse Collin
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
* This file has been put into the public domain.
* You can do whatever you want with this file.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
* See ../lzma.h for information about liblzma as a whole.
*/
#ifndef LZMA_H_INTERNAL
@@ -24,7 +20,7 @@
/**
* \brief Filter ID
*
* Filter ID of the Subblock filter. This is used as lzma_options_filter.id.
* Filter ID of the Subblock filter. This is used as lzma_filter.id.
*/
#define LZMA_FILTER_SUBBLOCK LZMA_VLI_C(0x01)
@@ -95,9 +91,10 @@ typedef struct {
* input_offset % alignment == output_offset % alignment
*
* The Subblock filter assumes that the first output byte will be
* written to a position in the output stream that is properly aligned.
*
* FIXME desc
* written to a position in the output stream that is properly
* aligned. This requirement is automatically met when the start
* offset of the Stream or Block is correctly told to Block or
* Stream encoder.
*/
uint32_t alignment;
# define LZMA_SUBBLOCK_ALIGNMENT_MIN 1
@@ -161,16 +158,17 @@ typedef struct {
*
* When subfilter_mode is LZMA_SUBFILTER_NONE, the application may
* put Subfilter options to subfilter_options structure, and then
* set subfilter_mode to LZMA_SUBFILTER_SET. This implies setting
* flush to true. No new input data will be read until the Subfilter
* has been enabled. Once the Subfilter has been enabled, liblzma
* will set subfilter_mode to LZMA_SUBFILTER_RUN.
* set subfilter_mode to LZMA_SUBFILTER_SET. No new input data will
* be read until the Subfilter has been enabled. Once the Subfilter
* has been enabled, liblzma will set subfilter_mode to
* LZMA_SUBFILTER_RUN.
*
* When subfilter_mode is LZMA_SUBFILTER_RUN, the application may
* set subfilter_mode to LZMA_SUBFILTER_FINISH. No new input data
* will be read until the Subfilter has been finished. Once the
* Subfilter has been finished, liblzma will set subfilter_mode
* to LZMA_SUBFILTER_NONE.
* set subfilter_mode to LZMA_SUBFILTER_FINISH. All the input
* currently available will be encoded before unsetting the
* Subfilter. Application must not change the amount of available
* input until the Subfilter has finished. Once the Subfilter has
* finished, liblzma will set subfilter_mode to LZMA_SUBFILTER_NONE.
*
* If the intent is to have Subfilter enabled to the very end of
* the data, it is not needed to separately disable Subfilter with
@@ -178,6 +176,11 @@ typedef struct {
* of lzma_code() will make the Subblock encoder to disable the
* Subfilter once all the data has been ran through the Subfilter.
*
* After the first call with LZMA_SYNC_FLUSH or LZMA_FINISH, the
* application must not change subfilter_mode until LZMA_STREAM_END.
* Setting LZMA_SUBFILTER_SET/LZMA_SUBFILTER_FINISH and
* LZMA_SYNC_FLUSH/LZMA_FINISH _at the same time_ is fine.
*
* \note This variable is ignored if allow_subfilters is false.
*/
lzma_subfilter_mode subfilter_mode;
@@ -192,6 +195,6 @@ typedef struct {
*
* \note This variable is ignored if allow_subfilters is false.
*/
lzma_options_filter subfilter_options;
lzma_filter subfilter_options;
} lzma_options_subblock;

View File

@@ -1,19 +1,15 @@
/**
* \file lzma/version.h
* \brief Version number
*/
/*
* Author: Lasse Collin
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
* This file has been put into the public domain.
* You can do whatever you want with this file.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
* See ../lzma.h for information about liblzma as a whole.
*/
#ifndef LZMA_H_INTERNAL
@@ -21,39 +17,105 @@
#endif
/*
* Version number splitted in components
*/
#define LZMA_VERSION_MAJOR 4
#define LZMA_VERSION_MINOR 999
#define LZMA_VERSION_PATCH 9
#define LZMA_VERSION_STABILITY LZMA_VERSION_STABILITY_BETA
#ifndef LZMA_VERSION_COMMIT
# define LZMA_VERSION_COMMIT ""
#endif
/*
* Map symbolic stability levels to integers.
*/
#define LZMA_VERSION_STABILITY_ALPHA 0
#define LZMA_VERSION_STABILITY_BETA 1
#define LZMA_VERSION_STABILITY_STABLE 2
/**
* \brief Compile-time version number
*
* The version number is of format xyyyuuus where
* - x is the major LZMA SDK version
* - yyy is the minor LZMA SDK version
* - uuu is LZMA Utils version (reset to zero every time SDK version
* is incremented)
* The version number is of format xyyyzzzs where
* - x = major
* - yyy = minor
* - zzz = revision
* - s indicates stability: 0 = alpha, 1 = beta, 2 = stable
*
* The same xyyyzzz triplet is never reused with different stability levels.
* For example, if 5.1.0alpha has been released, there will never be 5.1.0beta
* or 5.1.0 stable.
*
* \note The version number of liblzma has nothing to with
* the version number of Igor Pavlov's LZMA SDK.
*/
#define LZMA_VERSION UINT32_C(40420010)
#define LZMA_VERSION (LZMA_VERSION_MAJOR * UINT32_C(10000000) \
+ LZMA_VERSION_MINOR * UINT32_C(10000) \
+ LZMA_VERSION_PATCH * UINT32_C(10) \
+ LZMA_VERSION_STABILITY)
/*
* Macros to construct the compile-time version string
*/
#if LZMA_VERSION_STABILITY == LZMA_VERSION_STABILITY_ALPHA
# define LZMA_VERSION_STABILITY_STRING "alpha"
#elif LZMA_VERSION_STABILITY == LZMA_VERSION_STABILITY_BETA
# define LZMA_VERSION_STABILITY_STRING "beta"
#elif LZMA_VERSION_STABILITY == LZMA_VERSION_STABILITY_STABLE
# define LZMA_VERSION_STABILITY_STRING ""
#else
# error Incorrect LZMA_VERSION_STABILITY
#endif
#define LZMA_VERSION_STRING_C_(major, minor, patch, stability, commit) \
#major "." #minor "." #patch stability commit
#define LZMA_VERSION_STRING_C(major, minor, patch, stability, commit) \
LZMA_VERSION_STRING_C_(major, minor, patch, stability, commit)
/**
* \brief liblzma version number as an integer
* \brief Compile-time version as a string
*
* This is the value of LZMA_VERSION macro at the compile time of liblzma.
* This can be for example "4.999.5alpha", "4.999.8beta", or "5.0.0" (stable
* versions don't have any "stable" suffix). In future, a snapshot built
* from source code repository may include an additional suffix, for example
* "4.999.8beta-21-g1d92". The commit ID won't be available in numeric form
* in LZMA_VERSION macro.
*/
#define LZMA_VERSION_STRING LZMA_VERSION_STRING_C( \
LZMA_VERSION_MAJOR, LZMA_VERSION_MINOR, \
LZMA_VERSION_PATCH, LZMA_VERSION_STABILITY_STRING, \
LZMA_VERSION_COMMIT)
/* #ifndef is needed for use with windres (MinGW or Cygwin). */
#ifndef LZMA_H_INTERNAL_RC
/**
* \brief Run-time version number as an integer
*
* Return the value of LZMA_VERSION macro at the compile time of liblzma.
* This allows the application to compare if it was built against the same,
* older, or newer version of liblzma that is currently running.
*/
extern const uint32_t lzma_version_number;
extern LZMA_API(uint32_t) lzma_version_number(void)
lzma_nothrow lzma_attr_const;
/**
* \brief Returns versions number of liblzma as a string
* \brief Run-time version as a string
*
* This function may be useful if you want to display which version of
* libilzma your application is currently using.
*
* \return Returns a pointer to a statically allocated string constant,
* which contains the version number of liblzma. The format of
* the version string is usually (but not necessarily) x.y.z
* e.g. "4.42.1". Alpha and beta versions contain a suffix
* ("4.42.0alpha").
* liblzma your application is currently using.
*/
extern const char *const lzma_version_string;
extern LZMA_API(const char *) lzma_version_string(void)
lzma_nothrow lzma_attr_const;
#endif

View File

@@ -2,18 +2,25 @@
* \file lzma/vli.h
* \brief Variable-length integer handling
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
* In the .xz format, most integers are encoded in a variable-length
* representation, which is sometimes called little endian base-128 encoding.
* This saves space when smaller values are more likely than bigger values.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* The encoding scheme encodes seven bits to every byte, using minimum
* number of bytes required to represent the given value. Encodings that use
* non-minimum number of bytes are invalid, thus every integer has exactly
* one encoded representation. The maximum number of bits in a VLI is 63,
* thus the vli argument must be at maximum of UINT64_MAX / 2. You should
* use LZMA_VLI_MAX for clarity.
*/
/*
* Author: Lasse Collin
*
* 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
* Lesser General Public License for more details.
* This file has been put into the public domain.
* You can do whatever you want with this file.
*
* See ../lzma.h for information about liblzma as a whole.
*/
#ifndef LZMA_H_INTERNAL
@@ -24,12 +31,12 @@
/**
* \brief Maximum supported value of variable-length integer
*/
#define LZMA_VLI_VALUE_MAX (UINT64_MAX / 2)
#define LZMA_VLI_MAX (UINT64_MAX / 2)
/**
* \brief VLI value to denote that the value is unknown
*/
#define LZMA_VLI_VALUE_UNKNOWN UINT64_MAX
#define LZMA_VLI_UNKNOWN UINT64_MAX
/**
* \brief Maximum supported length of variable length integers
@@ -47,12 +54,11 @@
* \brief Variable-length integer type
*
* This will always be unsigned integer. Valid VLI values are in the range
* [0, LZMA_VLI_VALUE_MAX]. Unknown value is indicated with
* LZMA_VLI_VALUE_UNKNOWN, which is the maximum value of the underlaying
* integer type (this feature is useful in several situations).
* [0, LZMA_VLI_MAX]. Unknown value is indicated with LZMA_VLI_UNKNOWN,
* which is the maximum value of the underlaying integer type.
*
* In future, even if lzma_vli is typdefined to something else than uint64_t,
* it is guaranteed that 2 * LZMA_VLI_VALUE_MAX will not overflow lzma_vli.
* it is guaranteed that 2 * LZMA_VLI_MAX will not overflow lzma_vli.
* This simplifies integer overflow detection.
*/
typedef uint64_t lzma_vli;
@@ -68,177 +74,95 @@ typedef uint64_t lzma_vli;
* indicates unknown value.
*/
#define lzma_vli_is_valid(vli) \
((vli) <= LZMA_VLI_VALUE_MAX || (vli) == LZMA_VLI_VALUE_UNKNOWN)
((vli) <= LZMA_VLI_MAX || (vli) == LZMA_VLI_UNKNOWN)
/**
* \brief Sets VLI to given value with error checking
* \brief Encode a variable-length integer
*
* \param dest Target variable which must have type of lzma_vli.
* \param src New value to be stored to dest.
* \param limit Maximum allowed value for src.
*
* \return False on success, true on error. If an error occurred,
* dest is left in undefined state (i.e. it's possible that
* it will be different in newer liblzma versions).
*/
#define lzma_vli_set_lim(dest, src, limit) \
((src) > (limit) || ((dest) = (src)) > (limit))
/**
* \brief
*/
#define lzma_vli_add_lim(dest, src, limit) \
((src) > (limit) || ((dest) += (src)) > (limit))
#define lzma_vli_add2_lim(dest, src1, src2, limit) \
(lzma_vli_add_lim(dest, src1, limit) \
|| lzma_vli_add_lim(dest, src2, limit))
#define lzma_vli_add3_lim(dest, src1, src2, src3, limit) \
(lzma_vli_add_lim(dest, src1, limit) \
|| lzma_vli_add_lim(dest, src2, limit) \
|| lzma_vli_add_lim(dest, src3, limit))
#define lzma_vli_add4_lim(dest, src1, src2, src3, src4, limit) \
(lzma_vli_add_lim(dest, src1, limit) \
|| lzma_vli_add_lim(dest, src2, limit) \
|| lzma_vli_add_lim(dest, src3, limit) \
|| lzma_vli_add_lim(dest, src4, limit))
#define lzma_vli_sum_lim(dest, src1, src2, limit) \
(lzma_vli_set_lim(dest, src1, limit) \
|| lzma_vli_add_lim(dest, src2, limit))
#define lzma_vli_sum3_lim(dest, src1, src2, src3, limit) \
(lzma_vli_set_lim(dest, src1, limit) \
|| lzma_vli_add_lim(dest, src2, limit) \
|| lzma_vli_add_lim(dest, src3, limit))
#define lzma_vli_sum4_lim(dest, src1, src2, src3, src4, limit) \
(lzma_vli_set_lim(dest, src1, limit) \
|| lzma_vli_add_lim(dest, src2, limit) \
|| lzma_vli_add_lim(dest, src3, limit) \
|| lzma_vli_add_lim(dest, src4, limit))
#define lzma_vli_set(dest, src) lzma_vli_set_lim(dest, src, LZMA_VLI_VALUE_MAX)
#define lzma_vli_add(dest, src) lzma_vli_add_lim(dest, src, LZMA_VLI_VALUE_MAX)
#define lzma_vli_add2(dest, src1, src2) \
lzma_vli_add2_lim(dest, src1, src2, LZMA_VLI_VALUE_MAX)
#define lzma_vli_add3(dest, src1, src2, src3) \
lzma_vli_add3_lim(dest, src1, src2, src3, LZMA_VLI_VALUE_MAX)
#define lzma_vli_add4(dest, src1, src2, src3, src4) \
lzma_vli_add4_lim(dest, src1, src2, src3, src4, LZMA_VLI_VALUE_MAX)
#define lzma_vli_sum(dest, src1, src2) \
lzma_vli_sum_lim(dest, src1, src2, LZMA_VLI_VALUE_MAX)
#define lzma_vli_sum3(dest, src1, src2, src3) \
lzma_vli_sum3_lim(dest, src1, src2, src3, LZMA_VLI_VALUE_MAX)
#define lzma_vli_sum4(dest, src1, src2, src3, src4) \
lzma_vli_sum4_lim(dest, src1, src2, src3, src4, LZMA_VLI_VALUE_MAX)
/**
* \brief Encodes variable-length integer
*
* In the new .lzma format, most integers are encoded in variable-length
* representation. This saves space when smaller values are more likely
* than bigger values.
*
* The encoding scheme encodes seven bits to every byte, using minimum
* number of bytes required to represent the given value. In other words,
* it puts 7-63 bits into 1-9 bytes. This implementation limits the number
* of bits used to 63, thus num must be at maximum of INT64_MAX / 2. You
* may use LZMA_VLI_VALUE_MAX for clarity.
* This function has two modes: single-call and multi-call. Single-call mode
* encodes the whole integer at once; it is an error if the output buffer is
* too small. Multi-call mode saves the position in *vli_pos, and thus it is
* possible to continue encoding if the buffer becomes full before the whole
* integer has been encoded.
*
* \param vli Integer to be encoded
* \param vli_pos How many bytes have already been written out. This
* must be less than 9 before calling this function.
* \param vli_size Minimum size that the variable-length representation
* must take. This is useful if you want to use
* variable-length integers as padding. Usually you want
* to set this to zero. The maximum allowed value is 9.
* \param vli_pos How many VLI-encoded bytes have already been written
* out. When starting to encode a new integer, *vli_pos
* must be set to zero. To use single-call encoding,
* set vli_pos to NULL.
* \param out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos].
* \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size].
*
* \return - LZMA_OK: So far all OK, but the integer is not
* \return Slightly different return values are used in multi-call and
* single-call modes.
*
* Single-call (vli_pos == NULL):
* - LZMA_OK: Integer successfully encoded.
* - LZMA_PROG_ERROR: Arguments are not sane. This can be due
* to too little output space; single-call mode doesn't use
* LZMA_BUF_ERROR, since the application should have checked
* the encoded size with lzma_vli_size().
*
* Multi-call (vli_pos != NULL):
* - LZMA_OK: So far all OK, but the integer is not
* completely written out yet.
* - LZMA_STREAM_END: Integer successfully encoded.
* - LZMA_BUF_ERROR: No output space (*out_pos == out_size)
* - LZMA_BUF_ERROR: No output space was provided.
* - LZMA_PROG_ERROR: Arguments are not sane.
*/
extern lzma_ret lzma_vli_encode(
lzma_vli vli, size_t *lzma_restrict vli_pos, size_t vli_size,
uint8_t *lzma_restrict out, size_t *lzma_restrict out_pos,
size_t out_size);
extern LZMA_API(lzma_ret) lzma_vli_encode(lzma_vli vli,
size_t *lzma_restrict vli_pos, uint8_t *lzma_restrict out,
size_t *lzma_restrict out_pos, size_t out_size) lzma_nothrow;
/**
* \brief Decodes variable-length integer
* \brief Decode a variable-length integer
*
* Like lzma_vli_encode(), this function has single-call and multi-call modes.
*
* \param vli Pointer to decoded integer. The decoder will
* initialize it to zero when *vli_pos == 0, so
* application isn't required to initialize *vli.
* \param vli_pos How many bytes have already been decoded. When
* starting to decode a new integer, *vli_pos must
* be initialized to zero.
* be initialized to zero. To use single-call decoding,
* set this to NULL.
* \param in Beginning of the input buffer
* \param in_pos The next byte will be read from in[*in_pos].
* \param in_size Size of the input buffer; the first byte that
* won't be read is in[in_size].
*
* \return - LZMA_OK: So far all OK, but the integer is not
* \return Slightly different return values are used in multi-call and
* single-call modes.
*
* Single-call (vli_pos == NULL):
* - LZMA_OK: Integer successfully decoded.
* - LZMA_DATA_ERROR: Integer is corrupt. This includes hitting
* the end of the input buffer before the whole integer was
* decoded; providing no input at all will use LZMA_DATA_ERROR.
* - LZMA_PROG_ERROR: Arguments are not sane.
*
* Multi-call (vli_pos != NULL):
* - LZMA_OK: So far all OK, but the integer is not
* completely decoded yet.
* - LZMA_STREAM_END: Integer successfully decoded.
* - LZMA_BUF_ERROR: No input data (*in_pos == in_size)
* - LZMA_DATA_ERROR: Integer is longer than nine bytes.
* - LZMA_DATA_ERROR: Integer is corrupt.
* - LZMA_BUF_ERROR: No input was provided.
* - LZMA_PROG_ERROR: Arguments are not sane.
*/
extern lzma_ret lzma_vli_decode(lzma_vli *lzma_restrict vli,
extern LZMA_API(lzma_ret) lzma_vli_decode(lzma_vli *lzma_restrict vli,
size_t *lzma_restrict vli_pos, const uint8_t *lzma_restrict in,
size_t *lzma_restrict in_pos, size_t in_size);
size_t *lzma_restrict in_pos, size_t in_size) lzma_nothrow;
/**
* \brief Decodes variable-length integer reading buffer backwards
*
* The variable-length integer encoding is designed so that it can be read
* either from the beginning to the end, or from the end to the beginning.
* This feature is needed to make the Stream parseable backwards;
* specifically, to read the Backward Size field in Stream Footer.
*
* \param vli Pointer to variable to hold the decoded integer.
* \param in Beginning of the input buffer
* \param in_size Number of bytes available in the in[] buffer.
* On successful decoding, this is updated to match
* the number of bytes used. (in[*in_size - 1] is the
* first byte to process. After successful decoding,
* in[*in_size] will point to the first byte of the
* variable-length integer.)
*
* \return - LZMA_OK: Decoding successful
* - LZMA_DATA_ERROR: No valid variable-length integer was found.
* - LZMA_BUF_ERROR: Not enough input. Note that in practice,
* this tends to be a sign of broken input, because the
* applications usually do give as much input to this function
* as the applications have available.
*/
extern lzma_ret lzma_vli_reverse_decode(
lzma_vli *vli, const uint8_t *in, size_t *in_size);
/**
* \brief Gets the minimum number of bytes required to encode vli
* \brief Get the number of bytes required to encode a VLI
*
* \return Number of bytes on success (1-9). If vli isn't valid,
* zero is returned.
*/
extern size_t lzma_vli_size(lzma_vli vli);
extern LZMA_API(uint32_t) lzma_vli_size(lzma_vli vli)
lzma_nothrow lzma_attr_pure;

View File

@@ -1,64 +0,0 @@
##
## This code has been put into the public domain.
##
## 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
## Lesser General Public License for more details.
##
EXTRA_DIST = crc32_tablegen.c crc64_tablegen.c
noinst_LTLIBRARIES = libcheck.la
libcheck_la_SOURCES = \
check.c \
check.h \
check_init.c \
check_byteswap.h \
crc_macros.h
libcheck_la_CPPFLAGS = \
-I@top_srcdir@/src/liblzma/api \
-I@top_srcdir@/src/liblzma/common
if COND_CHECK_CRC32
if COND_ASM_X86
libcheck_la_SOURCES += crc32_x86.s
else
libcheck_la_SOURCES += crc32.c
endif
if COND_SMALL
libcheck_la_SOURCES += crc32_init.c
else
libcheck_la_SOURCES += crc32_table.c crc32_table_le.h crc32_table_be.h
endif
endif
if COND_CHECK_CRC64
if COND_ASM_X86
libcheck_la_SOURCES += crc64_x86.s
else
libcheck_la_SOURCES += crc64.c
endif
if COND_SMALL
libcheck_la_SOURCES += crc64_init.c
else
libcheck_la_SOURCES += crc64_table.c crc64_table_le.h crc64_table_be.h
endif
endif
if COND_CHECK_SHA256
libcheck_la_SOURCES += sha256.c
# Hide bogus warning to allow usage of -Werror. If more issues like this
# pop up, we'll drop -Werror.
if COND_WNO_UNINITIALIZED
CFLAGS += -Wno-uninitialized
endif
endif

View File

@@ -0,0 +1,51 @@
##
## Author: Lasse Collin
##
## This file has been put into the public domain.
## You can do whatever you want with this file.
##
EXTRA_DIST += \
check/crc32_tablegen.c \
check/crc64_tablegen.c
liblzma_la_SOURCES += \
check/check.c \
check/check.h \
check/crc_macros.h
if COND_CHECK_CRC32
if COND_SMALL
liblzma_la_SOURCES += check/crc32_small.c
else
liblzma_la_SOURCES += \
check/crc32_table.c \
check/crc32_table_le.h \
check/crc32_table_be.h
if COND_ASM_X86
liblzma_la_SOURCES += check/crc32_x86.S
else
liblzma_la_SOURCES += check/crc32_fast.c
endif
endif
endif
if COND_CHECK_CRC64
if COND_SMALL
liblzma_la_SOURCES += check/crc64_small.c
else
liblzma_la_SOURCES += \
check/crc64_table.c \
check/crc64_table_le.h \
check/crc64_table_be.h
if COND_ASM_X86
liblzma_la_SOURCES += check/crc64_x86.S
else
liblzma_la_SOURCES += check/crc64_fast.c
endif
endif
endif
if COND_CHECK_SHA256
liblzma_la_SOURCES += check/sha256.c
endif

View File

@@ -1,111 +1,138 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file check.c
/// \brief Check sizes
/// \brief Single API to access different integrity checks
//
// This code has been put into the public domain.
// Author: Lasse Collin
//
// 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 file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "check.h"
// See the .lzma header format specification section 2.2.2.
LZMA_API const uint32_t lzma_check_sizes[8] = { 0, 4, 4, 8, 16, 32, 32, 64 };
extern LZMA_API(lzma_bool)
lzma_check_is_supported(lzma_check type)
{
if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
return false;
LZMA_API const lzma_bool lzma_available_checks[LZMA_CHECK_ID_MAX + 1] = {
true, // LZMA_CHECK_NONE
static const lzma_bool available_checks[LZMA_CHECK_ID_MAX + 1] = {
true, // LZMA_CHECK_NONE
#ifdef HAVE_CHECK_CRC32
true,
true,
#else
false,
false,
#endif
false, // Reserved
false, // Reserved
false, // Reserved
#ifdef HAVE_CHECK_CRC64
true,
true,
#else
false,
false,
#endif
false, // Reserved
false, // Reserved
false, // Reserved
false, // Reserved
false, // Reserved
false, // Reserved
#ifdef HAVE_CHECK_SHA256
true,
true,
#else
false,
false,
#endif
false, // Reserved
false, // Reserved
};
false, // Reserved
false, // Reserved
false, // Reserved
false, // Reserved
false, // Reserved
};
return available_checks[(unsigned int)(type)];
}
extern lzma_ret
lzma_check_init(lzma_check *check, lzma_check_type type)
extern LZMA_API(uint32_t)
lzma_check_size(lzma_check type)
{
lzma_ret ret = LZMA_OK;
if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
return UINT32_MAX;
// See file-format.txt section 2.1.1.2.
static const uint8_t check_sizes[LZMA_CHECK_ID_MAX + 1] = {
0,
4, 4, 4,
8, 8, 8,
16, 16, 16,
32, 32, 32,
64, 64, 64
};
return check_sizes[(unsigned int)(type)];
}
extern void
lzma_check_init(lzma_check_state *check, lzma_check type)
{
switch (type) {
case LZMA_CHECK_NONE:
break;
#ifdef HAVE_CHECK_CRC32
case LZMA_CHECK_CRC32:
check->crc32 = 0;
check->state.crc32 = 0;
break;
#endif
#ifdef HAVE_CHECK_CRC64
case LZMA_CHECK_CRC64:
check->crc64 = 0;
check->state.crc64 = 0;
break;
#endif
#ifdef HAVE_CHECK_SHA256
case LZMA_CHECK_SHA256:
lzma_sha256_init(&check->sha256);
lzma_sha256_init(check);
break;
#endif
default:
if (type <= LZMA_CHECK_ID_MAX)
ret = LZMA_UNSUPPORTED_CHECK;
else
ret = LZMA_PROG_ERROR;
break;
}
return ret;
return;
}
extern void
lzma_check_update(lzma_check *check, lzma_check_type type,
lzma_check_update(lzma_check_state *check, lzma_check type,
const uint8_t *buf, size_t size)
{
switch (type) {
#ifdef HAVE_CHECK_CRC32
case LZMA_CHECK_CRC32:
check->crc32 = lzma_crc32(buf, size, check->crc32);
check->state.crc32 = lzma_crc32(buf, size, check->state.crc32);
break;
#endif
#ifdef HAVE_CHECK_CRC64
case LZMA_CHECK_CRC64:
check->crc64 = lzma_crc64(buf, size, check->crc64);
check->state.crc64 = lzma_crc64(buf, size, check->state.crc64);
break;
#endif
#ifdef HAVE_CHECK_SHA256
case LZMA_CHECK_SHA256:
lzma_sha256_update(buf, size, &check->sha256);
lzma_sha256_update(buf, size, check);
break;
#endif
@@ -118,43 +145,30 @@ lzma_check_update(lzma_check *check, lzma_check_type type,
extern void
lzma_check_finish(lzma_check *check, lzma_check_type type)
lzma_check_finish(lzma_check_state *check, lzma_check type)
{
#ifdef HAVE_CHECK_SHA256
if (type == LZMA_CHECK_SHA256)
lzma_sha256_finish(&check->sha256);
switch (type) {
#ifdef HAVE_CHECK_CRC32
case LZMA_CHECK_CRC32:
check->buffer.u32[0] = integer_le_32(check->state.crc32);
break;
#endif
return;
}
/*
extern bool
lzma_check_compare(
lzma_check *check1, lzma_check *check2, lzma_check_type type)
{
bool ret;
switch (type) {
case LZMA_CHECK_NONE:
break;
case LZMA_CHECK_CRC32:
ret = check1->crc32 != check2->crc32;
break;
#ifdef HAVE_CHECK_CRC64
case LZMA_CHECK_CRC64:
ret = check1->crc64 != check2->crc64;
check->buffer.u64[0] = integer_le_64(check->state.crc64);
break;
#endif
#ifdef HAVE_CHECK_SHA256
case LZMA_CHECK_SHA256:
lzma_sha256_finish(check);
break;
#endif
default:
// Unsupported check
assert(type <= 7);
ret = false;
break;
}
return ret;
return;
}
*/

View File

@@ -1,13 +1,12 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file check.h
/// \brief Prototypes for different check functions
/// \brief Internal API to different integrity check functions
//
// This code has been put into the public domain.
// Author: Lasse Collin
//
// 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 file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
@@ -17,86 +16,80 @@
#include "common.h"
// Index hashing needs the best possible hash function (preferably
// a cryptographic hash) for maximum reliability.
#if defined(HAVE_CHECK_SHA256)
# define LZMA_CHECK_BEST LZMA_CHECK_SHA256
#elif defined(HAVE_CHECK_CRC64)
# define LZMA_CHECK_BEST LZMA_CHECK_CRC64
#else
# define LZMA_CHECK_BEST LZMA_CHECK_CRC32
#endif
/// \brief Structure to hold internal state of the check being calculated
///
/// \note This is not in the public API because this structure may
/// change in future if new integrity check algorithms are added.
typedef struct {
/// Internal state
uint32_t state[8];
/// Buffer to hold the final result and a temporary buffer for SHA256.
union {
uint8_t u8[64];
uint32_t u32[16];
uint64_t u64[8];
} buffer;
/// Temporary 8-byte aligned buffer to hold incomplete chunk.
/// After lzma_check_finish(), the first 32 bytes will contain
/// the final digest in big endian byte order.
uint8_t buffer[64];
/// Check-specific data
union {
uint32_t crc32;
uint64_t crc64;
/// Size of the message excluding padding
uint64_t size;
struct {
/// Internal state
uint32_t state[8];
} lzma_sha256;
/// \note This is not in the public API because this structure will
/// change in future.
typedef union {
uint32_t crc32;
uint64_t crc64;
lzma_sha256 sha256;
} lzma_check;
/// Size of the message excluding padding
uint64_t size;
} sha256;
} state;
} lzma_check_state;
/// lzma_crc32_table[0] is needed by LZ encoder so we need to keep
/// the array two-dimensional.
#ifdef HAVE_SMALL
extern uint32_t lzma_crc32_table[8][256];
extern uint64_t lzma_crc64_table[4][256];
extern uint32_t lzma_crc32_table[1][256];
extern void lzma_crc32_init(void);
#else
extern const uint32_t lzma_crc32_table[8][256];
extern const uint64_t lzma_crc64_table[4][256];
#endif
// Generic
/// \brief Initializes *check depending on type
/// \brief Initialize *check depending on type
///
/// \return LZMA_OK on success. LZMA_UNSUPPORTED_CHECK if the type is not
/// supported by the current version or build of liblzma.
/// LZMA_PROG_ERROR if type > LZMA_CHECK_ID_MAX.
///
extern lzma_ret lzma_check_init(lzma_check *check, lzma_check_type type);
extern void lzma_check_init(lzma_check_state *check, lzma_check type);
/// \brief Updates *check
///
extern void lzma_check_update(lzma_check *check, lzma_check_type type,
/// Update the check state
extern void lzma_check_update(lzma_check_state *check, lzma_check type,
const uint8_t *buf, size_t size);
/// \brief Finishes *check
///
extern void lzma_check_finish(lzma_check *check, lzma_check_type type);
/// Finish the check calculation and store the result to check->buffer.u8.
extern void lzma_check_finish(lzma_check_state *check, lzma_check type);
/*
/// \brief Compare two checks
///
/// \return false if the checks are identical; true if they differ.
///
extern bool lzma_check_compare(
lzma_check *check1, lzma_check *check2, lzma_check_type type);
*/
// CRC32
extern void lzma_crc32_init(void);
// CRC64
extern void lzma_crc64_init(void);
// SHA256
extern void lzma_sha256_init(lzma_sha256 *sha256);
/// Prepare SHA-256 state for new input.
extern void lzma_sha256_init(lzma_check_state *check);
/// Update the SHA-256 hash state
extern void lzma_sha256_update(
const uint8_t *buf, size_t size, lzma_sha256 *sha256);
extern void lzma_sha256_finish(lzma_sha256 *sha256);
const uint8_t *buf, size_t size, lzma_check_state *check);
/// Finish the SHA-256 calculation and store the result to check->buffer.u8.
extern void lzma_sha256_finish(lzma_check_state *check);
#endif

View File

@@ -1,37 +0,0 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file check_init.c
/// \brief Static initializations for integrity checks
//
// This code has been put into the public domain.
//
// 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 "check.h"
extern LZMA_API void
lzma_init_check(void)
{
#ifdef HAVE_SMALL
static bool already_initialized = false;
if (already_initialized)
return;
# ifdef HAVE_CHECK_CRC32
lzma_crc32_init();
# endif
# ifdef HAVE_CHECK_CRC64
lzma_crc64_init();
# endif
already_initialized = true;
#endif
return;
}

View File

@@ -2,12 +2,17 @@
//
/// \file crc32.c
/// \brief CRC32 calculation
///
/// Calculate the CRC32 using the slice-by-eight algorithm.
/// It is explained in this document:
/// http://www.intel.com/technology/comms/perfnet/download/CRC_generators.pdf
/// The code in this file is not the same as in Intel's paper, but
/// the basic principle is identical.
//
// This code has been put into the public domain.
// Author: Lasse Collin
//
// 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 file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
@@ -18,7 +23,7 @@
// If you make any changes, do some bench marking! Seemingly unrelated
// changes can very easily ruin the performance (and very probably is
// very compiler dependent).
extern LZMA_API uint32_t
extern LZMA_API(uint32_t)
lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
{
crc = ~crc;
@@ -43,17 +48,6 @@ lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
size &= (size_t)(7);
// Calculate the CRC32 using the slice-by-eight algorithm.
// It is explained in this document:
// http://www.intel.com/technology/comms/perfnet/download/CRC_generators.pdf
//
// The code below is different than the code in Intel's
// paper, but the principle is identical. This should be
// faster with GCC than Intel's code. This is tested only
// with GCC 3.4.6 and 4.1.2 on x86, so your results may vary.
//
// Using -Os and -fomit-frame-pointer seem to give the best
// results at least with GCC 4.1.2 on x86. It's sill far
// from the speed of hand-optimized assembler.
while (buf < limit) {
crc ^= *(uint32_t *)(buf);
buf += 4;
@@ -66,9 +60,9 @@ lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
const uint32_t tmp = *(uint32_t *)(buf);
buf += 4;
// It is critical for performance, that
// the crc variable is XORed between the
// two table-lookup pairs.
// At least with some compilers, it is critical for
// performance, that the crc variable is XORed
// between the two table-lookup pairs.
crc = lzma_crc32_table[3][A(tmp)]
^ lzma_crc32_table[2][B(tmp)]
^ crc

View File

@@ -1,58 +0,0 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file crc32_init.c
/// \brief CRC32 table initialization
//
// This code is based on various public domain sources.
// This code has been put into the public domain.
//
// 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 HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#include <inttypes.h>
#ifdef WORDS_BIGENDIAN
# include "check_byteswap.h"
#endif
uint32_t lzma_crc32_table[8][256];
extern void
lzma_crc32_init(void)
{
static const uint32_t poly32 = UINT32_C(0xEDB88320);
for (size_t s = 0; s < 8; ++s) {
for (size_t b = 0; b < 256; ++b) {
uint32_t r = s == 0 ? b : lzma_crc32_table[s - 1][b];
for (size_t i = 0; i < 8; ++i) {
if (r & 1)
r = (r >> 1) ^ poly32;
else
r >>= 1;
}
lzma_crc32_table[s][b] = r;
}
}
#ifdef WORDS_BIGENDIAN
for (size_t s = 0; s < 8; ++s)
for (size_t b = 0; b < 256; ++b)
lzma_crc32_table[s][b]
= bswap_32(lzma_crc32_table[s][b]);
#endif
return;
}

View File

@@ -0,0 +1,61 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file crc32_small.c
/// \brief CRC32 calculation (size-optimized)
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "check.h"
uint32_t lzma_crc32_table[1][256];
static void
crc32_init(void)
{
static const uint32_t poly32 = UINT32_C(0xEDB88320);
for (size_t b = 0; b < 256; ++b) {
uint32_t r = b;
for (size_t i = 0; i < 8; ++i) {
if (r & 1)
r = (r >> 1) ^ poly32;
else
r >>= 1;
}
lzma_crc32_table[0][b] = r;
}
return;
}
extern void
lzma_crc32_init(void)
{
mythread_once(crc32_init);
return;
}
extern LZMA_API(uint32_t)
lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
{
lzma_crc32_init();
crc = ~crc;
while (size != 0) {
crc = lzma_crc32_table[0][*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
--size;
}
return ~crc;
}

View File

@@ -3,17 +3,14 @@
/// \file crc32_table.c
/// \brief Precalculated CRC32 table with correct endianness
//
// This code has been put into the public domain.
// Author: Lasse Collin
//
// 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 file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "common.h"
#ifdef WORDS_BIGENDIAN
# include "crc32_table_be.h"

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More