├── .gitignore
├── AUTHORS
├── CMakeLists.txt
├── COPYING
├── COPYING.GPLv2
├── COPYING.GPLv3
├── COPYING.LGPLv2.1
├── ChangeLog
├── Doxyfile.in
├── INSTALL
├── INSTALL.generic
├── Makefile.am
├── NEWS
├── PACKAGERS
├── README
├── THANKS
├── TODO
├── autogen.sh
├── build-aux
├── manconv.sh
└── version.sh
├── cmake
├── tuklib_common.cmake
├── tuklib_cpucores.cmake
├── tuklib_integer.cmake
├── tuklib_mbstr.cmake
├── tuklib_physmem.cmake
└── tuklib_progname.cmake
├── configure
├── configure.ac
├── debug
├── Makefile.am
├── README
├── crc32.c
├── full_flush.c
├── hex2bin.c
├── known_sizes.c
├── memusage.c
├── repeat.c
├── sync_flush.c
└── translation.bash
├── doc
├── examples
│ ├── 00_README.txt
│ ├── 01_compress_easy.c
│ ├── 02_decompress.c
│ ├── 03_compress_custom.c
│ ├── 04_compress_easy_mt.c
│ ├── 11_file_info.c
│ └── Makefile
├── examples_old
│ ├── xz_pipe_comp.c
│ └── xz_pipe_decomp.c
├── faq.txt
├── history.txt
├── lzma-file-format.txt
└── xz-file-format.txt
├── extra
├── 7z2lzma
│ └── 7z2lzma.bash
└── scanlzma
│ └── scanlzma.c
├── lib
├── Makefile.am
├── getopt.c
├── getopt.in.h
├── getopt1.c
└── getopt_int.h
├── m4
├── .gitignore
├── ax_check_capsicum.m4
├── ax_pthread.m4
├── getopt.m4
├── posix-shell.m4
├── tuklib_common.m4
├── tuklib_cpucores.m4
├── tuklib_integer.m4
├── tuklib_mbstr.m4
├── tuklib_physmem.m4
├── tuklib_progname.m4
└── visibility.m4
├── macosx
└── build.sh
├── po
├── .gitignore
├── LINGUAS
├── Makevars
├── POTFILES.in
├── cs.po
├── de.po
├── fr.po
├── it.po
├── pl.po
└── vi.po
├── src
├── Makefile.am
├── common
│ ├── atomic.h
│ ├── common_w32res.rc
│ ├── mythread.h
│ ├── sysdefs.h
│ ├── tuklib_common.h
│ ├── tuklib_config.h
│ ├── tuklib_cpucores.c
│ ├── tuklib_cpucores.h
│ ├── tuklib_exit.c
│ ├── tuklib_exit.h
│ ├── tuklib_gettext.h
│ ├── tuklib_integer.h
│ ├── tuklib_mbstr.h
│ ├── tuklib_mbstr_fw.c
│ ├── tuklib_mbstr_width.c
│ ├── tuklib_open_stdxxx.c
│ ├── tuklib_open_stdxxx.h
│ ├── tuklib_physmem.c
│ ├── tuklib_physmem.h
│ ├── tuklib_progname.c
│ └── tuklib_progname.h
├── liblzma
│ ├── Makefile.am
│ ├── api
│ │ ├── Makefile.am
│ │ ├── flzma.h
│ │ └── flzma
│ │ │ ├── base.h
│ │ │ ├── bcj.h
│ │ │ ├── block.h
│ │ │ ├── check.h
│ │ │ ├── container.h
│ │ │ ├── delta.h
│ │ │ ├── filter.h
│ │ │ ├── hardware.h
│ │ │ ├── index.h
│ │ │ ├── index_hash.h
│ │ │ ├── lzma12.h
│ │ │ ├── stream_flags.h
│ │ │ ├── version.h
│ │ │ └── vli.h
│ ├── check
│ │ ├── Makefile.inc
│ │ ├── check.c
│ │ ├── check.h
│ │ ├── crc32_fast.c
│ │ ├── crc32_small.c
│ │ ├── crc32_table.c
│ │ ├── crc32_table_be.h
│ │ ├── crc32_table_le.h
│ │ ├── crc32_tablegen.c
│ │ ├── crc32_x86.S
│ │ ├── crc64_fast.c
│ │ ├── crc64_small.c
│ │ ├── crc64_table.c
│ │ ├── crc64_table_be.h
│ │ ├── crc64_table_le.h
│ │ ├── crc64_tablegen.c
│ │ ├── crc64_x86.S
│ │ ├── crc_macros.h
│ │ └── sha256.c
│ ├── common
│ │ ├── Makefile.inc
│ │ ├── alone_decoder.c
│ │ ├── alone_decoder.h
│ │ ├── alone_encoder.c
│ │ ├── auto_decoder.c
│ │ ├── block_buffer_decoder.c
│ │ ├── block_buffer_encoder.c
│ │ ├── block_buffer_encoder.h
│ │ ├── block_decoder.c
│ │ ├── block_decoder.h
│ │ ├── block_encoder.c
│ │ ├── block_encoder.h
│ │ ├── block_header_decoder.c
│ │ ├── block_header_encoder.c
│ │ ├── block_util.c
│ │ ├── common.c
│ │ ├── common.h
│ │ ├── easy_buffer_encoder.c
│ │ ├── easy_decoder_memusage.c
│ │ ├── easy_encoder.c
│ │ ├── easy_encoder_memusage.c
│ │ ├── easy_preset.c
│ │ ├── easy_preset.h
│ │ ├── file_info.c
│ │ ├── filter_buffer_decoder.c
│ │ ├── filter_buffer_encoder.c
│ │ ├── filter_common.c
│ │ ├── filter_common.h
│ │ ├── filter_decoder.c
│ │ ├── filter_decoder.h
│ │ ├── filter_encoder.c
│ │ ├── filter_encoder.h
│ │ ├── filter_flags_decoder.c
│ │ ├── filter_flags_encoder.c
│ │ ├── hardware_cputhreads.c
│ │ ├── hardware_physmem.c
│ │ ├── index.c
│ │ ├── index.h
│ │ ├── index_decoder.c
│ │ ├── index_decoder.h
│ │ ├── index_encoder.c
│ │ ├── index_encoder.h
│ │ ├── index_hash.c
│ │ ├── memcmplen.h
│ │ ├── outqueue.c
│ │ ├── outqueue.h
│ │ ├── stream_buffer_decoder.c
│ │ ├── stream_buffer_encoder.c
│ │ ├── stream_decoder.c
│ │ ├── stream_decoder.h
│ │ ├── stream_encoder.c
│ │ ├── stream_encoder_mt.c
│ │ ├── stream_flags_common.c
│ │ ├── stream_flags_common.h
│ │ ├── stream_flags_decoder.c
│ │ ├── stream_flags_encoder.c
│ │ ├── vli_decoder.c
│ │ ├── vli_encoder.c
│ │ └── vli_size.c
│ ├── delta
│ │ ├── Makefile.inc
│ │ ├── delta_common.c
│ │ ├── delta_common.h
│ │ ├── delta_decoder.c
│ │ ├── delta_decoder.h
│ │ ├── delta_encoder.c
│ │ ├── delta_encoder.h
│ │ └── delta_private.h
│ ├── liblzma.map
│ ├── liblzma.pc.in
│ ├── liblzma_w32res.rc
│ ├── lz
│ │ ├── Makefile.inc
│ │ ├── lz_decoder.c
│ │ ├── lz_decoder.h
│ │ ├── lz_encoder.c
│ │ ├── lz_encoder.h
│ │ ├── lz_encoder_hash.h
│ │ ├── lz_encoder_hash_table.h
│ │ └── lz_encoder_mf.c
│ ├── lzma
│ │ ├── Makefile.inc
│ │ ├── data_block.h
│ │ ├── fastpos.h
│ │ ├── fastpos_table.c
│ │ ├── fastpos_tablegen.c
│ │ ├── lzma2_decoder.c
│ │ ├── lzma2_decoder.h
│ │ ├── lzma2_encoder.c
│ │ ├── lzma2_encoder.h
│ │ ├── lzma2_encoder_rmf.c
│ │ ├── lzma2_encoder_rmf.h
│ │ ├── lzma2_fast_encoder.c
│ │ ├── lzma2_fast_encoder.h
│ │ ├── lzma_common.h
│ │ ├── lzma_dec_x86_64.S
│ │ ├── lzma_decoder.c
│ │ ├── lzma_decoder.h
│ │ ├── lzma_encoder.c
│ │ ├── lzma_encoder.h
│ │ ├── lzma_encoder_optimum_fast.c
│ │ ├── lzma_encoder_optimum_normal.c
│ │ ├── lzma_encoder_presets.c
│ │ └── lzma_encoder_private.h
│ ├── radix
│ │ ├── Makefile.inc
│ │ ├── radix_bitpack.c
│ │ ├── radix_engine.h
│ │ ├── radix_get.h
│ │ ├── radix_internal.h
│ │ ├── radix_mf.c
│ │ ├── radix_mf.h
│ │ └── radix_struct.c
│ ├── rangecoder
│ │ ├── Makefile.inc
│ │ ├── price.h
│ │ ├── price_table.c
│ │ ├── price_tablegen.c
│ │ ├── range_common.h
│ │ ├── range_decoder.h
│ │ ├── range_encoder.h
│ │ ├── range_fast_enc.c
│ │ └── range_fast_enc.h
│ ├── simple
│ │ ├── Makefile.inc
│ │ ├── arm.c
│ │ ├── armthumb.c
│ │ ├── ia64.c
│ │ ├── powerpc.c
│ │ ├── simple_coder.c
│ │ ├── simple_coder.h
│ │ ├── simple_decoder.c
│ │ ├── simple_decoder.h
│ │ ├── simple_encoder.c
│ │ ├── simple_encoder.h
│ │ ├── simple_private.h
│ │ ├── sparc.c
│ │ └── x86.c
│ └── validate_map.sh
├── lzmainfo
│ ├── Makefile.am
│ ├── flzmainfo.1
│ ├── lzmainfo.c
│ └── lzmainfo_w32res.rc
├── scripts
│ ├── Makefile.am
│ ├── fxzdiff.1
│ ├── fxzdiff.in
│ ├── fxzgrep.1
│ ├── fxzgrep.in
│ ├── fxzless.1
│ ├── fxzless.in
│ ├── fxzmore.1
│ └── fxzmore.in
├── xz
│ ├── Makefile.am
│ ├── args.c
│ ├── args.h
│ ├── coder.c
│ ├── coder.h
│ ├── file_io.c
│ ├── file_io.h
│ ├── fxz.1
│ ├── hardware.c
│ ├── hardware.h
│ ├── list.c
│ ├── list.h
│ ├── main.c
│ ├── main.h
│ ├── message.c
│ ├── message.h
│ ├── mytime.c
│ ├── mytime.h
│ ├── options.c
│ ├── options.h
│ ├── private.h
│ ├── signals.c
│ ├── signals.h
│ ├── suffix.c
│ ├── suffix.h
│ ├── util.c
│ ├── util.h
│ └── xz_w32res.rc
└── xzdec
│ ├── Makefile.am
│ ├── fxzdec.1
│ ├── lzmadec_w32res.rc
│ ├── xzdec.c
│ └── xzdec_w32res.rc
├── tests
├── Makefile.am
├── bcj_test.c
├── compress_prepared_bcj_sparc
├── compress_prepared_bcj_x86
├── create_compress_files.c
├── files
│ ├── README
│ ├── bad-0-backward_size.xz
│ ├── bad-0-empty-truncated.xz
│ ├── bad-0-footer_magic.xz
│ ├── bad-0-header_magic.xz
│ ├── bad-0-nonempty_index.xz
│ ├── bad-0cat-alone.xz
│ ├── bad-0cat-header_magic.xz
│ ├── bad-0catpad-empty.xz
│ ├── bad-0pad-empty.xz
│ ├── bad-1-block_header-1.xz
│ ├── bad-1-block_header-2.xz
│ ├── bad-1-block_header-3.xz
│ ├── bad-1-block_header-4.xz
│ ├── bad-1-block_header-5.xz
│ ├── bad-1-block_header-6.xz
│ ├── bad-1-check-crc32-2.xz
│ ├── bad-1-check-crc32.xz
│ ├── bad-1-check-crc64.xz
│ ├── bad-1-check-sha256.xz
│ ├── bad-1-lzma2-1.xz
│ ├── bad-1-lzma2-10.xz
│ ├── bad-1-lzma2-2.xz
│ ├── bad-1-lzma2-3.xz
│ ├── bad-1-lzma2-4.xz
│ ├── bad-1-lzma2-5.xz
│ ├── bad-1-lzma2-6.xz
│ ├── bad-1-lzma2-7.xz
│ ├── bad-1-lzma2-8.xz
│ ├── bad-1-lzma2-9.xz
│ ├── bad-1-stream_flags-1.xz
│ ├── bad-1-stream_flags-2.xz
│ ├── bad-1-stream_flags-3.xz
│ ├── bad-1-vli-1.xz
│ ├── bad-1-vli-2.xz
│ ├── bad-2-compressed_data_padding.xz
│ ├── bad-2-index-1.xz
│ ├── bad-2-index-2.xz
│ ├── bad-2-index-3.xz
│ ├── bad-2-index-4.xz
│ ├── bad-2-index-5.xz
│ ├── good-0-empty.xz
│ ├── good-0cat-empty.xz
│ ├── good-0catpad-empty.xz
│ ├── good-0pad-empty.xz
│ ├── good-1-3delta-lzma2.xz
│ ├── good-1-block_header-1.xz
│ ├── good-1-block_header-2.xz
│ ├── good-1-block_header-3.xz
│ ├── good-1-check-crc32.xz
│ ├── good-1-check-crc64.xz
│ ├── good-1-check-none.xz
│ ├── good-1-check-sha256.xz
│ ├── good-1-delta-lzma2.tiff.xz
│ ├── good-1-lzma2-1.xz
│ ├── good-1-lzma2-2.xz
│ ├── good-1-lzma2-3.xz
│ ├── good-1-lzma2-4.xz
│ ├── good-1-lzma2-5.xz
│ ├── good-1-sparc-lzma2.xz
│ ├── good-1-x86-lzma2.xz
│ ├── good-2-lzma2.xz
│ ├── unsupported-block_header.xz
│ ├── unsupported-check.xz
│ ├── unsupported-filter_flags-1.xz
│ ├── unsupported-filter_flags-2.xz
│ └── unsupported-filter_flags-3.xz
├── ossfuzz
│ ├── Makefile
│ ├── config
│ │ ├── fuzz.dict
│ │ └── fuzz.options
│ └── fuzz.c
├── test_bcj_exact_size.c
├── test_block_header.c
├── test_check.c
├── test_compress.sh
├── test_files.sh
├── test_filter_flags.c
├── test_index.c
├── test_scripts.sh
├── test_stream_flags.c
├── tests.h
└── xzgrep_expected_output
└── windows
├── INSTALL-MSVC.txt
├── INSTALL-MinGW.txt
├── README-Windows.txt
├── build.bash
├── vs2013
├── config.h
├── liblzma.vcxproj
├── liblzma_dll.vcxproj
└── xz_win.sln
├── vs2017
├── config.h
├── liblzma.vcxproj
├── liblzma_dll.vcxproj
└── xz_win.sln
└── vs2019
├── config.h
├── liblzma.vcxproj
├── liblzma_dll.vcxproj
└── xz_win.sln
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | *.bak
3 | *.bak[0-9]
4 | .gdb_history
5 |
6 | .deps
7 | .libs
8 | *.la
9 | *.lo
10 | *.o
11 | Makefile.in
12 |
13 | /ABOUT-NLS
14 | /autom4te.cache
15 | /Doxyfile
16 | /aclocal.m4
17 | /config.h
18 | /config.h.in
19 | /config.log
20 | /config.status
21 | /libtool
22 | /stamp-h1
23 |
24 | build-aux/compile
25 | build-aux/config.guess
26 | build-aux/config.rpath
27 | build-aux/config.sub
28 | build-aux/depcomp
29 | build-aux/install-sh
30 | build-aux/ltmain.sh
31 | build-aux/missing
32 | build-aux/test-driver
33 |
34 | /src/liblzma/liblzma.pc
35 | /src/lzmainfo/lzmainfo
36 | /src/xz/xz
37 | /src/xzdec/lzmadec
38 | /src/xzdec/xzdec
39 |
40 | /src/scripts/xzdiff
41 | /src/scripts/xzgrep
42 | /src/scripts/xzless
43 | /src/scripts/xzmore
44 |
45 | /tests/compress_generated_abc
46 | /tests/compress_generated_random
47 | /tests/compress_generated_text
48 | /tests/create_compress_files
49 | /tests/test_bcj_exact_size
50 | /tests/test_block_header
51 | /tests/test_check
52 | /tests/test_filter_flags
53 | /tests/test_index
54 | /tests/test_stream_flags
55 | /tests/xzgrep_test_1.xz
56 | /tests/xzgrep_test_2.xz
57 | /tests/xzgrep_test_output
58 |
59 | /lib/Makefile
60 | /tests/Makefile
61 | /Makefile
62 | /debug/Makefile
63 | /src/scripts/Makefile
64 | /src/xz/Makefile
65 | /src/Makefile
66 | /src/liblzma/Makefile
67 | /src/liblzma/api/Makefile
68 | /src/lzmainfo/Makefile
69 | /src/xzdec/Makefile
70 |
71 | *.suo
72 | *.VC.*
73 | *.db
74 | *.opendb
75 | *.ipch
76 | *.obj
77 | *.dll
78 | *.exp
79 | *.tlog
80 | *.ilk
81 | *.lib
82 | *.pdb
83 | *.log
84 | *.res
85 | *.user
86 | *.filters
87 | *.exe
88 | *.iobj
89 | *.ipdb
90 |
--------------------------------------------------------------------------------
/AUTHORS:
--------------------------------------------------------------------------------
1 |
2 | Authors of FXZ Utils
3 | ===================
4 |
5 | FXZ Utils is a fork of the XZ Utils project by Lasse Collin
6 |
7 |
8 | FXZ Utils and the Fast LZMA2 Library are developed and maintained by
9 | Conor McCarthy .
10 |
11 | Major parts of liblzma and and the Fast LZMA2 Library are based on
12 | code written by Igor Pavlov, specifically the LZMA SDK
13 | . Without this code, FXZ Utils and Fast
14 | LZMA2 wouldn't exist.
15 |
16 | Some parts of the Fast LZMA2 Library use code written by Yann Collet
17 | and Tino Reichardt for ZStandard.
18 |
19 | The SHA-256 implementation in liblzma is based on the code found from
20 | 7-Zip , which has a modified version of the SHA-256
21 | code found from Crypto++ . The SHA-256 code
22 | in Crypto++ was written by Kevin Springle and Wei Dai.
23 |
24 | Some scripts have been adapted from gzip. The original versions
25 | were written by Jean-loup Gailly, Charles Levert, and Paul Eggert.
26 | Andrew Dudman helped adapting the scripts and their man pages for
27 | XZ Utils.
28 |
29 | The GNU Autotools-based build system contains files from many authors,
30 | which I'm not trying to list here.
31 |
32 | Several people have contributed fixes or reported bugs. Most of them
33 | are mentioned in the file THANKS.
34 |
35 |
--------------------------------------------------------------------------------
/ChangeLog:
--------------------------------------------------------------------------------
1 | See the commit log in the git repository:
2 |
3 | git clone https://github.com/conor42/fxz
4 |
5 | Note that "make dist" doesn't put this tiny file into the package.
6 | Instead, the git commit log is used as ChangeLog. See dist-hook in
7 | Makefile.am for details.
8 |
--------------------------------------------------------------------------------
/autogen.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | ###############################################################################
4 | #
5 | # Author: Lasse Collin
6 | #
7 | # This file has been put into the public domain.
8 | # You can do whatever you want with this file.
9 | #
10 | ###############################################################################
11 |
12 | # The result of using "autoreconf -fi" should be identical to using this
13 | # script. I'm leaving this script here just in case someone finds it useful.
14 |
15 | set -e -x
16 |
17 | ${AUTOPOINT:-autopoint} -f
18 | ${LIBTOOLIZE:-libtoolize} -c -f || glibtoolize -c -f
19 | ${ACLOCAL:-aclocal} -I m4
20 | ${AUTOCONF:-autoconf}
21 | ${AUTOHEADER:-autoheader}
22 | ${AUTOMAKE:-automake} -acf --foreign
23 |
--------------------------------------------------------------------------------
/build-aux/manconv.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | ###############################################################################
4 | #
5 | # Wrapper for GNU groff to convert man pages to a few formats
6 | #
7 | # Usage: manconv.sh FORMAT [PAPER_SIZE] < in.1 > out.suffix
8 | #
9 | # FORMAT can be ascii, utf8, ps, or pdf. PAPER_SIZE can be anything that
10 | # groff accepts, e.g. a4 or letter. See groff_font(5). PAPER_SIZE defaults
11 | # to a4 and is used only when FORMAT is ps (PostScript) or pdf.
12 | #
13 | # Multiple man pages can be given at once e.g. to create a single PDF file
14 | # with continuous page numbering.
15 | #
16 | ###############################################################################
17 | #
18 | # Author: Lasse Collin
19 | #
20 | # This file has been put into the public domain.
21 | # You can do whatever you want with this file.
22 | #
23 | ###############################################################################
24 |
25 | FORMAT=$1
26 | PAPER=${2-a4}
27 |
28 | # Make PostScript and PDF output more readable:
29 | # - Use 11 pt font instead of the default 10 pt.
30 | # - Use larger paragraph spacing than the default 0.4v (man(7) only).
31 | FONT=11
32 | PD=0.8
33 |
34 | SED_PD="
35 | /^\\.TH /s/\$/\\
36 | .PD $PD/
37 | s/^\\.PD\$/.PD $PD/"
38 |
39 | case $FORMAT in
40 | ascii)
41 | groff -t -mandoc -Tascii | col -bx
42 | ;;
43 | utf8)
44 | groff -t -mandoc -Tutf8 | col -bx
45 | ;;
46 | ps)
47 | sed "$SED_PD" | groff -dpaper=$PAPER -t -mandoc \
48 | -rC1 -rS$FONT -Tps -P-p$PAPER
49 | ;;
50 | pdf)
51 | sed "$SED_PD" | groff -dpaper=$PAPER -t -mandoc \
52 | -rC1 -rS$FONT -Tps -P-p$PAPER | ps2pdf - -
53 | ;;
54 | *)
55 | echo 'Invalid arguments' >&2
56 | exit 1
57 | ;;
58 | esac
59 |
--------------------------------------------------------------------------------
/build-aux/version.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | #############################################################################
4 | #
5 | # Get the version string from version.h and print it out without
6 | # trailing newline. This makes it suitable for use in configure.ac.
7 | #
8 | #############################################################################
9 | #
10 | # Author: Lasse Collin
11 | #
12 | # This file has been put into the public domain.
13 | # You can do whatever you want with this file.
14 | #
15 | #############################################################################
16 |
17 | sed -n 's/LZMA_VERSION_STABILITY_ALPHA/alpha/
18 | s/LZMA_VERSION_STABILITY_BETA/beta/
19 | s/LZMA_VERSION_STABILITY_STABLE//
20 | s/^#define LZMA_VERSION_[MPS][AIT][AJNT][A-Z]* //p' \
21 | src/liblzma/api/flzma/version.h \
22 | | tr '\n' '|' \
23 | | sed 's/|/./; s/|/./; s/|//g' \
24 | | tr -d '\r\n'
25 |
--------------------------------------------------------------------------------
/cmake/tuklib_common.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # tuklib_common.cmake - common functions and macros for tuklib_*.cmake files
3 | #
4 | # Author: Lasse Collin
5 | #
6 | # This file has been put into the public domain.
7 | # You can do whatever you want with this file.
8 | #
9 |
10 | function(tuklib_add_definitions TARGET_OR_ALL DEFINITIONS)
11 | # DEFINITIONS may be an empty string/list but it's fine here. There is
12 | # no need to quote ${DEFINITIONS} as empty arguments are fine here.
13 | if(TARGET_OR_ALL STREQUAL "ALL")
14 | add_compile_definitions(${DEFINITIONS})
15 | else()
16 | target_compile_definitions("${TARGET_OR_ALL}" PRIVATE ${DEFINITIONS})
17 | endif()
18 | endfunction()
19 |
20 | function(tuklib_add_definition_if TARGET_OR_ALL VAR)
21 | if(${VAR})
22 | tuklib_add_definitions("${TARGET_OR_ALL}" "${VAR}")
23 | endif()
24 | endfunction()
25 |
26 | # This is an over-simplified version of AC_USE_SYSTEM_EXTENSIONS in Autoconf
27 | # or gl_USE_SYSTEM_EXTENSIONS in gnulib.
28 | macro(tuklib_use_system_extensions TARGET_OR_ALL)
29 | if(NOT WIN32)
30 | # FIXME? The Solaris-specific __EXTENSIONS__ should be conditional
31 | # even on Solaris. See gnulib: git log m4/extensions.m4.
32 | # FIXME? gnulib and autoconf.git has lots of new stuff.
33 | tuklib_add_definitions("${TARGET_OR_ALL}"
34 | _GNU_SOURCE
35 | __EXTENSIONS__
36 | _POSIX_PTHREAD_SEMANTICS
37 | _TANDEM_SOURCE
38 | _ALL_SOURCE
39 | )
40 |
41 | list(APPEND CMAKE_REQUIRED_DEFINITIONS
42 | -D_GNU_SOURCE
43 | -D__EXTENSIONS__
44 | -D_POSIX_PTHREAD_SEMANTICS
45 | -D_TANDEM_SOURCE
46 | -D_ALL_SOURCE
47 | )
48 | endif()
49 | endmacro()
50 |
--------------------------------------------------------------------------------
/cmake/tuklib_mbstr.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # tuklib_mbstr.cmake - see tuklib_mbstr.m4 for description and comments
3 | #
4 | # Author: Lasse Collin
5 | #
6 | # This file has been put into the public domain.
7 | # You can do whatever you want with this file.
8 | #
9 |
10 | include("${CMAKE_CURRENT_LIST_DIR}/tuklib_common.cmake")
11 | include(CheckSymbolExists)
12 |
13 | function(tuklib_mbstr TARGET_OR_ALL)
14 | check_symbol_exists(mbrtowc wchar.h HAVE_MBRTOWC)
15 | tuklib_add_definition_if("${TARGET_OR_ALL}" HAVE_MBRTOWC)
16 |
17 | # NOTE: wcwidth() requires _GNU_SOURCE or _XOPEN_SOURCE on GNU/Linux.
18 | check_symbol_exists(wcwidth wchar.h HAVE_WCWIDTH)
19 | tuklib_add_definition_if("${TARGET_OR_ALL}" HAVE_WCWIDTH)
20 | endfunction()
21 |
--------------------------------------------------------------------------------
/cmake/tuklib_progname.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # tuklib_progname.cmake - see tuklib_progname.m4 for description and comments
3 | #
4 | # Author: Lasse Collin
5 | #
6 | # This file has been put into the public domain.
7 | # You can do whatever you want with this file.
8 | #
9 |
10 | include("${CMAKE_CURRENT_LIST_DIR}/tuklib_common.cmake")
11 | include(CheckSymbolExists)
12 |
13 | function(tuklib_progname TARGET_OR_ALL)
14 | # NOTE: This glibc extension requires _GNU_SOURCE.
15 | check_symbol_exists(program_invocation_name errno.h
16 | HAVE_DECL_PROGRAM_INVOCATION_NAME)
17 | tuklib_add_definition_if("${TARGET_OR_ALL}"
18 | HAVE_DECL_PROGRAM_INVOCATION_NAME)
19 | endfunction()
20 |
--------------------------------------------------------------------------------
/debug/Makefile.am:
--------------------------------------------------------------------------------
1 | ##
2 | ## Author: Lasse Collin
3 | ##
4 | ## This file has been put into the public domain.
5 | ## You can do whatever you want with this file.
6 | ##
7 |
8 | EXTRA_DIST = \
9 | translation.bash
10 |
11 | noinst_PROGRAMS = \
12 | repeat \
13 | sync_flush \
14 | full_flush \
15 | memusage \
16 | crc32 \
17 | known_sizes \
18 | hex2bin
19 |
20 | AM_CPPFLAGS = \
21 | -I$(top_srcdir)/src/common \
22 | -I$(top_srcdir)/src/liblzma/api
23 |
24 | LDADD = $(top_builddir)/src/liblzma/libflzma.la
25 |
26 | if COND_GNULIB
27 | LDADD += $(top_builddir)/lib/libgnu.a
28 | endif
29 |
30 | LDADD += $(LTLIBINTL)
31 |
--------------------------------------------------------------------------------
/debug/README:
--------------------------------------------------------------------------------
1 |
2 | Debug tools
3 | -----------
4 |
5 | This directory contains a few tiny programs that may be helpful when
6 | debugging XZ Utils.
7 |
8 | These tools are not meant to be installed. Often one needs to edit
9 | the source code a little to make the programs do the wanted things.
10 | If you don't know how these programs could help you, it is likely
11 | that they really are useless to you.
12 |
13 | These aren't intended to be used as example programs. They take some
14 | shortcuts here and there, which correct programs should not do. Many
15 | possible errors (especially I/O errors) are ignored. Don't report
16 | bugs or send patches to fix this kind of bugs.
17 |
18 |
--------------------------------------------------------------------------------
/debug/crc32.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file crc32.c
4 | /// \brief Primitive CRC32 calculation tool
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "sysdefs.h"
14 | #include "flzma.h"
15 | #include
16 |
17 |
18 | int
19 | main(void)
20 | {
21 | uint32_t crc = 0;
22 |
23 | do {
24 | uint8_t buf[BUFSIZ];
25 | const size_t size = fread(buf, 1, sizeof(buf), stdin);
26 | crc = lzma_crc32(buf, size, crc);
27 | } while (!ferror(stdin) && !feof(stdin));
28 |
29 | //printf("%08" PRIX32 "\n", crc);
30 |
31 | // I want it little endian so it's easy to work with hex editor.
32 | printf("%02" PRIX32 " ", crc & 0xFF);
33 | printf("%02" PRIX32 " ", (crc >> 8) & 0xFF);
34 | printf("%02" PRIX32 " ", (crc >> 16) & 0xFF);
35 | printf("%02" PRIX32 " ", crc >> 24);
36 | printf("\n");
37 |
38 | return 0;
39 | }
40 |
--------------------------------------------------------------------------------
/debug/hex2bin.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file hex2bin.c
4 | /// \brief Converts hexadecimal input strings to binary
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "sysdefs.h"
14 | #include
15 | #include
16 |
17 |
18 | static int
19 | getbin(int x)
20 | {
21 | if (x >= '0' && x <= '9')
22 | return x - '0';
23 |
24 | if (x >= 'A' && x <= 'F')
25 | return x - 'A' + 10;
26 |
27 | return x - 'a' + 10;
28 | }
29 |
30 |
31 | int
32 | main(void)
33 | {
34 | while (true) {
35 | int byte = getchar();
36 | if (byte == EOF)
37 | return 0;
38 | if (!isxdigit(byte))
39 | continue;
40 |
41 | const int digit = getchar();
42 | if (digit == EOF || !isxdigit(digit)) {
43 | fprintf(stderr, "Invalid input\n");
44 | return 1;
45 | }
46 |
47 | byte = (getbin(byte) << 4) | getbin(digit);
48 | if (putchar(byte) == EOF) {
49 | perror(NULL);
50 | return 1;
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/debug/memusage.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file memusage.c
4 | /// \brief Calculates memory usage using lzma_memory_usage()
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "sysdefs.h"
14 | #include "flzma.h"
15 | #include
16 |
17 | int
18 | main(void)
19 | {
20 | lzma_options_lzma lzma = {
21 | .dict_size = (1U << 30) + (1U << 29),
22 | .lc = 3,
23 | .lp = 0,
24 | .pb = 2,
25 | .preset_dict = NULL,
26 | .preset_dict_size = 0,
27 | .mode = LZMA_MODE_NORMAL,
28 | .nice_len = 48,
29 | .mf = LZMA_MF_BT4,
30 | .depth = 0,
31 | };
32 |
33 | /*
34 | lzma_options_filter filters[] = {
35 | { LZMA_FILTER_LZMA1,
36 | (lzma_options_lzma *)&lzma_preset_lzma[6 - 1] },
37 | { UINT64_MAX, NULL }
38 | };
39 | */
40 | lzma_filter filters[] = {
41 | { LZMA_FILTER_LZMA1, &lzma },
42 | { UINT64_MAX, NULL }
43 | };
44 |
45 | printf("Encoder: %10" PRIu64 " B\n",
46 | lzma_raw_encoder_memusage(filters));
47 | printf("Decoder: %10" PRIu64 " B\n",
48 | lzma_raw_decoder_memusage(filters));
49 |
50 | return 0;
51 | }
52 |
--------------------------------------------------------------------------------
/debug/repeat.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file repeat.c
4 | /// \brief Repeats given string given times
5 | ///
6 | /// This program can be useful when debugging run-length encoder in
7 | /// the Subblock filter, especially the condition when repeat count
8 | /// doesn't fit into 28-bit integer.
9 | //
10 | // Author: Lasse Collin
11 | //
12 | // This file has been put into the public domain.
13 | // You can do whatever you want with this file.
14 | //
15 | ///////////////////////////////////////////////////////////////////////////////
16 |
17 | #include "sysdefs.h"
18 | #include
19 |
20 |
21 | int
22 | main(int argc, char **argv)
23 | {
24 | if (argc != 3) {
25 | fprintf(stderr, "Usage: %s COUNT STRING\n", argv[0]);
26 | exit(1);
27 | }
28 |
29 | unsigned long long count = strtoull(argv[1], NULL, 10);
30 | const size_t size = strlen(argv[2]);
31 |
32 | while (count-- != 0)
33 | fwrite(argv[2], 1, size, stdout);
34 |
35 | return !!(ferror(stdout) || fclose(stdout));
36 | }
37 |
--------------------------------------------------------------------------------
/doc/examples/00_README.txt:
--------------------------------------------------------------------------------
1 |
2 | liblzma example programs
3 | ========================
4 |
5 | Introduction
6 |
7 | The examples are written so that the same comments aren't
8 | repeated (much) in later files.
9 |
10 | On POSIX systems, the examples should build by just typing "make".
11 |
12 | The examples that use stdin or stdout don't set stdin and stdout
13 | to binary mode. On systems where it matters (e.g. Windows) it is
14 | possible that the examples won't work without modification.
15 |
16 |
17 | List of examples
18 |
19 | 01_compress_easy.c Multi-call compression using
20 | a compression preset
21 |
22 | 02_decompress.c Multi-call decompression
23 |
24 | 03_compress_custom.c Like 01_compress_easy.c but using
25 | a custom filter chain
26 | (x86 BCJ + LZMA2)
27 |
28 | 04_compress_easy_mt.c Multi-threaded multi-call
29 | compression using a compression
30 | preset
31 |
32 |
--------------------------------------------------------------------------------
/doc/examples/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Author: Lasse Collin
3 | #
4 | # This file has been put into the public domain.
5 | # You can do whatever you want with this file.
6 | #
7 |
8 | CC = c99
9 | CFLAGS = -g
10 | LDFLAGS = -lflzma
11 |
12 | PROGS = \
13 | 01_compress_easy \
14 | 02_decompress \
15 | 03_compress_custom \
16 | 04_compress_easy_mt \
17 | 11_file_info
18 |
19 | all: $(PROGS)
20 |
21 | .c:
22 | $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
23 |
24 | clean:
25 | -rm -f $(PROGS)
26 |
--------------------------------------------------------------------------------
/lib/Makefile.am:
--------------------------------------------------------------------------------
1 | ##
2 | ## Copyright (C) 2004-2007 Free Software Foundation, Inc.
3 | ##
4 | ## This program is free software; you can redistribute it and/or modify
5 | ## it under the terms of the GNU General Public License as published by
6 | ## the Free Software Foundation; either version 2 of the License, or
7 | ## (at your option) any later version.
8 | ##
9 | ## This program is distributed in the hope that it will be useful,
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | ## GNU General Public License for more details.
13 | ##
14 |
15 | ## Not using gnulib-tool, at least for now. It is likely that we won't
16 | ## need anything else from Gnulib than getopt_long().
17 |
18 | noinst_LIBRARIES = libgnu.a
19 |
20 | libgnu_a_SOURCES =
21 | libgnu_a_DEPENDENCIES = $(LIBOBJS)
22 | libgnu_a_LIBADD = $(LIBOBJS)
23 |
24 | EXTRA_DIST = getopt.in.h getopt.c getopt1.c getopt_int.h
25 | BUILT_SOURCES = $(GETOPT_H)
26 | MOSTLYCLEANFILES = getopt.h getopt.h-t
27 |
28 | getopt.h: getopt.in.h
29 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
30 | cat $(srcdir)/getopt.in.h; \
31 | } > $@-t
32 | mv -f $@-t $@
33 |
--------------------------------------------------------------------------------
/m4/.gitignore:
--------------------------------------------------------------------------------
1 | codeset.m4
2 | extern-inline.m4
3 | fcntl-o.m4
4 | gettext.m4
5 | glibc2.m4
6 | glibc21.m4
7 | host-cpu-c-abi.m4
8 | iconv.m4
9 | intdiv0.m4
10 | intl.m4
11 | intldir.m4
12 | intlmacosx.m4
13 | intmax.m4
14 | inttypes-pri.m4
15 | inttypes_h.m4
16 | lcmessage.m4
17 | lib-ld.m4
18 | lib-link.m4
19 | lib-prefix.m4
20 | libtool.m4
21 | lock.m4
22 | longdouble.m4
23 | longlong.m4
24 | ltoptions.m4
25 | ltsugar.m4
26 | ltversion.m4
27 | lt~obsolete.m4
28 | nls.m4
29 | po.m4
30 | printf-posix.m4
31 | progtest.m4
32 | size_max.m4
33 | stdint_h.m4
34 | threadlib.m4
35 | uintmax_t.m4
36 | ulonglong.m4
37 | wchar_t.m4
38 | wint_t.m4
39 | xsize.m4
40 |
--------------------------------------------------------------------------------
/m4/posix-shell.m4:
--------------------------------------------------------------------------------
1 | # Find a POSIX-conforming shell.
2 |
3 | # Copyright (C) 2007-2008 Free Software Foundation, Inc.
4 |
5 | # This file is free software; the Free Software Foundation
6 | # gives unlimited permission to copy and/or distribute it,
7 | # with or without modifications, as long as this notice is preserved.
8 |
9 | # Written by Paul Eggert.
10 |
11 | # If a POSIX-conforming shell can be found, set POSIX_SHELL and
12 | # PREFERABLY_POSIX_SHELL to it. If not, set POSIX_SHELL to the
13 | # empty string and PREFERABLY_POSIX_SHELL to '/bin/sh'.
14 |
15 | AC_DEFUN([gl_POSIX_SHELL],
16 | [
17 | AC_CACHE_CHECK([for a shell that conforms to POSIX], [gl_cv_posix_shell],
18 | [gl_test_posix_shell_script='
19 | func_return () {
20 | (exit [$]1)
21 | }
22 | func_success () {
23 | func_return 0
24 | }
25 | func_failure () {
26 | func_return 1
27 | }
28 | func_ret_success () {
29 | return 0
30 | }
31 | func_ret_failure () {
32 | return 1
33 | }
34 | subshell_umask_sanity () {
35 | (umask 22; (umask 0); test $(umask) -eq 22)
36 | }
37 | test "[$](echo foo)" = foo &&
38 | func_success &&
39 | ! func_failure &&
40 | func_ret_success &&
41 | ! func_ret_failure &&
42 | (set x && func_ret_success y && test x = "[$]1") &&
43 | subshell_umask_sanity
44 | '
45 | for gl_cv_posix_shell in \
46 | "$CONFIG_SHELL" "$SHELL" /bin/sh /bin/bash /bin/ksh /bin/sh5 no; do
47 | case $gl_cv_posix_shell in
48 | /*)
49 | "$gl_cv_posix_shell" -c "$gl_test_posix_shell_script" 2>/dev/null \
50 | && break;;
51 | esac
52 | done])
53 |
54 | if test "$gl_cv_posix_shell" != no; then
55 | POSIX_SHELL=$gl_cv_posix_shell
56 | PREFERABLY_POSIX_SHELL=$POSIX_SHELL
57 | else
58 | POSIX_SHELL=
59 | PREFERABLY_POSIX_SHELL=/bin/sh
60 | fi
61 | AC_SUBST([POSIX_SHELL])
62 | AC_SUBST([PREFERABLY_POSIX_SHELL])
63 | ])
64 |
--------------------------------------------------------------------------------
/m4/tuklib_common.m4:
--------------------------------------------------------------------------------
1 | #
2 | # SYNOPSIS
3 | #
4 | # TUKLIB_COMMON
5 | #
6 | # DESCRIPTION
7 | #
8 | # Common checks for tuklib.
9 | #
10 | # COPYING
11 | #
12 | # Author: Lasse Collin
13 | #
14 | # This file has been put into the public domain.
15 | # You can do whatever you want with this file.
16 | #
17 |
18 | AC_DEFUN_ONCE([TUKLIB_COMMON], [
19 | AC_REQUIRE([AC_CANONICAL_HOST])
20 | AC_REQUIRE([AC_PROG_CC_C99])
21 | AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
22 | ])dnl
23 |
--------------------------------------------------------------------------------
/m4/tuklib_mbstr.m4:
--------------------------------------------------------------------------------
1 | #
2 | # SYNOPSIS
3 | #
4 | # TUKLIB_MBSTR
5 | #
6 | # DESCRIPTION
7 | #
8 | # Check if multibyte and wide character functionality is available
9 | # for use by tuklib_mbstr_* functions. If not enough multibyte string
10 | # support is available in the C library, the functions keep working
11 | # with the assumption that all strings are a in single-byte character
12 | # set without combining characters, e.g. US-ASCII or ISO-8859-*.
13 | #
14 | # This .m4 file and tuklib_mbstr.h are common to all tuklib_mbstr_*
15 | # functions, but each function is put into a separate .c file so
16 | # that it is possible to pick only what is strictly needed.
17 | #
18 | # COPYING
19 | #
20 | # Author: Lasse Collin
21 | #
22 | # This file has been put into the public domain.
23 | # You can do whatever you want with this file.
24 | #
25 |
26 | AC_DEFUN_ONCE([TUKLIB_MBSTR], [
27 | AC_REQUIRE([TUKLIB_COMMON])
28 | AC_FUNC_MBRTOWC
29 | AC_CHECK_FUNCS([wcwidth])
30 | ])dnl
31 |
--------------------------------------------------------------------------------
/m4/tuklib_progname.m4:
--------------------------------------------------------------------------------
1 | #
2 | # SYNOPSIS
3 | #
4 | # TUKLIB_PROGNAME
5 | #
6 | # DESCRIPTION
7 | #
8 | # Put argv[0] into a global variable progname. On DOS-like systems,
9 | # modify it so that it looks nice (no full path or .exe suffix).
10 | #
11 | # This .m4 file is needed allow this module to use glibc's
12 | # program_invocation_name.
13 | #
14 | # COPYING
15 | #
16 | # Author: Lasse Collin
17 | #
18 | # This file has been put into the public domain.
19 | # You can do whatever you want with this file.
20 | #
21 |
22 | AC_DEFUN_ONCE([TUKLIB_PROGNAME], [
23 | AC_REQUIRE([TUKLIB_COMMON])
24 | AC_CHECK_DECLS([program_invocation_name], [], [], [#include ])
25 | ])dnl
26 |
--------------------------------------------------------------------------------
/po/.gitignore:
--------------------------------------------------------------------------------
1 | # autopoint
2 | Makefile.in.in
3 | Makevars.template
4 | Rules-quot
5 | boldquot.sed
6 | en@boldquot.header
7 | en@quot.header
8 | insert-header.sin
9 | quot.sed
10 | remove-potcdate.sin
11 |
12 | # configure
13 | Makefile.in
14 | Makefile
15 | POTFILES
16 |
17 | # intermediate files (make)
18 | stamp-poT
19 | xz.po
20 | xz.1po
21 | xz.2po
22 | *.new.po
23 |
24 | # make
25 | remove-potcdate.sed
26 | xz.mo
27 | stamp-po
28 | *.gmo
29 |
30 | # cached templates (make)
31 | xz.pot
32 |
--------------------------------------------------------------------------------
/po/LINGUAS:
--------------------------------------------------------------------------------
1 | cs
2 | de
3 | fr
4 | it
5 | pl
6 | vi
7 |
--------------------------------------------------------------------------------
/po/Makevars:
--------------------------------------------------------------------------------
1 | # Makefile variables for PO directory in any package using GNU gettext.
2 |
3 | # Usually the message domain is the same as the package name.
4 | DOMAIN = $(PACKAGE)
5 |
6 | # These two variables depend on the location of this directory.
7 | subdir = po
8 | top_builddir = ..
9 |
10 | # These options get passed to xgettext.
11 | XGETTEXT_OPTIONS = --keyword=_ --keyword=N_
12 |
13 | # This is the copyright holder that gets inserted into the header of the
14 | # $(DOMAIN).pot file. Set this to the copyright holder of the surrounding
15 | # package. (Note that the msgstr strings, extracted from the package's
16 | # sources, belong to the copyright holder of the package.) Translators are
17 | # expected to transfer the copyright for their translations to this person
18 | # or entity, or to disclaim their copyright. The empty string stands for
19 | # the public domain; in this case the translators are expected to disclaim
20 | # their copyright.
21 | COPYRIGHT_HOLDER =
22 |
23 | # This is the email address or URL to which the translators shall report
24 | # bugs in the untranslated strings:
25 | # - Strings which are not entire sentences, see the maintainer guidelines
26 | # in the GNU gettext documentation, section 'Preparing Strings'.
27 | # - Strings which use unclear terms or require additional context to be
28 | # understood.
29 | # - Strings which make invalid assumptions about notation of date, time or
30 | # money.
31 | # - Pluralisation problems.
32 | # - Incorrect English spelling.
33 | # - Incorrect formatting.
34 | # It can be your email address, or a mailing list address where translators
35 | # can write to without being subscribed, or the URL of a web page through
36 | # which the translators can contact you.
37 | MSGID_BUGS_ADDRESS =
38 |
39 | # This is the list of locale categories, beyond LC_MESSAGES, for which the
40 | # message catalogs shall be used. It is usually empty.
41 | EXTRA_LOCALE_CATEGORIES =
42 |
43 | # Although you may need slightly wider terminal than 80 chars, it is
44 | # much nicer to edit the output of --help when this is set.
45 | XGETTEXT_OPTIONS += --no-wrap
46 | MSGMERGE += --no-wrap
47 |
--------------------------------------------------------------------------------
/po/POTFILES.in:
--------------------------------------------------------------------------------
1 | # List of source files which contain translatable strings.
2 | src/xz/args.c
3 | src/xz/coder.c
4 | src/xz/file_io.c
5 | src/xz/hardware.c
6 | src/xz/list.c
7 | src/xz/main.c
8 | src/xz/message.c
9 | src/xz/options.c
10 | src/xz/signals.c
11 | src/xz/suffix.c
12 | src/xz/util.c
13 | src/common/tuklib_exit.c
14 |
--------------------------------------------------------------------------------
/src/Makefile.am:
--------------------------------------------------------------------------------
1 | ##
2 | ## Author: Lasse Collin
3 | ##
4 | ## This file has been put into the public domain.
5 | ## You can do whatever you want with this file.
6 | ##
7 |
8 | SUBDIRS = liblzma xzdec
9 |
10 | if COND_XZ
11 | SUBDIRS += xz
12 | endif
13 |
14 | if COND_LZMAINFO
15 | SUBDIRS += lzmainfo
16 | endif
17 |
18 | if COND_SCRIPTS
19 | SUBDIRS += scripts
20 | endif
21 |
22 | EXTRA_DIST = \
23 | common/common_w32res.rc \
24 | common/mythread.h \
25 | common/sysdefs.h \
26 | common/tuklib_common.h \
27 | common/tuklib_config.h \
28 | common/tuklib_cpucores.c \
29 | common/tuklib_cpucores.h \
30 | common/tuklib_exit.c \
31 | common/tuklib_exit.h \
32 | common/tuklib_gettext.h \
33 | common/tuklib_integer.h \
34 | common/tuklib_mbstr_fw.c \
35 | common/tuklib_mbstr.h \
36 | common/tuklib_mbstr_width.c \
37 | common/tuklib_open_stdxxx.c \
38 | common/tuklib_open_stdxxx.h \
39 | common/tuklib_physmem.c \
40 | common/tuklib_physmem.h \
41 | common/tuklib_progname.c \
42 | common/tuklib_progname.h
43 |
--------------------------------------------------------------------------------
/src/common/atomic.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file atomic.h
4 | /// \brief Atomic addition function wrapper
5 | ///
6 | // Author: Conor McCarthy
7 | //
8 | // This source code is licensed under both the BSD-style license (found in the
9 | // LICENSE file in the root directory of this source tree) and the GPLv2 (found
10 | // in the COPYING file in the root directory of this source tree).
11 | // You may select, at your option, one of the above-listed licenses.
12 | //
13 | ///////////////////////////////////////////////////////////////////////////////
14 |
15 | #ifndef LZMA_ATOMIC_H
16 | #define LZMA_ATOMIC_H
17 |
18 | #include "mythread.h"
19 |
20 |
21 | #if defined(MYTHREAD_ENABLED) && defined(_WIN32)
22 |
23 |
24 | typedef LONG volatile lzma_atomic;
25 |
26 | #define ATOMIC_INITIAL_VALUE -1
27 |
28 | #define lzma_atomic_increment(n) InterlockedIncrement(&n)
29 | #define lzma_atomic_add(n, a) InterlockedAdd(&n, a)
30 | #define lzma_nonatomic_increment(n) (++n)
31 |
32 |
33 | #elif defined(MYTHREAD_ENABLED) && defined(__GNUC__)
34 |
35 |
36 | typedef long lzma_atomic;
37 |
38 | #define ATOMIC_INITIAL_VALUE 0
39 |
40 | #define lzma_atomic_increment(n) __sync_fetch_and_add(&n, 1)
41 | #define lzma_atomic_add(n, a) __sync_fetch_and_add(&n, a)
42 | #define lzma_nonatomic_increment(n) (n++)
43 |
44 |
45 | #elif defined(MYTHREAD_ENABLED) && defined(HAVE_STDATOMIC_H) // C11
46 |
47 |
48 | #include
49 |
50 | typedef _Atomic long lzma_atomic;
51 |
52 | #define ATOMIC_INITIAL_VALUE 0
53 |
54 | #define lzma_atomic_increment(n) atomic_fetch_add(&n, 1)
55 | #define lzma_atomic_add(n, a) atomic_fetch_add(&n, a)
56 | #define lzma_nonatomic_increment(n) (n++)
57 |
58 |
59 | #else // No atomics
60 |
61 |
62 | # ifdef MYTHREAD_ENABLED
63 | # error No atomic operations available. Use --disable-threads to configure a single-threaded build.
64 | # endif
65 |
66 | typedef long lzma_atomic;
67 |
68 | #define ATOMIC_INITIAL_VALUE 0
69 |
70 | #define lzma_atomic_increment(n) (n++)
71 | #define lzma_atomic_add(n, a) (n += (a))
72 | #define lzma_nonatomic_increment(n) (n++)
73 |
74 |
75 | #endif // atomics
76 |
77 |
78 | #endif // LZMA_ATOMIC_H
79 |
--------------------------------------------------------------------------------
/src/common/common_w32res.rc:
--------------------------------------------------------------------------------
1 | /*
2 | * Author: Lasse Collin
3 | *
4 | * This file has been put into the public domain.
5 | * You can do whatever you want with this file.
6 | */
7 |
8 | #include
9 | #ifdef HAVE_CONFIG_H
10 | # include "config.h"
11 | #endif
12 | #define LZMA_H_INTERNAL
13 | #define LZMA_H_INTERNAL_RC
14 | #include "flzma/version.h"
15 |
16 | #ifndef MY_BUILD
17 | # define MY_BUILD 0
18 | #endif
19 | #define MY_VERSION LZMA_VERSION_MAJOR,LZMA_VERSION_MINOR,LZMA_VERSION_PATCH,MY_BUILD
20 |
21 | #define MY_FILENAME MY_NAME MY_SUFFIX
22 | #define MY_COMPANY "The Tukaani Project "
23 | #define MY_PRODUCT PACKAGE_NAME " <" PACKAGE_URL ">"
24 |
25 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
26 | VS_VERSION_INFO VERSIONINFO
27 | FILEVERSION MY_VERSION
28 | PRODUCTVERSION MY_VERSION
29 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
30 | FILEFLAGS 0
31 | FILEOS VOS_NT_WINDOWS32
32 | FILETYPE MY_TYPE
33 | FILESUBTYPE 0x0L
34 | BEGIN
35 | BLOCK "StringFileInfo"
36 | BEGIN
37 | BLOCK "040904b0"
38 | BEGIN
39 | VALUE "CompanyName", MY_COMPANY
40 | VALUE "FileDescription", MY_DESC
41 | VALUE "FileVersion", LZMA_VERSION_STRING
42 | VALUE "InternalName", MY_NAME
43 | VALUE "OriginalFilename", MY_FILENAME
44 | VALUE "ProductName", MY_PRODUCT
45 | VALUE "ProductVersion", LZMA_VERSION_STRING
46 | END
47 | END
48 | BLOCK "VarFileInfo"
49 | BEGIN
50 | VALUE "Translation", 0x409, 1200
51 | END
52 | END
53 |
--------------------------------------------------------------------------------
/src/common/tuklib_common.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file tuklib_common.h
4 | /// \brief Common definitions for tuklib modules
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef TUKLIB_COMMON_H
14 | #define TUKLIB_COMMON_H
15 |
16 | // The config file may be replaced by a package-specific file.
17 | // It should include at least stddef.h, stdbool.h, inttypes.h, and limits.h.
18 | #include "tuklib_config.h"
19 |
20 | // TUKLIB_SYMBOL_PREFIX is prefixed to all symbols exported by
21 | // the tuklib modules. If you use a tuklib module in a library,
22 | // you should use TUKLIB_SYMBOL_PREFIX to make sure that there
23 | // are no symbol conflicts in case someone links your library
24 | // into application that also uses the same tuklib module.
25 | #ifndef TUKLIB_SYMBOL_PREFIX
26 | # define TUKLIB_SYMBOL_PREFIX
27 | #endif
28 |
29 | #define TUKLIB_CAT_X(a, b) a ## b
30 | #define TUKLIB_CAT(a, b) TUKLIB_CAT_X(a, b)
31 |
32 | #ifndef TUKLIB_SYMBOL
33 | # define TUKLIB_SYMBOL(sym) TUKLIB_CAT(TUKLIB_SYMBOL_PREFIX, sym)
34 | #endif
35 |
36 | #ifndef TUKLIB_DECLS_BEGIN
37 | # ifdef __cplusplus
38 | # define TUKLIB_DECLS_BEGIN extern "C" {
39 | # else
40 | # define TUKLIB_DECLS_BEGIN
41 | # endif
42 | #endif
43 |
44 | #ifndef TUKLIB_DECLS_END
45 | # ifdef __cplusplus
46 | # define TUKLIB_DECLS_END }
47 | # else
48 | # define TUKLIB_DECLS_END
49 | # endif
50 | #endif
51 |
52 | #if defined(__GNUC__) && defined(__GNUC_MINOR__)
53 | # define TUKLIB_GNUC_REQ(major, minor) \
54 | ((__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)) \
55 | || __GNUC__ > (major))
56 | #else
57 | # define TUKLIB_GNUC_REQ(major, minor) 0
58 | #endif
59 |
60 | #if TUKLIB_GNUC_REQ(2, 5)
61 | # define tuklib_attr_noreturn __attribute__((__noreturn__))
62 | #else
63 | # define tuklib_attr_noreturn
64 | #endif
65 |
66 | #if (defined(_WIN32) && !defined(__CYGWIN__)) \
67 | || defined(__OS2__) || defined(__MSDOS__)
68 | # define TUKLIB_DOSLIKE 1
69 | #endif
70 |
71 | #endif
72 |
--------------------------------------------------------------------------------
/src/common/tuklib_config.h:
--------------------------------------------------------------------------------
1 | #ifdef HAVE_CONFIG_H
2 | # include "sysdefs.h"
3 | #else
4 | # include
5 | # include
6 | # include
7 | # include
8 | #endif
9 |
--------------------------------------------------------------------------------
/src/common/tuklib_cpucores.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file tuklib_cpucores.h
4 | /// \brief Get the number of CPU cores online
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef TUKLIB_CPUCORES_H
14 | #define TUKLIB_CPUCORES_H
15 |
16 | #include "tuklib_common.h"
17 | TUKLIB_DECLS_BEGIN
18 |
19 | #define tuklib_cpucores TUKLIB_SYMBOL(tuklib_cpucores)
20 | extern uint32_t tuklib_cpucores(void);
21 |
22 | TUKLIB_DECLS_END
23 | #endif
24 |
--------------------------------------------------------------------------------
/src/common/tuklib_exit.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file tuklib_exit.c
4 | /// \brief Close stdout and stderr, and exit
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "tuklib_common.h"
14 |
15 | #include
16 | #include
17 | #include
18 |
19 | #include "tuklib_gettext.h"
20 | #include "tuklib_progname.h"
21 | #include "tuklib_exit.h"
22 |
23 |
24 | extern void
25 | tuklib_exit(int status, int err_status, int show_error)
26 | {
27 | if (status != err_status) {
28 | // Close stdout. If something goes wrong,
29 | // print an error message to stderr.
30 | const int ferror_err = ferror(stdout);
31 | const int fclose_err = fclose(stdout);
32 | if (ferror_err || fclose_err) {
33 | status = err_status;
34 |
35 | // If it was fclose() that failed, we have the reason
36 | // in errno. If only ferror() indicated an error,
37 | // we have no idea what the reason was.
38 | if (show_error)
39 | fprintf(stderr, "%s: %s: %s\n", progname,
40 | _("Writing to standard "
41 | "output failed"),
42 | fclose_err ? strerror(errno)
43 | : _("Unknown error"));
44 | }
45 | }
46 |
47 | if (status != err_status) {
48 | // Close stderr. If something goes wrong, there's
49 | // nothing where we could print an error message.
50 | // Just set the exit status.
51 | const int ferror_err = ferror(stderr);
52 | const int fclose_err = fclose(stderr);
53 | if (fclose_err || ferror_err)
54 | status = err_status;
55 | }
56 |
57 | exit(status);
58 | }
59 |
--------------------------------------------------------------------------------
/src/common/tuklib_exit.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file tuklib_exit.h
4 | /// \brief Close stdout and stderr, and exit
5 | /// \note Requires tuklib_progname and tuklib_gettext modules
6 | //
7 | // Author: Lasse Collin
8 | //
9 | // This file has been put into the public domain.
10 | // You can do whatever you want with this file.
11 | //
12 | ///////////////////////////////////////////////////////////////////////////////
13 |
14 | #ifndef TUKLIB_EXIT_H
15 | #define TUKLIB_EXIT_H
16 |
17 | #include "tuklib_common.h"
18 | TUKLIB_DECLS_BEGIN
19 |
20 | #define tuklib_exit TUKLIB_SYMBOL(tuklib_exit)
21 | extern void tuklib_exit(int status, int err_status, int show_error)
22 | tuklib_attr_noreturn;
23 |
24 | TUKLIB_DECLS_END
25 | #endif
26 |
--------------------------------------------------------------------------------
/src/common/tuklib_gettext.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file tuklib_gettext.h
4 | /// \brief Wrapper for gettext and friends
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef TUKLIB_GETTEXT_H
14 | #define TUKLIB_GETTEXT_H
15 |
16 | #include "tuklib_common.h"
17 | #include
18 |
19 | #ifndef TUKLIB_GETTEXT
20 | # ifdef ENABLE_NLS
21 | # define TUKLIB_GETTEXT 1
22 | # else
23 | # define TUKLIB_GETTEXT 0
24 | # endif
25 | #endif
26 |
27 | #if TUKLIB_GETTEXT
28 | # include
29 | # define tuklib_gettext_init(package, localedir) \
30 | do { \
31 | setlocale(LC_ALL, ""); \
32 | bindtextdomain(package, localedir); \
33 | textdomain(package); \
34 | } while (0)
35 | # define _(msgid) gettext(msgid)
36 | #else
37 | # define tuklib_gettext_init(package, localedir) \
38 | setlocale(LC_ALL, "")
39 | # define _(msgid) (msgid)
40 | # define ngettext(msgid1, msgid2, n) ((n) == 1 ? (msgid1) : (msgid2))
41 | #endif
42 | #define N_(msgid) msgid
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/src/common/tuklib_mbstr_fw.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file tuklib_mbstr_fw.c
4 | /// \brief Get the field width for printf() e.g. to align table columns
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "tuklib_mbstr.h"
14 |
15 |
16 | extern int
17 | tuklib_mbstr_fw(const char *str, int columns_min)
18 | {
19 | size_t len;
20 | const size_t width = tuklib_mbstr_width(str, &len);
21 | if (width == (size_t)-1)
22 | return -1;
23 |
24 | if (width > (size_t)columns_min)
25 | return 0;
26 |
27 | if (width < (size_t)columns_min)
28 | len += (size_t)columns_min - width;
29 |
30 | return len;
31 | }
32 |
--------------------------------------------------------------------------------
/src/common/tuklib_mbstr_width.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file tuklib_mbstr_width.c
4 | /// \brief Calculate width of a multibyte string
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "tuklib_mbstr.h"
14 | #include
15 |
16 | #if defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH)
17 | # include
18 | #endif
19 |
20 |
21 | extern size_t
22 | tuklib_mbstr_width(const char *str, size_t *bytes)
23 | {
24 | const size_t len = strlen(str);
25 | if (bytes != NULL)
26 | *bytes = len;
27 |
28 | #if !(defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH))
29 | // In single-byte mode, the width of the string is the same
30 | // as its length.
31 | return len;
32 |
33 | #else
34 | mbstate_t state;
35 | memset(&state, 0, sizeof(state));
36 |
37 | size_t width = 0;
38 | size_t i = 0;
39 |
40 | // Convert one multibyte character at a time to wchar_t
41 | // and get its width using wcwidth().
42 | while (i < len) {
43 | wchar_t wc;
44 | const size_t ret = mbrtowc(&wc, str + i, len - i, &state);
45 | if (ret < 1 || ret > len)
46 | return (size_t)-1;
47 |
48 | i += ret;
49 |
50 | const int wc_width = wcwidth(wc);
51 | if (wc_width < 0)
52 | return (size_t)-1;
53 |
54 | width += (size_t)wc_width;
55 | }
56 |
57 | // Require that the string ends in the initial shift state.
58 | // This way the caller can be combine the string with other
59 | // strings without needing to worry about the shift states.
60 | if (!mbsinit(&state))
61 | return (size_t)-1;
62 |
63 | return width;
64 | #endif
65 | }
66 |
--------------------------------------------------------------------------------
/src/common/tuklib_open_stdxxx.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file tuklib_open_stdxxx.c
4 | /// \brief Make sure that file descriptors 0, 1, and 2 are open
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "tuklib_open_stdxxx.h"
14 |
15 | #ifndef TUKLIB_DOSLIKE
16 | # include
17 | # include
18 | # include
19 | # include
20 | #endif
21 |
22 |
23 | extern void
24 | tuklib_open_stdxxx(int err_status)
25 | {
26 | #ifdef TUKLIB_DOSLIKE
27 | // Do nothing, just silence warnings.
28 | (void)err_status;
29 |
30 | #else
31 | for (int i = 0; i <= 2; ++i) {
32 | // We use fcntl() to check if the file descriptor is open.
33 | if (fcntl(i, F_GETFD) == -1 && errno == EBADF) {
34 | // With stdin, we could use /dev/full so that
35 | // writing to stdin would fail. However, /dev/full
36 | // is Linux specific, and if the program tries to
37 | // write to stdin, there's already a problem anyway.
38 | const int fd = open("/dev/null", O_NOCTTY
39 | | (i == 0 ? O_WRONLY : O_RDONLY));
40 |
41 | if (fd != i) {
42 | if (fd != -1)
43 | (void)close(fd);
44 |
45 | // Something went wrong. Exit with the
46 | // exit status we were given. Don't try
47 | // to print an error message, since stderr
48 | // may very well be non-existent. This
49 | // error should be extremely rare.
50 | exit(err_status);
51 | }
52 | }
53 | }
54 | #endif
55 |
56 | return;
57 | }
58 |
--------------------------------------------------------------------------------
/src/common/tuklib_open_stdxxx.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file tuklib_open_stdxxx.h
4 | /// \brief Make sure that file descriptors 0, 1, and 2 are open
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef TUKLIB_OPEN_STDXXX_H
14 | #define TUKLIB_OPEN_STDXXX_H
15 |
16 | #include "tuklib_common.h"
17 | TUKLIB_DECLS_BEGIN
18 |
19 | #define tuklib_open_stdxx TUKLIB_SYMBOL(tuklib_open_stdxxx)
20 | extern void tuklib_open_stdxxx(int err_status);
21 |
22 | TUKLIB_DECLS_END
23 | #endif
24 |
--------------------------------------------------------------------------------
/src/common/tuklib_physmem.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file tuklib_physmem.h
4 | /// \brief Get the amount of physical memory
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef TUKLIB_PHYSMEM_H
14 | #define TUKLIB_PHYSMEM_H
15 |
16 | #include "tuklib_common.h"
17 | TUKLIB_DECLS_BEGIN
18 |
19 | #define tuklib_physmem TUKLIB_SYMBOL(tuklib_physmem)
20 | extern uint64_t tuklib_physmem(void);
21 | ///<
22 | /// \brief Get the amount of physical memory in bytes
23 | ///
24 | /// \return Amount of physical memory in bytes. On error, zero is
25 | /// returned.
26 |
27 | TUKLIB_DECLS_END
28 | #endif
29 |
--------------------------------------------------------------------------------
/src/common/tuklib_progname.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file tuklib_progname.c
4 | /// \brief Program name to be displayed in messages
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "tuklib_progname.h"
14 | #include
15 |
16 |
17 | #if !HAVE_DECL_PROGRAM_INVOCATION_NAME
18 | char *progname = NULL;
19 | #endif
20 |
21 |
22 | extern void
23 | tuklib_progname_init(char **argv)
24 | {
25 | #ifdef TUKLIB_DOSLIKE
26 | // On these systems, argv[0] always has the full path and .exe
27 | // suffix even if the user just types the plain program name.
28 | // We modify argv[0] to make it nicer to read.
29 |
30 | // Strip the leading path.
31 | char *p = argv[0] + strlen(argv[0]);
32 | while (argv[0] < p && p[-1] != '/' && p[-1] != '\\')
33 | --p;
34 |
35 | argv[0] = p;
36 |
37 | // Strip the .exe suffix.
38 | p = strrchr(p, '.');
39 | if (p != NULL)
40 | *p = '\0';
41 |
42 | // Make it lowercase.
43 | for (p = argv[0]; *p != '\0'; ++p)
44 | if (*p >= 'A' && *p <= 'Z')
45 | *p = *p - 'A' + 'a';
46 | #endif
47 |
48 | progname = argv[0];
49 | return;
50 | }
51 |
--------------------------------------------------------------------------------
/src/common/tuklib_progname.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file tuklib_progname.h
4 | /// \brief Program name to be displayed in messages
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef TUKLIB_PROGNAME_H
14 | #define TUKLIB_PROGNAME_H
15 |
16 | #include "tuklib_common.h"
17 | #include
18 |
19 | TUKLIB_DECLS_BEGIN
20 |
21 | #if HAVE_DECL_PROGRAM_INVOCATION_NAME
22 | # define progname program_invocation_name
23 | #else
24 | # define progname TUKLIB_SYMBOL(tuklib_progname)
25 | extern char *progname;
26 | #endif
27 |
28 | #define tuklib_progname_init TUKLIB_SYMBOL(tuklib_progname_init)
29 | extern void tuklib_progname_init(char **argv);
30 |
31 | TUKLIB_DECLS_END
32 | #endif
33 |
--------------------------------------------------------------------------------
/src/liblzma/api/Makefile.am:
--------------------------------------------------------------------------------
1 | ##
2 | ## Author: Lasse Collin
3 | ##
4 | ## This file has been put into the public domain.
5 | ## You can do whatever you want with this file.
6 | ##
7 |
8 | nobase_include_HEADERS = \
9 | flzma.h \
10 | flzma/base.h \
11 | flzma/bcj.h \
12 | flzma/block.h \
13 | flzma/check.h \
14 | flzma/container.h \
15 | flzma/delta.h \
16 | flzma/filter.h \
17 | flzma/hardware.h \
18 | flzma/index.h \
19 | flzma/index_hash.h \
20 | flzma/lzma12.h \
21 | flzma/stream_flags.h \
22 | flzma/version.h \
23 | flzma/vli.h
24 |
--------------------------------------------------------------------------------
/src/liblzma/api/flzma/delta.h:
--------------------------------------------------------------------------------
1 | /**
2 | * \file flzma/delta.h
3 | * \brief Delta filter
4 | */
5 |
6 | /*
7 | * Author: Lasse Collin
8 | *
9 | * This file has been put into the public domain.
10 | * You can do whatever you want with this file.
11 | *
12 | * See ../flzma.h for information about liblzma as a whole.
13 | */
14 |
15 | #ifndef LZMA_H_INTERNAL
16 | # error Never include this file directly. Use instead.
17 | #endif
18 |
19 |
20 | /**
21 | * \brief Filter ID
22 | *
23 | * Filter ID of the Delta filter. This is used as lzma_filter.id.
24 | */
25 | #define LZMA_FILTER_DELTA LZMA_VLI_C(0x03)
26 |
27 |
28 | /**
29 | * \brief Type of the delta calculation
30 | *
31 | * Currently only byte-wise delta is supported. Other possible types could
32 | * be, for example, delta of 16/32/64-bit little/big endian integers, but
33 | * these are not currently planned since byte-wise delta is almost as good.
34 | */
35 | typedef enum {
36 | LZMA_DELTA_TYPE_BYTE
37 | } lzma_delta_type;
38 |
39 |
40 | /**
41 | * \brief Options for the Delta filter
42 | *
43 | * These options are needed by both encoder and decoder.
44 | */
45 | typedef struct {
46 | /** For now, this must always be LZMA_DELTA_TYPE_BYTE. */
47 | lzma_delta_type type;
48 |
49 | /**
50 | * \brief Delta distance
51 | *
52 | * With the only currently supported type, LZMA_DELTA_TYPE_BYTE,
53 | * the distance is as bytes.
54 | *
55 | * Examples:
56 | * - 16-bit stereo audio: distance = 4 bytes
57 | * - 24-bit RGB image data: distance = 3 bytes
58 | */
59 | uint32_t dist;
60 | # define LZMA_DELTA_DIST_MIN 1
61 | # define LZMA_DELTA_DIST_MAX 256
62 |
63 | /*
64 | * Reserved space to allow possible future extensions without
65 | * breaking the ABI. You should not touch these, because the names
66 | * of these variables may change. These are and will never be used
67 | * when type is LZMA_DELTA_TYPE_BYTE, so it is safe to leave these
68 | * uninitialized.
69 | */
70 | uint32_t reserved_int1;
71 | uint32_t reserved_int2;
72 | uint32_t reserved_int3;
73 | uint32_t reserved_int4;
74 | void *reserved_ptr1;
75 | void *reserved_ptr2;
76 |
77 | } lzma_options_delta;
78 |
--------------------------------------------------------------------------------
/src/liblzma/check/Makefile.inc:
--------------------------------------------------------------------------------
1 | ##
2 | ## Author: Lasse Collin
3 | ##
4 | ## This file has been put into the public domain.
5 | ## You can do whatever you want with this file.
6 | ##
7 |
8 | EXTRA_DIST += \
9 | check/crc32_tablegen.c \
10 | check/crc64_tablegen.c
11 |
12 | libflzma_la_SOURCES += \
13 | check/check.c \
14 | check/check.h \
15 | check/crc_macros.h
16 |
17 | if COND_CHECK_CRC32
18 | if COND_SMALL
19 | libflzma_la_SOURCES += check/crc32_small.c
20 | else
21 | libflzma_la_SOURCES += \
22 | check/crc32_table.c \
23 | check/crc32_table_le.h \
24 | check/crc32_table_be.h
25 | if COND_ASM_X86
26 | libflzma_la_SOURCES += check/crc32_x86.S
27 | else
28 | libflzma_la_SOURCES += check/crc32_fast.c
29 | endif
30 | endif
31 | endif
32 |
33 | if COND_CHECK_CRC64
34 | if COND_SMALL
35 | libflzma_la_SOURCES += check/crc64_small.c
36 | else
37 | libflzma_la_SOURCES += \
38 | check/crc64_table.c \
39 | check/crc64_table_le.h \
40 | check/crc64_table_be.h
41 | if COND_ASM_X86
42 | libflzma_la_SOURCES += check/crc64_x86.S
43 | else
44 | libflzma_la_SOURCES += check/crc64_fast.c
45 | endif
46 | endif
47 | endif
48 |
49 | if COND_CHECK_SHA256
50 | if COND_INTERNAL_SHA256
51 | libflzma_la_SOURCES += check/sha256.c
52 | endif
53 | endif
54 |
--------------------------------------------------------------------------------
/src/liblzma/check/crc32_small.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file crc32_small.c
4 | /// \brief CRC32 calculation (size-optimized)
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "check.h"
14 |
15 |
16 | uint32_t lzma_crc32_table[1][256];
17 |
18 |
19 | static void
20 | crc32_init(void)
21 | {
22 | static const uint32_t poly32 = UINT32_C(0xEDB88320);
23 |
24 | for (size_t b = 0; b < 256; ++b) {
25 | uint32_t r = b;
26 | for (size_t i = 0; i < 8; ++i) {
27 | if (r & 1)
28 | r = (r >> 1) ^ poly32;
29 | else
30 | r >>= 1;
31 | }
32 |
33 | lzma_crc32_table[0][b] = r;
34 | }
35 |
36 | return;
37 | }
38 |
39 |
40 | extern void
41 | lzma_crc32_init(void)
42 | {
43 | mythread_once(crc32_init);
44 | return;
45 | }
46 |
47 |
48 | extern LZMA_API(uint32_t)
49 | lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
50 | {
51 | lzma_crc32_init();
52 |
53 | crc = ~crc;
54 |
55 | while (size != 0) {
56 | crc = lzma_crc32_table[0][*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
57 | --size;
58 | }
59 |
60 | return ~crc;
61 | }
62 |
--------------------------------------------------------------------------------
/src/liblzma/check/crc32_table.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file crc32_table.c
4 | /// \brief Precalculated CRC32 table with correct endianness
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "common.h"
14 |
15 | // Having the declaration here silences clang -Wmissing-variable-declarations.
16 | extern const uint32_t lzma_crc32_table[8][256];
17 |
18 | #ifdef WORDS_BIGENDIAN
19 | # include "crc32_table_be.h"
20 | #else
21 | # include "crc32_table_le.h"
22 | #endif
23 |
--------------------------------------------------------------------------------
/src/liblzma/check/crc64_fast.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file crc64.c
4 | /// \brief CRC64 calculation
5 | ///
6 | /// Calculate the CRC64 using the slice-by-four algorithm. This is the same
7 | /// idea that is used in crc32_fast.c, but for CRC64 we use only four tables
8 | /// instead of eight to avoid increasing CPU cache usage.
9 | //
10 | // Author: Lasse Collin
11 | //
12 | // This file has been put into the public domain.
13 | // You can do whatever you want with this file.
14 | //
15 | ///////////////////////////////////////////////////////////////////////////////
16 |
17 | #include "check.h"
18 | #include "crc_macros.h"
19 |
20 |
21 | #ifdef WORDS_BIGENDIAN
22 | # define A1(x) ((x) >> 56)
23 | #else
24 | # define A1 A
25 | #endif
26 |
27 |
28 | // See the comments in crc32_fast.c. They aren't duplicated here.
29 | extern LZMA_API(uint64_t)
30 | lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc)
31 | {
32 | crc = ~crc;
33 |
34 | #ifdef WORDS_BIGENDIAN
35 | crc = bswap64(crc);
36 | #endif
37 |
38 | if (size > 4) {
39 | while ((uintptr_t)(buf) & 3) {
40 | crc = lzma_crc64_table[0][*buf++ ^ A1(crc)] ^ S8(crc);
41 | --size;
42 | }
43 |
44 | const uint8_t *const limit = buf + (size & ~(size_t)(3));
45 | size &= (size_t)(3);
46 |
47 | while (buf < limit) {
48 | #ifdef WORDS_BIGENDIAN
49 | const uint32_t tmp = (crc >> 32)
50 | ^ aligned_read32ne(buf);
51 | #else
52 | const uint32_t tmp = crc ^ aligned_read32ne(buf);
53 | #endif
54 | buf += 4;
55 |
56 | crc = lzma_crc64_table[3][A(tmp)]
57 | ^ lzma_crc64_table[2][B(tmp)]
58 | ^ S32(crc)
59 | ^ lzma_crc64_table[1][C(tmp)]
60 | ^ lzma_crc64_table[0][D(tmp)];
61 | }
62 | }
63 |
64 | while (size-- != 0)
65 | crc = lzma_crc64_table[0][*buf++ ^ A1(crc)] ^ S8(crc);
66 |
67 | #ifdef WORDS_BIGENDIAN
68 | crc = bswap64(crc);
69 | #endif
70 |
71 | return ~crc;
72 | }
73 |
--------------------------------------------------------------------------------
/src/liblzma/check/crc64_small.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file crc64_small.c
4 | /// \brief CRC64 calculation (size-optimized)
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "check.h"
14 |
15 |
16 | static uint64_t crc64_table[256];
17 |
18 |
19 | static void
20 | crc64_init(void)
21 | {
22 | static const uint64_t poly64 = UINT64_C(0xC96C5795D7870F42);
23 |
24 | for (size_t b = 0; b < 256; ++b) {
25 | uint64_t r = b;
26 | for (size_t i = 0; i < 8; ++i) {
27 | if (r & 1)
28 | r = (r >> 1) ^ poly64;
29 | else
30 | r >>= 1;
31 | }
32 |
33 | crc64_table[b] = r;
34 | }
35 |
36 | return;
37 | }
38 |
39 |
40 | extern LZMA_API(uint64_t)
41 | lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc)
42 | {
43 | mythread_once(crc64_init);
44 |
45 | crc = ~crc;
46 |
47 | while (size != 0) {
48 | crc = crc64_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
49 | --size;
50 | }
51 |
52 | return ~crc;
53 | }
54 |
--------------------------------------------------------------------------------
/src/liblzma/check/crc64_table.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file crc64_table.c
4 | /// \brief Precalculated CRC64 table with correct endianness
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "common.h"
14 |
15 | // Having the declaration here silences clang -Wmissing-variable-declarations.
16 | extern const uint64_t lzma_crc64_table[4][256];
17 |
18 | #ifdef WORDS_BIGENDIAN
19 | # include "crc64_table_be.h"
20 | #else
21 | # include "crc64_table_le.h"
22 | #endif
23 |
--------------------------------------------------------------------------------
/src/liblzma/check/crc64_tablegen.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file crc64_tablegen.c
4 | /// \brief Generate crc64_table_le.h and crc64_table_be.h
5 | ///
6 | /// Compiling: gcc -std=c99 -o crc64_tablegen crc64_tablegen.c
7 | /// Add -DWORDS_BIGENDIAN to generate big endian table.
8 | //
9 | // Author: Lasse Collin
10 | //
11 | // This file has been put into the public domain.
12 | // You can do whatever you want with this file.
13 | //
14 | ///////////////////////////////////////////////////////////////////////////////
15 |
16 | #include
17 | #include "../../common/tuklib_integer.h"
18 |
19 |
20 | static uint64_t crc64_table[4][256];
21 |
22 |
23 | extern void
24 | init_crc64_table(void)
25 | {
26 | static const uint64_t poly64 = UINT64_C(0xC96C5795D7870F42);
27 |
28 | for (size_t s = 0; s < 4; ++s) {
29 | for (size_t b = 0; b < 256; ++b) {
30 | uint64_t r = s == 0 ? b : crc64_table[s - 1][b];
31 |
32 | for (size_t i = 0; i < 8; ++i) {
33 | if (r & 1)
34 | r = (r >> 1) ^ poly64;
35 | else
36 | r >>= 1;
37 | }
38 |
39 | crc64_table[s][b] = r;
40 | }
41 | }
42 |
43 | #ifdef WORDS_BIGENDIAN
44 | for (size_t s = 0; s < 4; ++s)
45 | for (size_t b = 0; b < 256; ++b)
46 | crc64_table[s][b] = bswap64(crc64_table[s][b]);
47 | #endif
48 |
49 | return;
50 | }
51 |
52 |
53 | static void
54 | print_crc64_table(void)
55 | {
56 | printf("/* This file has been automatically generated by "
57 | "crc64_tablegen.c. */\n\n"
58 | "const uint64_t lzma_crc64_table[4][256] = {\n\t{");
59 |
60 | for (size_t s = 0; s < 4; ++s) {
61 | for (size_t b = 0; b < 256; ++b) {
62 | if ((b % 2) == 0)
63 | printf("\n\t\t");
64 |
65 | printf("UINT64_C(0x%016" PRIX64 ")",
66 | crc64_table[s][b]);
67 |
68 | if (b != 255)
69 | printf(",%s", (b+1) % 2 == 0 ? "" : " ");
70 | }
71 |
72 | if (s == 3)
73 | printf("\n\t}\n};\n");
74 | else
75 | printf("\n\t}, {");
76 | }
77 |
78 | return;
79 | }
80 |
81 |
82 | int
83 | main(void)
84 | {
85 | init_crc64_table();
86 | print_crc64_table();
87 | return 0;
88 | }
89 |
--------------------------------------------------------------------------------
/src/liblzma/check/crc_macros.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file crc_macros.h
4 | /// \brief Some endian-dependent macros for CRC32 and CRC64
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifdef WORDS_BIGENDIAN
14 | # define A(x) ((x) >> 24)
15 | # define B(x) (((x) >> 16) & 0xFF)
16 | # define C(x) (((x) >> 8) & 0xFF)
17 | # define D(x) ((x) & 0xFF)
18 |
19 | # define S8(x) ((x) << 8)
20 | # define S32(x) ((x) << 32)
21 |
22 | #else
23 | # define A(x) ((x) & 0xFF)
24 | # define B(x) (((x) >> 8) & 0xFF)
25 | # define C(x) (((x) >> 16) & 0xFF)
26 | # define D(x) ((x) >> 24)
27 |
28 | # define S8(x) ((x) >> 8)
29 | # define S32(x) ((x) >> 32)
30 | #endif
31 |
--------------------------------------------------------------------------------
/src/liblzma/common/Makefile.inc:
--------------------------------------------------------------------------------
1 | ##
2 | ## Author: Lasse Collin
3 | ##
4 | ## This file has been put into the public domain.
5 | ## You can do whatever you want with this file.
6 | ##
7 |
8 | libflzma_la_SOURCES += \
9 | common/common.c \
10 | common/common.h \
11 | common/memcmplen.h \
12 | common/block_util.c \
13 | common/easy_preset.c \
14 | common/easy_preset.h \
15 | common/filter_common.c \
16 | common/filter_common.h \
17 | common/hardware_physmem.c \
18 | common/index.c \
19 | common/index.h \
20 | common/stream_flags_common.c \
21 | common/stream_flags_common.h \
22 | common/vli_size.c
23 |
24 | if COND_THREADS
25 | libflzma_la_SOURCES += common/hardware_cputhreads.c
26 | endif
27 |
28 | if COND_MAIN_ENCODER
29 | libflzma_la_SOURCES += \
30 | common/alone_encoder.c \
31 | common/block_buffer_encoder.c \
32 | common/block_buffer_encoder.h \
33 | common/block_encoder.c \
34 | common/block_encoder.h \
35 | common/block_header_encoder.c \
36 | common/easy_buffer_encoder.c \
37 | common/easy_encoder.c \
38 | common/easy_encoder_memusage.c \
39 | common/filter_buffer_encoder.c \
40 | common/filter_encoder.c \
41 | common/filter_encoder.h \
42 | common/filter_flags_encoder.c \
43 | common/index_encoder.c \
44 | common/index_encoder.h \
45 | common/stream_buffer_encoder.c \
46 | common/stream_encoder.c \
47 | common/stream_flags_encoder.c \
48 | common/vli_encoder.c
49 |
50 | if COND_THREADS
51 | libflzma_la_SOURCES += \
52 | common/outqueue.c \
53 | common/outqueue.h \
54 | common/stream_encoder_mt.c
55 | endif
56 | endif
57 |
58 | if COND_MAIN_DECODER
59 | libflzma_la_SOURCES += \
60 | common/alone_decoder.c \
61 | common/alone_decoder.h \
62 | common/auto_decoder.c \
63 | common/block_buffer_decoder.c \
64 | common/block_decoder.c \
65 | common/block_decoder.h \
66 | common/block_header_decoder.c \
67 | common/easy_decoder_memusage.c \
68 | common/file_info.c \
69 | common/filter_buffer_decoder.c \
70 | common/filter_decoder.c \
71 | common/filter_decoder.h \
72 | common/filter_flags_decoder.c \
73 | common/index_decoder.c \
74 | common/index_decoder.h \
75 | common/index_hash.c \
76 | common/stream_buffer_decoder.c \
77 | common/stream_decoder.c \
78 | common/stream_decoder.h \
79 | common/stream_flags_decoder.c \
80 | common/vli_decoder.c
81 | endif
82 |
--------------------------------------------------------------------------------
/src/liblzma/common/alone_decoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file alone_decoder.h
4 | /// \brief Decoder for LZMA_Alone files
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_ALONE_DECODER_H
14 | #define LZMA_ALONE_DECODER_H
15 |
16 | #include "common.h"
17 |
18 |
19 | extern lzma_ret lzma_alone_decoder_init(
20 | lzma_next_coder *next, const lzma_allocator *allocator,
21 | uint64_t memlimit, bool picky);
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/src/liblzma/common/block_buffer_encoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file block_buffer_encoder.h
4 | /// \brief Single-call .xz Block encoder
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_BLOCK_BUFFER_ENCODER_H
14 | #define LZMA_BLOCK_BUFFER_ENCODER_H
15 |
16 | #include "common.h"
17 |
18 |
19 | /// uint64_t version of lzma_block_buffer_bound(). It is used by
20 | /// stream_encoder_mt.c. Probably the original lzma_block_buffer_bound()
21 | /// should have been 64-bit, but fixing it would break the ABI.
22 | extern uint64_t lzma_block_buffer_bound64(uint64_t uncompressed_size);
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/src/liblzma/common/block_decoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file block_decoder.h
4 | /// \brief Decodes .xz Blocks
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_BLOCK_DECODER_H
14 | #define LZMA_BLOCK_DECODER_H
15 |
16 | #include "common.h"
17 |
18 |
19 | extern lzma_ret lzma_block_decoder_init(lzma_next_coder *next,
20 | const lzma_allocator *allocator, lzma_block *block);
21 |
22 | #endif
23 |
--------------------------------------------------------------------------------
/src/liblzma/common/block_encoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file block_encoder.h
4 | /// \brief Encodes .xz Blocks
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_BLOCK_ENCODER_H
14 | #define LZMA_BLOCK_ENCODER_H
15 |
16 | #include "common.h"
17 |
18 |
19 | /// \brief Biggest Compressed Size value that the Block encoder supports
20 | ///
21 | /// The maximum size of a single Block is limited by the maximum size of
22 | /// a Stream, which in theory is 2^63 - 3 bytes (i.e. LZMA_VLI_MAX - 3).
23 | /// While the size is really big and no one should hit it in practice, we
24 | /// take it into account in some places anyway to catch some errors e.g. if
25 | /// application passes insanely big value to some function.
26 | ///
27 | /// We could take into account the headers etc. to determine the exact
28 | /// maximum size of the Compressed Data field, but the complexity would give
29 | /// us nothing useful. Instead, limit the size of Compressed Data so that
30 | /// even with biggest possible Block Header and Check fields the total
31 | /// encoded size of the Block stays as a valid VLI. This doesn't guarantee
32 | /// that the size of the Stream doesn't grow too big, but that problem is
33 | /// taken care outside the Block handling code.
34 | ///
35 | /// ~LZMA_VLI_C(3) is to guarantee that if we need padding at the end of
36 | /// the Compressed Data field, it will still stay in the proper limit.
37 | ///
38 | /// This constant is in this file because it is needed in both
39 | /// block_encoder.c and block_buffer_encoder.c.
40 | #define COMPRESSED_SIZE_MAX ((LZMA_VLI_MAX - LZMA_BLOCK_HEADER_SIZE_MAX \
41 | - LZMA_CHECK_SIZE_MAX) & ~LZMA_VLI_C(3))
42 |
43 |
44 | extern lzma_ret lzma_block_encoder_init(lzma_next_coder *next,
45 | const lzma_allocator *allocator, lzma_block *block);
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/src/liblzma/common/easy_buffer_encoder.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file easy_buffer_encoder.c
4 | /// \brief Easy single-call .xz Stream encoder
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "easy_preset.h"
14 |
15 |
16 | extern LZMA_API(lzma_ret)
17 | lzma_easy_buffer_encode(uint32_t preset, lzma_check check,
18 | const lzma_allocator *allocator, const uint8_t *in,
19 | size_t in_size, uint8_t *out, size_t *out_pos, size_t out_size)
20 | {
21 | lzma_options_easy opt_easy;
22 | if (lzma_easy_preset(&opt_easy, preset))
23 | return LZMA_OPTIONS_ERROR;
24 |
25 | return lzma_stream_buffer_encode(opt_easy.filters, check,
26 | allocator, in, in_size, out, out_pos, out_size);
27 | }
28 |
--------------------------------------------------------------------------------
/src/liblzma/common/easy_decoder_memusage.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file easy_decoder_memusage.c
4 | /// \brief Decoder memory usage calculation to match easy encoder presets
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "easy_preset.h"
14 |
15 |
16 | extern LZMA_API(uint64_t)
17 | lzma_easy_decoder_memusage(uint32_t preset)
18 | {
19 | lzma_options_easy opt_easy;
20 | if (lzma_easy_preset(&opt_easy, preset))
21 | return UINT32_MAX;
22 |
23 | return lzma_raw_decoder_memusage(opt_easy.filters);
24 | }
25 |
--------------------------------------------------------------------------------
/src/liblzma/common/easy_encoder.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file easy_encoder.c
4 | /// \brief Easy .xz Stream encoder initialization
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "easy_preset.h"
14 |
15 |
16 | extern LZMA_API(lzma_ret)
17 | lzma_easy_encoder(lzma_stream *strm, uint32_t preset, lzma_check check)
18 | {
19 | lzma_options_easy opt_easy;
20 | if (lzma_easy_preset(&opt_easy, preset))
21 | return LZMA_OPTIONS_ERROR;
22 |
23 | return lzma_stream_encoder(strm, opt_easy.filters, check);
24 | }
25 |
--------------------------------------------------------------------------------
/src/liblzma/common/easy_encoder_memusage.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file easy_encoder_memusage.c
4 | /// \brief Easy .xz Stream encoder memory usage calculation
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "easy_preset.h"
14 |
15 |
16 | extern LZMA_API(uint64_t)
17 | lzma_easy_encoder_memusage(uint32_t preset)
18 | {
19 | lzma_options_easy opt_easy;
20 | if (lzma_easy_preset(&opt_easy, preset))
21 | return UINT32_MAX;
22 |
23 | return lzma_raw_encoder_memusage(opt_easy.filters);
24 | }
25 |
--------------------------------------------------------------------------------
/src/liblzma/common/easy_preset.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file easy_preset.c
4 | /// \brief Preset handling for easy encoder and decoder
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "easy_preset.h"
14 |
15 |
16 | extern bool
17 | lzma_easy_preset(lzma_options_easy *opt_easy, uint32_t preset)
18 | {
19 | if (lzma_lzma_preset(&opt_easy->opt_lzma, preset))
20 | return true;
21 |
22 | opt_easy->filters[0].id = LZMA_FILTER_LZMA2;
23 | opt_easy->filters[0].options = &opt_easy->opt_lzma;
24 | opt_easy->filters[1].id = LZMA_VLI_UNKNOWN;
25 |
26 | return false;
27 | }
28 |
--------------------------------------------------------------------------------
/src/liblzma/common/easy_preset.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file easy_preset.h
4 | /// \brief Preset handling for easy encoder and decoder
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "common.h"
14 |
15 |
16 | typedef struct {
17 | /// We need to keep the filters array available in case
18 | /// LZMA_FULL_FLUSH is used.
19 | lzma_filter filters[LZMA_FILTERS_MAX + 1];
20 |
21 | /// Options for LZMA2
22 | lzma_options_lzma opt_lzma;
23 |
24 | // Options for more filters can be added later, so this struct
25 | // is not ready to be put into the public API.
26 |
27 | } lzma_options_easy;
28 |
29 |
30 | /// Set *easy to the settings given by the preset. Returns true on error,
31 | /// false on success.
32 | extern bool lzma_easy_preset(lzma_options_easy *easy, uint32_t preset);
33 |
--------------------------------------------------------------------------------
/src/liblzma/common/filter_buffer_encoder.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file filter_buffer_encoder.c
4 | /// \brief Single-call raw encoding
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "filter_encoder.h"
14 |
15 |
16 | extern LZMA_API(lzma_ret)
17 | lzma_raw_buffer_encode(
18 | const lzma_filter *filters, const lzma_allocator *allocator,
19 | const uint8_t *in, size_t in_size,
20 | uint8_t *out, size_t *out_pos, size_t out_size)
21 | {
22 | // Validate what isn't validated later in filter_common.c.
23 | if ((in == NULL && in_size != 0) || out == NULL
24 | || out_pos == NULL || *out_pos > out_size)
25 | return LZMA_PROG_ERROR;
26 |
27 | // Initialize the encoder
28 | lzma_next_coder next = LZMA_NEXT_CODER_INIT;
29 | return_if_error(lzma_raw_encoder_init(&next, allocator, filters));
30 |
31 | // Store the output position so that we can restore it if
32 | // something goes wrong.
33 | const size_t out_start = *out_pos;
34 |
35 | // Do the actual encoding and free coder's memory.
36 | size_t in_pos = 0;
37 | lzma_ret ret = next.code(next.coder, allocator, in, &in_pos, in_size,
38 | out, out_pos, out_size, LZMA_FINISH);
39 | lzma_next_end(&next, allocator);
40 |
41 | if (ret == LZMA_STREAM_END) {
42 | ret = LZMA_OK;
43 | } else {
44 | if (ret == LZMA_OK) {
45 | // Output buffer was too small.
46 | assert(*out_pos == out_size);
47 | ret = LZMA_BUF_ERROR;
48 | }
49 |
50 | // Restore the output position.
51 | *out_pos = out_start;
52 | }
53 |
54 | return ret;
55 | }
56 |
--------------------------------------------------------------------------------
/src/liblzma/common/filter_common.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file filter_common.h
4 | /// \brief Filter-specific stuff common for both encoder and decoder
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_FILTER_COMMON_H
14 | #define LZMA_FILTER_COMMON_H
15 |
16 | #include "common.h"
17 |
18 |
19 | /// Both lzma_filter_encoder and lzma_filter_decoder begin with these members.
20 | typedef struct {
21 | /// Filter ID
22 | lzma_vli id;
23 |
24 | /// Initializes the filter encoder and calls lzma_next_filter_init()
25 | /// for filters + 1.
26 | lzma_init_function init;
27 |
28 | /// Calculates memory usage of the encoder. If the options are
29 | /// invalid, UINT64_MAX is returned.
30 | uint64_t (*memusage)(const void *options);
31 |
32 | } lzma_filter_coder;
33 |
34 |
35 | typedef const lzma_filter_coder *(*lzma_filter_find)(lzma_vli id);
36 |
37 |
38 | extern lzma_ret lzma_raw_coder_init(
39 | lzma_next_coder *next, const lzma_allocator *allocator,
40 | const lzma_filter *filters,
41 | lzma_filter_find coder_find, bool is_encoder);
42 |
43 |
44 | extern uint64_t lzma_raw_coder_memusage(lzma_filter_find coder_find,
45 | const lzma_filter *filters);
46 |
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/src/liblzma/common/filter_decoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file filter_decoder.h
4 | /// \brief Filter ID mapping to filter-specific functions
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_FILTER_DECODER_H
14 | #define LZMA_FILTER_DECODER_H
15 |
16 | #include "common.h"
17 |
18 |
19 | extern lzma_ret lzma_raw_decoder_init(
20 | lzma_next_coder *next, const lzma_allocator *allocator,
21 | const lzma_filter *options);
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/src/liblzma/common/filter_encoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file filter_encoder.c
4 | /// \brief Filter ID mapping to filter-specific functions
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_FILTER_ENCODER_H
14 | #define LZMA_FILTER_ENCODER_H
15 |
16 | #include "common.h"
17 |
18 |
19 | // FIXME: Might become a part of the public API.
20 | extern uint64_t lzma_mt_block_size(const lzma_filter *filters);
21 |
22 |
23 | extern lzma_ret lzma_raw_encoder_init(
24 | lzma_next_coder *next, const lzma_allocator *allocator,
25 | const lzma_filter *filters);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/src/liblzma/common/filter_flags_decoder.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file filter_flags_decoder.c
4 | /// \brief Decodes a Filter Flags field
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "filter_decoder.h"
14 |
15 |
16 | extern LZMA_API(lzma_ret)
17 | lzma_filter_flags_decode(
18 | lzma_filter *filter, const lzma_allocator *allocator,
19 | const uint8_t *in, size_t *in_pos, size_t in_size)
20 | {
21 | // Set the pointer to NULL so the caller can always safely free it.
22 | filter->options = NULL;
23 |
24 | // Filter ID
25 | return_if_error(lzma_vli_decode(&filter->id, NULL,
26 | in, in_pos, in_size));
27 |
28 | if (filter->id >= LZMA_FILTER_RESERVED_START)
29 | return LZMA_DATA_ERROR;
30 |
31 | // Size of Properties
32 | lzma_vli props_size;
33 | return_if_error(lzma_vli_decode(&props_size, NULL,
34 | in, in_pos, in_size));
35 |
36 | // Filter Properties
37 | if (in_size - *in_pos < props_size)
38 | return LZMA_DATA_ERROR;
39 |
40 | const lzma_ret ret = lzma_properties_decode(
41 | filter, allocator, in + *in_pos, props_size);
42 |
43 | *in_pos += props_size;
44 |
45 | return ret;
46 | }
47 |
--------------------------------------------------------------------------------
/src/liblzma/common/filter_flags_encoder.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file filter_flags_encoder.c
4 | /// \brief Encodes a Filter Flags field
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "filter_encoder.h"
14 |
15 |
16 | extern LZMA_API(lzma_ret)
17 | lzma_filter_flags_size(uint32_t *size, const lzma_filter *filter)
18 | {
19 | if (filter->id >= LZMA_FILTER_RESERVED_START)
20 | return LZMA_PROG_ERROR;
21 |
22 | return_if_error(lzma_properties_size(size, filter));
23 |
24 | *size += lzma_vli_size(filter->id) + lzma_vli_size(*size);
25 |
26 | return LZMA_OK;
27 | }
28 |
29 |
30 | extern LZMA_API(lzma_ret)
31 | lzma_filter_flags_encode(const lzma_filter *filter,
32 | uint8_t *out, size_t *out_pos, size_t out_size)
33 | {
34 | // Filter ID
35 | if (filter->id >= LZMA_FILTER_RESERVED_START)
36 | return LZMA_PROG_ERROR;
37 |
38 | return_if_error(lzma_vli_encode(filter->id, NULL,
39 | out, out_pos, out_size));
40 |
41 | // Size of Properties
42 | uint32_t props_size;
43 | return_if_error(lzma_properties_size(&props_size, filter));
44 | return_if_error(lzma_vli_encode(props_size, NULL,
45 | out, out_pos, out_size));
46 |
47 | // Filter Properties
48 | if (out_size - *out_pos < props_size)
49 | return LZMA_PROG_ERROR;
50 |
51 | return_if_error(lzma_properties_encode(filter, out + *out_pos));
52 |
53 | *out_pos += props_size;
54 |
55 | return LZMA_OK;
56 | }
57 |
--------------------------------------------------------------------------------
/src/liblzma/common/hardware_cputhreads.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file hardware_cputhreads.c
4 | /// \brief Get the number of CPU threads or cores
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "common.h"
14 |
15 | #include "tuklib_cpucores.h"
16 |
17 |
18 | extern LZMA_API(uint32_t)
19 | lzma_cputhreads(void)
20 | {
21 | return tuklib_cpucores();
22 | }
23 |
--------------------------------------------------------------------------------
/src/liblzma/common/hardware_physmem.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file hardware_physmem.c
4 | /// \brief Get the total amount of physical memory (RAM)
5 | //
6 | // Author: Jonathan Nieder
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "common.h"
14 |
15 | #include "tuklib_physmem.h"
16 |
17 |
18 | extern LZMA_API(uint64_t)
19 | lzma_physmem(void)
20 | {
21 | // It is simpler to make lzma_physmem() a wrapper for
22 | // tuklib_physmem() than to hack appropriate symbol visibility
23 | // support for the tuklib modules.
24 | return tuklib_physmem();
25 | }
26 |
--------------------------------------------------------------------------------
/src/liblzma/common/index.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file index.h
4 | /// \brief Handling of Index
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_INDEX_H
14 | #define LZMA_INDEX_H
15 |
16 | #include "common.h"
17 |
18 |
19 | /// Minimum Unpadded Size
20 | #define UNPADDED_SIZE_MIN LZMA_VLI_C(5)
21 |
22 | /// Maximum Unpadded Size
23 | #define UNPADDED_SIZE_MAX (LZMA_VLI_MAX & ~LZMA_VLI_C(3))
24 |
25 |
26 | /// Get the size of the Index Padding field. This is needed by Index encoder
27 | /// and decoder, but applications should have no use for this.
28 | extern uint32_t lzma_index_padding_size(const lzma_index *i);
29 |
30 |
31 | /// Set for how many Records to allocate memory the next time
32 | /// lzma_index_append() needs to allocate space for a new Record.
33 | /// This is used only by the Index decoder.
34 | extern void lzma_index_prealloc(lzma_index *i, lzma_vli records);
35 |
36 |
37 | /// Round the variable-length integer to the next multiple of four.
38 | static inline lzma_vli
39 | vli_ceil4(lzma_vli vli)
40 | {
41 | assert(vli <= LZMA_VLI_MAX);
42 | return (vli + 3) & ~LZMA_VLI_C(3);
43 | }
44 |
45 |
46 | /// Calculate the size of the Index field excluding Index Padding
47 | static inline lzma_vli
48 | index_size_unpadded(lzma_vli count, lzma_vli index_list_size)
49 | {
50 | // Index Indicator + Number of Records + List of Records + CRC32
51 | return 1 + lzma_vli_size(count) + index_list_size + 4;
52 | }
53 |
54 |
55 | /// Calculate the size of the Index field including Index Padding
56 | static inline lzma_vli
57 | index_size(lzma_vli count, lzma_vli index_list_size)
58 | {
59 | return vli_ceil4(index_size_unpadded(count, index_list_size));
60 | }
61 |
62 |
63 | /// Calculate the total size of the Stream
64 | static inline lzma_vli
65 | index_stream_size(lzma_vli blocks_size,
66 | lzma_vli count, lzma_vli index_list_size)
67 | {
68 | return LZMA_STREAM_HEADER_SIZE + blocks_size
69 | + index_size(count, index_list_size)
70 | + LZMA_STREAM_HEADER_SIZE;
71 | }
72 |
73 | #endif
74 |
--------------------------------------------------------------------------------
/src/liblzma/common/index_decoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file index_decoder.h
4 | /// \brief Decodes the Index field
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_INDEX_DECODER_H
14 | #define LZMA_INDEX_DECODER_H
15 |
16 | #include "index.h"
17 |
18 |
19 | extern lzma_ret lzma_index_decoder_init(lzma_next_coder *next,
20 | const lzma_allocator *allocator,
21 | lzma_index **i, uint64_t memlimit);
22 |
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/src/liblzma/common/index_encoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file index_encoder.h
4 | /// \brief Encodes the Index field
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_INDEX_ENCODER_H
14 | #define LZMA_INDEX_ENCODER_H
15 |
16 | #include "common.h"
17 |
18 |
19 | extern lzma_ret lzma_index_encoder_init(lzma_next_coder *next,
20 | const lzma_allocator *allocator, const lzma_index *i);
21 |
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/src/liblzma/common/stream_decoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file stream_decoder.h
4 | /// \brief Decodes .xz Streams
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_STREAM_DECODER_H
14 | #define LZMA_STREAM_DECODER_H
15 |
16 | #include "common.h"
17 |
18 | extern lzma_ret lzma_stream_decoder_init(
19 | lzma_next_coder *next, const lzma_allocator *allocator,
20 | uint64_t memlimit, uint32_t flags);
21 |
22 | #endif
23 |
--------------------------------------------------------------------------------
/src/liblzma/common/stream_flags_common.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file stream_flags_common.c
4 | /// \brief Common stuff for Stream flags coders
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "stream_flags_common.h"
14 |
15 |
16 | const uint8_t lzma_header_magic[6] = { 0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00 };
17 | const uint8_t lzma_footer_magic[2] = { 0x59, 0x5A };
18 |
19 |
20 | extern LZMA_API(lzma_ret)
21 | lzma_stream_flags_compare(
22 | const lzma_stream_flags *a, const lzma_stream_flags *b)
23 | {
24 | // We can compare only version 0 structures.
25 | if (a->version != 0 || b->version != 0)
26 | return LZMA_OPTIONS_ERROR;
27 |
28 | // Check type
29 | if ((unsigned int)(a->check) > LZMA_CHECK_ID_MAX
30 | || (unsigned int)(b->check) > LZMA_CHECK_ID_MAX)
31 | return LZMA_PROG_ERROR;
32 |
33 | if (a->check != b->check)
34 | return LZMA_DATA_ERROR;
35 |
36 | // Backward Sizes are compared only if they are known in both.
37 | if (a->backward_size != LZMA_VLI_UNKNOWN
38 | && b->backward_size != LZMA_VLI_UNKNOWN) {
39 | if (!is_backward_size_valid(a) || !is_backward_size_valid(b))
40 | return LZMA_PROG_ERROR;
41 |
42 | if (a->backward_size != b->backward_size)
43 | return LZMA_DATA_ERROR;
44 | }
45 |
46 | return LZMA_OK;
47 | }
48 |
--------------------------------------------------------------------------------
/src/liblzma/common/stream_flags_common.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file stream_flags_common.h
4 | /// \brief Common stuff for Stream flags coders
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_STREAM_FLAGS_COMMON_H
14 | #define LZMA_STREAM_FLAGS_COMMON_H
15 |
16 | #include "common.h"
17 |
18 | /// Size of the Stream Flags field
19 | #define LZMA_STREAM_FLAGS_SIZE 2
20 |
21 | extern const uint8_t lzma_header_magic[6];
22 | extern const uint8_t lzma_footer_magic[2];
23 |
24 |
25 | static inline bool
26 | is_backward_size_valid(const lzma_stream_flags *options)
27 | {
28 | return options->backward_size >= LZMA_BACKWARD_SIZE_MIN
29 | && options->backward_size <= LZMA_BACKWARD_SIZE_MAX
30 | && (options->backward_size & 3) == 0;
31 | }
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/src/liblzma/common/stream_flags_encoder.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file stream_flags_encoder.c
4 | /// \brief Encodes Stream Header and Stream Footer for .xz files
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "stream_flags_common.h"
14 |
15 |
16 | static bool
17 | stream_flags_encode(const lzma_stream_flags *options, uint8_t *out)
18 | {
19 | if ((unsigned int)(options->check) > LZMA_CHECK_ID_MAX)
20 | return true;
21 |
22 | out[0] = 0x00;
23 | out[1] = options->check;
24 |
25 | return false;
26 | }
27 |
28 |
29 | extern LZMA_API(lzma_ret)
30 | lzma_stream_header_encode(const lzma_stream_flags *options, uint8_t *out)
31 | {
32 | assert(sizeof(lzma_header_magic) + LZMA_STREAM_FLAGS_SIZE
33 | + 4 == LZMA_STREAM_HEADER_SIZE);
34 |
35 | if (options->version != 0)
36 | return LZMA_OPTIONS_ERROR;
37 |
38 | // Magic
39 | memcpy(out, lzma_header_magic, sizeof(lzma_header_magic));
40 |
41 | // Stream Flags
42 | if (stream_flags_encode(options, out + sizeof(lzma_header_magic)))
43 | return LZMA_PROG_ERROR;
44 |
45 | // CRC32 of the Stream Header
46 | const uint32_t crc = lzma_crc32(out + sizeof(lzma_header_magic),
47 | LZMA_STREAM_FLAGS_SIZE, 0);
48 |
49 | write32le(out + sizeof(lzma_header_magic) + LZMA_STREAM_FLAGS_SIZE,
50 | crc);
51 |
52 | return LZMA_OK;
53 | }
54 |
55 |
56 | extern LZMA_API(lzma_ret)
57 | lzma_stream_footer_encode(const lzma_stream_flags *options, uint8_t *out)
58 | {
59 | assert(2 * 4 + LZMA_STREAM_FLAGS_SIZE + sizeof(lzma_footer_magic)
60 | == LZMA_STREAM_HEADER_SIZE);
61 |
62 | if (options->version != 0)
63 | return LZMA_OPTIONS_ERROR;
64 |
65 | // Backward Size
66 | if (!is_backward_size_valid(options))
67 | return LZMA_PROG_ERROR;
68 |
69 | write32le(out + 4, options->backward_size / 4 - 1);
70 |
71 | // Stream Flags
72 | if (stream_flags_encode(options, out + 2 * 4))
73 | return LZMA_PROG_ERROR;
74 |
75 | // CRC32
76 | const uint32_t crc = lzma_crc32(
77 | out + 4, 4 + LZMA_STREAM_FLAGS_SIZE, 0);
78 |
79 | write32le(out, crc);
80 |
81 | // Magic
82 | memcpy(out + 2 * 4 + LZMA_STREAM_FLAGS_SIZE,
83 | lzma_footer_magic, sizeof(lzma_footer_magic));
84 |
85 | return LZMA_OK;
86 | }
87 |
--------------------------------------------------------------------------------
/src/liblzma/common/vli_encoder.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file vli_encoder.c
4 | /// \brief Encodes variable-length integers
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "common.h"
14 |
15 |
16 | extern LZMA_API(lzma_ret)
17 | lzma_vli_encode(lzma_vli vli, size_t *vli_pos,
18 | uint8_t *restrict out, size_t *restrict out_pos,
19 | size_t out_size)
20 | {
21 | // If we haven't been given vli_pos, work in single-call mode.
22 | size_t vli_pos_internal = 0;
23 | if (vli_pos == NULL) {
24 | vli_pos = &vli_pos_internal;
25 |
26 | // In single-call mode, we expect that the caller has
27 | // reserved enough output space.
28 | if (*out_pos >= out_size)
29 | return LZMA_PROG_ERROR;
30 | } else {
31 | // This never happens when we are called by liblzma, but
32 | // may happen if called directly from an application.
33 | if (*out_pos >= out_size)
34 | return LZMA_BUF_ERROR;
35 | }
36 |
37 | // Validate the arguments.
38 | if (*vli_pos >= LZMA_VLI_BYTES_MAX || vli > LZMA_VLI_MAX)
39 | return LZMA_PROG_ERROR;
40 |
41 | // Shift vli so that the next bits to encode are the lowest. In
42 | // single-call mode this never changes vli since *vli_pos is zero.
43 | vli >>= *vli_pos * 7;
44 |
45 | // Write the non-last bytes in a loop.
46 | while (vli >= 0x80) {
47 | // We don't need *vli_pos during this function call anymore,
48 | // but update it here so that it is ready if we need to
49 | // return before the whole integer has been decoded.
50 | ++*vli_pos;
51 | assert(*vli_pos < LZMA_VLI_BYTES_MAX);
52 |
53 | // Write the next byte.
54 | out[*out_pos] = (uint8_t)(vli) | 0x80;
55 | vli >>= 7;
56 |
57 | if (++*out_pos == out_size)
58 | return vli_pos == &vli_pos_internal
59 | ? LZMA_PROG_ERROR : LZMA_OK;
60 | }
61 |
62 | // Write the last byte.
63 | out[*out_pos] = (uint8_t)(vli);
64 | ++*out_pos;
65 | ++*vli_pos;
66 |
67 | return vli_pos == &vli_pos_internal ? LZMA_OK : LZMA_STREAM_END;
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/src/liblzma/common/vli_size.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file vli_size.c
4 | /// \brief Calculates the encoded size of a variable-length integer
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "common.h"
14 |
15 |
16 | extern LZMA_API(uint32_t)
17 | lzma_vli_size(lzma_vli vli)
18 | {
19 | if (vli > LZMA_VLI_MAX)
20 | return 0;
21 |
22 | uint32_t i = 0;
23 | do {
24 | vli >>= 7;
25 | ++i;
26 | } while (vli != 0);
27 |
28 | assert(i <= LZMA_VLI_BYTES_MAX);
29 | return i;
30 | }
31 |
--------------------------------------------------------------------------------
/src/liblzma/delta/Makefile.inc:
--------------------------------------------------------------------------------
1 | ##
2 | ## Author: Lasse Collin
3 | ##
4 | ## This file has been put into the public domain.
5 | ## You can do whatever you want with this file.
6 | ##
7 |
8 | libflzma_la_SOURCES += \
9 | delta/delta_common.c \
10 | delta/delta_common.h \
11 | delta/delta_private.h
12 |
13 | if COND_ENCODER_DELTA
14 | libflzma_la_SOURCES += \
15 | delta/delta_encoder.c \
16 | delta/delta_encoder.h
17 | endif
18 |
19 | if COND_DECODER_DELTA
20 | libflzma_la_SOURCES += \
21 | delta/delta_decoder.c \
22 | delta/delta_decoder.h
23 | endif
24 |
--------------------------------------------------------------------------------
/src/liblzma/delta/delta_common.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file delta_common.c
4 | /// \brief Common stuff for Delta encoder and decoder
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "delta_common.h"
14 | #include "delta_private.h"
15 |
16 |
17 | static void
18 | delta_coder_end(void *coder_ptr, const lzma_allocator *allocator)
19 | {
20 | lzma_delta_coder *coder = coder_ptr;
21 | lzma_next_end(&coder->next, allocator);
22 | lzma_free(coder, allocator);
23 | return;
24 | }
25 |
26 |
27 | extern lzma_ret
28 | lzma_delta_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
29 | const lzma_filter_info *filters)
30 | {
31 | // Allocate memory for the decoder if needed.
32 | lzma_delta_coder *coder = next->coder;
33 | if (coder == NULL) {
34 | coder = lzma_alloc(sizeof(lzma_delta_coder), allocator);
35 | if (coder == NULL)
36 | return LZMA_MEM_ERROR;
37 |
38 | next->coder = coder;
39 |
40 | // End function is the same for encoder and decoder.
41 | next->end = &delta_coder_end;
42 | coder->next = LZMA_NEXT_CODER_INIT;
43 | }
44 |
45 | // Validate the options.
46 | if (lzma_delta_coder_memusage(filters[0].options) == UINT64_MAX)
47 | return LZMA_OPTIONS_ERROR;
48 |
49 | // Set the delta distance.
50 | const lzma_options_delta *opt = filters[0].options;
51 | coder->distance = opt->dist;
52 |
53 | // Initialize the rest of the variables.
54 | coder->pos = 0;
55 | memzero(coder->history, LZMA_DELTA_DIST_MAX);
56 |
57 | // Initialize the next decoder in the chain, if any.
58 | return lzma_next_filter_init(&coder->next, allocator, filters + 1);
59 | }
60 |
61 |
62 | extern uint64_t
63 | lzma_delta_coder_memusage(const void *options)
64 | {
65 | const lzma_options_delta *opt = options;
66 |
67 | if (opt == NULL || opt->type != LZMA_DELTA_TYPE_BYTE
68 | || opt->dist < LZMA_DELTA_DIST_MIN
69 | || opt->dist > LZMA_DELTA_DIST_MAX)
70 | return UINT64_MAX;
71 |
72 | return sizeof(lzma_delta_coder);
73 | }
74 |
--------------------------------------------------------------------------------
/src/liblzma/delta/delta_common.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file delta_common.h
4 | /// \brief Common stuff for Delta encoder and decoder
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_DELTA_COMMON_H
14 | #define LZMA_DELTA_COMMON_H
15 |
16 | #include "common.h"
17 |
18 | extern uint64_t lzma_delta_coder_memusage(const void *options);
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/src/liblzma/delta/delta_decoder.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file delta_decoder.c
4 | /// \brief Delta filter decoder
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "delta_decoder.h"
14 | #include "delta_private.h"
15 |
16 |
17 | static void
18 | decode_buffer(lzma_delta_coder *coder, uint8_t *buffer, size_t size)
19 | {
20 | const size_t distance = coder->distance;
21 |
22 | for (size_t i = 0; i < size; ++i) {
23 | buffer[i] += coder->history[(distance + coder->pos) & 0xFF];
24 | coder->history[coder->pos-- & 0xFF] = buffer[i];
25 | }
26 | }
27 |
28 |
29 | static lzma_ret
30 | delta_decode(void *coder_ptr, const lzma_allocator *allocator,
31 | const uint8_t *restrict in, size_t *restrict in_pos,
32 | size_t in_size, uint8_t *restrict out,
33 | size_t *restrict out_pos, size_t out_size, lzma_action action)
34 | {
35 | lzma_delta_coder *coder = coder_ptr;
36 |
37 | assert(coder->next.code != NULL);
38 |
39 | const size_t out_start = *out_pos;
40 |
41 | const lzma_ret ret = coder->next.code(coder->next.coder, allocator,
42 | in, in_pos, in_size, out, out_pos, out_size,
43 | action);
44 |
45 | decode_buffer(coder, out + out_start, *out_pos - out_start);
46 |
47 | return ret;
48 | }
49 |
50 |
51 | extern lzma_ret
52 | lzma_delta_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
53 | const lzma_filter_info *filters)
54 | {
55 | next->code = &delta_decode;
56 | return lzma_delta_coder_init(next, allocator, filters);
57 | }
58 |
59 |
60 | extern lzma_ret
61 | lzma_delta_props_decode(void **options, const lzma_allocator *allocator,
62 | const uint8_t *props, size_t props_size)
63 | {
64 | if (props_size != 1)
65 | return LZMA_OPTIONS_ERROR;
66 |
67 | lzma_options_delta *opt
68 | = lzma_alloc(sizeof(lzma_options_delta), allocator);
69 | if (opt == NULL)
70 | return LZMA_MEM_ERROR;
71 |
72 | opt->type = LZMA_DELTA_TYPE_BYTE;
73 | opt->dist = props[0] + 1U;
74 |
75 | *options = opt;
76 |
77 | return LZMA_OK;
78 | }
79 |
--------------------------------------------------------------------------------
/src/liblzma/delta/delta_decoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file delta_decoder.h
4 | /// \brief Delta filter decoder
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_DELTA_DECODER_H
14 | #define LZMA_DELTA_DECODER_H
15 |
16 | #include "delta_common.h"
17 |
18 | extern lzma_ret lzma_delta_decoder_init(lzma_next_coder *next,
19 | const lzma_allocator *allocator,
20 | const lzma_filter_info *filters);
21 |
22 | extern lzma_ret lzma_delta_props_decode(
23 | void **options, const lzma_allocator *allocator,
24 | const uint8_t *props, size_t props_size);
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/src/liblzma/delta/delta_encoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file delta_encoder.h
4 | /// \brief Delta filter encoder
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_DELTA_ENCODER_H
14 | #define LZMA_DELTA_ENCODER_H
15 |
16 | #include "delta_common.h"
17 |
18 | extern lzma_ret lzma_delta_encoder_init(lzma_next_coder *next,
19 | const lzma_allocator *allocator,
20 | const lzma_filter_info *filters);
21 |
22 | extern lzma_ret lzma_delta_props_encode(const void *options, uint8_t *out);
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/src/liblzma/delta/delta_private.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file delta_private.h
4 | /// \brief Private common stuff for Delta encoder and decoder
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_DELTA_PRIVATE_H
14 | #define LZMA_DELTA_PRIVATE_H
15 |
16 | #include "delta_common.h"
17 |
18 | typedef struct {
19 | /// Next coder in the chain
20 | lzma_next_coder next;
21 |
22 | /// Delta distance
23 | size_t distance;
24 |
25 | /// Position in history[]
26 | uint8_t pos;
27 |
28 | /// Buffer to hold history of the original data
29 | uint8_t history[LZMA_DELTA_DIST_MAX];
30 | } lzma_delta_coder;
31 |
32 |
33 | extern lzma_ret lzma_delta_coder_init(
34 | lzma_next_coder *next, const lzma_allocator *allocator,
35 | const lzma_filter_info *filters);
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/src/liblzma/liblzma.pc.in:
--------------------------------------------------------------------------------
1 | #
2 | # Author: Lasse Collin
3 | #
4 | # This file has been put into the public domain.
5 | # You can do whatever you want with this file.
6 | #
7 |
8 | prefix=@prefix@
9 | exec_prefix=@exec_prefix@
10 | libdir=@libdir@
11 | includedir=@includedir@
12 |
13 | Name: libflzma
14 | Description: General purpose data compression library
15 | URL: @PACKAGE_URL@
16 | Version: @PACKAGE_VERSION@
17 | Cflags: -I${includedir}
18 | Libs: -L${libdir} -lflzma
19 | Libs.private: @PTHREAD_CFLAGS@ @LIBS@
20 |
--------------------------------------------------------------------------------
/src/liblzma/liblzma_w32res.rc:
--------------------------------------------------------------------------------
1 | /*
2 | * Author: Lasse Collin
3 | *
4 | * This file has been put into the public domain.
5 | * You can do whatever you want with this file.
6 | */
7 |
8 | #define MY_TYPE VFT_DLL
9 | #define MY_NAME "liblzma"
10 | #define MY_SUFFIX ".dll"
11 | #define MY_DESC "liblzma data compression library"
12 | #include "common_w32res.rc"
13 |
--------------------------------------------------------------------------------
/src/liblzma/lz/Makefile.inc:
--------------------------------------------------------------------------------
1 | ##
2 | ## Author: Lasse Collin
3 | ##
4 | ## This file has been put into the public domain.
5 | ## You can do whatever you want with this file.
6 | ##
7 |
8 | if COND_ENCODER_LZ
9 | libflzma_la_SOURCES += \
10 | lz/lz_encoder.c \
11 | lz/lz_encoder.h \
12 | lz/lz_encoder_hash.h \
13 | lz/lz_encoder_hash_table.h \
14 | lz/lz_encoder_mf.c
15 | endif
16 |
17 |
18 | if COND_DECODER_LZ
19 | libflzma_la_SOURCES += \
20 | lz/lz_decoder.c \
21 | lz/lz_decoder.h
22 | endif
23 |
--------------------------------------------------------------------------------
/src/liblzma/lzma/Makefile.inc:
--------------------------------------------------------------------------------
1 | ##
2 | ## Authors: Lasse Collin
3 | ## Conor McCarthy
4 | ##
5 | ## This file has been put into the public domain.
6 | ## You can do whatever you want with this file.
7 | ##
8 |
9 | EXTRA_DIST += lzma/fastpos_tablegen.c
10 |
11 | libflzma_la_SOURCES += lzma/lzma_common.h
12 |
13 | if COND_FILTER_LZMA1
14 | libflzma_la_SOURCES += \
15 | lzma/lzma_encoder_presets.c
16 | endif
17 |
18 | if COND_ENCODER_LZMA1
19 | libflzma_la_SOURCES += \
20 | lzma/fastpos.h \
21 | lzma/lzma_encoder.h \
22 | lzma/lzma_encoder.c \
23 | lzma/lzma_encoder_private.h \
24 | lzma/lzma_encoder_optimum_fast.c \
25 | lzma/lzma_encoder_optimum_normal.c
26 |
27 | if !COND_SMALL
28 | libflzma_la_SOURCES += lzma/fastpos_table.c
29 | endif
30 | endif
31 |
32 | if COND_DECODER_LZMA1
33 | libflzma_la_SOURCES += \
34 | lzma/lzma_decoder.c \
35 | lzma/lzma_decoder.h
36 |
37 | if COND_ASM_X86_64
38 | libflzma_la_SOURCES += lzma/lzma_dec_x86_64.S
39 | libflzma_la_CPPFLAGS += -DLZMA_ASM_OPT_64
40 | if COND_W32
41 | libflzma_la_CPPFLAGS += -DMS_x64_CALL=1
42 | else
43 | libflzma_la_CPPFLAGS += -DMS_x64_CALL=0
44 | endif
45 | endif
46 | endif
47 |
48 | if COND_ENCODER_LZMA2
49 | libflzma_la_SOURCES += \
50 | lzma/lzma2_encoder.c \
51 | lzma/lzma2_encoder.h \
52 | lzma/lzma2_encoder_rmf.c \
53 | lzma/lzma2_encoder_rmf.h \
54 | lzma/lzma2_fast_encoder.c \
55 | lzma/lzma2_fast_encoder.h \
56 | lzma/data_block.h
57 | endif
58 |
59 | if COND_DECODER_LZMA2
60 | libflzma_la_SOURCES += \
61 | lzma/lzma2_decoder.c \
62 | lzma/lzma2_decoder.h
63 | endif
64 |
--------------------------------------------------------------------------------
/src/liblzma/lzma/data_block.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file data_block.h
4 | /// \brief Radix match-finder overlapped data block
5 | ///
6 | // Author: Conor McCarthy
7 | //
8 | // This source code is licensed under both the BSD-style license (found in the
9 | // LICENSE file in the root directory of this source tree) and the GPLv2 (found
10 | // in the COPYING file in the root directory of this source tree).
11 | // You may select, at your option, one of the above-listed licenses.
12 | //
13 | ///////////////////////////////////////////////////////////////////////////////
14 |
15 | #ifndef LZMA_DATA_BLOCK_H
16 | #define LZMA_DATA_BLOCK_H
17 |
18 |
19 | typedef struct {
20 | const uint8_t *data;
21 | size_t start;
22 | size_t end;
23 | } lzma_data_block;
24 |
25 |
26 | #endif
--------------------------------------------------------------------------------
/src/liblzma/lzma/fastpos_tablegen.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file fastpos_tablegen.c
4 | /// \brief Generates the lzma_fastpos[] lookup table
5 | ///
6 | // Authors: Igor Pavlov
7 | // Lasse Collin
8 | //
9 | // This file has been put into the public domain.
10 | // You can do whatever you want with this file.
11 | //
12 | ///////////////////////////////////////////////////////////////////////////////
13 |
14 | #include
15 | #include
16 | #include "fastpos.h"
17 |
18 |
19 | int
20 | main(void)
21 | {
22 | uint8_t fastpos[1 << FASTPOS_BITS];
23 |
24 | const uint8_t fast_slots = 2 * FASTPOS_BITS;
25 | uint32_t c = 2;
26 |
27 | fastpos[0] = 0;
28 | fastpos[1] = 1;
29 |
30 | for (uint8_t slot_fast = 2; slot_fast < fast_slots; ++slot_fast) {
31 | const uint32_t k = 1 << ((slot_fast >> 1) - 1);
32 | for (uint32_t j = 0; j < k; ++j, ++c)
33 | fastpos[c] = slot_fast;
34 | }
35 |
36 | printf("/* This file has been automatically generated "
37 | "by fastpos_tablegen.c. */\n\n"
38 | "#include \"common.h\"\n"
39 | "#include \"fastpos.h\"\n\n"
40 | "const uint8_t lzma_fastpos[1 << FASTPOS_BITS] = {");
41 |
42 | for (size_t i = 0; i < (1 << FASTPOS_BITS); ++i) {
43 | if (i % 16 == 0)
44 | printf("\n\t");
45 |
46 | printf("%3u", (unsigned int)(fastpos[i]));
47 |
48 | if (i != (1 << FASTPOS_BITS) - 1)
49 | printf(",");
50 | }
51 |
52 | printf("\n};\n");
53 |
54 | return 0;
55 | }
56 |
--------------------------------------------------------------------------------
/src/liblzma/lzma/lzma2_decoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file lzma2_decoder.h
4 | /// \brief LZMA2 decoder
5 | ///
6 | // Authors: Igor Pavlov
7 | // Lasse Collin
8 | //
9 | // This file has been put into the public domain.
10 | // You can do whatever you want with this file.
11 | //
12 | ///////////////////////////////////////////////////////////////////////////////
13 |
14 | #ifndef LZMA_LZMA2_DECODER_H
15 | #define LZMA_LZMA2_DECODER_H
16 |
17 | #include "common.h"
18 |
19 | extern lzma_ret lzma_lzma2_decoder_init(lzma_next_coder *next,
20 | const lzma_allocator *allocator,
21 | const lzma_filter_info *filters);
22 |
23 | extern uint64_t lzma_lzma2_decoder_memusage(const void *options);
24 |
25 | extern lzma_ret lzma_lzma2_props_decode(
26 | void **options, const lzma_allocator *allocator,
27 | const uint8_t *props, size_t props_size);
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/src/liblzma/lzma/lzma2_encoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file lzma2_encoder.h
4 | /// \brief LZMA2 encoder
5 | ///
6 | // Authors: Igor Pavlov
7 | // Lasse Collin
8 | //
9 | // This file has been put into the public domain.
10 | // You can do whatever you want with this file.
11 | //
12 | ///////////////////////////////////////////////////////////////////////////////
13 |
14 | #ifndef LZMA_LZMA2_ENCODER_H
15 | #define LZMA_LZMA2_ENCODER_H
16 |
17 | #include "common.h"
18 |
19 |
20 | /// Maximum number of bytes of actual data per chunk (no headers)
21 | #define LZMA2_CHUNK_MAX (UINT32_C(1) << 16)
22 |
23 | /// Maximum uncompressed size of LZMA chunk (no headers)
24 | #define LZMA2_UNCOMPRESSED_MAX (UINT32_C(1) << 21)
25 |
26 | /// Maximum size of LZMA2 headers
27 | #define LZMA2_HEADER_MAX 6
28 |
29 | /// Size of a header for uncompressed chunk
30 | #define LZMA2_HEADER_UNCOMPRESSED 3
31 |
32 |
33 | extern lzma_ret lzma_lzma2_encoder_init(
34 | lzma_next_coder *next, const lzma_allocator *allocator,
35 | const lzma_filter_info *filters);
36 |
37 | extern uint64_t lzma_lzma2_encoder_memusage(const void *options);
38 |
39 | extern lzma_ret lzma_lzma2_props_encode(const void *options, uint8_t *out);
40 |
41 | extern uint64_t lzma_lzma2_block_size(const void *options);
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/src/liblzma/lzma/lzma2_fast_encoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file lzma2_fast_encoder.h
4 | /// \brief Fast LZMA2 encoder wrapper
5 | ///
6 | // Authors: Conor McCarthy
7 | // Lasse Collin
8 | //
9 | // This file has been put into the public domain.
10 | // You can do whatever you want with this file.
11 | //
12 | ///////////////////////////////////////////////////////////////////////////////
13 |
14 | #ifndef LZMA_LZMA2_FAST_ENCODER_H
15 | #define LZMA_LZMA2_FAST_ENCODER_H
16 |
17 | #include "common.h"
18 |
19 | extern lzma_ret lzma_flzma2_encoder_init(
20 | lzma_next_coder *next, const lzma_allocator *allocator,
21 | const lzma_filter_info *filters);
22 |
23 | extern uint64_t lzma_flzma2_encoder_memusage(const void *options);
24 |
25 | #endif
26 |
--------------------------------------------------------------------------------
/src/liblzma/lzma/lzma_decoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file lzma_decoder.h
4 | /// \brief LZMA decoder API
5 | ///
6 | // Authors: Igor Pavlov
7 | // Lasse Collin
8 | //
9 | // This file has been put into the public domain.
10 | // You can do whatever you want with this file.
11 | //
12 | ///////////////////////////////////////////////////////////////////////////////
13 |
14 | #ifndef LZMA_LZMA_DECODER_H
15 | #define LZMA_LZMA_DECODER_H
16 |
17 | #include "common.h"
18 |
19 |
20 | /// Allocates and initializes LZMA decoder
21 | extern lzma_ret lzma_lzma_decoder_init(lzma_next_coder *next,
22 | const lzma_allocator *allocator,
23 | const lzma_filter_info *filters);
24 |
25 | extern uint64_t lzma_lzma_decoder_memusage(const void *options);
26 |
27 | extern lzma_ret lzma_lzma_props_decode(
28 | void **options, const lzma_allocator *allocator,
29 | const uint8_t *props, size_t props_size);
30 |
31 |
32 | /// \brief Decodes the LZMA Properties byte (lc/lp/pb)
33 | ///
34 | /// \return true if error occurred, false on success
35 | ///
36 | extern bool lzma_lzma_lclppb_decode(
37 | lzma_options_lzma *options, uint8_t byte);
38 |
39 |
40 | #ifdef LZMA_LZ_DECODER_H
41 | /// Allocate and setup function pointers only. This is used by LZMA1 and
42 | /// LZMA2 decoders.
43 | extern lzma_ret lzma_lzma_decoder_create(
44 | lzma_lz_decoder *lz, const lzma_allocator *allocator,
45 | const void *opt, lzma_lz_options *lz_options);
46 |
47 | /// Gets memory usage without validating lc/lp/pb. This is used by LZMA2
48 | /// decoder, because raw LZMA2 decoding doesn't need lc/lp/pb.
49 | extern uint64_t lzma_lzma_decoder_memusage_nocheck(const void *options);
50 |
51 | #endif
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/src/liblzma/lzma/lzma_encoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file lzma_encoder.h
4 | /// \brief LZMA encoder API
5 | ///
6 | // Authors: Igor Pavlov
7 | // Lasse Collin
8 | //
9 | // This file has been put into the public domain.
10 | // You can do whatever you want with this file.
11 | //
12 | ///////////////////////////////////////////////////////////////////////////////
13 |
14 | #ifndef LZMA_LZMA_ENCODER_H
15 | #define LZMA_LZMA_ENCODER_H
16 |
17 | #include "common.h"
18 |
19 |
20 | typedef struct lzma_lzma1_encoder_s lzma_lzma1_encoder;
21 |
22 |
23 | extern lzma_ret lzma_lzma_encoder_init(lzma_next_coder *next,
24 | const lzma_allocator *allocator,
25 | const lzma_filter_info *filters);
26 |
27 |
28 | extern uint64_t lzma_lzma_encoder_memusage(const void *options);
29 |
30 | extern lzma_ret lzma_lzma_props_encode(const void *options, uint8_t *out);
31 |
32 |
33 | /// Encodes lc/lp/pb into one byte. Returns false on success and true on error.
34 | extern bool lzma_lzma_lclppb_encode(
35 | const lzma_options_lzma *options, uint8_t *byte);
36 |
37 |
38 | #ifdef LZMA_LZ_ENCODER_H
39 |
40 | /// Initializes raw LZMA encoder; this is used by LZMA2.
41 | extern lzma_ret lzma_lzma_encoder_create(
42 | void **coder_ptr, const lzma_allocator *allocator,
43 | const lzma_options_lzma *options, lzma_lz_options *lz_options);
44 |
45 |
46 | /// Resets an already initialized LZMA encoder; this is used by LZMA2.
47 | extern lzma_ret lzma_lzma_encoder_reset(
48 | lzma_lzma1_encoder *coder, const lzma_options_lzma *options);
49 |
50 |
51 | extern lzma_ret lzma_lzma_encode(lzma_lzma1_encoder *restrict coder,
52 | lzma_mf *restrict mf, uint8_t *restrict out,
53 | size_t *restrict out_pos, size_t out_size,
54 | uint32_t read_limit);
55 |
56 | #endif
57 |
58 | #endif
59 |
--------------------------------------------------------------------------------
/src/liblzma/radix/Makefile.inc:
--------------------------------------------------------------------------------
1 | ##
2 | ## Author: Conor McCarthy
3 | ##
4 | ## This file has been put into the public domain.
5 | ## You can do whatever you want with this file.
6 | ##
7 |
8 | if COND_ENCODER_LZMA2
9 | libflzma_la_SOURCES += \
10 | radix/radix_bitpack.c \
11 | radix/radix_engine.h \
12 | radix/radix_get.h \
13 | radix/radix_internal.h \
14 | radix/radix_mf.c \
15 | radix/radix_mf.h \
16 | radix/radix_struct.c
17 | endif
18 |
--------------------------------------------------------------------------------
/src/liblzma/radix/radix_bitpack.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file radix_bitpack.c
4 | /// \brief Radix match-finder for uint32_t table
5 | ///
6 | // Author: Conor McCarthy
7 | //
8 | // This source code is licensed under both the BSD-style license (found in the
9 | // LICENSE file in the root directory of this source tree) and the GPLv2 (found
10 | // in the COPYING file in the root directory of this source tree).
11 | // You may select, at your option, one of the above-listed licenses.
12 | //
13 | ///////////////////////////////////////////////////////////////////////////////
14 |
15 | #include "radix_internal.h"
16 |
17 |
18 | #define RMF_BITPACK
19 |
20 | #define RADIX_MAX_LENGTH BITPACK_MAX_LENGTH
21 |
22 | #define init_match_link(pos, link) tbl->table[pos] = link
23 |
24 | #define get_match_link(link) (tbl->table[link] & RADIX_LINK_MASK)
25 |
26 | #define get_raw_match_link(pos) tbl->table[pos]
27 |
28 | #define get_match_length(pos) (tbl->table[pos] >> RADIX_LINK_BITS)
29 |
30 | #define set_match_length(pos, link, length) tbl->table[pos] = (link) | ((uint32_t)(length) << RADIX_LINK_BITS)
31 |
32 | #define set_match_link_and_length(pos, link, length) \
33 | tbl->table[pos] = (link) | ((uint32_t)(length) << RADIX_LINK_BITS)
34 |
35 | #define set_null(pos) tbl->table[pos] = RADIX_NULL_LINK
36 |
37 | #define is_null(pos) (tbl->table[pos] == RADIX_NULL_LINK)
38 |
39 |
40 | extern uint8_t*
41 | rmf_bitpack_output_buffer(rmf_match_table* const tbl, size_t const pos)
42 | {
43 | return (uint8_t*)(tbl->table + pos);
44 | }
45 |
46 |
47 | // Restrict the match lengths so that they don't reach beyond pos.
48 | extern void
49 | rmf_bitpack_limit_lengths(rmf_match_table* const tbl, size_t const pos)
50 | {
51 | set_null(pos - 1);
52 | for (uint32_t length = 2; length < RADIX_MAX_LENGTH && length <= pos; ++length) {
53 | uint32_t const link = tbl->table[pos - length];
54 | if (link != RADIX_NULL_LINK)
55 | tbl->table[pos - length] = (my_min(length, link >> RADIX_LINK_BITS) << RADIX_LINK_BITS) | (link & RADIX_LINK_MASK);
56 | }
57 | }
58 |
59 |
60 | #include "radix_engine.h"
--------------------------------------------------------------------------------
/src/liblzma/radix/radix_internal.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file radix_internal.h
4 | /// \brief Radix match-finder definitions and declarations
5 | ///
6 | // Author: Conor McCarthy
7 | //
8 | // This source code is licensed under both the BSD-style license (found in the
9 | // LICENSE file in the root directory of this source tree) and the GPLv2 (found
10 | // in the COPYING file in the root directory of this source tree).
11 | // You may select, at your option, one of the above-listed licenses.
12 | //
13 | ///////////////////////////////////////////////////////////////////////////////
14 |
15 | #ifndef LZMA_RADIX_INTERNAL_H
16 | #define LZMA_RADIX_INTERNAL_H
17 |
18 | #include "common.h"
19 | #include "radix_mf.h"
20 | #include "lzma_encoder_private.h"
21 |
22 |
23 | #define DICTIONARY_SIZE_MIN (1U << 12)
24 | #define DICTIONARY_SIZE_MAX (UINT32_C(3) << 29)
25 | #define MAX_REPEAT 24
26 | #define MAX_BRUTE_FORCE_LIST_SIZE 5
27 | #define BUFFER_LINK_MASK 0xFFFFFFU
28 | #define MATCH_BUFFER_OVERLAP 6
29 | #define DEPTH_MIN 6U
30 | #define DEPTH_MAX 254U
31 | #define OVERLAP_MAX 14
32 |
33 | // Table building is stopped by adding this value to the stack atomic index.
34 | #define RADIX_CANCEL_INDEX (long)(RADIX16_TABLE_SIZE + LZMA_THREADS_MAX + 2)
35 |
36 |
37 | extern void rmf_bitpack_init(rmf_match_table* const tbl, const void* data, size_t const end);
38 |
39 | extern void rmf_structured_init(rmf_match_table* const tbl, const void* data, size_t const end);
40 |
41 | extern void rmf_bitpack_build_table(rmf_match_table* const tbl,
42 | rmf_builder* const builder,
43 | int const thread,
44 | lzma_data_block const block);
45 |
46 | extern void rmf_structured_build_table(rmf_match_table* const tbl,
47 | rmf_builder* const builder,
48 | int const thread,
49 | lzma_data_block const block);
50 |
51 | extern void rmf_recurse_list_chunk(rmf_builder* const tbl,
52 | const uint8_t* const data_block,
53 | size_t const block_start,
54 | uint32_t const depth,
55 | uint32_t const max_depth,
56 | uint32_t const list_count,
57 | size_t const stack_base);
58 |
59 | extern void rmf_bitpack_limit_lengths(rmf_match_table* const tbl, size_t const pos);
60 |
61 | extern void rmf_structured_limit_lengths(rmf_match_table* const tbl, size_t const pos);
62 |
63 | extern uint8_t* rmf_bitpack_output_buffer(rmf_match_table* const tbl, size_t const pos);
64 |
65 | extern uint8_t* rmf_structured_output_buffer(rmf_match_table* const tbl, size_t const pos);
66 |
67 | #endif // LZMA_RADIX_INTERNAL_H
--------------------------------------------------------------------------------
/src/liblzma/rangecoder/Makefile.inc:
--------------------------------------------------------------------------------
1 | ##
2 | ## Authors: Lasse Collin
3 | ## Conor McCarthy
4 | ##
5 | ## This file has been put into the public domain.
6 | ## You can do whatever you want with this file.
7 | ##
8 |
9 | EXTRA_DIST += rangecoder/price_tablegen.c
10 |
11 | libflzma_la_SOURCES += rangecoder/range_common.h
12 |
13 | if COND_ENCODER_LZMA1
14 | libflzma_la_SOURCES += \
15 | rangecoder/range_encoder.h \
16 | rangecoder/price.h \
17 | rangecoder/price_table.c
18 | endif
19 |
20 | if COND_ENCODER_LZMA2
21 | libflzma_la_SOURCES += \
22 | rangecoder/range_fast_enc.h \
23 | rangecoder/range_fast_enc.c
24 | endif
25 |
26 | if COND_DECODER_LZMA1
27 | libflzma_la_SOURCES += rangecoder/range_decoder.h
28 | endif
29 |
--------------------------------------------------------------------------------
/src/liblzma/rangecoder/price.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file price.h
4 | /// \brief Probability price calculation
5 | //
6 | // Author: Igor Pavlov
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_PRICE_H
14 | #define LZMA_PRICE_H
15 |
16 |
17 | #define RC_MOVE_REDUCING_BITS 4
18 | #define RC_BIT_PRICE_SHIFT_BITS 5
19 | #define RC_PRICE_TABLE_SIZE (RC_BIT_MODEL_TOTAL >> RC_MOVE_REDUCING_BITS)
20 |
21 | #define RC_INFINITY_PRICE (UINT32_C(1) << 30)
22 |
23 |
24 | /// Lookup table for the inline functions defined in this file.
25 | extern const uint8_t lzma_rc_prices[2][RC_PRICE_TABLE_SIZE];
26 |
27 |
28 | static inline uint32_t
29 | rc_bit_price(const probability prob, const uint32_t bit)
30 | {
31 | return lzma_rc_prices[bit][prob >> RC_MOVE_REDUCING_BITS];
32 | }
33 |
34 |
35 | static inline uint32_t
36 | rc_bit_0_price(const probability prob)
37 | {
38 | return lzma_rc_prices[0][prob >> RC_MOVE_REDUCING_BITS];
39 | }
40 |
41 |
42 | static inline uint32_t
43 | rc_bit_1_price(const probability prob)
44 | {
45 | return lzma_rc_prices[1][prob >> RC_MOVE_REDUCING_BITS];
46 | }
47 |
48 |
49 | static inline uint32_t
50 | rc_bittree_price(const probability *const probs,
51 | const uint32_t bit_levels, uint32_t symbol)
52 | {
53 | uint32_t price = 0;
54 | symbol += UINT32_C(1) << bit_levels;
55 |
56 | do {
57 | const uint32_t bit = symbol & 1;
58 | symbol >>= 1;
59 | price += rc_bit_price(probs[symbol], bit);
60 | } while (symbol != 1);
61 |
62 | return price;
63 | }
64 |
65 |
66 | static inline uint32_t
67 | rc_bittree_reverse_price(const probability *const probs,
68 | uint32_t bit_levels, uint32_t symbol)
69 | {
70 | uint32_t price = 0;
71 | uint32_t model_index = 1;
72 |
73 | do {
74 | const uint32_t bit = symbol & 1;
75 | symbol >>= 1;
76 | price += rc_bit_price(probs[model_index], bit);
77 | model_index = (model_index << 1) + bit;
78 | } while (--bit_levels != 0);
79 |
80 | return price;
81 | }
82 |
83 |
84 | static inline uint32_t
85 | rc_direct_price(const uint32_t bits)
86 | {
87 | return bits << RC_BIT_PRICE_SHIFT_BITS;
88 | }
89 |
90 | #endif
91 |
--------------------------------------------------------------------------------
/src/liblzma/rangecoder/price_table.c:
--------------------------------------------------------------------------------
1 | // This file has been automatically generated by price_tablegen.c.
2 | // The first and last elements of each table are never used.
3 |
4 | #include "range_encoder.h"
5 |
6 | const uint8_t lzma_rc_prices[2][RC_PRICE_TABLE_SIZE] = { {
7 | 0, 193, 182, 166, 154, 145, 137, 131,
8 | 125, 120, 115, 111, 107, 103, 100, 97,
9 | 94, 91, 89, 86, 84, 82, 80, 78,
10 | 76, 74, 72, 71, 69, 67, 66, 64,
11 | 63, 61, 60, 59, 57, 56, 55, 54,
12 | 53, 52, 50, 49, 48, 47, 46, 45,
13 | 44, 43, 42, 42, 41, 40, 39, 38,
14 | 37, 36, 36, 35, 34, 33, 33, 32,
15 | 31, 30, 30, 29, 28, 28, 27, 26,
16 | 26, 25, 25, 24, 23, 23, 22, 21,
17 | 21, 20, 20, 19, 19, 18, 18, 17,
18 | 17, 16, 16, 15, 15, 14, 14, 13,
19 | 13, 12, 12, 11, 11, 10, 10, 9,
20 | 9, 8, 8, 8, 7, 7, 6, 6,
21 | 5, 5, 5, 4, 4, 3, 3, 3,
22 | 2, 2, 2, 1, 1, 0, 0, 0
23 | }, {
24 |
25 | 0, 0, 0, 1, 1, 2, 2, 2,
26 | 3, 3, 3, 4, 4, 5, 5, 5,
27 | 6, 6, 7, 7, 8, 8, 8, 9,
28 | 9, 10, 10, 11, 11, 12, 12, 13,
29 | 13, 13, 14, 14, 15, 15, 16, 17,
30 | 17, 18, 18, 19, 19, 20, 20, 21,
31 | 21, 22, 23, 23, 24, 24, 25, 26,
32 | 26, 27, 28, 28, 29, 30, 30, 31,
33 | 32, 33, 33, 34, 35, 36, 36, 37,
34 | 38, 39, 40, 41, 41, 42, 43, 44,
35 | 45, 46, 47, 48, 49, 50, 51, 53,
36 | 54, 55, 56, 57, 59, 60, 61, 63,
37 | 64, 66, 67, 69, 70, 72, 74, 76,
38 | 78, 80, 82, 84, 86, 89, 91, 94,
39 | 97, 100, 103, 107, 111, 115, 119, 125,
40 | 130, 137, 145, 154, 165, 181, 192, 0
41 | } };
42 |
--------------------------------------------------------------------------------
/src/liblzma/simple/Makefile.inc:
--------------------------------------------------------------------------------
1 | ##
2 | ## Author: Lasse Collin
3 | ##
4 | ## This file has been put into the public domain.
5 | ## You can do whatever you want with this file.
6 | ##
7 |
8 | libflzma_la_SOURCES += \
9 | simple/simple_coder.c \
10 | simple/simple_coder.h \
11 | simple/simple_private.h
12 |
13 | if COND_ENCODER_SIMPLE
14 | libflzma_la_SOURCES += \
15 | simple/simple_encoder.c \
16 | simple/simple_encoder.h
17 | endif
18 |
19 | if COND_DECODER_SIMPLE
20 | libflzma_la_SOURCES += \
21 | simple/simple_decoder.c \
22 | simple/simple_decoder.h
23 | endif
24 |
25 | if COND_FILTER_X86
26 | libflzma_la_SOURCES += simple/x86.c
27 | endif
28 |
29 | if COND_FILTER_POWERPC
30 | libflzma_la_SOURCES += simple/powerpc.c
31 | endif
32 |
33 | if COND_FILTER_IA64
34 | libflzma_la_SOURCES += simple/ia64.c
35 | endif
36 |
37 | if COND_FILTER_ARM
38 | libflzma_la_SOURCES += simple/arm.c
39 | endif
40 |
41 | if COND_FILTER_ARMTHUMB
42 | libflzma_la_SOURCES += simple/armthumb.c
43 | endif
44 |
45 | if COND_FILTER_SPARC
46 | libflzma_la_SOURCES += simple/sparc.c
47 | endif
48 |
--------------------------------------------------------------------------------
/src/liblzma/simple/arm.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file arm.c
4 | /// \brief Filter for ARM binaries
5 | ///
6 | // Authors: Igor Pavlov
7 | // Lasse Collin
8 | //
9 | // This file has been put into the public domain.
10 | // You can do whatever you want with this file.
11 | //
12 | ///////////////////////////////////////////////////////////////////////////////
13 |
14 | #include "simple_private.h"
15 |
16 |
17 | static size_t
18 | arm_code(void *simple lzma_attribute((__unused__)),
19 | uint32_t now_pos, bool is_encoder,
20 | uint8_t *buffer, size_t size)
21 | {
22 | size_t i;
23 | for (i = 0; i + 4 <= size; i += 4) {
24 | if (buffer[i + 3] == 0xEB) {
25 | uint32_t src = ((uint32_t)(buffer[i + 2]) << 16)
26 | | ((uint32_t)(buffer[i + 1]) << 8)
27 | | (uint32_t)(buffer[i + 0]);
28 | src <<= 2;
29 |
30 | uint32_t dest;
31 | if (is_encoder)
32 | dest = now_pos + (uint32_t)(i) + 8 + src;
33 | else
34 | dest = src - (now_pos + (uint32_t)(i) + 8);
35 |
36 | dest >>= 2;
37 | buffer[i + 2] = (dest >> 16);
38 | buffer[i + 1] = (dest >> 8);
39 | buffer[i + 0] = dest;
40 | }
41 | }
42 |
43 | return i;
44 | }
45 |
46 |
47 | static lzma_ret
48 | arm_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
49 | const lzma_filter_info *filters, bool is_encoder)
50 | {
51 | return lzma_simple_coder_init(next, allocator, filters,
52 | &arm_code, 0, 4, 4, is_encoder);
53 | }
54 |
55 |
56 | extern lzma_ret
57 | lzma_simple_arm_encoder_init(lzma_next_coder *next,
58 | const lzma_allocator *allocator,
59 | const lzma_filter_info *filters)
60 | {
61 | return arm_coder_init(next, allocator, filters, true);
62 | }
63 |
64 |
65 | extern lzma_ret
66 | lzma_simple_arm_decoder_init(lzma_next_coder *next,
67 | const lzma_allocator *allocator,
68 | const lzma_filter_info *filters)
69 | {
70 | return arm_coder_init(next, allocator, filters, false);
71 | }
72 |
--------------------------------------------------------------------------------
/src/liblzma/simple/armthumb.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file armthumb.c
4 | /// \brief Filter for ARM-Thumb binaries
5 | ///
6 | // Authors: Igor Pavlov
7 | // Lasse Collin
8 | //
9 | // This file has been put into the public domain.
10 | // You can do whatever you want with this file.
11 | //
12 | ///////////////////////////////////////////////////////////////////////////////
13 |
14 | #include "simple_private.h"
15 |
16 |
17 | static size_t
18 | armthumb_code(void *simple lzma_attribute((__unused__)),
19 | uint32_t now_pos, bool is_encoder,
20 | uint8_t *buffer, size_t size)
21 | {
22 | size_t i;
23 | for (i = 0; i + 4 <= size; i += 2) {
24 | if ((buffer[i + 1] & 0xF8) == 0xF0
25 | && (buffer[i + 3] & 0xF8) == 0xF8) {
26 | uint32_t src = (((uint32_t)(buffer[i + 1]) & 7) << 19)
27 | | ((uint32_t)(buffer[i + 0]) << 11)
28 | | (((uint32_t)(buffer[i + 3]) & 7) << 8)
29 | | (uint32_t)(buffer[i + 2]);
30 |
31 | src <<= 1;
32 |
33 | uint32_t dest;
34 | if (is_encoder)
35 | dest = now_pos + (uint32_t)(i) + 4 + src;
36 | else
37 | dest = src - (now_pos + (uint32_t)(i) + 4);
38 |
39 | dest >>= 1;
40 | buffer[i + 1] = 0xF0 | ((dest >> 19) & 0x7);
41 | buffer[i + 0] = (dest >> 11);
42 | buffer[i + 3] = 0xF8 | ((dest >> 8) & 0x7);
43 | buffer[i + 2] = (dest);
44 | i += 2;
45 | }
46 | }
47 |
48 | return i;
49 | }
50 |
51 |
52 | static lzma_ret
53 | armthumb_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
54 | const lzma_filter_info *filters, bool is_encoder)
55 | {
56 | return lzma_simple_coder_init(next, allocator, filters,
57 | &armthumb_code, 0, 4, 2, is_encoder);
58 | }
59 |
60 |
61 | extern lzma_ret
62 | lzma_simple_armthumb_encoder_init(lzma_next_coder *next,
63 | const lzma_allocator *allocator,
64 | const lzma_filter_info *filters)
65 | {
66 | return armthumb_coder_init(next, allocator, filters, true);
67 | }
68 |
69 |
70 | extern lzma_ret
71 | lzma_simple_armthumb_decoder_init(lzma_next_coder *next,
72 | const lzma_allocator *allocator,
73 | const lzma_filter_info *filters)
74 | {
75 | return armthumb_coder_init(next, allocator, filters, false);
76 | }
77 |
--------------------------------------------------------------------------------
/src/liblzma/simple/powerpc.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file powerpc.c
4 | /// \brief Filter for PowerPC (big endian) binaries
5 | ///
6 | // Authors: Igor Pavlov
7 | // Lasse Collin
8 | //
9 | // This file has been put into the public domain.
10 | // You can do whatever you want with this file.
11 | //
12 | ///////////////////////////////////////////////////////////////////////////////
13 |
14 | #include "simple_private.h"
15 |
16 |
17 | static size_t
18 | powerpc_code(void *simple lzma_attribute((__unused__)),
19 | uint32_t now_pos, bool is_encoder,
20 | uint8_t *buffer, size_t size)
21 | {
22 | size_t i;
23 | for (i = 0; i + 4 <= size; i += 4) {
24 | // PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link)
25 | if ((buffer[i] >> 2) == 0x12
26 | && ((buffer[i + 3] & 3) == 1)) {
27 |
28 | const uint32_t src
29 | = (((uint32_t)(buffer[i + 0]) & 3) << 24)
30 | | ((uint32_t)(buffer[i + 1]) << 16)
31 | | ((uint32_t)(buffer[i + 2]) << 8)
32 | | ((uint32_t)(buffer[i + 3]) & ~UINT32_C(3));
33 |
34 | uint32_t dest;
35 | if (is_encoder)
36 | dest = now_pos + (uint32_t)(i) + src;
37 | else
38 | dest = src - (now_pos + (uint32_t)(i));
39 |
40 | buffer[i + 0] = 0x48 | ((dest >> 24) & 0x03);
41 | buffer[i + 1] = (dest >> 16);
42 | buffer[i + 2] = (dest >> 8);
43 | buffer[i + 3] &= 0x03;
44 | buffer[i + 3] |= dest;
45 | }
46 | }
47 |
48 | return i;
49 | }
50 |
51 |
52 | static lzma_ret
53 | powerpc_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
54 | const lzma_filter_info *filters, bool is_encoder)
55 | {
56 | return lzma_simple_coder_init(next, allocator, filters,
57 | &powerpc_code, 0, 4, 4, is_encoder);
58 | }
59 |
60 |
61 | extern lzma_ret
62 | lzma_simple_powerpc_encoder_init(lzma_next_coder *next,
63 | const lzma_allocator *allocator,
64 | const lzma_filter_info *filters)
65 | {
66 | return powerpc_coder_init(next, allocator, filters, true);
67 | }
68 |
69 |
70 | extern lzma_ret
71 | lzma_simple_powerpc_decoder_init(lzma_next_coder *next,
72 | const lzma_allocator *allocator,
73 | const lzma_filter_info *filters)
74 | {
75 | return powerpc_coder_init(next, allocator, filters, false);
76 | }
77 |
--------------------------------------------------------------------------------
/src/liblzma/simple/simple_coder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file simple_coder.h
4 | /// \brief Wrapper for simple filters
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_SIMPLE_CODER_H
14 | #define LZMA_SIMPLE_CODER_H
15 |
16 | #include "common.h"
17 |
18 |
19 | extern lzma_ret lzma_simple_x86_encoder_init(lzma_next_coder *next,
20 | const lzma_allocator *allocator,
21 | const lzma_filter_info *filters);
22 |
23 | extern lzma_ret lzma_simple_x86_decoder_init(lzma_next_coder *next,
24 | const lzma_allocator *allocator,
25 | const lzma_filter_info *filters);
26 |
27 |
28 | extern lzma_ret lzma_simple_powerpc_encoder_init(lzma_next_coder *next,
29 | const lzma_allocator *allocator,
30 | const lzma_filter_info *filters);
31 |
32 | extern lzma_ret lzma_simple_powerpc_decoder_init(lzma_next_coder *next,
33 | const lzma_allocator *allocator,
34 | const lzma_filter_info *filters);
35 |
36 |
37 | extern lzma_ret lzma_simple_ia64_encoder_init(lzma_next_coder *next,
38 | const lzma_allocator *allocator,
39 | const lzma_filter_info *filters);
40 |
41 | extern lzma_ret lzma_simple_ia64_decoder_init(lzma_next_coder *next,
42 | const lzma_allocator *allocator,
43 | const lzma_filter_info *filters);
44 |
45 |
46 | extern lzma_ret lzma_simple_arm_encoder_init(lzma_next_coder *next,
47 | const lzma_allocator *allocator,
48 | const lzma_filter_info *filters);
49 |
50 | extern lzma_ret lzma_simple_arm_decoder_init(lzma_next_coder *next,
51 | const lzma_allocator *allocator,
52 | const lzma_filter_info *filters);
53 |
54 |
55 | extern lzma_ret lzma_simple_armthumb_encoder_init(lzma_next_coder *next,
56 | const lzma_allocator *allocator,
57 | const lzma_filter_info *filters);
58 |
59 | extern lzma_ret lzma_simple_armthumb_decoder_init(lzma_next_coder *next,
60 | const lzma_allocator *allocator,
61 | const lzma_filter_info *filters);
62 |
63 |
64 | extern lzma_ret lzma_simple_sparc_encoder_init(lzma_next_coder *next,
65 | const lzma_allocator *allocator,
66 | const lzma_filter_info *filters);
67 |
68 | extern lzma_ret lzma_simple_sparc_decoder_init(lzma_next_coder *next,
69 | const lzma_allocator *allocator,
70 | const lzma_filter_info *filters);
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/src/liblzma/simple/simple_decoder.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file simple_decoder.c
4 | /// \brief Properties decoder for simple filters
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "simple_decoder.h"
14 |
15 |
16 | extern lzma_ret
17 | lzma_simple_props_decode(void **options, const lzma_allocator *allocator,
18 | const uint8_t *props, size_t props_size)
19 | {
20 | if (props_size == 0)
21 | return LZMA_OK;
22 |
23 | if (props_size != 4)
24 | return LZMA_OPTIONS_ERROR;
25 |
26 | lzma_options_bcj *opt = lzma_alloc(
27 | sizeof(lzma_options_bcj), allocator);
28 | if (opt == NULL)
29 | return LZMA_MEM_ERROR;
30 |
31 | opt->start_offset = read32le(props);
32 |
33 | // Don't leave an options structure allocated if start_offset is zero.
34 | if (opt->start_offset == 0)
35 | lzma_free(opt, allocator);
36 | else
37 | *options = opt;
38 |
39 | return LZMA_OK;
40 | }
41 |
--------------------------------------------------------------------------------
/src/liblzma/simple/simple_decoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file simple_decoder.h
4 | /// \brief Properties decoder for simple filters
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_SIMPLE_DECODER_H
14 | #define LZMA_SIMPLE_DECODER_H
15 |
16 | #include "simple_coder.h"
17 |
18 | extern lzma_ret lzma_simple_props_decode(
19 | void **options, const lzma_allocator *allocator,
20 | const uint8_t *props, size_t props_size);
21 |
22 | #endif
23 |
--------------------------------------------------------------------------------
/src/liblzma/simple/simple_encoder.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file simple_encoder.c
4 | /// \brief Properties encoder for simple filters
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "simple_encoder.h"
14 |
15 |
16 | extern lzma_ret
17 | lzma_simple_props_size(uint32_t *size, const void *options)
18 | {
19 | const lzma_options_bcj *const opt = options;
20 | *size = (opt == NULL || opt->start_offset == 0) ? 0 : 4;
21 | return LZMA_OK;
22 | }
23 |
24 |
25 | extern lzma_ret
26 | lzma_simple_props_encode(const void *options, uint8_t *out)
27 | {
28 | const lzma_options_bcj *const opt = options;
29 |
30 | // The default start offset is zero, so we don't need to store any
31 | // options unless the start offset is non-zero.
32 | if (opt == NULL || opt->start_offset == 0)
33 | return LZMA_OK;
34 |
35 | write32le(out, opt->start_offset);
36 |
37 | return LZMA_OK;
38 | }
39 |
--------------------------------------------------------------------------------
/src/liblzma/simple/simple_encoder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file simple_encoder.c
4 | /// \brief Properties encoder for simple filters
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_SIMPLE_ENCODER_H
14 | #define LZMA_SIMPLE_ENCODER_H
15 |
16 | #include "simple_coder.h"
17 |
18 |
19 | extern lzma_ret lzma_simple_props_size(uint32_t *size, const void *options);
20 |
21 | extern lzma_ret lzma_simple_props_encode(const void *options, uint8_t *out);
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/src/liblzma/simple/simple_private.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file simple_private.h
4 | /// \brief Private definitions for so called simple filters
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #ifndef LZMA_SIMPLE_PRIVATE_H
14 | #define LZMA_SIMPLE_PRIVATE_H
15 |
16 | #include "simple_coder.h"
17 |
18 |
19 | typedef struct {
20 | /// Next filter in the chain
21 | lzma_next_coder next;
22 |
23 | /// True if the next coder in the chain has returned LZMA_STREAM_END.
24 | bool end_was_reached;
25 |
26 | /// True if filter() should encode the data; false to decode.
27 | /// Currently all simple filters use the same function for encoding
28 | /// and decoding, because the difference between encoders and decoders
29 | /// is very small.
30 | bool is_encoder;
31 |
32 | /// Pointer to filter-specific function, which does
33 | /// the actual filtering.
34 | size_t (*filter)(void *simple, uint32_t now_pos,
35 | bool is_encoder, uint8_t *buffer, size_t size);
36 |
37 | /// Pointer to filter-specific data, or NULL if filter doesn't need
38 | /// any extra data.
39 | void *simple;
40 |
41 | /// The lowest 32 bits of the current position in the data. Most
42 | /// filters need this to do conversions between absolute and relative
43 | /// addresses.
44 | uint32_t now_pos;
45 |
46 | /// Size of the memory allocated for the buffer.
47 | size_t allocated;
48 |
49 | /// Flushing position in the temporary buffer. buffer[pos] is the
50 | /// next byte to be copied to out[].
51 | size_t pos;
52 |
53 | /// buffer[filtered] is the first unfiltered byte. When pos is smaller
54 | /// than filtered, there is unflushed filtered data in the buffer.
55 | size_t filtered;
56 |
57 | /// Total number of bytes (both filtered and unfiltered) currently
58 | /// in the temporary buffer.
59 | size_t size;
60 |
61 | /// Temporary buffer
62 | uint8_t buffer[];
63 | } lzma_simple_coder;
64 |
65 |
66 | extern lzma_ret lzma_simple_coder_init(lzma_next_coder *next,
67 | const lzma_allocator *allocator,
68 | const lzma_filter_info *filters,
69 | size_t (*filter)(void *simple, uint32_t now_pos,
70 | bool is_encoder, uint8_t *buffer, size_t size),
71 | size_t simple_size, size_t unfiltered_max,
72 | uint32_t alignment, bool is_encoder);
73 |
74 | #endif
75 |
--------------------------------------------------------------------------------
/src/liblzma/simple/sparc.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file sparc.c
4 | /// \brief Filter for SPARC binaries
5 | ///
6 | // Authors: Igor Pavlov
7 | // Lasse Collin
8 | //
9 | // This file has been put into the public domain.
10 | // You can do whatever you want with this file.
11 | //
12 | ///////////////////////////////////////////////////////////////////////////////
13 |
14 | #include "simple_private.h"
15 |
16 |
17 | static size_t
18 | sparc_code(void *simple lzma_attribute((__unused__)),
19 | uint32_t now_pos, bool is_encoder,
20 | uint8_t *buffer, size_t size)
21 | {
22 | size_t i;
23 | for (i = 0; i + 4 <= size; i += 4) {
24 |
25 | if ((buffer[i] == 0x40 && (buffer[i + 1] & 0xC0) == 0x00)
26 | || (buffer[i] == 0x7F
27 | && (buffer[i + 1] & 0xC0) == 0xC0)) {
28 |
29 | uint32_t src = ((uint32_t)buffer[i + 0] << 24)
30 | | ((uint32_t)buffer[i + 1] << 16)
31 | | ((uint32_t)buffer[i + 2] << 8)
32 | | ((uint32_t)buffer[i + 3]);
33 |
34 | src <<= 2;
35 |
36 | uint32_t dest;
37 | if (is_encoder)
38 | dest = now_pos + (uint32_t)(i) + src;
39 | else
40 | dest = src - (now_pos + (uint32_t)(i));
41 |
42 | dest >>= 2;
43 |
44 | dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF)
45 | | (dest & 0x3FFFFF)
46 | | 0x40000000;
47 |
48 | buffer[i + 0] = (uint8_t)(dest >> 24);
49 | buffer[i + 1] = (uint8_t)(dest >> 16);
50 | buffer[i + 2] = (uint8_t)(dest >> 8);
51 | buffer[i + 3] = (uint8_t)(dest);
52 | }
53 | }
54 |
55 | return i;
56 | }
57 |
58 |
59 | static lzma_ret
60 | sparc_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
61 | const lzma_filter_info *filters, bool is_encoder)
62 | {
63 | return lzma_simple_coder_init(next, allocator, filters,
64 | &sparc_code, 0, 4, 4, is_encoder);
65 | }
66 |
67 |
68 | extern lzma_ret
69 | lzma_simple_sparc_encoder_init(lzma_next_coder *next,
70 | const lzma_allocator *allocator,
71 | const lzma_filter_info *filters)
72 | {
73 | return sparc_coder_init(next, allocator, filters, true);
74 | }
75 |
76 |
77 | extern lzma_ret
78 | lzma_simple_sparc_decoder_init(lzma_next_coder *next,
79 | const lzma_allocator *allocator,
80 | const lzma_filter_info *filters)
81 | {
82 | return sparc_coder_init(next, allocator, filters, false);
83 | }
84 |
--------------------------------------------------------------------------------
/src/liblzma/validate_map.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | ###############################################################################
4 | #
5 | # Check liblzma.map for certain types of errors
6 | #
7 | # Author: Lasse Collin
8 | #
9 | # This file has been put into the public domain.
10 | # You can do whatever you want with this file.
11 | #
12 | ###############################################################################
13 |
14 | LC_ALL=C
15 | export LC_ALL
16 |
17 | STATUS=0
18 |
19 | cd "$(dirname "$0")"
20 |
21 | # Get the list of symbols that aren't defined in liblzma.map.
22 | SYMS=$(sed -n 's/^extern LZMA_API([^)]*) \([a-z0-9_]*\)(.*$/\1;/p' \
23 | api/flzma/*.h \
24 | | sort \
25 | | grep -Fve "$(sed '/[{}:*]/d;/^$/d;s/^ //' liblzma.map)")
26 |
27 | # Check that there are no old alpha or beta versions listed.
28 | VER=$(cd ../.. && sh build-aux/version.sh)
29 | NAMES=
30 | case $VER in
31 | *alpha | *beta)
32 | NAMES=$(sed -n 's/^.*XZ_\([^ ]*\)\(alpha\|beta\) .*$/\1\2/p' \
33 | liblzma.map | grep -Fv "$VER")
34 | ;;
35 | esac
36 |
37 | # Check for duplicate lines. It can catch missing dependencies.
38 | DUPS=$(sort liblzma.map | sed '/^$/d;/^global:$/d' | uniq -d)
39 |
40 | # Print error messages if needed.
41 | if test -n "$SYMS$NAMES$DUPS"; then
42 | echo
43 | echo 'validate_map.sh found problems from liblzma.map:'
44 | echo
45 |
46 | if test -n "$SYMS"; then
47 | echo 'liblzma.map lacks the following symbols:'
48 | echo "$SYMS"
49 | echo
50 | fi
51 |
52 | if test -n "$NAMES"; then
53 | echo 'Obsolete alpha or beta version names:'
54 | echo "$NAMES"
55 | echo
56 | fi
57 |
58 | if test -n "$DUPS"; then
59 | echo 'Duplicate lines:'
60 | echo "$DUPS"
61 | echo
62 | fi
63 |
64 | STATUS=1
65 | fi
66 |
67 | # Exit status is 1 if problems were found, 0 otherwise.
68 | exit "$STATUS"
69 |
--------------------------------------------------------------------------------
/src/lzmainfo/Makefile.am:
--------------------------------------------------------------------------------
1 | ##
2 | ## Author: Lasse Collin
3 | ##
4 | ## This file has been put into the public domain.
5 | ## You can do whatever you want with this file.
6 | ##
7 |
8 | bin_PROGRAMS = flzmainfo
9 |
10 | flzmainfo_SOURCES = \
11 | lzmainfo.c \
12 | ../common/tuklib_progname.c \
13 | ../common/tuklib_exit.c
14 |
15 | if COND_W32
16 | flzmainfo_SOURCES += lzmainfo_w32res.rc
17 | endif
18 |
19 | flzmainfo_CPPFLAGS = \
20 | -DLOCALEDIR=\"$(localedir)\" \
21 | -I$(top_srcdir)/src/common \
22 | -I$(top_srcdir)/src/liblzma/api \
23 | -I$(top_builddir)/lib
24 |
25 | flzmainfo_LDADD = $(top_builddir)/src/liblzma/libflzma.la
26 |
27 | if COND_GNULIB
28 | flzmainfo_LDADD += $(top_builddir)/lib/libgnu.a
29 | endif
30 |
31 | flzmainfo_LDADD += $(LTLIBINTL)
32 |
33 |
34 | dist_man_MANS = flzmainfo.1
35 |
36 | # Windows resource compiler support
37 | .rc.o:
38 | $(RC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
39 | $(flzmainfo_CPPFLAGS) $(CPPFLAGS) $(RCFLAGS) -i $< -o $@
40 |
--------------------------------------------------------------------------------
/src/lzmainfo/flzmainfo.1:
--------------------------------------------------------------------------------
1 | .\"
2 | .\" Author: Lasse Collin
3 | .\"
4 | .\" This file has been put into the public domain.
5 | .\" You can do whatever you want with this file.
6 | .\"
7 | .TH LZMAINFO 1 "2013-06-30" "Tukaani" "XZ Utils"
8 | .SH NAME
9 | lzmainfo \- show information stored in the .lzma file header
10 | .SH SYNOPSIS
11 | .B lzmainfo
12 | .RB [ \-\-help ]
13 | .RB [ \-\-version ]
14 | .RI [ file... ]
15 | .SH DESCRIPTION
16 | .B lzmainfo
17 | shows information stored in the
18 | .B .lzma
19 | file header.
20 | It reads the first 13 bytes from the specified
21 | .IR file ,
22 | decodes the header, and prints it to standard output in human
23 | readable format.
24 | If no
25 | .I files
26 | are given or
27 | .I file
28 | is
29 | .BR \- ,
30 | standard input is read.
31 | .PP
32 | Usually the most interesting information is
33 | the uncompressed size and the dictionary size.
34 | Uncompressed size can be shown only if
35 | the file is in the non-streamed
36 | .B .lzma
37 | format variant.
38 | The amount of memory required to decompress the file is
39 | a few dozen kilobytes plus the dictionary size.
40 | .PP
41 | .B lzmainfo
42 | is included in XZ Utils primarily for
43 | backward compatibility with LZMA Utils.
44 | .SH "EXIT STATUS"
45 | .TP
46 | .B 0
47 | All is good.
48 | .TP
49 | .B 1
50 | An error occurred.
51 | .SH BUGS
52 | .B lzmainfo
53 | uses
54 | .B MB
55 | while the correct suffix would be
56 | .B MiB
57 | (2^20 bytes).
58 | This is to keep the output compatible with LZMA Utils.
59 | .SH "SEE ALSO"
60 | .BR xz (1)
61 |
--------------------------------------------------------------------------------
/src/lzmainfo/lzmainfo_w32res.rc:
--------------------------------------------------------------------------------
1 | /*
2 | * Author: Lasse Collin
3 | *
4 | * This file has been put into the public domain.
5 | * You can do whatever you want with this file.
6 | */
7 |
8 | #define MY_TYPE VFT_APP
9 | #define MY_NAME "flzmainfo"
10 | #define MY_SUFFIX ".exe"
11 | #define MY_DESC "flzmainfo shows information about .lzma files"
12 | #include "common_w32res.rc"
13 |
--------------------------------------------------------------------------------
/src/scripts/Makefile.am:
--------------------------------------------------------------------------------
1 | ##
2 | ## Author: Lasse Collin
3 | ##
4 | ## This file has been put into the public domain.
5 | ## You can do whatever you want with this file.
6 | ##
7 |
8 | nodist_bin_SCRIPTS = fxzdiff fxzgrep fxzmore fxzless
9 | dist_man_MANS = fxzdiff.1 fxzgrep.1 fxzmore.1 fxzless.1
10 |
11 | links = \
12 | fxzdiff-fxzcmp \
13 | fxzgrep-fxzegrep \
14 | fxzgrep-fxzfgrep
15 |
16 | if COND_LZMALINKS
17 | links += \
18 | fxzdiff-flzdiff \
19 | fxzdiff-flzcmp \
20 | fxzgrep-flzgrep \
21 | fxzgrep-flzegrep \
22 | fxzgrep-flzfgrep \
23 | fxzmore-flzmore \
24 | fxzless-flzless
25 | endif
26 |
27 | install-exec-hook:
28 | cd $(DESTDIR)$(bindir) && \
29 | for pair in $(links); do \
30 | target=`echo $$pair | sed 's/-.*$$//' | sed '$(transform)'` && \
31 | link=`echo $$pair | sed 's/^.*-//' | sed '$(transform)'` && \
32 | rm -f $$link && \
33 | $(LN_S) $$target $$link; \
34 | done
35 |
36 | install-data-hook:
37 | cd $(DESTDIR)$(mandir)/man1 && \
38 | for pair in $(links); do \
39 | target=`echo $$pair | sed 's/-.*$$//' | sed '$(transform)'` && \
40 | link=`echo $$pair | sed 's/^.*-//' | sed '$(transform)'` && \
41 | rm -f $$link.1 && \
42 | $(LN_S) $$target.1 $$link.1; \
43 | done
44 |
45 | uninstall-hook:
46 | cd $(DESTDIR)$(bindir) && \
47 | for pair in $(links); do \
48 | link=`echo $$pair | sed 's/^.*-//' | sed '$(transform)'` && \
49 | rm -f $$link; \
50 | done
51 | cd $(DESTDIR)$(mandir)/man1 && \
52 | for pair in $(links); do \
53 | link=`echo $$pair | sed 's/^.*-//' | sed '$(transform)'` && \
54 | rm -f $$link.1; \
55 | done
56 |
--------------------------------------------------------------------------------
/src/scripts/fxzdiff.1:
--------------------------------------------------------------------------------
1 | .\"
2 | .\" Original zdiff.1 for gzip: Jean-loup Gailly
3 | .\"
4 | .\" Modifications for XZ Utils: Lasse Collin
5 | .\" Andrew Dudman
6 | .\"
7 | .\" License: GNU GPLv2+
8 | .\"
9 | .TH XZDIFF 1 "2021-06-04" "Tukaani" "XZ Utils"
10 | .SH NAME
11 | xzcmp, xzdiff, lzcmp, lzdiff \- compare compressed files
12 | .SH SYNOPSIS
13 | .B xzcmp
14 | .RI [ cmp_options "] " file1 " [" file2 ]
15 | .br
16 | .B xzdiff
17 | .RI [ diff_options "] " file1 " [" file2 ]
18 | .br
19 | .B lzcmp
20 | .RI [ cmp_options "] " file1 " [" file2 ]
21 | .br
22 | .B lzdiff
23 | .RI [ diff_options "] " file1 " [" file2 ]
24 | .SH DESCRIPTION
25 | .B xzcmp
26 | and
27 | .B xzdiff
28 | invoke
29 | .BR cmp (1)
30 | or
31 | .BR diff (1)
32 | on files compressed with
33 | .BR xz (1),
34 | .BR lzma (1),
35 | .BR gzip (1),
36 | .BR bzip2 (1),
37 | .BR lzop (1),
38 | or
39 | .BR zstd (1).
40 | All options specified are passed directly to
41 | .BR cmp (1)
42 | or
43 | .BR diff (1).
44 | If only one file is specified, then the files compared are
45 | .I file1
46 | (which must have a suffix of a supported compression format) and
47 | .I file1
48 | from which the compression format suffix has been stripped.
49 | If two files are specified,
50 | then they are uncompressed if necessary and fed to
51 | .BR cmp (1)
52 | or
53 | .BR diff (1).
54 | The exit status from
55 | .BR cmp (1)
56 | or
57 | .BR diff (1)
58 | is preserved unless a decompression error occurs; then exit status is 2.
59 | .PP
60 | The names
61 | .B lzcmp
62 | and
63 | .B lzdiff
64 | are provided for backward compatibility with LZMA Utils.
65 | .SH "SEE ALSO"
66 | .BR cmp (1),
67 | .BR diff (1),
68 | .BR xz (1),
69 | .BR gzip (1),
70 | .BR bzip2 (1),
71 | .BR lzop (1),
72 | .BR zstd (1),
73 | .BR zdiff (1)
74 | .SH BUGS
75 | Messages from the
76 | .BR cmp (1)
77 | or
78 | .BR diff (1)
79 | programs refer to temporary filenames instead of those specified.
80 |
--------------------------------------------------------------------------------
/src/scripts/fxzgrep.1:
--------------------------------------------------------------------------------
1 | .\"
2 | .\" Original zgrep.1 for gzip: Jean-loup Gailly
3 | .\" Charles Levert
4 | .\"
5 | .\" Modifications for XZ Utils: Lasse Collin
6 | .\"
7 | .\" License: GNU GPLv2+
8 | .\"
9 | .TH XZGREP 1 "2021-11-13" "Tukaani" "XZ Utils"
10 | .SH NAME
11 | xzgrep \- search compressed files for a regular expression
12 | .SH SYNOPSIS
13 | .B xzgrep
14 | .RI [ grep_options ]
15 | .RB [ \-e ]
16 | .I pattern
17 | .RI [ file... ]
18 | .br
19 | .B xzegrep
20 | \&...
21 | .br
22 | .B xzfgrep
23 | \&...
24 | .br
25 | .B lzgrep
26 | \&...
27 | .br
28 | .B lzegrep
29 | \&...
30 | .br
31 | .B lzfgrep
32 | \&...
33 | .SH DESCRIPTION
34 | .B xzgrep
35 | invokes
36 | .BR grep (1)
37 | on
38 | .I files
39 | which may be either uncompressed or compressed with
40 | .BR xz (1),
41 | .BR lzma (1),
42 | .BR gzip (1),
43 | .BR bzip2 (1),
44 | .BR lzop (1),
45 | or
46 | .BR zstd (1).
47 | All options specified are passed directly to
48 | .BR grep (1).
49 | .PP
50 | If no
51 | .I file
52 | is specified, then standard input is decompressed if necessary
53 | and fed to
54 | .BR grep (1).
55 | When reading from standard input,
56 | .BR gzip (1),
57 | .BR bzip2 (1),
58 | .BR lzop (1),
59 | and
60 | .BR zstd (1)
61 | compressed files are not supported.
62 | .PP
63 | If
64 | .B xzgrep
65 | is invoked as
66 | .B xzegrep
67 | or
68 | .B xzfgrep
69 | then
70 | .B grep \-E
71 | or
72 | .B grep \-F
73 | is used instead of
74 | .BR grep (1).
75 | The same applies to names
76 | .BR lzgrep ,
77 | .BR lzegrep ,
78 | and
79 | .BR lzfgrep ,
80 | which are provided for backward compatibility with LZMA Utils.
81 | .SH ENVIRONMENT
82 | .TP
83 | .B GREP
84 | If the
85 | .B GREP
86 | environment variable is set,
87 | .B xzgrep
88 | uses it instead of
89 | .BR grep (1),
90 | .BR "grep \-E" ,
91 | or
92 | .BR "grep \-F" .
93 | .SH "SEE ALSO"
94 | .BR grep (1),
95 | .BR xz (1),
96 | .BR gzip (1),
97 | .BR bzip2 (1),
98 | .BR lzop (1),
99 | .BR zstd (1),
100 | .BR zgrep (1)
101 |
--------------------------------------------------------------------------------
/src/scripts/fxzless.1:
--------------------------------------------------------------------------------
1 | .\"
2 | .\" Authors: Andrew Dudman
3 | .\" Lasse Collin
4 | .\"
5 | .\" This file has been put into the public domain.
6 | .\" You can do whatever you want with this file.
7 | .\"
8 | .\" (Note that this file is not based on gzip's zless.1.)
9 | .\"
10 | .TH XZLESS 1 "2010-09-27" "Tukaani" "XZ Utils"
11 | .SH NAME
12 | xzless, lzless \- view xz or lzma compressed (text) files
13 | .SH SYNOPSIS
14 | .B xzless
15 | .RI [ file ...]
16 | .br
17 | .B lzless
18 | .RI [ file ...]
19 | .SH DESCRIPTION
20 | .B xzless
21 | is a filter that displays text from compressed files to a terminal.
22 | It works on files compressed with
23 | .BR xz (1)
24 | or
25 | .BR lzma (1).
26 | If no
27 | .I files
28 | are given,
29 | .B xzless
30 | reads from standard input.
31 | .PP
32 | .B xzless
33 | uses
34 | .BR less (1)
35 | to present its output.
36 | Unlike
37 | .BR xzmore ,
38 | its choice of pager cannot be altered by
39 | setting an environment variable.
40 | Commands are based on both
41 | .BR more (1)
42 | and
43 | .BR vi (1)
44 | and allow back and forth movement and searching.
45 | See the
46 | .BR less (1)
47 | manual for more information.
48 | .PP
49 | The command named
50 | .B lzless
51 | is provided for backward compatibility with LZMA Utils.
52 | .SH ENVIRONMENT
53 | .TP
54 | .B LESSMETACHARS
55 | A list of characters special to the shell.
56 | Set by
57 | .B xzless
58 | unless it is already set in the environment.
59 | .TP
60 | .B LESSOPEN
61 | Set to a command line to invoke the
62 | .BR xz (1)
63 | decompressor for preprocessing the input files to
64 | .BR less (1).
65 | .SH "SEE ALSO"
66 | .BR less (1),
67 | .BR xz (1),
68 | .BR xzmore (1),
69 | .BR zless (1)
70 |
--------------------------------------------------------------------------------
/src/scripts/fxzless.in:
--------------------------------------------------------------------------------
1 | #!@POSIX_SHELL@
2 |
3 | # Copyright (C) 1998, 2002, 2006, 2007 Free Software Foundation
4 |
5 | # The original version for gzip was written by Paul Eggert.
6 | # Modified for XZ Utils by Andrew Dudman and Lasse Collin.
7 |
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 |
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 |
18 | @enable_path_for_scripts@
19 | #SET_PATH - This line is a placeholder to ease patching this script.
20 |
21 | # Instead of unsetting XZ_OPT, just make sure that xz will use file format
22 | # autodetection. This way memory usage limit and thread limit can be
23 | # specified via XZ_OPT.
24 | xz='@fxz@ --format=auto'
25 |
26 | version='xzless (@PACKAGE_NAME@) @VERSION@'
27 |
28 | usage="Usage: ${0##*/} [OPTION]... [FILE]...
29 | Like 'less', but operate on the uncompressed contents of xz compressed FILEs.
30 |
31 | Options are the same as for 'less'.
32 |
33 | Report bugs to <@PACKAGE_BUGREPORT@>."
34 |
35 | case $1 in
36 | --help) echo "$usage" || exit 2; exit;;
37 | --version) echo "$version" || exit 2; exit;;
38 | esac
39 |
40 | if test "${LESSMETACHARS+set}" != set; then
41 | # Work around a bug in less 394 and earlier;
42 | # it mishandles the metacharacters '$%=~'.
43 | space=' '
44 | tab=' '
45 | nl='
46 | '
47 | LESSMETACHARS="$space$tab$nl'"';*?"()<>[|&^`#\$%=~'
48 | fi
49 |
50 | if test "$(less -V | { read _ ver _ && echo ${ver%%.*}; })" -ge 429; then
51 | # less 429 or later: LESSOPEN pipe will be used on
52 | # standard input if $LESSOPEN begins with |-.
53 | LESSOPEN="|-$xz -cdfq -- %s"
54 | else
55 | LESSOPEN="|$xz -cdfq -- %s"
56 | fi
57 | export LESSMETACHARS LESSOPEN
58 |
59 | exec less "$@"
60 |
--------------------------------------------------------------------------------
/src/scripts/fxzmore.1:
--------------------------------------------------------------------------------
1 | .\"
2 | .\" Original zdiff.1 for gzip: Jean-loup Gailly
3 | .\" Modifications for XZ Utils: Lasse Collin
4 | .\"
5 | .\" License: GNU GPLv2+
6 | .\"
7 | .TH XZMORE 1 "2013-06-30" "Tukaani" "XZ Utils"
8 | .SH NAME
9 | xzmore, lzmore \- view xz or lzma compressed (text) files
10 | .SH SYNOPSIS
11 | .B xzmore
12 | .RI [ file... ]
13 | .br
14 | .B lzmore
15 | .RI [ file... ]
16 | .SH DESCRIPTION
17 | .B xzmore
18 | is a filter which allows examination of
19 | .BR xz (1)
20 | or
21 | .BR lzma (1)
22 | compressed text files one screenful at a time
23 | on a soft-copy terminal.
24 | .PP
25 | To use a pager other than the default
26 | .B more,
27 | set environment variable
28 | .B PAGER
29 | to the name of the desired program.
30 | The name
31 | .B lzmore
32 | is provided for backward compatibility with LZMA Utils.
33 | .TP
34 | .BR e " or " q
35 | When the prompt \-\-More\-\-(Next file:
36 | .IR file )
37 | is printed, this command causes
38 | .B xzmore
39 | to exit.
40 | .TP
41 | .B s
42 | When the prompt \-\-More\-\-(Next file:
43 | .IR file )
44 | is printed, this command causes
45 | .B xzmore
46 | to skip the next file and continue.
47 | .PP
48 | For list of keyboard commands supported while actually viewing the
49 | content of a file, refer to manual of the pager you use, usually
50 | .BR more (1).
51 | .SH "SEE ALSO"
52 | .BR more (1),
53 | .BR xz (1),
54 | .BR xzless (1),
55 | .BR zmore (1)
56 |
--------------------------------------------------------------------------------
/src/scripts/fxzmore.in:
--------------------------------------------------------------------------------
1 | #!@POSIX_SHELL@
2 |
3 | # Copyright (C) 2001, 2002, 2007 Free Software Foundation
4 | # Copyright (C) 1992, 1993 Jean-loup Gailly
5 |
6 | # Modified for XZ Utils by Andrew Dudman and Lasse Collin.
7 |
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 |
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 |
18 | @enable_path_for_scripts@
19 | #SET_PATH - This line is a placeholder to ease patching this script.
20 |
21 | # Instead of unsetting XZ_OPT, just make sure that xz will use file format
22 | # autodetection. This way memory usage limit and thread limit can be
23 | # specified via XZ_OPT.
24 | xz='@fxz@ --format=auto'
25 |
26 | version='xzmore (@PACKAGE_NAME@) @VERSION@'
27 |
28 | usage="Usage: ${0##*/} [OPTION]... [FILE]...
29 | Like 'more', but operate on the uncompressed contents of xz compressed FILEs.
30 |
31 | Report bugs to <@PACKAGE_BUGREPORT@>."
32 |
33 | case $1 in
34 | --help) echo "$usage" || exit 2; exit;;
35 | --version) echo "$version" || exit 2; exit;;
36 | esac
37 |
38 | oldtty=`stty -g 2>/dev/null`
39 | if stty -cbreak 2>/dev/null; then
40 | cb='cbreak'; ncb='-cbreak'
41 | else
42 | # 'stty min 1' resets eof to ^a on both SunOS and SysV!
43 | cb='min 1 -icanon'; ncb='icanon eof ^d'
44 | fi
45 | if test $? -eq 0 && test -n "$oldtty"; then
46 | trap 'stty $oldtty 2>/dev/null; exit' 0 2 3 5 10 13 15
47 | else
48 | trap 'stty $ncb echo 2>/dev/null; exit' 0 2 3 5 10 13 15
49 | fi
50 |
51 | if test $# = 0; then
52 | if test -t 0; then
53 | echo "$usage"; exit 1
54 | else
55 | $xz -cdfq | eval "${PAGER:-more}"
56 | fi
57 | else
58 | FIRST=1
59 | for FILE; do
60 | < "$FILE" || continue
61 | if test $FIRST -eq 0; then
62 | printf "%s--More--(Next file: %s)" "" "$FILE"
63 | stty $cb -echo 2>/dev/null
64 | ANS=`dd bs=1 count=1 2>/dev/null`
65 | stty $ncb echo 2>/dev/null
66 | echo " "
67 | case "$ANS" in
68 | [eq]) exit;;
69 | esac
70 | fi
71 | if test "$ANS" != 's'; then
72 | echo "------> $FILE <------"
73 | $xz -cdfq -- "$FILE" | eval "${PAGER:-more}"
74 | fi
75 | if test -t 1; then
76 | FIRST=0
77 | fi
78 | done
79 | fi
80 |
--------------------------------------------------------------------------------
/src/xz/args.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file args.h
4 | /// \brief Argument parsing
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | typedef struct {
14 | /// Filenames from command line
15 | char **arg_names;
16 |
17 | /// Number of filenames from command line
18 | unsigned int arg_count;
19 |
20 | /// Name of the file from which to read filenames. This is NULL
21 | /// if --files or --files0 was not used.
22 | char *files_name;
23 |
24 | /// File opened for reading from which filenames are read. This is
25 | /// non-NULL only if files_name is non-NULL.
26 | FILE *files_file;
27 |
28 | /// Delimiter for filenames read from files_file
29 | char files_delim;
30 |
31 | } args_info;
32 |
33 |
34 | extern bool opt_stdout;
35 | extern bool opt_force;
36 | extern bool opt_keep_original;
37 | // extern bool opt_recursive;
38 | extern bool opt_robot;
39 | extern bool opt_ignore_check;
40 |
41 | extern bool use_rmf;
42 |
43 | extern const char stdin_filename[];
44 |
45 | extern void args_parse(args_info *args, int argc, char **argv);
46 | extern void args_free(void);
47 |
--------------------------------------------------------------------------------
/src/xz/coder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file coder.h
4 | /// \brief Compresses or uncompresses a file
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | enum operation_mode {
14 | MODE_COMPRESS,
15 | MODE_DECOMPRESS,
16 | MODE_TEST,
17 | MODE_LIST,
18 | };
19 |
20 |
21 | // NOTE: The order of these is significant in suffix.c.
22 | enum format_type {
23 | FORMAT_AUTO,
24 | FORMAT_XZ,
25 | FORMAT_LZMA,
26 | // HEADER_GZIP,
27 | FORMAT_RAW,
28 | };
29 |
30 |
31 | /// Operation mode of the command line tool. This is set in args.c and read
32 | /// in several files.
33 | extern enum operation_mode opt_mode;
34 |
35 | /// File format to use when encoding or what format(s) to accept when
36 | /// decoding. This is a global because it's needed also in suffix.c.
37 | /// This is set in args.c.
38 | extern enum format_type opt_format;
39 |
40 | /// If true, the compression settings are automatically adjusted down if
41 | /// they exceed the memory usage limit.
42 | extern bool opt_auto_adjust;
43 |
44 | /// If true, stop after decoding the first stream.
45 | extern bool opt_single_stream;
46 |
47 | /// If non-zero, start a new .xz Block after every opt_block_size bytes
48 | /// of input. This has an effect only when compressing to the .xz format.
49 | extern uint64_t opt_block_size;
50 |
51 | /// This is non-NULL if --block-list was used. This contains the Block sizes
52 | /// as an array that is terminated with 0.
53 | extern uint64_t *opt_block_list;
54 |
55 | /// Set the integrity check type used when compressing
56 | extern void coder_set_check(lzma_check check);
57 |
58 | /// Set preset number
59 | extern void coder_set_preset(uint32_t new_preset);
60 |
61 | /// Enable extreme mode
62 | extern void coder_set_extreme(void);
63 |
64 | /// Enable orig mode
65 | extern void coder_set_orig(void);
66 |
67 | /// Add a filter to the custom filter chain
68 | extern void coder_add_filter(lzma_vli id, void *options);
69 |
70 | ///
71 | extern void coder_set_compression_settings(void);
72 |
73 | /// Compress or decompress the given file
74 | extern void coder_run(const char *filename);
75 |
76 | #ifndef NDEBUG
77 | /// Free the memory allocated for the coder and kill the worker threads.
78 | extern void coder_free(void);
79 | #endif
80 |
--------------------------------------------------------------------------------
/src/xz/hardware.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file hardware.h
4 | /// \brief Detection of available hardware resources
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | /// Initialize some hardware-specific variables, which are needed by other
14 | /// hardware_* functions.
15 | extern void hardware_init(void);
16 |
17 |
18 | /// Set the maximum number of worker threads.
19 | extern void hardware_threads_set(uint32_t threadlimit);
20 |
21 | /// Get the maximum number of worker threads.
22 | extern uint32_t hardware_threads_get(void);
23 |
24 |
25 | /// Set the memory usage limit. There are separate limits for compression
26 | /// and decompression (the latter includes also --list), one or both can
27 | /// be set with a single call to this function. Zero indicates resetting
28 | /// the limit back to the defaults. The limit can also be set as a percentage
29 | /// of installed RAM; the percentage must be in the range [1, 100].
30 | extern void hardware_memlimit_set(uint64_t new_memlimit,
31 | bool set_compress, bool set_decompress, bool is_percentage);
32 |
33 | /// Get the current memory usage limit for compression or decompression.
34 | extern uint64_t hardware_memlimit_get(enum operation_mode mode);
35 |
36 | /// Display the amount of RAM and memory usage limits and exit.
37 | extern void hardware_memlimit_show(void) lzma_attribute((__noreturn__));
38 |
--------------------------------------------------------------------------------
/src/xz/list.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file list.h
4 | /// \brief List information about .xz files
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | /// \brief List information about the given .xz file
14 | extern void list_file(const char *filename);
15 |
16 |
17 | /// \brief Show the totals after all files have been listed
18 | extern void list_totals(void);
19 |
--------------------------------------------------------------------------------
/src/xz/main.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file main.h
4 | /// \brief Miscellaneous declarations
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | /// Possible exit status values. These are the same as used by gzip and bzip2.
14 | enum exit_status_type {
15 | E_SUCCESS = 0,
16 | E_ERROR = 1,
17 | E_WARNING = 2,
18 | };
19 |
20 |
21 | /// Sets the exit status after a warning or error has occurred. If new_status
22 | /// is E_WARNING and the old exit status was already E_ERROR, the exit
23 | /// status is not changed.
24 | extern void set_exit_status(enum exit_status_type new_status);
25 |
26 |
27 | /// Use E_SUCCESS instead of E_WARNING if something worth a warning occurs
28 | /// but nothing worth an error has occurred. This is called when --no-warn
29 | /// is specified.
30 | extern void set_exit_no_warn(void);
31 |
--------------------------------------------------------------------------------
/src/xz/mytime.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file mytime.c
4 | /// \brief Time handling functions
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "private.h"
14 |
15 | #if !(defined(HAVE_CLOCK_GETTIME) && HAVE_DECL_CLOCK_MONOTONIC)
16 | # include
17 | #endif
18 |
19 | uint64_t opt_flush_timeout = 0;
20 |
21 | static uint64_t start_time;
22 | static uint64_t next_flush;
23 |
24 |
25 | /// \brief Get the current time as milliseconds
26 | ///
27 | /// It's relative to some point but not necessarily to the UNIX Epoch.
28 | static uint64_t
29 | mytime_now(void)
30 | {
31 | // NOTE: HAVE_DECL_CLOCK_MONOTONIC is always defined to 0 or 1.
32 | #if defined(HAVE_CLOCK_GETTIME) && HAVE_DECL_CLOCK_MONOTONIC
33 | // If CLOCK_MONOTONIC was available at compile time but for some
34 | // reason isn't at runtime, fallback to CLOCK_REALTIME which
35 | // according to POSIX is mandatory for all implementations.
36 | static clockid_t clk_id = CLOCK_MONOTONIC;
37 | struct timespec tv;
38 | while (clock_gettime(clk_id, &tv))
39 | clk_id = CLOCK_REALTIME;
40 |
41 | return (uint64_t)tv.tv_sec * 1000 + (uint64_t)(tv.tv_nsec / 1000000);
42 | #else
43 | struct timeval tv;
44 | gettimeofday(&tv, NULL);
45 | return (uint64_t)tv.tv_sec * 1000 + (uint64_t)(tv.tv_usec / 1000);
46 | #endif
47 | }
48 |
49 |
50 | extern void
51 | mytime_set_start_time(void)
52 | {
53 | start_time = mytime_now();
54 | return;
55 | }
56 |
57 |
58 | extern uint64_t
59 | mytime_get_elapsed(void)
60 | {
61 | return mytime_now() - start_time;
62 | }
63 |
64 |
65 | extern void
66 | mytime_set_flush_time(void)
67 | {
68 | next_flush = mytime_now() + opt_flush_timeout;
69 | return;
70 | }
71 |
72 |
73 | extern int
74 | mytime_get_flush_timeout(void)
75 | {
76 | if (opt_flush_timeout == 0 || opt_mode != MODE_COMPRESS)
77 | return -1;
78 |
79 | const uint64_t now = mytime_now();
80 | if (now >= next_flush)
81 | return 0;
82 |
83 | const uint64_t remaining = next_flush - now;
84 | return remaining > INT_MAX ? INT_MAX : (int)remaining;
85 | }
86 |
--------------------------------------------------------------------------------
/src/xz/mytime.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file mytime.h
4 | /// \brief Time handling functions
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 |
14 | /// \brief Number of milliseconds to between LZMA_SYNC_FLUSHes
15 | ///
16 | /// If 0, timed flushing is disabled. Otherwise if no more input is available
17 | /// and not at the end of the file and at least opt_flush_timeout milliseconds
18 | /// has elapsed since the start of compression or the previous flushing
19 | /// (LZMA_SYNC_FLUSH or LZMA_FULL_FLUSH), set LZMA_SYNC_FLUSH to flush
20 | /// the pending data.
21 | extern uint64_t opt_flush_timeout;
22 |
23 |
24 | /// \brief Store the time when (de)compression was started
25 | ///
26 | /// The start time is also stored as the time of the first flush.
27 | extern void mytime_set_start_time(void);
28 |
29 |
30 | /// \brief Get the number of milliseconds since the operation started
31 | extern uint64_t mytime_get_elapsed(void);
32 |
33 |
34 | /// \brief Store the time of when compressor was flushed
35 | extern void mytime_set_flush_time(void);
36 |
37 |
38 | /// \brief Get the number of milliseconds until the next flush
39 | ///
40 | /// This returns -1 if no timed flushing is used.
41 | ///
42 | /// The return value is intended for use with poll().
43 | extern int mytime_get_flush_timeout(void);
44 |
--------------------------------------------------------------------------------
/src/xz/options.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file options.h
4 | /// \brief Parser for filter-specific options
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | /// \brief Parser for Delta options
14 | ///
15 | /// \return Pointer to allocated options structure.
16 | /// Doesn't return on error.
17 | extern lzma_options_delta *options_delta(const char *str);
18 |
19 |
20 | /// \brief Parser for BCJ options
21 | ///
22 | /// \return Pointer to allocated options structure.
23 | /// Doesn't return on error.
24 | extern lzma_options_bcj *options_bcj(const char *str);
25 |
26 |
27 | /// \brief Parser for LZMA options
28 | ///
29 | /// \return Pointer to allocated options structure.
30 | /// Doesn't return on error.
31 | extern lzma_options_lzma *options_lzma(const char *str);
32 |
--------------------------------------------------------------------------------
/src/xz/private.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file private.h
4 | /// \brief Common includes, definitions, and prototypes
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "sysdefs.h"
14 | #include "mythread.h"
15 |
16 | #include "flzma.h"
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | #include "tuklib_gettext.h"
27 | #include "tuklib_progname.h"
28 | #include "tuklib_exit.h"
29 | #include "tuklib_mbstr.h"
30 |
31 | #if defined(_WIN32) && !defined(__CYGWIN__)
32 | # define WIN32_LEAN_AND_MEAN
33 | # include
34 | #endif
35 |
36 | #ifndef STDIN_FILENO
37 | # define STDIN_FILENO (fileno(stdin))
38 | #endif
39 |
40 | #ifndef STDOUT_FILENO
41 | # define STDOUT_FILENO (fileno(stdout))
42 | #endif
43 |
44 | #ifndef STDERR_FILENO
45 | # define STDERR_FILENO (fileno(stderr))
46 | #endif
47 |
48 | #ifdef HAVE_CAPSICUM
49 | # define ENABLE_SANDBOX 1
50 | #endif
51 |
52 | #include "main.h"
53 | #include "mytime.h"
54 | #include "coder.h"
55 | #include "message.h"
56 | #include "args.h"
57 | #include "hardware.h"
58 | #include "file_io.h"
59 | #include "options.h"
60 | #include "signals.h"
61 | #include "suffix.h"
62 | #include "util.h"
63 |
64 | #ifdef HAVE_DECODERS
65 | # include "list.h"
66 | #endif
67 |
--------------------------------------------------------------------------------
/src/xz/signals.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file signals.h
4 | /// \brief Handling signals to abort operation
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | /// If this is true, we will clean up the possibly incomplete output file,
14 | /// return to main() as soon as practical. That is, the code needs to poll
15 | /// this variable in various places.
16 | extern volatile sig_atomic_t user_abort;
17 |
18 |
19 | /// Initialize the signal handler, which will set user_abort to true when
20 | /// user e.g. presses C-c.
21 | extern void signals_init(void);
22 |
23 |
24 | #if (defined(_WIN32) && !defined(__CYGWIN__)) || defined(__VMS)
25 | # define signals_block() do { } while (0)
26 | # define signals_unblock() do { } while (0)
27 | #else
28 | /// Block the signals which don't have SA_RESTART and which would just set
29 | /// user_abort to true. This is handy when we don't want to handle EINTR
30 | /// and don't want SA_RESTART either.
31 | extern void signals_block(void);
32 |
33 | /// Unblock the signals blocked by signals_block().
34 | extern void signals_unblock(void);
35 | #endif
36 |
37 | #if defined(_WIN32) && !defined(__CYGWIN__)
38 | # define signals_exit() do { } while (0)
39 | #else
40 | /// If user has sent us a signal earlier to terminate the process,
41 | /// re-raise that signal to actually terminate the process.
42 | extern void signals_exit(void);
43 | #endif
44 |
--------------------------------------------------------------------------------
/src/xz/suffix.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file suffix.h
4 | /// \brief Checks filename suffix and creates the destination filename
5 | //
6 | // Author: Lasse Collin
7 | //
8 | // This file has been put into the public domain.
9 | // You can do whatever you want with this file.
10 | //
11 | ///////////////////////////////////////////////////////////////////////////////
12 |
13 | /// \brief Get the name of the destination file
14 | ///
15 | /// Depending on the global variable opt_mode, this tries to find a matching
16 | /// counterpart for src_name. If the name can be constructed, it is allocated
17 | /// and returned (caller must free it). On error, a message is printed and
18 | /// NULL is returned.
19 | extern char *suffix_get_dest_name(const char *src_name);
20 |
21 |
22 | /// \brief Set a custom filename suffix
23 | ///
24 | /// This function calls xstrdup() for the given suffix, thus the caller
25 | /// doesn't need to keep the memory allocated. There can be only one custom
26 | /// suffix, thus if this is called multiple times, the old suffixes are freed
27 | /// and forgotten.
28 | extern void suffix_set(const char *suffix);
29 |
--------------------------------------------------------------------------------
/src/xz/xz_w32res.rc:
--------------------------------------------------------------------------------
1 | /*
2 | * Author: Lasse Collin
3 | *
4 | * This file has been put into the public domain.
5 | * You can do whatever you want with this file.
6 | */
7 |
8 | #define MY_TYPE VFT_APP
9 | #define MY_NAME "fxz"
10 | #define MY_SUFFIX ".exe"
11 | #define MY_DESC "fxz data compression tool for .xz and .lzma files"
12 | #include "common_w32res.rc"
13 |
--------------------------------------------------------------------------------
/src/xzdec/Makefile.am:
--------------------------------------------------------------------------------
1 | ##
2 | ## Author: Lasse Collin
3 | ##
4 | ## This file has been put into the public domain.
5 | ## You can do whatever you want with this file.
6 | ##
7 |
8 | # Windows resource compiler support. It's fine to use fxz_CPPFLAGS
9 | # also for flzmadec.
10 | .rc.o:
11 | $(RC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
12 | $(fxzdec_CPPFLAGS) $(CPPFLAGS) $(RCFLAGS) -i $< -o $@
13 |
14 |
15 | fxzdec_SOURCES = \
16 | xzdec.c \
17 | ../common/tuklib_progname.c \
18 | ../common/tuklib_exit.c
19 |
20 | if COND_W32
21 | fxzdec_SOURCES += xzdec_w32res.rc
22 | endif
23 |
24 | fxzdec_CPPFLAGS = \
25 | -DTUKLIB_GETTEXT=0 \
26 | -I$(top_srcdir)/src/common \
27 | -I$(top_srcdir)/src/liblzma/api \
28 | -I$(top_builddir)/lib
29 | fxzdec_LDADD = $(top_builddir)/src/liblzma/libflzma.la
30 |
31 | if COND_GNULIB
32 | fxzdec_LDADD += $(top_builddir)/lib/libgnu.a
33 | endif
34 |
35 | fxzdec_LDADD += $(LTLIBINTL)
36 |
37 |
38 | flzmadec_SOURCES = \
39 | xzdec.c \
40 | ../common/tuklib_progname.c \
41 | ../common/tuklib_exit.c
42 |
43 | if COND_W32
44 | flzmadec_SOURCES += lzmadec_w32res.rc
45 | endif
46 |
47 | flzmadec_CPPFLAGS = $(fxzdec_CPPFLAGS) -DLZMADEC
48 | flzmadec_LDFLAGS = $(fxzdec_LDFLAGS)
49 | flzmadec_LDADD = $(fxzdec_LDADD)
50 |
51 |
52 | bin_PROGRAMS =
53 |
54 | if COND_XZDEC
55 | bin_PROGRAMS += fxzdec
56 | dist_man_MANS = fxzdec.1
57 | endif
58 |
59 | if COND_LZMADEC
60 | bin_PROGRAMS += flzmadec
61 |
62 | # Create the symlink flzmadec.1->fxzdec.1 only if fxzdec.1 was installed.
63 | # This is better than creating a dangling symlink, especially
64 | # because creating the link may fail due to the directory being missing.
65 | #
66 | # FIXME: The correct solution would be to install fxzdec.1 as flzmadec.1
67 | # but I don't know what is the sane way to do it and since this is a bit
68 | # unusual situation anyway, it's not that important.
69 | if COND_XZDEC
70 | install-data-hook:
71 | cd $(DESTDIR)$(mandir)/man1 && \
72 | target=`echo fxzdec | sed '$(transform)'` && \
73 | link=`echo flzmadec | sed '$(transform)'` && \
74 | rm -f $$link.1 && \
75 | $(LN_S) $$target.1 $$link.1
76 |
77 | uninstall-hook:
78 | cd $(DESTDIR)$(mandir)/man1 && \
79 | link=`echo flzmadec | sed '$(transform)'` && \
80 | rm -f $$link.1
81 | endif
82 | endif
83 |
--------------------------------------------------------------------------------
/src/xzdec/lzmadec_w32res.rc:
--------------------------------------------------------------------------------
1 | /*
2 | * Author: Lasse Collin
3 | *
4 | * This file has been put into the public domain.
5 | * You can do whatever you want with this file.
6 | */
7 |
8 | #define MY_TYPE VFT_APP
9 | #define MY_NAME "flzmadec"
10 | #define MY_SUFFIX ".exe"
11 | #define MY_DESC "flzmadec decompression tool for .lzma files"
12 | #include "common_w32res.rc"
13 |
--------------------------------------------------------------------------------
/src/xzdec/xzdec_w32res.rc:
--------------------------------------------------------------------------------
1 | /*
2 | * Author: Lasse Collin
3 | *
4 | * This file has been put into the public domain.
5 | * You can do whatever you want with this file.
6 | */
7 |
8 | #define MY_TYPE VFT_APP
9 | #define MY_NAME "fxzdec"
10 | #define MY_SUFFIX ".exe"
11 | #define MY_DESC "fxzdec decompression tool for .xz files"
12 | #include "common_w32res.rc"
13 |
--------------------------------------------------------------------------------
/tests/Makefile.am:
--------------------------------------------------------------------------------
1 | ##
2 | ## Author: Lasse Collin
3 | ##
4 | ## This file has been put into the public domain.
5 | ## You can do whatever you want with this file.
6 | ##
7 |
8 | EXTRA_DIST = \
9 | files \
10 | ossfuzz \
11 | tests.h \
12 | test_compress.sh \
13 | test_scripts.sh \
14 | bcj_test.c \
15 | compress_prepared_bcj_sparc \
16 | compress_prepared_bcj_x86 \
17 | xzgrep_expected_output \
18 | test_files.sh
19 |
20 | AM_CPPFLAGS = \
21 | -I$(top_srcdir)/src/common \
22 | -I$(top_srcdir)/src/liblzma/api \
23 | -I$(top_builddir)/lib
24 |
25 | LDADD = $(top_builddir)/src/liblzma/libflzma.la
26 |
27 | if COND_GNULIB
28 | LDADD += $(top_builddir)/lib/libgnu.a
29 | endif
30 |
31 | LDADD += $(LTLIBINTL)
32 |
33 | check_PROGRAMS = \
34 | create_compress_files \
35 | test_check \
36 | test_stream_flags \
37 | test_filter_flags \
38 | test_block_header \
39 | test_index \
40 | test_bcj_exact_size
41 |
42 | TESTS = \
43 | test_check \
44 | test_stream_flags \
45 | test_filter_flags \
46 | test_block_header \
47 | test_index \
48 | test_bcj_exact_size \
49 | test_compress.sh \
50 | test_files.sh
51 |
52 | if COND_SCRIPTS
53 | TESTS += test_scripts.sh
54 | endif
55 |
56 | clean-local:
57 | -rm -f compress_generated_* \
58 | xzgrep_test_output xzgrep_test_1.xz xzgrep_test_2.xz
59 |
--------------------------------------------------------------------------------
/tests/bcj_test.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file bcj_test.c
4 | /// \brief Source code of compress_prepared_bcj_*
5 | ///
6 | /// This is a simple program that should make the compiler to generate
7 | /// PC-relative branches, jumps, and calls. The compiled files can then
8 | /// be used to test the branch conversion filters. Note that this program
9 | /// itself does nothing useful.
10 | ///
11 | /// Compiling: gcc -std=c99 -fPIC -c bcj_test.c
12 | /// Don't optimize or strip.
13 | //
14 | // Author: Lasse Collin
15 | //
16 | // This file has been put into the public domain.
17 | // You can do whatever you want with this file.
18 | //
19 | ///////////////////////////////////////////////////////////////////////////////
20 |
21 | extern int jump(int a, int b);
22 |
23 |
24 | extern int
25 | call(int a, int b)
26 | {
27 | if (a < b)
28 | a = jump(a, b);
29 |
30 | return a;
31 | }
32 |
33 |
34 | extern int
35 | jump(int a, int b)
36 | {
37 | // The loop generates conditional jump backwards.
38 | while (1) {
39 | if (a < b) {
40 | a *= 2;
41 | a += 3 * b;
42 | break;
43 | } else {
44 | // Put enough code here to prevent JMP SHORT on x86.
45 | a += b;
46 | a /= 2;
47 | b += b % 5;
48 | a -= b / 3;
49 | b = 2 * b + a - 1;
50 | a *= b + a + 1;
51 | b += a - 1;
52 | a += b * 2 - a / 5;
53 | }
54 | }
55 |
56 | return a;
57 | }
58 |
59 |
60 | int
61 | main(int argc, char **argv)
62 | {
63 | int a = call(argc, argc + 1);
64 | return a == 0;
65 | }
66 |
--------------------------------------------------------------------------------
/tests/compress_prepared_bcj_sparc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/compress_prepared_bcj_sparc
--------------------------------------------------------------------------------
/tests/compress_prepared_bcj_x86:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/compress_prepared_bcj_x86
--------------------------------------------------------------------------------
/tests/files/bad-0-backward_size.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-0-backward_size.xz
--------------------------------------------------------------------------------
/tests/files/bad-0-empty-truncated.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-0-empty-truncated.xz
--------------------------------------------------------------------------------
/tests/files/bad-0-footer_magic.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-0-footer_magic.xz
--------------------------------------------------------------------------------
/tests/files/bad-0-header_magic.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-0-header_magic.xz
--------------------------------------------------------------------------------
/tests/files/bad-0-nonempty_index.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-0-nonempty_index.xz
--------------------------------------------------------------------------------
/tests/files/bad-0cat-alone.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-0cat-alone.xz
--------------------------------------------------------------------------------
/tests/files/bad-0cat-header_magic.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-0cat-header_magic.xz
--------------------------------------------------------------------------------
/tests/files/bad-0catpad-empty.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-0catpad-empty.xz
--------------------------------------------------------------------------------
/tests/files/bad-0pad-empty.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-0pad-empty.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-block_header-1.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-block_header-1.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-block_header-2.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-block_header-2.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-block_header-3.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-block_header-3.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-block_header-4.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-block_header-4.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-block_header-5.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-block_header-5.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-block_header-6.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-block_header-6.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-check-crc32-2.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-check-crc32-2.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-check-crc32.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-check-crc32.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-check-crc64.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-check-crc64.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-check-sha256.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-check-sha256.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-lzma2-1.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-lzma2-1.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-lzma2-10.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-lzma2-10.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-lzma2-2.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-lzma2-2.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-lzma2-3.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-lzma2-3.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-lzma2-4.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-lzma2-4.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-lzma2-5.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-lzma2-5.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-lzma2-6.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-lzma2-6.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-lzma2-7.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-lzma2-7.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-lzma2-8.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-lzma2-8.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-lzma2-9.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-lzma2-9.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-stream_flags-1.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-stream_flags-1.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-stream_flags-2.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-stream_flags-2.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-stream_flags-3.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-stream_flags-3.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-vli-1.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-vli-1.xz
--------------------------------------------------------------------------------
/tests/files/bad-1-vli-2.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-1-vli-2.xz
--------------------------------------------------------------------------------
/tests/files/bad-2-compressed_data_padding.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-2-compressed_data_padding.xz
--------------------------------------------------------------------------------
/tests/files/bad-2-index-1.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-2-index-1.xz
--------------------------------------------------------------------------------
/tests/files/bad-2-index-2.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-2-index-2.xz
--------------------------------------------------------------------------------
/tests/files/bad-2-index-3.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-2-index-3.xz
--------------------------------------------------------------------------------
/tests/files/bad-2-index-4.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-2-index-4.xz
--------------------------------------------------------------------------------
/tests/files/bad-2-index-5.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/bad-2-index-5.xz
--------------------------------------------------------------------------------
/tests/files/good-0-empty.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-0-empty.xz
--------------------------------------------------------------------------------
/tests/files/good-0cat-empty.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-0cat-empty.xz
--------------------------------------------------------------------------------
/tests/files/good-0catpad-empty.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-0catpad-empty.xz
--------------------------------------------------------------------------------
/tests/files/good-0pad-empty.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-0pad-empty.xz
--------------------------------------------------------------------------------
/tests/files/good-1-3delta-lzma2.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-1-3delta-lzma2.xz
--------------------------------------------------------------------------------
/tests/files/good-1-block_header-1.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-1-block_header-1.xz
--------------------------------------------------------------------------------
/tests/files/good-1-block_header-2.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-1-block_header-2.xz
--------------------------------------------------------------------------------
/tests/files/good-1-block_header-3.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-1-block_header-3.xz
--------------------------------------------------------------------------------
/tests/files/good-1-check-crc32.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-1-check-crc32.xz
--------------------------------------------------------------------------------
/tests/files/good-1-check-crc64.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-1-check-crc64.xz
--------------------------------------------------------------------------------
/tests/files/good-1-check-none.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-1-check-none.xz
--------------------------------------------------------------------------------
/tests/files/good-1-check-sha256.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-1-check-sha256.xz
--------------------------------------------------------------------------------
/tests/files/good-1-delta-lzma2.tiff.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-1-delta-lzma2.tiff.xz
--------------------------------------------------------------------------------
/tests/files/good-1-lzma2-1.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-1-lzma2-1.xz
--------------------------------------------------------------------------------
/tests/files/good-1-lzma2-2.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-1-lzma2-2.xz
--------------------------------------------------------------------------------
/tests/files/good-1-lzma2-3.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-1-lzma2-3.xz
--------------------------------------------------------------------------------
/tests/files/good-1-lzma2-4.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-1-lzma2-4.xz
--------------------------------------------------------------------------------
/tests/files/good-1-lzma2-5.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-1-lzma2-5.xz
--------------------------------------------------------------------------------
/tests/files/good-1-sparc-lzma2.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-1-sparc-lzma2.xz
--------------------------------------------------------------------------------
/tests/files/good-1-x86-lzma2.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-1-x86-lzma2.xz
--------------------------------------------------------------------------------
/tests/files/good-2-lzma2.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/good-2-lzma2.xz
--------------------------------------------------------------------------------
/tests/files/unsupported-block_header.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/unsupported-block_header.xz
--------------------------------------------------------------------------------
/tests/files/unsupported-check.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/unsupported-check.xz
--------------------------------------------------------------------------------
/tests/files/unsupported-filter_flags-1.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/unsupported-filter_flags-1.xz
--------------------------------------------------------------------------------
/tests/files/unsupported-filter_flags-2.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/unsupported-filter_flags-2.xz
--------------------------------------------------------------------------------
/tests/files/unsupported-filter_flags-3.xz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conor42/fxz/f12d7eb3ecebcfa5e2d3dc8a016772b3cd101f39/tests/files/unsupported-filter_flags-3.xz
--------------------------------------------------------------------------------
/tests/ossfuzz/Makefile:
--------------------------------------------------------------------------------
1 | fuzz: fuzz.c
2 | $(CC) $(CFLAGS) -c fuzz.c -I ../../src/liblzma/api/
3 | $(CXX) $(CXXFLAGS) $(LIB_FUZZING_ENGINE) fuzz.o -o $(OUT)/fuzz \
4 | ../../src/liblzma/.libs/libflzma.a
5 |
6 | clean:
7 | rm -f *.o
8 |
--------------------------------------------------------------------------------
/tests/ossfuzz/config/fuzz.dict:
--------------------------------------------------------------------------------
1 | "\xFD7zXZ\x00"
2 | "YZ"
3 |
--------------------------------------------------------------------------------
/tests/ossfuzz/config/fuzz.options:
--------------------------------------------------------------------------------
1 | [libfuzzer]
2 | dict = fuzz.dict
3 |
--------------------------------------------------------------------------------
/tests/test_check.c:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////////
2 | //
3 | /// \file test_check.c
4 | /// \brief Tests integrity checks
5 | ///
6 | /// \todo Add SHA256
7 | //
8 | // Author: Lasse Collin
9 | //
10 | // This file has been put into the public domain.
11 | // You can do whatever you want with this file.
12 | //
13 | ///////////////////////////////////////////////////////////////////////////////
14 |
15 | #include "tests.h"
16 |
17 |
18 | // These must be specified as numbers so that the test works on EBCDIC
19 | // systems too.
20 | // static const uint8_t test_string[9] = "123456789";
21 | // static const uint8_t test_unaligned[12] = "xxx123456789";
22 | static const uint8_t test_string[9] = { 49, 50, 51, 52, 53, 54, 55, 56, 57 };
23 | static const uint8_t test_unaligned[12]
24 | = { 120, 120, 120, 49, 50, 51, 52, 53, 54, 55, 56, 57 };
25 |
26 |
27 | static bool
28 | test_crc32(void)
29 | {
30 | static const uint32_t test_vector = 0xCBF43926;
31 |
32 | // Test 1
33 | uint32_t crc = lzma_crc32(test_string, sizeof(test_string), 0);
34 | if (crc != test_vector)
35 | return true;
36 |
37 | // Test 2
38 | crc = lzma_crc32(test_unaligned + 3, sizeof(test_string), 0);
39 | if (crc != test_vector)
40 | return true;
41 |
42 | // Test 3
43 | crc = 0;
44 | for (size_t i = 0; i < sizeof(test_string); ++i)
45 | crc = lzma_crc32(test_string + i, 1, crc);
46 | if (crc != test_vector)
47 | return true;
48 |
49 | return false;
50 | }
51 |
52 |
53 | static bool
54 | test_crc64(void)
55 | {
56 | static const uint64_t test_vector = 0x995DC9BBDF1939FA;
57 |
58 | // Test 1
59 | uint64_t crc = lzma_crc64(test_string, sizeof(test_string), 0);
60 | if (crc != test_vector)
61 | return true;
62 |
63 | // Test 2
64 | crc = lzma_crc64(test_unaligned + 3, sizeof(test_string), 0);
65 | if (crc != test_vector)
66 | return true;
67 |
68 | // Test 3
69 | crc = 0;
70 | for (size_t i = 0; i < sizeof(test_string); ++i)
71 | crc = lzma_crc64(test_string + i, 1, crc);
72 | if (crc != test_vector)
73 | return true;
74 |
75 | return false;
76 | }
77 |
78 |
79 | int
80 | main(void)
81 | {
82 | bool error = false;
83 |
84 | error |= test_crc32();
85 | error |= test_crc64();
86 |
87 | return error ? 1 : 0;
88 | }
89 |
--------------------------------------------------------------------------------
/tests/test_files.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | ###############################################################################
4 | #
5 | # Author: Lasse Collin
6 | #
7 | # This file has been put into the public domain.
8 | # You can do whatever you want with this file.
9 | #
10 | ###############################################################################
11 |
12 | # If both fxz and fxzdec were not build, skip this test.
13 | XZ=../src/xz/fxz
14 | XZDEC=../src/xzdec/fxzdec
15 | test -x "$XZ" || XZ=
16 | test -x "$XZDEC" || XZDEC=
17 | if test -z "$XZ$XZDEC"; then
18 | (exit 77)
19 | exit 77
20 | fi
21 |
22 | for I in "$srcdir"/files/good-*.xz
23 | do
24 | if test -z "$XZ" || "$XZ" -dc "$I" > /dev/null; then
25 | :
26 | else
27 | echo "Good file failed: $I"
28 | (exit 1)
29 | exit 1
30 | fi
31 |
32 | if test -z "$XZDEC" || "$XZDEC" "$I" > /dev/null; then
33 | :
34 | else
35 | echo "Good file failed: $I"
36 | (exit 1)
37 | exit 1
38 | fi
39 | done
40 |
41 | for I in "$srcdir"/files/bad-*.xz
42 | do
43 | if test -n "$XZ" && "$XZ" -dc "$I" > /dev/null 2>&1; then
44 | echo "Bad file succeeded: $I"
45 | (exit 1)
46 | exit 1
47 | fi
48 |
49 | if test -n "$XZDEC" && "$XZDEC" "$I" > /dev/null 2>&1; then
50 | echo "Bad file succeeded: $I"
51 | (exit 1)
52 | exit 1
53 | fi
54 | done
55 |
56 | (exit 0)
57 | exit 0
58 |
--------------------------------------------------------------------------------
/tests/test_scripts.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | ###############################################################################
4 | #
5 | # Author: Jonathan Nieder
6 | #
7 | # This file has been put into the public domain.
8 | # You can do whatever you want with this file.
9 | #
10 | ###############################################################################
11 |
12 | # If scripts weren't built, this test is skipped.
13 | XZ=../src/xz/fxz
14 | XZDIFF=../src/scripts/fxzdiff
15 | XZGREP=../src/scripts/fxzgrep
16 |
17 | for i in XZ XZDIFF XZGREP; do
18 | eval test -x "\$$i" && continue
19 | (exit 77)
20 | exit 77
21 | done
22 |
23 | PATH=`pwd`/../src/xz:$PATH
24 | export PATH
25 |
26 | test -z "$srcdir" && srcdir=.
27 | preimage=$srcdir/files/good-1-check-crc32.xz
28 | samepostimage=$srcdir/files/good-1-check-crc64.xz
29 | otherpostimage=$srcdir/files/good-1-lzma2-1.xz
30 |
31 | "$XZDIFF" "$preimage" "$samepostimage" >/dev/null
32 | status=$?
33 | if test "$status" != 0 ; then
34 | echo "fxzdiff with no changes exited with status $status != 0"
35 | (exit 1)
36 | exit 1
37 | fi
38 |
39 | "$XZDIFF" "$preimage" "$otherpostimage" >/dev/null
40 | status=$?
41 | if test "$status" != 1 ; then
42 | echo "fxzdiff with changes exited with status $status != 1"
43 | (exit 1)
44 | exit 1
45 | fi
46 |
47 | "$XZDIFF" "$preimage" "$srcdir/files/missing.xz" >/dev/null 2>&1
48 | status=$?
49 | if test "$status" != 2 ; then
50 | echo "fxzdiff with missing operand exited with status $status != 2"
51 | (exit 1)
52 | exit 1
53 | fi
54 |
55 | # The exit status must be 0 when a match was found at least from one file,
56 | # and 1 when no match was found in any file.
57 | cp "$srcdir/files/good-1-lzma2-1.xz" xzgrep_test_1.xz
58 | cp "$srcdir/files/good-2-lzma2.xz" xzgrep_test_2.xz
59 | for pattern in el Hello NOMATCH; do
60 | for opts in "" "-l" "-h" "-H"; do
61 | echo "=> fxzgrep $opts $pattern <="
62 | "$XZGREP" $opts $pattern xzgrep_test_1.xz xzgrep_test_2.xz
63 | echo retval $?
64 | done
65 | done > xzgrep_test_output 2>&1
66 |
67 | if cmp -s "$srcdir/xzgrep_expected_output" xzgrep_test_output ; then
68 | :
69 | else
70 | echo "unexpected output from fxzgrep"
71 | (exit 1)
72 | exit 1
73 | fi
74 |
75 | (exit 0)
76 | exit 0
77 |
--------------------------------------------------------------------------------
/tests/xzgrep_expected_output:
--------------------------------------------------------------------------------
1 | => fxzgrep el <=
2 | xzgrep_test_1.xz:elit, sed do eiusmod tempor incididunt ut
3 | xzgrep_test_1.xz:in voluptate velit esse cillum dolore eu
4 | xzgrep_test_2.xz:Hello
5 | retval 0
6 | => fxzgrep -l el <=
7 | xzgrep_test_1.xz
8 | xzgrep_test_2.xz
9 | retval 0
10 | => fxzgrep -h el <=
11 | elit, sed do eiusmod tempor incididunt ut
12 | in voluptate velit esse cillum dolore eu
13 | Hello
14 | retval 0
15 | => fxzgrep -H el <=
16 | xzgrep_test_1.xz:elit, sed do eiusmod tempor incididunt ut
17 | xzgrep_test_1.xz:in voluptate velit esse cillum dolore eu
18 | xzgrep_test_2.xz:Hello
19 | retval 0
20 | => fxzgrep Hello <=
21 | xzgrep_test_2.xz:Hello
22 | retval 0
23 | => fxzgrep -l Hello <=
24 | xzgrep_test_2.xz
25 | retval 0
26 | => fxzgrep -h Hello <=
27 | Hello
28 | retval 0
29 | => fxzgrep -H Hello <=
30 | xzgrep_test_2.xz:Hello
31 | retval 0
32 | => fxzgrep NOMATCH <=
33 | retval 1
34 | => fxzgrep -l NOMATCH <=
35 | retval 1
36 | => fxzgrep -h NOMATCH <=
37 | retval 1
38 | => fxzgrep -H NOMATCH <=
39 | retval 1
40 |
--------------------------------------------------------------------------------
/windows/INSTALL-MSVC.txt:
--------------------------------------------------------------------------------
1 |
2 | Building XZ Utils with Microsoft Visual Studio
3 | ==============================================
4 |
5 | Introduction
6 | ------------
7 |
8 | MSVC 2013 update 2 and later have enough C99 support to build
9 | liblzma from XZ Utils 5.2.0 and later without modifications.
10 | Older MSVC versions would require a large number of changes to
11 | the XZ Utils code and thus the old MSVC versions aren't supported.
12 |
13 | As of 2015-06-19, some work has been done to get xz.exe and other
14 | command line tools built with MSVC, but it's not complete enough
15 | to be included in XZ Utils.
16 |
17 |
18 | Building
19 | --------
20 |
21 | The following files in this directory are for MSVC:
22 |
23 | config.h liblzma configuration #defines for MSVC.
24 | liblzma.vcxproj This builds static liblzma.
25 | liblzma_dll.vcxproj This builds liblzma.dll.
26 | xz_win.sln Solution using the above project files.
27 |
28 | The projects have x86 and x86-64 platform configurations, as well
29 | as a Debug, Release, and ReleaseMT configuration -- MT is the
30 | compiler switch to link to the CRT statically, so it will not
31 | have any other DLL dependencies.
32 |
33 | The VS2017 project files don't set .
34 | This means that you may need to either install Windows SDK 8.1 or
35 | you may need to set the target platform version before building.
36 |
37 | Currently no test programs are built or run under MSVC.
38 |
39 | MSVC gives a bunch of compiler warnings. Some warnings are specific
40 | to 32-bit or 64-bit build and some appear for both builds. These
41 | are known and shouldn't be a problem. Some of them will probably
42 | be fixed in the future.
43 |
44 |
45 | Notes
46 | -----
47 |
48 | liblzma API headers declare the functions with __declspec(dllimport)
49 | by default. To avoid this when using static liblzma from your code,
50 | #define LZMA_API_STATIC before #including .
51 |
52 |
--------------------------------------------------------------------------------