├── AUTHORS ├── CMakeLists.txt ├── COPYING ├── COPYING.0BSD ├── COPYING.GPLv2 ├── COPYING.GPLv3 ├── COPYING.LGPLv2.1 ├── ChangeLog ├── INSTALL ├── INSTALL.generic ├── Makefile.am ├── NEWS ├── PACKAGERS ├── README ├── README.markdown ├── SMP ├── SMP.patch ├── appveyor.yml ├── config.h ├── liblzma.sln ├── liblzma.vcxproj ├── liblzma.vcxproj.filters ├── liblzma_files.props ├── liblzma_winrt.vcxproj ├── liblzma_winrt.vcxproj.filters ├── liblzma_with_latest_sdk.bat ├── readme.txt ├── smp.props └── smp_winrt.props ├── THANKS ├── TODO ├── autogen.sh ├── build-aux ├── manconv.sh └── version.sh ├── cmake ├── remove-ordinals.cmake ├── tuklib_common.cmake ├── tuklib_cpucores.cmake ├── tuklib_integer.cmake ├── tuklib_large_file_support.cmake ├── tuklib_mbstr.cmake ├── tuklib_physmem.cmake └── tuklib_progname.cmake ├── configure.ac ├── debug ├── Makefile.am ├── README ├── crc32.c ├── full_flush.c ├── hex2bin.c ├── known_sizes.c ├── memusage.c ├── repeat.c ├── sync_flush.c ├── testfilegen-arm64.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 ├── faq.txt ├── history.txt ├── lzma-file-format.txt └── xz-file-format.txt ├── dos ├── INSTALL.txt ├── Makefile ├── README.txt └── config.h ├── doxygen ├── Doxyfile └── update-doxygen ├── extra ├── 7z2lzma │ └── 7z2lzma.bash └── scanlzma │ └── scanlzma.c ├── lib ├── Makefile.am ├── getopt-cdefs.h ├── getopt-core.h ├── getopt-ext.h ├── getopt-pfx-core.h ├── getopt-pfx-ext.h ├── getopt.c ├── getopt.in.h ├── getopt1.c └── getopt_int.h ├── 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 ├── po ├── LINGUAS ├── Makevars ├── POTFILES.in ├── ca.po ├── cs.po ├── da.po ├── de.po ├── eo.po ├── es.po ├── fi.po ├── fr.po ├── hr.po ├── hu.po ├── it.po ├── ko.po ├── pl.po ├── pt.po ├── pt_BR.po ├── ro.po ├── sr.po ├── sv.po ├── tr.po ├── uk.po ├── vi.po ├── xz.pot-header ├── zh_CN.po └── zh_TW.po ├── po4a ├── de.po ├── fr.po ├── ko.po ├── po4a.conf ├── pt_BR.po ├── ro.po ├── uk.po └── update-po ├── src ├── Makefile.am ├── common │ ├── 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 │ ├── w32_application.manifest │ └── w32_application.manifest.comments.txt ├── liblzma │ ├── Makefile.am │ ├── api │ │ ├── Makefile.am │ │ ├── lzma.h │ │ └── lzma │ │ │ ├── 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_arm64.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_common.h │ │ ├── crc_x86_clmul.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 │ │ ├── lzip_decoder.c │ │ ├── lzip_decoder.h │ │ ├── memcmplen.h │ │ ├── microlzma_decoder.c │ │ ├── microlzma_encoder.c │ │ ├── outqueue.c │ │ ├── outqueue.h │ │ ├── stream_buffer_decoder.c │ │ ├── stream_buffer_encoder.c │ │ ├── stream_decoder.c │ │ ├── stream_decoder.h │ │ ├── stream_decoder_mt.c │ │ ├── stream_encoder.c │ │ ├── stream_encoder_mt.c │ │ ├── stream_flags_common.c │ │ ├── stream_flags_common.h │ │ ├── stream_flags_decoder.c │ │ ├── stream_flags_encoder.c │ │ ├── string_conversion.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.pc.in │ ├── liblzma_generic.map │ ├── liblzma_linux.map │ ├── 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 │ │ ├── fastpos.h │ │ ├── fastpos_table.c │ │ ├── fastpos_tablegen.c │ │ ├── lzma2_decoder.c │ │ ├── lzma2_decoder.h │ │ ├── lzma2_encoder.c │ │ ├── lzma2_encoder.h │ │ ├── lzma_common.h │ │ ├── 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 │ ├── rangecoder │ │ ├── Makefile.inc │ │ ├── price.h │ │ ├── price_table.c │ │ ├── price_tablegen.c │ │ ├── range_common.h │ │ ├── range_decoder.h │ │ └── range_encoder.h │ ├── simple │ │ ├── Makefile.inc │ │ ├── arm.c │ │ ├── arm64.c │ │ ├── armthumb.c │ │ ├── ia64.c │ │ ├── powerpc.c │ │ ├── riscv.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 │ ├── lzmainfo.1 │ ├── lzmainfo.c │ └── lzmainfo_w32res.rc ├── scripts │ ├── Makefile.am │ ├── xzdiff.1 │ ├── xzdiff.in │ ├── xzgrep.1 │ ├── xzgrep.in │ ├── xzless.1 │ ├── xzless.in │ ├── xzmore.1 │ └── xzmore.in ├── xz │ ├── Makefile.am │ ├── args.c │ ├── args.h │ ├── coder.c │ ├── coder.h │ ├── file_io.c │ ├── file_io.h │ ├── 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 │ ├── sandbox.c │ ├── sandbox.h │ ├── signals.c │ ├── signals.h │ ├── suffix.c │ ├── suffix.h │ ├── util.c │ ├── util.h │ ├── xz.1 │ └── xz_w32res.rc └── xzdec │ ├── Makefile.am │ ├── lzmadec_w32res.rc │ ├── xzdec.1 │ ├── xzdec.c │ └── xzdec_w32res.rc ├── tests ├── Makefile.am ├── code_coverage.sh ├── 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-11.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-v0-uncomp-size.lz │ ├── bad-1-v1-crc32.lz │ ├── bad-1-v1-dict-1.lz │ ├── bad-1-v1-dict-2.lz │ ├── bad-1-v1-magic-1.lz │ ├── bad-1-v1-magic-2.lz │ ├── bad-1-v1-member-size.lz │ ├── bad-1-v1-trailing-magic.lz │ ├── bad-1-v1-uncomp-size.lz │ ├── 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 │ ├── bad-3-index-uncomp-overflow.xz │ ├── bad-too_big_size-with_eopm.lzma │ ├── bad-too_small_size-without_eopm-1.lzma │ ├── bad-too_small_size-without_eopm-2.lzma │ ├── bad-too_small_size-without_eopm-3.lzma │ ├── bad-unknown_size-without_eopm.lzma │ ├── good-0-empty.xz │ ├── good-0cat-empty.xz │ ├── good-0catpad-empty.xz │ ├── good-0pad-empty.xz │ ├── good-1-3delta-lzma2.xz │ ├── good-1-arm64-lzma2-1.xz │ ├── good-1-arm64-lzma2-2.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-empty-bcj-lzma2.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-v0-trailing-1.lz │ ├── good-1-v0.lz │ ├── good-1-v1-trailing-1.lz │ ├── good-1-v1-trailing-2.lz │ ├── good-1-v1.lz │ ├── good-2-lzma2.xz │ ├── good-2-v0-v1.lz │ ├── good-2-v1-v0.lz │ ├── good-2-v1-v1.lz │ ├── good-known_size-with_eopm.lzma │ ├── good-known_size-without_eopm.lzma │ ├── good-unknown_size-with_eopm.lzma │ ├── unsupported-1-v234.lz │ ├── 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_decode_alone.options │ │ ├── fuzz_decode_stream.options │ │ ├── fuzz_encode_stream.options │ │ ├── fuzz_lzma.dict │ │ └── fuzz_xz.dict │ ├── fuzz_common.h │ ├── fuzz_decode_alone.c │ ├── fuzz_decode_stream.c │ └── fuzz_encode_stream.c ├── test_bcj_exact_size.c ├── test_block_header.c ├── test_check.c ├── test_compress.sh ├── test_compress_generated_abc ├── test_compress_generated_random ├── test_compress_generated_text ├── test_files.sh ├── test_filter_flags.c ├── test_filter_str.c ├── test_hardware.c ├── test_index.c ├── test_index_hash.c ├── test_lzip_decoder.c ├── test_memlimit.c ├── test_microlzma.c ├── test_scripts.sh ├── test_stream_flags.c ├── test_suffix.sh ├── test_vli.c ├── tests.cmake ├── tests.h ├── tests_w32res.rc ├── tuktest.h └── xzgrep_expected_output └── windows ├── INSTALL-MSVC.txt ├── INSTALL-MinGW-w64_with_Autotools.txt ├── INSTALL-MinGW-w64_with_CMake.txt ├── README-Windows.txt ├── build-with-cmake.bat ├── build.bash └── liblzma-crt-mixing.txt /AUTHORS: -------------------------------------------------------------------------------- 1 | 2 | Authors of XZ Utils 3 | =================== 4 | 5 | XZ Utils is developed and maintained by 6 | Lasse Collin . 7 | 8 | Major parts of liblzma are based on code written by Igor Pavlov, 9 | specifically the LZMA SDK . Without 10 | this code, XZ Utils wouldn't exist. 11 | 12 | The SHA-256 implementation in liblzma is based on code written by 13 | Wei Dai in Crypto++ Library . 14 | 15 | A few scripts have been adapted from GNU gzip. The original 16 | versions were written by Jean-loup Gailly, Charles Levert, and 17 | Paul Eggert. Andrew Dudman helped adapting the scripts and their 18 | man pages for XZ Utils. 19 | 20 | The initial version of the threaded .xz decompressor was written 21 | by Sebastian Andrzej Siewior. 22 | 23 | The initial version of the .lz (lzip) decoder was written 24 | by Michał Górny. 25 | 26 | Architecture-specific CRC optimizations were contributed by 27 | Ilya Kurdyukov, Hans Jansen, and Chenxi Mao. 28 | 29 | Other authors: 30 | - Jonathan Nieder 31 | - Joachim Henke 32 | 33 | Special author: Jia Tan was a co-maintainer in 2022-2024. He and 34 | the team behind him inserted a backdoor (CVE-2024-3094) into 35 | XZ Utils 5.6.0 and 5.6.1 releases. He suddenly disappeared when 36 | this was discovered. 37 | 38 | Many people have contributed improvements or reported bugs. 39 | Most of these people are mentioned in the file THANKS. 40 | 41 | The translations of the command line tools and man pages have been 42 | contributed by many people via the Translation Project: 43 | 44 | - https://translationproject.org/domain/xz.html 45 | - https://translationproject.org/domain/xz-man.html 46 | 47 | The authors of the translated man pages are in the header comments 48 | of the man page files. In the source package, the authors of the 49 | translations are in po/*.po and po4a/*.po files. 50 | 51 | Third-party code whose authors aren't listed here: 52 | 53 | - GNU getopt_long() in the 'lib' directory is included for 54 | platforms that don't have a usable getopt_long(). 55 | 56 | - The build system files from GNU Autoconf, GNU Automake, 57 | GNU Libtool, GNU Gettext, Autoconf Archive, and related files. 58 | 59 | -------------------------------------------------------------------------------- /COPYING.0BSD: -------------------------------------------------------------------------------- 1 | Permission to use, copy, modify, and/or distribute this 2 | software for any purpose with or without fee is hereby granted. 3 | 4 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 5 | WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 6 | WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL 7 | THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR 8 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 9 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 10 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 11 | CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 12 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | See the commit log in the git repository: 2 | 3 | git clone https://github.com/tukaani-project/xz 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 | -------------------------------------------------------------------------------- /SMP/SMP.patch: -------------------------------------------------------------------------------- 1 | diff --git a/src/common/mythread.h b/src/common/mythread.h 2 | index 10ea2d42..d544a7ec 100644 3 | --- a/src/common/mythread.h 4 | +++ b/src/common/mythread.h 5 | @@ -357,8 +357,10 @@ mythread_condtime_set(mythread_condtime *condtime, const mythread_cond *cond, 6 | 7 | #define WIN32_LEAN_AND_MEAN 8 | #ifdef MYTHREAD_VISTA 9 | -# undef _WIN32_WINNT 10 | -# define _WIN32_WINNT 0x0600 11 | +# if !defined(WINAPI_FAMILY) || !(WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP) 12 | +# undef _WIN32_WINNT 13 | +# define _WIN32_WINNT 0x0600 14 | +# endif 15 | #endif 16 | #include 17 | #include 18 | diff --git a/src/common/tuklib_cpucores.c b/src/common/tuklib_cpucores.c 19 | index c4a781ac..25d3fa6b 100644 20 | --- a/src/common/tuklib_cpucores.c 21 | +++ b/src/common/tuklib_cpucores.c 22 | @@ -13,7 +13,9 @@ 23 | 24 | #if defined(_WIN32) || defined(__CYGWIN__) 25 | # ifndef _WIN32_WINNT 26 | -# define _WIN32_WINNT 0x0500 27 | +# if !defined(WINAPI_FAMILY) || !(WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP) 28 | +# define _WIN32_WINNT 0x0500 29 | +# endif 30 | # endif 31 | # include 32 | 33 | diff --git a/src/common/tuklib_physmem.c b/src/common/tuklib_physmem.c 34 | index 1009df14..77ef362a 100644 35 | --- a/src/common/tuklib_physmem.c 36 | +++ b/src/common/tuklib_physmem.c 37 | @@ -16,7 +16,9 @@ 38 | // gives wrong results (from our point of view). 39 | #if defined(_WIN32) || defined(__CYGWIN__) 40 | # ifndef _WIN32_WINNT 41 | -# define _WIN32_WINNT 0x0500 42 | +# if !defined(WINAPI_FAMILY) || !(WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP) 43 | +# define _WIN32_WINNT 0x0500 44 | +# endif 45 | # endif 46 | # include 47 | 48 | -------------------------------------------------------------------------------- /SMP/liblzma_with_latest_sdk.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | SET PROJECT=liblzma 4 | 5 | @REM Detect the newest available Windows SDK 6 | CALL :GetWindowsSdkVer 7 | 8 | @REM Open the project 9 | %PROJECT%.sln 10 | 11 | EXIT /B 0 12 | 13 | :GetWindowsSdkVer 14 | SET WindowsTargetPlatformVersion= 15 | 16 | IF "%WindowsTargetPlatformVersion%"=="" CALL :GetWin10SdkVer 17 | IF "%WindowsTargetPlatformVersion%"=="" CALL :GetWin81SdkVer 18 | EXIT /B 0 19 | 20 | :GetWin10SdkVer 21 | CALL :GetWin10SdkVerHelper HKLM\SOFTWARE\Wow6432Node > nul 2>&1 22 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKCU\SOFTWARE\Wow6432Node > nul 2>&1 23 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKLM\SOFTWARE > nul 2>&1 24 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKCU\SOFTWARE > nul 2>&1 25 | IF errorlevel 1 EXIT /B 1 26 | EXIT /B 0 27 | 28 | :GetWin10SdkVerHelper 29 | @REM Get Windows 10 SDK installed folder 30 | FOR /F "tokens=1,2*" %%i IN ('reg query "%1\Microsoft\Microsoft SDKs\Windows\v10.0" /v "InstallationFolder"') DO ( 31 | IF "%%i"=="InstallationFolder" ( 32 | SET WindowsSdkDir=%%~k 33 | ) 34 | ) 35 | 36 | @REM get windows 10 sdk version number 37 | SETLOCAL enableDelayedExpansion 38 | IF NOT "%WindowsSdkDir%"=="" FOR /f %%i IN ('dir "%WindowsSdkDir%include\" /b /ad-h /on') DO ( 39 | @REM Skip if Windows.h is not found in %%i\um. This would indicate that only the UCRT MSIs were 40 | @REM installed for this Windows SDK version. 41 | IF EXIST "%WindowsSdkDir%include\%%i\um\Windows.h" ( 42 | SET result=%%i 43 | IF "!result:~0,3!"=="10." ( 44 | SET SDK=!result! 45 | IF "!result!"=="%VSCMD_ARG_WINSDK%" SET findSDK=1 46 | ) 47 | ) 48 | ) 49 | 50 | IF "%findSDK%"=="1" SET SDK=%VSCMD_ARG_WINSDK% 51 | ENDLOCAL & SET WindowsTargetPlatformVersion=%SDK% 52 | IF "%WindowsTargetPlatformVersion%"=="" ( 53 | EXIT /B 1 54 | ) 55 | EXIT /B 0 56 | 57 | :GetWin81SdkVer 58 | SET WindowsTargetPlatformVersion=8.1 59 | EXIT /B 0 60 | -------------------------------------------------------------------------------- /SMP/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a small list of steps in order to build liblzma into a msvc dll and/or lib file. 3 | 4 | The project contains Release and Debug builds for static lib files (Debug/Release) 5 | as well as dynamic shared dll files (DebugDLL/ReleaseDLL). Along with the standard 6 | windows dll/lib configurations mentioned above there are also equivalent variants that 7 | can be used to compile for WinRT/UWP (These configurations have a WinRT suffix). 8 | There are also architecture configurations for either 32bit (x86) or 64bit (x64) compilation. 9 | Choose whichever project configuration meets your requirements. 10 | 11 | The project configurations support being built with various different windows SDK versions. 12 | By default they will use the lowest SDK version that would be available for Visual Studio 13 | version 2013 and up (This is the 8.1 SDK). However a batch file is also included 14 | (liblzma_with_latest_sdk.bat) which can be used to auto detect the newest available SDK 15 | installed on the host machine and then open the project using that as the compilation SDK. 16 | 17 | When using the WinRT/UWP project configurations the projects will automatically compile towards 18 | the default application target for the Version of Visual Studio being used: 19 | VS 2013: 8.1 20 | VS 2015: 8.1 21 | VS 2017+: 10.0.10240.0 22 | 23 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SPDX-License-Identifier: 0BSD 3 | 4 | ############################################################################### 5 | # 6 | # Author: Lasse Collin 7 | # 8 | ############################################################################### 9 | 10 | set -e -x 11 | 12 | # The following six lines are almost identical to "autoreconf -fi" but faster. 13 | ${AUTOPOINT:-autopoint} -f 14 | ${LIBTOOLIZE:-libtoolize} -c -f || glibtoolize -c -f 15 | ${ACLOCAL:-aclocal} -I m4 16 | ${AUTOCONF:-autoconf} 17 | ${AUTOHEADER:-autoheader} 18 | ${AUTOMAKE:-automake} -acf --foreign 19 | 20 | # Generate the translated man pages if the "po4a" tool is available. 21 | # This is *NOT* done by "autoreconf -fi" or when "make" is run. 22 | # Pass --no-po4a to this script to skip this step. 23 | # It can be useful when you know that po4a isn't available and 24 | # don't want autogen.sh to exit with non-zero exit status. 25 | generate_po4a="y" 26 | 27 | for arg in "$@" 28 | do 29 | case $arg in 30 | "--no-po4a") 31 | generate_po4a="n" 32 | ;; 33 | esac 34 | done 35 | 36 | if test "$generate_po4a" != "n"; then 37 | cd po4a 38 | sh update-po 39 | cd .. 40 | fi 41 | 42 | exit 0 43 | -------------------------------------------------------------------------------- /build-aux/manconv.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SPDX-License-Identifier: 0BSD 3 | 4 | ############################################################################### 5 | # 6 | # Wrapper for GNU groff to convert man pages to a few formats 7 | # 8 | # Usage: manconv.sh FORMAT [PAPER_SIZE] < in.1 > out.suffix 9 | # 10 | # FORMAT can be ascii, utf8, ps, or pdf. PAPER_SIZE can be anything that 11 | # groff accepts, e.g. a4 or letter. See groff_font(5). PAPER_SIZE defaults 12 | # to a4 and is used only when FORMAT is ps (PostScript) or pdf. 13 | # 14 | # Multiple man pages can be given at once e.g. to create a single PDF file 15 | # with continuous page numbering. 16 | # 17 | ############################################################################### 18 | # 19 | # Author: Lasse Collin 20 | # 21 | ############################################################################### 22 | 23 | FORMAT=$1 24 | PAPER=${2-a4} 25 | 26 | # Make PostScript and PDF output more readable: 27 | # - Use 11 pt font instead of the default 10 pt. 28 | # - Use larger paragraph spacing than the default 0.4v (man(7) only). 29 | FONT=11 30 | PD=0.8 31 | 32 | SED_PD=" 33 | /^\\.TH /s/\$/\\ 34 | .PD $PD/ 35 | s/^\\.PD\$/.PD $PD/" 36 | 37 | case $FORMAT in 38 | ascii) 39 | groff -t -mandoc -Tascii -P-c | col -bx 40 | ;; 41 | utf8) 42 | groff -t -mandoc -Tutf8 -P-c | col -bx 43 | ;; 44 | ps) 45 | sed "$SED_PD" | groff -dpaper=$PAPER -t -mandoc \ 46 | -rC1 -rS$FONT -Tps -P-p$PAPER 47 | ;; 48 | pdf) 49 | sed "$SED_PD" | groff -dpaper=$PAPER -t -mandoc \ 50 | -rC1 -rS$FONT -Tps -P-p$PAPER | ps2pdf - - 51 | ;; 52 | *) 53 | echo 'Invalid arguments' >&2 54 | exit 1 55 | ;; 56 | esac 57 | -------------------------------------------------------------------------------- /build-aux/version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SPDX-License-Identifier: 0BSD 3 | 4 | ############################################################################# 5 | # 6 | # Get the version string from version.h and print it out without 7 | # trailing newline. This makes it suitable for use in configure.ac. 8 | # 9 | ############################################################################# 10 | # 11 | # Author: Lasse Collin 12 | # 13 | ############################################################################# 14 | 15 | sed -n 's/LZMA_VERSION_STABILITY_ALPHA/alpha/ 16 | s/LZMA_VERSION_STABILITY_BETA/beta/ 17 | s/LZMA_VERSION_STABILITY_STABLE// 18 | s/^#define LZMA_VERSION_[MPS][AIT][AJNT][A-Z]* //p' \ 19 | src/liblzma/api/lzma/version.h \ 20 | | sed 'N; N; N; s/\n/./g; s/\.$//' \ 21 | | tr -d '\012\015\025' 22 | -------------------------------------------------------------------------------- /cmake/remove-ordinals.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | 3 | ############################################################################# 4 | # 5 | # remove-ordinals.cmake 6 | # 7 | # Removes the ordinal numbers from a DEF file that has been created by 8 | # GNU ld or LLVM lld option --output-def (when creating a Windows DLL). 9 | # This should be equivalent: sed 's/ \+@ *[0-9]\+//' 10 | # 11 | # Usage: 12 | # 13 | # cmake -DINPUT_FILE=infile.def.in \ 14 | # -DOUTPUT_FILE=outfile.def \ 15 | # -P remove-ordinals.cmake 16 | # 17 | ############################################################################# 18 | # 19 | # Author: Lasse Collin 20 | # 21 | ############################################################################# 22 | 23 | file(READ "${INPUT_FILE}" STR) 24 | string(REGEX REPLACE " +@ *[0-9]+" "" STR "${STR}") 25 | file(WRITE "${OUTPUT_FILE}" "${STR}") 26 | -------------------------------------------------------------------------------- /cmake/tuklib_common.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | 3 | ############################################################################# 4 | # 5 | # tuklib_common.cmake - common functions and macros for tuklib_*.cmake files 6 | # 7 | # Author: Lasse Collin 8 | # 9 | ############################################################################# 10 | 11 | function(tuklib_add_definitions TARGET_OR_ALL DEFINITIONS) 12 | # DEFINITIONS may be an empty string/list but it's fine here. There is 13 | # no need to quote ${DEFINITIONS} as empty arguments are fine here. 14 | if(TARGET_OR_ALL STREQUAL "ALL") 15 | add_compile_definitions(${DEFINITIONS}) 16 | else() 17 | target_compile_definitions("${TARGET_OR_ALL}" PRIVATE ${DEFINITIONS}) 18 | endif() 19 | endfunction() 20 | 21 | function(tuklib_add_definition_if TARGET_OR_ALL VAR) 22 | if(${VAR}) 23 | tuklib_add_definitions("${TARGET_OR_ALL}" "${VAR}") 24 | endif() 25 | endfunction() 26 | 27 | # This is an over-simplified version of AC_USE_SYSTEM_EXTENSIONS in Autoconf 28 | # or gl_USE_SYSTEM_EXTENSIONS in gnulib. 29 | macro(tuklib_use_system_extensions TARGET_OR_ALL) 30 | if(NOT WIN32) 31 | # FIXME? The Solaris-specific __EXTENSIONS__ should be conditional 32 | # even on Solaris. See gnulib: git log m4/extensions.m4. 33 | # FIXME? gnulib and autoconf.git has lots of new stuff. 34 | tuklib_add_definitions("${TARGET_OR_ALL}" 35 | _GNU_SOURCE 36 | __EXTENSIONS__ 37 | _POSIX_PTHREAD_SEMANTICS 38 | _TANDEM_SOURCE 39 | _ALL_SOURCE 40 | ) 41 | 42 | list(APPEND CMAKE_REQUIRED_DEFINITIONS 43 | -D_GNU_SOURCE 44 | -D__EXTENSIONS__ 45 | -D_POSIX_PTHREAD_SEMANTICS 46 | -D_TANDEM_SOURCE 47 | -D_ALL_SOURCE 48 | ) 49 | endif() 50 | endmacro() 51 | -------------------------------------------------------------------------------- /cmake/tuklib_large_file_support.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | 3 | ############################################################################# 4 | # 5 | # tuklib_large_file_support.cmake 6 | # 7 | # If off_t is less than 64 bits by default and -D_FILE_OFFSET_BITS=64 8 | # makes off_t become 64-bit, the CMake option LARGE_FILE_SUPPORT is 9 | # provided (ON by default) and -D_FILE_OFFSET_BITS=64 is added to 10 | # the compile definitions if LARGE_FILE_SUPPORT is ON. 11 | # 12 | # Author: Lasse Collin 13 | # 14 | ############################################################################# 15 | 16 | include("${CMAKE_CURRENT_LIST_DIR}/tuklib_common.cmake") 17 | include(CheckCSourceCompiles) 18 | 19 | function(tuklib_large_file_support TARGET_OR_ALL) 20 | # MSVC must be handled specially in the C code. 21 | if(MSVC) 22 | return() 23 | endif() 24 | 25 | set(TUKLIB_LARGE_FILE_SUPPORT_TEST 26 | "#include 27 | int foo[sizeof(off_t) >= 8 ? 1 : -1]; 28 | int main(void) { return 0; }") 29 | 30 | check_c_source_compiles("${TUKLIB_LARGE_FILE_SUPPORT_TEST}" 31 | TUKLIB_LARGE_FILE_SUPPORT_BY_DEFAULT) 32 | 33 | if(NOT TUKLIB_LARGE_FILE_SUPPORT_BY_DEFAULT) 34 | cmake_push_check_state() 35 | # This needs -D. 36 | list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64") 37 | check_c_source_compiles("${TUKLIB_LARGE_FILE_SUPPORT_TEST}" 38 | TUKLIB_LARGE_FILE_SUPPORT_WITH_FOB64) 39 | cmake_pop_check_state() 40 | endif() 41 | 42 | if(TUKLIB_LARGE_FILE_SUPPORT_WITH_FOB64) 43 | # Show the option only when _FILE_OFFSET_BITS=64 affects sizeof(off_t). 44 | option(LARGE_FILE_SUPPORT 45 | "Use -D_FILE_OFFSET_BITS=64 to support files larger than 2 GiB." 46 | ON) 47 | 48 | if(LARGE_FILE_SUPPORT) 49 | # This must not use -D. 50 | tuklib_add_definitions("${TARGET_OR_ALL}" "_FILE_OFFSET_BITS=64") 51 | endif() 52 | endif() 53 | endfunction() 54 | -------------------------------------------------------------------------------- /cmake/tuklib_mbstr.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | 3 | ############################################################################# 4 | # 5 | # tuklib_mbstr.cmake - see tuklib_mbstr.m4 for description and comments 6 | # 7 | # Author: Lasse Collin 8 | # 9 | ############################################################################# 10 | 11 | include("${CMAKE_CURRENT_LIST_DIR}/tuklib_common.cmake") 12 | include(CheckSymbolExists) 13 | 14 | function(tuklib_mbstr TARGET_OR_ALL) 15 | check_symbol_exists(mbrtowc wchar.h HAVE_MBRTOWC) 16 | tuklib_add_definition_if("${TARGET_OR_ALL}" HAVE_MBRTOWC) 17 | 18 | # NOTE: wcwidth() requires _GNU_SOURCE or _XOPEN_SOURCE on GNU/Linux. 19 | check_symbol_exists(wcwidth wchar.h HAVE_WCWIDTH) 20 | tuklib_add_definition_if("${TARGET_OR_ALL}" HAVE_WCWIDTH) 21 | endfunction() 22 | -------------------------------------------------------------------------------- /cmake/tuklib_progname.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | 3 | ############################################################################# 4 | # 5 | # tuklib_progname.cmake - see tuklib_progname.m4 for description and comments 6 | # 7 | # Author: Lasse Collin 8 | # 9 | ############################################################################# 10 | 11 | include("${CMAKE_CURRENT_LIST_DIR}/tuklib_common.cmake") 12 | include(CheckSymbolExists) 13 | 14 | function(tuklib_progname TARGET_OR_ALL) 15 | # NOTE: This glibc extension requires _GNU_SOURCE. 16 | check_symbol_exists(program_invocation_name errno.h 17 | HAVE_PROGRAM_INVOCATION_NAME) 18 | tuklib_add_definition_if("${TARGET_OR_ALL}" HAVE_PROGRAM_INVOCATION_NAME) 19 | endfunction() 20 | -------------------------------------------------------------------------------- /debug/Makefile.am: -------------------------------------------------------------------------------- 1 | ## SPDX-License-Identifier: 0BSD 2 | ## Author: Lasse Collin 3 | 4 | EXTRA_DIST = \ 5 | translation.bash 6 | 7 | noinst_PROGRAMS = \ 8 | repeat \ 9 | sync_flush \ 10 | full_flush \ 11 | memusage \ 12 | crc32 \ 13 | known_sizes \ 14 | hex2bin \ 15 | testfilegen-arm64 16 | 17 | AM_CPPFLAGS = \ 18 | -I$(top_srcdir)/src/common \ 19 | -I$(top_srcdir)/src/liblzma/api 20 | 21 | LDADD = $(top_builddir)/src/liblzma/liblzma.la 22 | 23 | if COND_GNULIB 24 | LDADD += $(top_builddir)/lib/libgnu.a 25 | endif 26 | 27 | LDADD += $(LTLIBINTL) 28 | -------------------------------------------------------------------------------- /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 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file crc32.c 6 | /// \brief Primitive CRC32 calculation tool 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "sysdefs.h" 13 | #include "lzma.h" 14 | #include 15 | 16 | 17 | int 18 | main(void) 19 | { 20 | uint32_t crc = 0; 21 | 22 | do { 23 | uint8_t buf[BUFSIZ]; 24 | const size_t size = fread(buf, 1, sizeof(buf), stdin); 25 | crc = lzma_crc32(buf, size, crc); 26 | } while (!ferror(stdin) && !feof(stdin)); 27 | 28 | //printf("%08" PRIX32 "\n", crc); 29 | 30 | // I want it little endian so it's easy to work with hex editor. 31 | printf("%02" PRIX32 " ", crc & 0xFF); 32 | printf("%02" PRIX32 " ", (crc >> 8) & 0xFF); 33 | printf("%02" PRIX32 " ", (crc >> 16) & 0xFF); 34 | printf("%02" PRIX32 " ", crc >> 24); 35 | printf("\n"); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /debug/hex2bin.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file hex2bin.c 6 | /// \brief Converts hexadecimal input strings to binary 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "sysdefs.h" 13 | #include 14 | #include 15 | 16 | 17 | static int 18 | getbin(int x) 19 | { 20 | if (x >= '0' && x <= '9') 21 | return x - '0'; 22 | 23 | if (x >= 'A' && x <= 'F') 24 | return x - 'A' + 10; 25 | 26 | return x - 'a' + 10; 27 | } 28 | 29 | 30 | int 31 | main(void) 32 | { 33 | while (true) { 34 | int byte = getchar(); 35 | if (byte == EOF) 36 | return 0; 37 | if (!isxdigit(byte)) 38 | continue; 39 | 40 | const int digit = getchar(); 41 | if (digit == EOF || !isxdigit(digit)) { 42 | fprintf(stderr, "Invalid input\n"); 43 | return 1; 44 | } 45 | 46 | byte = (getbin(byte) << 4) | getbin(digit); 47 | if (putchar(byte) == EOF) { 48 | perror(NULL); 49 | return 1; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /debug/memusage.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file memusage.c 6 | /// \brief Calculates memory usage using lzma_memory_usage() 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "sysdefs.h" 13 | #include "lzma.h" 14 | #include 15 | 16 | int 17 | main(void) 18 | { 19 | lzma_options_lzma lzma = { 20 | .dict_size = (1U << 30) + (1U << 29), 21 | .lc = 3, 22 | .lp = 0, 23 | .pb = 2, 24 | .preset_dict = NULL, 25 | .preset_dict_size = 0, 26 | .mode = LZMA_MODE_NORMAL, 27 | .nice_len = 48, 28 | .mf = LZMA_MF_BT4, 29 | .depth = 0, 30 | }; 31 | 32 | /* 33 | lzma_options_filter filters[] = { 34 | { LZMA_FILTER_LZMA1, 35 | (lzma_options_lzma *)&lzma_preset_lzma[6 - 1] }, 36 | { UINT64_MAX, NULL } 37 | }; 38 | */ 39 | lzma_filter filters[] = { 40 | { LZMA_FILTER_LZMA1, &lzma }, 41 | { UINT64_MAX, NULL } 42 | }; 43 | 44 | printf("Encoder: %10" PRIu64 " B\n", 45 | lzma_raw_encoder_memusage(filters)); 46 | printf("Decoder: %10" PRIu64 " B\n", 47 | lzma_raw_decoder_memusage(filters)); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /debug/repeat.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file repeat.c 6 | /// \brief Repeats given string given times 7 | /// 8 | /// This program can be useful when debugging run-length encoder in 9 | /// the Subblock filter, especially the condition when repeat count 10 | /// doesn't fit into 28-bit integer. 11 | // 12 | // Author: Lasse Collin 13 | // 14 | /////////////////////////////////////////////////////////////////////////////// 15 | 16 | #include "sysdefs.h" 17 | #include 18 | 19 | 20 | int 21 | main(int argc, char **argv) 22 | { 23 | if (argc != 3) { 24 | fprintf(stderr, "Usage: %s COUNT STRING\n", argv[0]); 25 | exit(1); 26 | } 27 | 28 | unsigned long long count = strtoull(argv[1], NULL, 10); 29 | const size_t size = strlen(argv[2]); 30 | 31 | while (count-- != 0) 32 | fwrite(argv[2], 1, size, stdout); 33 | 34 | return !!(ferror(stdout) || fclose(stdout)); 35 | } 36 | -------------------------------------------------------------------------------- /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 | # SPDX-License-Identifier: 0BSD 2 | # Author: Lasse Collin 3 | 4 | CC = c99 5 | CFLAGS = -g 6 | LDFLAGS = -llzma 7 | 8 | PROGS = \ 9 | 01_compress_easy \ 10 | 02_decompress \ 11 | 03_compress_custom \ 12 | 04_compress_easy_mt \ 13 | 11_file_info 14 | 15 | all: $(PROGS) 16 | 17 | .c: 18 | $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) 19 | 20 | clean: 21 | -rm -f $(PROGS) 22 | -------------------------------------------------------------------------------- /doxygen/Doxyfile: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | 3 | # Run "doxygen" in this directory to generate the liblzma API documentation 4 | # into ../doc/api. 5 | # 6 | # Use the "update-doxygen" script for more choices: 7 | # - Include the liblzma version number in the generated documentation. 8 | # - Instead of API docs, docs of XZ Utils internals may be built. 9 | # - Change the output directory for out-of-tree builds. 10 | # 11 | # These options were tested with Doxygen 1.10.0. 12 | 13 | PROJECT_NAME = "liblzma (XZ Utils)" 14 | OUTPUT_DIRECTORY = ../doc 15 | STRIP_FROM_PATH = ../src/liblzma/api 16 | INPUT = ../src/liblzma/api 17 | FILE_PATTERNS = *.c *.h 18 | RECURSIVE = YES 19 | OPTIMIZE_OUTPUT_FOR_C = YES 20 | EXTRACT_STATIC = YES 21 | SORT_MEMBER_DOCS = NO 22 | SOURCE_TOOLTIPS = NO 23 | VERBATIM_HEADERS = NO 24 | ALPHABETICAL_INDEX = NO 25 | HTML_OUTPUT = api 26 | HTML_COLORSTYLE_HUE = 210 27 | HTML_COLORSTYLE_SAT = 180 28 | HTML_COLORSTYLE_GAMMA = 110 29 | HTML_DYNAMIC_MENUS = NO 30 | SEARCHENGINE = NO 31 | GENERATE_LATEX = NO 32 | MACRO_EXPANSION = YES 33 | EXPAND_ONLY_PREDEF = YES 34 | PREDEFINED = LZMA_API(type)=type \ 35 | LZMA_API_IMPORT= \ 36 | LZMA_API_CALL= \ 37 | tuklib_attr_noreturn= \ 38 | lzma_attribute(attr)= \ 39 | lzma_attr_alloc_size(size)= 40 | -------------------------------------------------------------------------------- /lib/Makefile.am: -------------------------------------------------------------------------------- 1 | ## SPDX-License-Identifier: GPL-2.0-or-later 2 | 3 | ## 4 | ## Copyright (C) 2004-2007 Free Software Foundation, Inc. 5 | ## 6 | ## This program is free software; you can redistribute it and/or modify 7 | ## it under the terms of the GNU General Public License as published by 8 | ## the Free Software Foundation; either version 2 of the License, or 9 | ## (at your option) any later version. 10 | ## 11 | ## This program is distributed in the hope that it will be useful, 12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ## GNU General Public License for more details. 15 | ## 16 | 17 | ## Not using gnulib-tool, at least for now. It is likely that we won't 18 | ## need anything else from Gnulib than getopt_long(). 19 | 20 | noinst_LIBRARIES = libgnu.a 21 | 22 | libgnu_a_SOURCES = 23 | libgnu_a_DEPENDENCIES = $(LIBOBJS) 24 | libgnu_a_LIBADD = $(LIBOBJS) 25 | 26 | EXTRA_DIST = \ 27 | getopt.in.h \ 28 | getopt.c \ 29 | getopt1.c \ 30 | getopt_int.h \ 31 | getopt-cdefs.h \ 32 | getopt-core.h \ 33 | getopt-ext.h \ 34 | getopt-pfx-core.h \ 35 | getopt-pfx-ext.h 36 | 37 | BUILT_SOURCES = $(GETOPT_H) 38 | MOSTLYCLEANFILES = getopt.h getopt.h-t 39 | 40 | getopt.h: getopt.in.h 41 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 42 | cat $(srcdir)/getopt.in.h; \ 43 | } > $@-t 44 | mv -f $@-t $@ 45 | -------------------------------------------------------------------------------- /lib/getopt-cdefs.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 | 3 | /* getopt-on-non-glibc compatibility macros. 4 | Copyright (C) 1989-2023 Free Software Foundation, Inc. 5 | This file is part of gnulib. 6 | Unlike most of the getopt implementation, it is NOT shared 7 | with the GNU C Library. 8 | 9 | This file is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU Lesser General Public License as 11 | published by the Free Software Foundation; either version 2.1 of the 12 | License, or (at your option) any later version. 13 | 14 | This file is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with this program. If not, see . */ 21 | 22 | #ifndef _GETOPT_CDEFS_H 23 | #define _GETOPT_CDEFS_H 1 24 | 25 | /* This header should not be used directly; include getopt.h or 26 | unistd.h instead. It does not have a protective #error, because 27 | the guard macro for getopt.h in gnulib is not fixed. */ 28 | 29 | /* getopt-core.h and getopt-ext.h are shared with GNU libc, and expect 30 | a number of the internal macros supplied to GNU libc's headers by 31 | sys/cdefs.h. Provide fallback definitions for all of them. */ 32 | #ifdef HAVE_SYS_CDEFS_H 33 | # include 34 | #endif 35 | 36 | #ifndef __BEGIN_DECLS 37 | # ifdef __cplusplus 38 | # define __BEGIN_DECLS extern "C" { 39 | # else 40 | # define __BEGIN_DECLS /* nothing */ 41 | # endif 42 | #endif 43 | #ifndef __END_DECLS 44 | # ifdef __cplusplus 45 | # define __END_DECLS } 46 | # else 47 | # define __END_DECLS /* nothing */ 48 | # endif 49 | #endif 50 | 51 | #ifndef __GNUC_PREREQ 52 | # if defined __GNUC__ && defined __GNUC_VERSION__ 53 | # define __GNUC_PREREQ(maj, min) \ 54 | ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) 55 | # else 56 | # define __GNUC_PREREQ(maj, min) 0 57 | # endif 58 | #endif 59 | 60 | #ifndef __THROW 61 | # if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major__ >= 4) 62 | # if __cplusplus >= 201103L 63 | # define __THROW noexcept (true) 64 | # else 65 | # define __THROW throw () 66 | # endif 67 | # else 68 | # define __THROW 69 | # endif 70 | #endif 71 | 72 | #endif /* _GETOPT_CDEFS_H */ 73 | -------------------------------------------------------------------------------- /lib/getopt.in.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 | 3 | /* Declarations for getopt. 4 | Copyright (C) 1989-2023 Free Software Foundation, Inc. 5 | This file is part of gnulib. 6 | Unlike most of the getopt implementation, it is NOT shared 7 | with the GNU C Library, which supplies a different version of 8 | this file. 9 | 10 | This file is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU Lesser General Public License as 12 | published by the Free Software Foundation; either version 2.1 of the 13 | License, or (at your option) any later version. 14 | 15 | This file is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public License 21 | along with this program. If not, see . */ 22 | 23 | #ifndef _GETOPT_H 24 | 25 | #define _GETOPT_H 1 26 | 27 | /* Standalone applications should #define __GETOPT_PREFIX to an 28 | identifier that prefixes the external functions and variables 29 | defined in this header. When this happens, include the 30 | headers that might declare getopt so that they will not cause 31 | confusion if included after this file. Then systematically rename 32 | identifiers so that they do not collide with the system functions 33 | and variables. Renaming avoids problems with some compilers and 34 | linkers. */ 35 | #if defined __GETOPT_PREFIX 36 | # include 37 | # include 38 | 39 | # ifndef _MSC_VER 40 | # include 41 | # endif 42 | #endif 43 | 44 | /* From Gnulib's lib/arg-nonnull.h: */ 45 | /* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools 46 | that the values passed as arguments n, ..., m must be non-NULL pointers. 47 | n = 1 stands for the first argument, n = 2 for the second argument etc. */ 48 | #ifndef _GL_ARG_NONNULL 49 | # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || defined __clang__ 50 | # define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params)) 51 | # else 52 | # define _GL_ARG_NONNULL(params) 53 | # endif 54 | #endif 55 | 56 | #include 57 | #include 58 | #include 59 | 60 | #endif /* _GETOPT_H */ 61 | -------------------------------------------------------------------------------- /m4/posix-shell.m4: -------------------------------------------------------------------------------- 1 | dnl SPDX-License-Identifier: FSFULLR 2 | 3 | # Find a POSIX-conforming shell. 4 | 5 | # Copyright (C) 2007-2008 Free Software Foundation, Inc. 6 | 7 | # This file is free software; the Free Software Foundation 8 | # gives unlimited permission to copy and/or distribute it, 9 | # with or without modifications, as long as this notice is preserved. 10 | 11 | # Written by Paul Eggert. 12 | 13 | # If a POSIX-conforming shell can be found, set POSIX_SHELL and 14 | # PREFERABLY_POSIX_SHELL to it. If not, set POSIX_SHELL to the 15 | # empty string and PREFERABLY_POSIX_SHELL to '/bin/sh'. 16 | 17 | AC_DEFUN([gl_POSIX_SHELL], 18 | [ 19 | AC_CACHE_CHECK([for a shell that conforms to POSIX], [gl_cv_posix_shell], 20 | [gl_test_posix_shell_script=' 21 | func_return () { 22 | (exit [$]1) 23 | } 24 | func_success () { 25 | func_return 0 26 | } 27 | func_failure () { 28 | func_return 1 29 | } 30 | func_ret_success () { 31 | return 0 32 | } 33 | func_ret_failure () { 34 | return 1 35 | } 36 | subshell_umask_sanity () { 37 | (umask 22; (umask 0); test $(umask) -eq 22) 38 | } 39 | test "[$](echo foo)" = foo && 40 | func_success && 41 | ! func_failure && 42 | func_ret_success && 43 | ! func_ret_failure && 44 | (set x && func_ret_success y && test x = "[$]1") && 45 | subshell_umask_sanity 46 | ' 47 | for gl_cv_posix_shell in \ 48 | "$CONFIG_SHELL" "$SHELL" /bin/sh /bin/bash /bin/ksh /bin/sh5 no; do 49 | case $gl_cv_posix_shell in 50 | /*) 51 | "$gl_cv_posix_shell" -c "$gl_test_posix_shell_script" 2>/dev/null \ 52 | && break;; 53 | esac 54 | done]) 55 | 56 | if test "$gl_cv_posix_shell" != no; then 57 | POSIX_SHELL=$gl_cv_posix_shell 58 | PREFERABLY_POSIX_SHELL=$POSIX_SHELL 59 | else 60 | POSIX_SHELL= 61 | PREFERABLY_POSIX_SHELL=/bin/sh 62 | fi 63 | AC_SUBST([POSIX_SHELL]) 64 | AC_SUBST([PREFERABLY_POSIX_SHELL]) 65 | ]) 66 | -------------------------------------------------------------------------------- /m4/tuklib_common.m4: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | 3 | ############################################################################# 4 | # 5 | # SYNOPSIS 6 | # 7 | # TUKLIB_COMMON 8 | # 9 | # DESCRIPTION 10 | # 11 | # Common checks for tuklib. 12 | # 13 | ############################################################################# 14 | # 15 | # Author: Lasse Collin 16 | # 17 | ############################################################################# 18 | 19 | AC_DEFUN_ONCE([TUKLIB_COMMON], [ 20 | AC_REQUIRE([AC_CANONICAL_HOST]) 21 | AC_REQUIRE([AC_PROG_CC_C99]) 22 | AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) 23 | ])dnl 24 | -------------------------------------------------------------------------------- /m4/tuklib_mbstr.m4: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | 3 | ############################################################################# 4 | # 5 | # SYNOPSIS 6 | # 7 | # TUKLIB_MBSTR 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check if multibyte and wide character functionality is available 12 | # for use by tuklib_mbstr_* functions. If not enough multibyte string 13 | # support is available in the C library, the functions keep working 14 | # with the assumption that all strings are a in single-byte character 15 | # set without combining characters, e.g. US-ASCII or ISO-8859-*. 16 | # 17 | # This .m4 file and tuklib_mbstr.h are common to all tuklib_mbstr_* 18 | # functions, but each function is put into a separate .c file so 19 | # that it is possible to pick only what is strictly needed. 20 | # 21 | ############################################################################# 22 | # 23 | # Author: Lasse Collin 24 | # 25 | ############################################################################# 26 | 27 | AC_DEFUN_ONCE([TUKLIB_MBSTR], [ 28 | AC_REQUIRE([TUKLIB_COMMON]) 29 | AC_FUNC_MBRTOWC 30 | AC_CHECK_FUNCS([wcwidth]) 31 | ])dnl 32 | -------------------------------------------------------------------------------- /m4/tuklib_progname.m4: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | 3 | ############################################################################# 4 | # 5 | # SYNOPSIS 6 | # 7 | # TUKLIB_PROGNAME 8 | # 9 | # DESCRIPTION 10 | # 11 | # Put argv[0] into a global variable progname. On DOS-like systems, 12 | # modify it so that it looks nice (no full path or .exe suffix). 13 | # 14 | # This .m4 file is needed allow this module to use glibc's 15 | # program_invocation_name. 16 | # 17 | ############################################################################# 18 | # 19 | # Author: Lasse Collin 20 | # 21 | ############################################################################# 22 | 23 | AC_DEFUN_ONCE([TUKLIB_PROGNAME], [ 24 | AC_REQUIRE([TUKLIB_COMMON]) 25 | AC_CHECK_DECL([program_invocation_name], [AC_DEFINE( 26 | [HAVE_PROGRAM_INVOCATION_NAME], [1], 27 | [Define to 1 if 'program_invocation_name' is declared in .])], 28 | [], [#include ]) 29 | ])dnl 30 | -------------------------------------------------------------------------------- /po/LINGUAS: -------------------------------------------------------------------------------- 1 | ca 2 | cs 3 | da 4 | de 5 | eo 6 | es 7 | fi 8 | fr 9 | hr 10 | hu 11 | it 12 | ko 13 | pl 14 | pt 15 | pt_BR 16 | ro 17 | sr 18 | sv 19 | tr 20 | uk 21 | vi 22 | zh_CN 23 | zh_TW 24 | -------------------------------------------------------------------------------- /po/POTFILES.in: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | 3 | # List of source files which contain translatable strings. 4 | src/xz/args.c 5 | src/xz/coder.c 6 | src/xz/file_io.c 7 | src/xz/hardware.c 8 | src/xz/list.c 9 | src/xz/main.c 10 | src/xz/message.c 11 | src/xz/mytime.c 12 | src/xz/options.c 13 | src/xz/signals.c 14 | src/xz/suffix.c 15 | src/xz/util.c 16 | src/lzmainfo/lzmainfo.c 17 | src/common/tuklib_exit.c 18 | -------------------------------------------------------------------------------- /po/xz.pot-header: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | # 3 | # SOME DESCRIPTIVE TITLE. 4 | # Copyright (C) The XZ Utils authors and contributors 5 | # This file is published under the BSD Zero Clause License. 6 | # FIRST AUTHOR , YEAR. 7 | # 8 | -------------------------------------------------------------------------------- /po4a/po4a.conf: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | 3 | # To add a new language, add it to po4a_langs and run "update-po" 4 | # to get a new .po file. After translating the .po file, run 5 | # "update-po" again to generate the translated man pages. 6 | 7 | [po4a_langs] de fr ko pt_BR ro uk 8 | [po4a_paths] xz-man.pot $lang:$lang.po 9 | 10 | [type: man] ../src/xz/xz.1 $lang:man/$lang/xz.1 add_$lang:?$lang.po.authors 11 | [type: man] ../src/xzdec/xzdec.1 $lang:man/$lang/xzdec.1 add_$lang:?$lang.po.authors 12 | [type: man] ../src/lzmainfo/lzmainfo.1 $lang:man/$lang/lzmainfo.1 add_$lang:?$lang.po.authors 13 | [type: man] ../src/scripts/xzdiff.1 $lang:man/$lang/xzdiff.1 add_$lang:?$lang.po.authors 14 | [type: man] ../src/scripts/xzgrep.1 $lang:man/$lang/xzgrep.1 add_$lang:?$lang.po.authors 15 | [type: man] ../src/scripts/xzless.1 $lang:man/$lang/xzless.1 add_$lang:?$lang.po.authors 16 | [type: man] ../src/scripts/xzmore.1 $lang:man/$lang/xzmore.1 add_$lang:?$lang.po.authors 17 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## SPDX-License-Identifier: 0BSD 2 | ## Author: Lasse Collin 3 | 4 | SUBDIRS = liblzma xzdec 5 | 6 | if COND_XZ 7 | SUBDIRS += xz 8 | endif 9 | 10 | if COND_LZMAINFO 11 | SUBDIRS += lzmainfo 12 | endif 13 | 14 | if COND_SCRIPTS 15 | SUBDIRS += scripts 16 | endif 17 | 18 | EXTRA_DIST = \ 19 | common/common_w32res.rc \ 20 | common/mythread.h \ 21 | common/sysdefs.h \ 22 | common/tuklib_common.h \ 23 | common/tuklib_config.h \ 24 | common/tuklib_cpucores.c \ 25 | common/tuklib_cpucores.h \ 26 | common/tuklib_exit.c \ 27 | common/tuklib_exit.h \ 28 | common/tuklib_gettext.h \ 29 | common/tuklib_integer.h \ 30 | common/tuklib_mbstr_fw.c \ 31 | common/tuklib_mbstr.h \ 32 | common/tuklib_mbstr_width.c \ 33 | common/tuklib_open_stdxxx.c \ 34 | common/tuklib_open_stdxxx.h \ 35 | common/tuklib_physmem.c \ 36 | common/tuklib_physmem.h \ 37 | common/tuklib_progname.c \ 38 | common/tuklib_progname.h \ 39 | common/w32_application.manifest \ 40 | common/w32_application.manifest.comments.txt 41 | -------------------------------------------------------------------------------- /src/common/common_w32res.rc: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: 0BSD */ 2 | 3 | /* 4 | * Author: Lasse Collin 5 | */ 6 | 7 | #include 8 | #ifdef HAVE_CONFIG_H 9 | # include "config.h" 10 | #endif 11 | #define LZMA_H_INTERNAL 12 | #define LZMA_H_INTERNAL_RC 13 | #include "lzma/version.h" 14 | 15 | #ifndef MY_BUILD 16 | # define MY_BUILD 0 17 | #endif 18 | #define MY_VERSION LZMA_VERSION_MAJOR,LZMA_VERSION_MINOR,LZMA_VERSION_PATCH,MY_BUILD 19 | 20 | #define MY_FILENAME MY_NAME MY_SUFFIX 21 | #define MY_COMPANY "The Tukaani Project " 22 | #define MY_PRODUCT PACKAGE_NAME " <" PACKAGE_URL ">" 23 | 24 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 25 | 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 | 54 | /* Omit the manifest on Cygwin and MSYS2 (both define __CYGWIN__). */ 55 | #if MY_TYPE == VFT_APP && !defined(__CYGWIN__) 56 | CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "w32_application.manifest" 57 | #endif 58 | -------------------------------------------------------------------------------- /src/common/tuklib_config.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | // If config.h isn't available, assume that the headers required by 4 | // tuklib_common.h are available. This is required by crc32_tablegen.c. 5 | #ifdef HAVE_CONFIG_H 6 | # include "sysdefs.h" 7 | #else 8 | # include 9 | # include 10 | # include 11 | # include 12 | #endif 13 | -------------------------------------------------------------------------------- /src/common/tuklib_cpucores.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file tuklib_cpucores.h 6 | /// \brief Get the number of CPU cores online 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef TUKLIB_CPUCORES_H 13 | #define TUKLIB_CPUCORES_H 14 | 15 | #include "tuklib_common.h" 16 | TUKLIB_DECLS_BEGIN 17 | 18 | #define tuklib_cpucores TUKLIB_SYMBOL(tuklib_cpucores) 19 | extern uint32_t tuklib_cpucores(void); 20 | 21 | TUKLIB_DECLS_END 22 | #endif 23 | -------------------------------------------------------------------------------- /src/common/tuklib_exit.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file tuklib_exit.c 6 | /// \brief Close stdout and stderr, and exit 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "tuklib_common.h" 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include "tuklib_gettext.h" 19 | #include "tuklib_progname.h" 20 | #include "tuklib_exit.h" 21 | 22 | 23 | extern void 24 | tuklib_exit(int status, int err_status, int show_error) 25 | { 26 | if (status != err_status) { 27 | // Close stdout. If something goes wrong, 28 | // print an error message to stderr. 29 | const int ferror_err = ferror(stdout); 30 | const int fclose_err = fclose(stdout); 31 | if (ferror_err || fclose_err) { 32 | status = err_status; 33 | 34 | // If it was fclose() that failed, we have the reason 35 | // in errno. If only ferror() indicated an error, 36 | // we have no idea what the reason was. 37 | if (show_error) 38 | fprintf(stderr, "%s: %s: %s\n", progname, 39 | _("Writing to standard " 40 | "output failed"), 41 | fclose_err ? strerror(errno) 42 | : _("Unknown error")); 43 | } 44 | } 45 | 46 | if (status != err_status) { 47 | // Close stderr. If something goes wrong, there's 48 | // nothing where we could print an error message. 49 | // Just set the exit status. 50 | const int ferror_err = ferror(stderr); 51 | const int fclose_err = fclose(stderr); 52 | if (fclose_err || ferror_err) 53 | status = err_status; 54 | } 55 | 56 | exit(status); 57 | } 58 | -------------------------------------------------------------------------------- /src/common/tuklib_exit.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file tuklib_exit.h 6 | /// \brief Close stdout and stderr, and exit 7 | /// \note Requires tuklib_progname and tuklib_gettext modules 8 | // 9 | // Author: Lasse Collin 10 | // 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | #ifndef TUKLIB_EXIT_H 14 | #define TUKLIB_EXIT_H 15 | 16 | #include "tuklib_common.h" 17 | TUKLIB_DECLS_BEGIN 18 | 19 | #define tuklib_exit TUKLIB_SYMBOL(tuklib_exit) 20 | tuklib_attr_noreturn 21 | extern void tuklib_exit(int status, int err_status, int show_error); 22 | 23 | TUKLIB_DECLS_END 24 | #endif 25 | -------------------------------------------------------------------------------- /src/common/tuklib_gettext.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file tuklib_gettext.h 6 | /// \brief Wrapper for gettext and friends 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef TUKLIB_GETTEXT_H 13 | #define TUKLIB_GETTEXT_H 14 | 15 | #include "tuklib_common.h" 16 | #include 17 | 18 | #ifndef TUKLIB_GETTEXT 19 | # ifdef ENABLE_NLS 20 | # define TUKLIB_GETTEXT 1 21 | # else 22 | # define TUKLIB_GETTEXT 0 23 | # endif 24 | #endif 25 | 26 | #if TUKLIB_GETTEXT 27 | # include 28 | # define tuklib_gettext_init(package, localedir) \ 29 | do { \ 30 | setlocale(LC_ALL, ""); \ 31 | bindtextdomain(package, localedir); \ 32 | textdomain(package); \ 33 | } while (0) 34 | # define _(msgid) gettext(msgid) 35 | #else 36 | # define tuklib_gettext_init(package, localedir) \ 37 | setlocale(LC_ALL, "") 38 | # define _(msgid) (msgid) 39 | # define ngettext(msgid1, msgid2, n) ((n) == 1 ? (msgid1) : (msgid2)) 40 | #endif 41 | #define N_(msgid) msgid 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/common/tuklib_mbstr_fw.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file tuklib_mbstr_fw.c 6 | /// \brief Get the field width for printf() e.g. to align table columns 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "tuklib_mbstr.h" 13 | 14 | 15 | extern int 16 | tuklib_mbstr_fw(const char *str, int columns_min) 17 | { 18 | size_t len; 19 | const size_t width = tuklib_mbstr_width(str, &len); 20 | if (width == (size_t)-1) 21 | return -1; 22 | 23 | if (width > (size_t)columns_min) 24 | return 0; 25 | 26 | if (width < (size_t)columns_min) 27 | len += (size_t)columns_min - width; 28 | 29 | return (int)len; 30 | } 31 | -------------------------------------------------------------------------------- /src/common/tuklib_mbstr_width.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file tuklib_mbstr_width.c 6 | /// \brief Calculate width of a multibyte string 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "tuklib_mbstr.h" 13 | #include 14 | 15 | #if defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH) 16 | # include 17 | #endif 18 | 19 | 20 | extern size_t 21 | tuklib_mbstr_width(const char *str, size_t *bytes) 22 | { 23 | const size_t len = strlen(str); 24 | if (bytes != NULL) 25 | *bytes = len; 26 | 27 | #if !(defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH)) 28 | // In single-byte mode, the width of the string is the same 29 | // as its length. 30 | return len; 31 | 32 | #else 33 | mbstate_t state; 34 | memset(&state, 0, sizeof(state)); 35 | 36 | size_t width = 0; 37 | size_t i = 0; 38 | 39 | // Convert one multibyte character at a time to wchar_t 40 | // and get its width using wcwidth(). 41 | while (i < len) { 42 | wchar_t wc; 43 | const size_t ret = mbrtowc(&wc, str + i, len - i, &state); 44 | if (ret < 1 || ret > len) 45 | return (size_t)-1; 46 | 47 | i += ret; 48 | 49 | const int wc_width = wcwidth(wc); 50 | if (wc_width < 0) 51 | return (size_t)-1; 52 | 53 | width += (size_t)wc_width; 54 | } 55 | 56 | // Require that the string ends in the initial shift state. 57 | // This way the caller can be combine the string with other 58 | // strings without needing to worry about the shift states. 59 | if (!mbsinit(&state)) 60 | return (size_t)-1; 61 | 62 | return width; 63 | #endif 64 | } 65 | -------------------------------------------------------------------------------- /src/common/tuklib_open_stdxxx.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file tuklib_open_stdxxx.c 6 | /// \brief Make sure that file descriptors 0, 1, and 2 are open 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "tuklib_open_stdxxx.h" 13 | 14 | #ifndef TUKLIB_DOSLIKE 15 | # include 16 | # include 17 | # include 18 | # include 19 | #endif 20 | 21 | 22 | extern void 23 | tuklib_open_stdxxx(int err_status) 24 | { 25 | #ifdef TUKLIB_DOSLIKE 26 | // Do nothing, just silence warnings. 27 | (void)err_status; 28 | 29 | #else 30 | for (int i = 0; i <= 2; ++i) { 31 | // We use fcntl() to check if the file descriptor is open. 32 | if (fcntl(i, F_GETFD) == -1 && errno == EBADF) { 33 | // With stdin, we could use /dev/full so that 34 | // writing to stdin would fail. However, /dev/full 35 | // is Linux specific, and if the program tries to 36 | // write to stdin, there's already a problem anyway. 37 | const int fd = open("/dev/null", O_NOCTTY 38 | | (i == 0 ? O_WRONLY : O_RDONLY)); 39 | 40 | if (fd != i) { 41 | if (fd != -1) 42 | (void)close(fd); 43 | 44 | // Something went wrong. Exit with the 45 | // exit status we were given. Don't try 46 | // to print an error message, since stderr 47 | // may very well be non-existent. This 48 | // error should be extremely rare. 49 | exit(err_status); 50 | } 51 | } 52 | } 53 | #endif 54 | 55 | return; 56 | } 57 | -------------------------------------------------------------------------------- /src/common/tuklib_open_stdxxx.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file tuklib_open_stdxxx.h 6 | /// \brief Make sure that file descriptors 0, 1, and 2 are open 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef TUKLIB_OPEN_STDXXX_H 13 | #define TUKLIB_OPEN_STDXXX_H 14 | 15 | #include "tuklib_common.h" 16 | TUKLIB_DECLS_BEGIN 17 | 18 | #define tuklib_open_stdxx TUKLIB_SYMBOL(tuklib_open_stdxxx) 19 | extern void tuklib_open_stdxxx(int err_status); 20 | 21 | TUKLIB_DECLS_END 22 | #endif 23 | -------------------------------------------------------------------------------- /src/common/tuklib_physmem.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file tuklib_physmem.h 6 | /// \brief Get the amount of physical memory 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef TUKLIB_PHYSMEM_H 13 | #define TUKLIB_PHYSMEM_H 14 | 15 | #include "tuklib_common.h" 16 | TUKLIB_DECLS_BEGIN 17 | 18 | #define tuklib_physmem TUKLIB_SYMBOL(tuklib_physmem) 19 | extern uint64_t tuklib_physmem(void); 20 | ///< 21 | /// \brief Get the amount of physical memory in bytes 22 | /// 23 | /// \return Amount of physical memory in bytes. On error, zero is 24 | /// returned. 25 | 26 | TUKLIB_DECLS_END 27 | #endif 28 | -------------------------------------------------------------------------------- /src/common/tuklib_progname.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file tuklib_progname.c 6 | /// \brief Program name to be displayed in messages 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "tuklib_progname.h" 13 | #include 14 | 15 | 16 | #ifndef HAVE_PROGRAM_INVOCATION_NAME 17 | char *progname = NULL; 18 | #endif 19 | 20 | 21 | extern void 22 | tuklib_progname_init(char **argv) 23 | { 24 | #ifdef TUKLIB_DOSLIKE 25 | // On these systems, argv[0] always has the full path and .exe 26 | // suffix even if the user just types the plain program name. 27 | // We modify argv[0] to make it nicer to read. 28 | 29 | // Strip the leading path. 30 | char *p = argv[0] + strlen(argv[0]); 31 | while (argv[0] < p && p[-1] != '/' && p[-1] != '\\') 32 | --p; 33 | 34 | argv[0] = p; 35 | 36 | // Strip the .exe suffix. 37 | p = strrchr(p, '.'); 38 | if (p != NULL) 39 | *p = '\0'; 40 | 41 | // Make it lowercase. 42 | for (p = argv[0]; *p != '\0'; ++p) 43 | if (*p >= 'A' && *p <= 'Z') 44 | *p = *p - 'A' + 'a'; 45 | #endif 46 | 47 | progname = argv[0]; 48 | return; 49 | } 50 | -------------------------------------------------------------------------------- /src/common/tuklib_progname.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file tuklib_progname.h 6 | /// \brief Program name to be displayed in messages 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef TUKLIB_PROGNAME_H 13 | #define TUKLIB_PROGNAME_H 14 | 15 | #include "tuklib_common.h" 16 | #include 17 | 18 | TUKLIB_DECLS_BEGIN 19 | 20 | #ifdef HAVE_PROGRAM_INVOCATION_NAME 21 | # define progname program_invocation_name 22 | #else 23 | # define progname TUKLIB_SYMBOL(tuklib_progname) 24 | extern char *progname; 25 | #endif 26 | 27 | #define tuklib_progname_init TUKLIB_SYMBOL(tuklib_progname_init) 28 | extern void tuklib_progname_init(char **argv); 29 | 30 | TUKLIB_DECLS_END 31 | #endif 32 | -------------------------------------------------------------------------------- /src/common/w32_application.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | true 25 | UTF-8 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/liblzma/api/Makefile.am: -------------------------------------------------------------------------------- 1 | ## SPDX-License-Identifier: 0BSD 2 | ## Author: Lasse Collin 3 | 4 | nobase_include_HEADERS = \ 5 | lzma.h \ 6 | lzma/base.h \ 7 | lzma/bcj.h \ 8 | lzma/block.h \ 9 | lzma/check.h \ 10 | lzma/container.h \ 11 | lzma/delta.h \ 12 | lzma/filter.h \ 13 | lzma/hardware.h \ 14 | lzma/index.h \ 15 | lzma/index_hash.h \ 16 | lzma/lzma12.h \ 17 | lzma/stream_flags.h \ 18 | lzma/version.h \ 19 | lzma/vli.h 20 | 21 | if COND_DOXYGEN 22 | $(top_builddir)/doc/api/index.html: $(top_srcdir)/doxygen/update-doxygen $(top_srcdir)/doxygen/Doxyfile $(nobase_include_HEADERS) 23 | $(MKDIR_P) "$(top_builddir)/doc" 24 | "$(top_srcdir)/doxygen/update-doxygen" api \ 25 | "$(top_srcdir)" "$(top_builddir)/doc" 26 | 27 | all-local: $(top_builddir)/doc/api/index.html 28 | 29 | install-data-local: 30 | $(MKDIR_P) "$(DESTDIR)$(docdir)/api" 31 | $(INSTALL_DATA) "$(top_builddir)"/doc/api/* "$(DESTDIR)$(docdir)/api" 32 | 33 | uninstall-local: 34 | rm -rf "$(DESTDIR)$(docdir)/api" 35 | 36 | clean-local: 37 | rm -rf "$(top_builddir)/doc/api" 38 | endif 39 | -------------------------------------------------------------------------------- /src/liblzma/check/Makefile.inc: -------------------------------------------------------------------------------- 1 | ## SPDX-License-Identifier: 0BSD 2 | ## Author: Lasse Collin 3 | 4 | ## Note: There is no check for COND_CHECK_CRC32 because 5 | ## currently crc32 is always enabled. 6 | 7 | EXTRA_DIST += \ 8 | check/crc32_tablegen.c \ 9 | check/crc64_tablegen.c 10 | 11 | liblzma_la_SOURCES += \ 12 | check/check.c \ 13 | check/check.h \ 14 | check/crc_common.h \ 15 | check/crc_x86_clmul.h \ 16 | check/crc32_arm64.h 17 | 18 | if COND_SMALL 19 | liblzma_la_SOURCES += check/crc32_small.c 20 | else 21 | liblzma_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 | liblzma_la_SOURCES += check/crc32_x86.S 27 | else 28 | liblzma_la_SOURCES += check/crc32_fast.c 29 | endif 30 | endif 31 | 32 | if COND_CHECK_CRC64 33 | if COND_SMALL 34 | liblzma_la_SOURCES += check/crc64_small.c 35 | else 36 | liblzma_la_SOURCES += \ 37 | check/crc64_table.c \ 38 | check/crc64_table_le.h \ 39 | check/crc64_table_be.h 40 | if COND_ASM_X86 41 | liblzma_la_SOURCES += check/crc64_x86.S 42 | else 43 | liblzma_la_SOURCES += check/crc64_fast.c 44 | endif 45 | endif 46 | endif 47 | 48 | if COND_CHECK_SHA256 49 | if COND_INTERNAL_SHA256 50 | liblzma_la_SOURCES += check/sha256.c 51 | endif 52 | endif 53 | -------------------------------------------------------------------------------- /src/liblzma/check/crc32_small.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file crc32_small.c 6 | /// \brief CRC32 calculation (size-optimized) 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "check.h" 13 | 14 | 15 | uint32_t lzma_crc32_table[1][256]; 16 | 17 | 18 | #ifdef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR 19 | __attribute__((__constructor__)) 20 | #endif 21 | static void 22 | crc32_init(void) 23 | { 24 | static const uint32_t poly32 = UINT32_C(0xEDB88320); 25 | 26 | for (size_t b = 0; b < 256; ++b) { 27 | uint32_t r = b; 28 | for (size_t i = 0; i < 8; ++i) { 29 | if (r & 1) 30 | r = (r >> 1) ^ poly32; 31 | else 32 | r >>= 1; 33 | } 34 | 35 | lzma_crc32_table[0][b] = r; 36 | } 37 | 38 | return; 39 | } 40 | 41 | 42 | #ifndef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR 43 | extern void 44 | lzma_crc32_init(void) 45 | { 46 | mythread_once(crc32_init); 47 | return; 48 | } 49 | #endif 50 | 51 | 52 | extern LZMA_API(uint32_t) 53 | lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc) 54 | { 55 | #ifndef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR 56 | lzma_crc32_init(); 57 | #endif 58 | 59 | crc = ~crc; 60 | 61 | while (size != 0) { 62 | crc = lzma_crc32_table[0][*buf++ ^ (crc & 0xFF)] ^ (crc >> 8); 63 | --size; 64 | } 65 | 66 | return ~crc; 67 | } 68 | -------------------------------------------------------------------------------- /src/liblzma/check/crc32_table.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file crc32_table.c 6 | /// \brief Precalculated CRC32 table with correct endianness 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "common.h" 13 | 14 | 15 | // FIXME: Compared to crc_common.h this has to check for __x86_64__ too 16 | // so that in 32-bit builds crc32_x86.S won't break due to a missing table. 17 | #if defined(HAVE_USABLE_CLMUL) && ((defined(__x86_64__) && defined(__SSSE3__) \ 18 | && defined(__SSE4_1__) && defined(__PCLMUL__)) \ 19 | || (defined(__e2k__) && __iset__ >= 6)) 20 | # define NO_CRC32_TABLE 21 | 22 | #elif defined(HAVE_ARM64_CRC32) \ 23 | && !defined(WORDS_BIGENDIAN) \ 24 | && defined(__ARM_FEATURE_CRC32) 25 | # define NO_CRC32_TABLE 26 | #endif 27 | 28 | 29 | #if !defined(HAVE_ENCODERS) && defined(NO_CRC32_TABLE) 30 | // No table needed. Use a typedef to avoid an empty translation unit. 31 | typedef void lzma_crc32_dummy; 32 | 33 | #else 34 | // Having the declaration here silences clang -Wmissing-variable-declarations. 35 | extern const uint32_t lzma_crc32_table[8][256]; 36 | 37 | # ifdef WORDS_BIGENDIAN 38 | # include "crc32_table_be.h" 39 | # else 40 | # include "crc32_table_le.h" 41 | # endif 42 | #endif 43 | -------------------------------------------------------------------------------- /src/liblzma/check/crc64_small.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file crc64_small.c 6 | /// \brief CRC64 calculation (size-optimized) 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "check.h" 13 | 14 | 15 | static uint64_t crc64_table[256]; 16 | 17 | 18 | #ifdef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR 19 | __attribute__((__constructor__)) 20 | #endif 21 | static void 22 | crc64_init(void) 23 | { 24 | static const uint64_t poly64 = UINT64_C(0xC96C5795D7870F42); 25 | 26 | for (size_t b = 0; b < 256; ++b) { 27 | uint64_t r = b; 28 | for (size_t i = 0; i < 8; ++i) { 29 | if (r & 1) 30 | r = (r >> 1) ^ poly64; 31 | else 32 | r >>= 1; 33 | } 34 | 35 | crc64_table[b] = r; 36 | } 37 | 38 | return; 39 | } 40 | 41 | 42 | extern LZMA_API(uint64_t) 43 | lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc) 44 | { 45 | #ifndef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR 46 | mythread_once(crc64_init); 47 | #endif 48 | 49 | crc = ~crc; 50 | 51 | while (size != 0) { 52 | crc = crc64_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8); 53 | --size; 54 | } 55 | 56 | return ~crc; 57 | } 58 | -------------------------------------------------------------------------------- /src/liblzma/check/crc64_table.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file crc64_table.c 6 | /// \brief Precalculated CRC64 table with correct endianness 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "common.h" 13 | 14 | 15 | // FIXME: Compared to crc_common.h this has to check for __x86_64__ too 16 | // so that in 32-bit builds crc64_x86.S won't break due to a missing table. 17 | #if defined(HAVE_USABLE_CLMUL) && ((defined(__x86_64__) && defined(__SSSE3__) \ 18 | && defined(__SSE4_1__) && defined(__PCLMUL__)) \ 19 | || (defined(__e2k__) && __iset__ >= 6)) 20 | # define NO_CRC64_TABLE 21 | #endif 22 | 23 | 24 | #ifdef NO_CRC64_TABLE 25 | // No table needed. Use a typedef to avoid an empty translation unit. 26 | typedef void lzma_crc64_dummy; 27 | 28 | #else 29 | // Having the declaration here silences clang -Wmissing-variable-declarations. 30 | extern const uint64_t lzma_crc64_table[4][256]; 31 | 32 | # if defined(WORDS_BIGENDIAN) 33 | # include "crc64_table_be.h" 34 | # else 35 | # include "crc64_table_le.h" 36 | # endif 37 | #endif 38 | -------------------------------------------------------------------------------- /src/liblzma/check/crc64_tablegen.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file crc64_tablegen.c 6 | /// \brief Generate crc64_table_le.h and crc64_table_be.h 7 | /// 8 | /// Compiling: gcc -std=c99 -o crc64_tablegen crc64_tablegen.c 9 | /// Add -DWORDS_BIGENDIAN to generate big endian table. 10 | // 11 | // Author: Lasse Collin 12 | // 13 | /////////////////////////////////////////////////////////////////////////////// 14 | 15 | #include 16 | #include "../../common/tuklib_integer.h" 17 | 18 | 19 | static uint64_t crc64_table[4][256]; 20 | 21 | 22 | extern void 23 | init_crc64_table(void) 24 | { 25 | static const uint64_t poly64 = UINT64_C(0xC96C5795D7870F42); 26 | 27 | for (size_t s = 0; s < 4; ++s) { 28 | for (size_t b = 0; b < 256; ++b) { 29 | uint64_t r = s == 0 ? b : crc64_table[s - 1][b]; 30 | 31 | for (size_t i = 0; i < 8; ++i) { 32 | if (r & 1) 33 | r = (r >> 1) ^ poly64; 34 | else 35 | r >>= 1; 36 | } 37 | 38 | crc64_table[s][b] = r; 39 | } 40 | } 41 | 42 | #ifdef WORDS_BIGENDIAN 43 | for (size_t s = 0; s < 4; ++s) 44 | for (size_t b = 0; b < 256; ++b) 45 | crc64_table[s][b] = byteswap64(crc64_table[s][b]); 46 | #endif 47 | 48 | return; 49 | } 50 | 51 | 52 | static void 53 | print_crc64_table(void) 54 | { 55 | // Split the SPDX string so that it won't accidentally match 56 | // when tools search for the string. 57 | printf("// SPDX" "-License-Identifier" ": 0BSD\n\n" 58 | "// This file has been generated by crc64_tablegen.c.\n\n" 59 | "const uint64_t lzma_crc64_table[4][256] = {\n\t{"); 60 | 61 | for (size_t s = 0; s < 4; ++s) { 62 | for (size_t b = 0; b < 256; ++b) { 63 | if ((b % 2) == 0) 64 | printf("\n\t\t"); 65 | 66 | printf("UINT64_C(0x%016" PRIX64 ")", 67 | crc64_table[s][b]); 68 | 69 | if (b != 255) 70 | printf(",%s", (b+1) % 2 == 0 ? "" : " "); 71 | } 72 | 73 | if (s == 3) 74 | printf("\n\t}\n};\n"); 75 | else 76 | printf("\n\t}, {"); 77 | } 78 | 79 | return; 80 | } 81 | 82 | 83 | int 84 | main(void) 85 | { 86 | init_crc64_table(); 87 | print_crc64_table(); 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /src/liblzma/common/alone_decoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file alone_decoder.h 6 | /// \brief Decoder for LZMA_Alone files 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_ALONE_DECODER_H 13 | #define LZMA_ALONE_DECODER_H 14 | 15 | #include "common.h" 16 | 17 | 18 | extern lzma_ret lzma_alone_decoder_init( 19 | lzma_next_coder *next, const lzma_allocator *allocator, 20 | uint64_t memlimit, bool picky); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/liblzma/common/block_buffer_encoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file block_buffer_encoder.h 6 | /// \brief Single-call .xz Block encoder 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_BLOCK_BUFFER_ENCODER_H 13 | #define LZMA_BLOCK_BUFFER_ENCODER_H 14 | 15 | #include "common.h" 16 | 17 | 18 | /// uint64_t version of lzma_block_buffer_bound(). It is used by 19 | /// stream_encoder_mt.c. Probably the original lzma_block_buffer_bound() 20 | /// should have been 64-bit, but fixing it would break the ABI. 21 | extern uint64_t lzma_block_buffer_bound64(uint64_t uncompressed_size); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/liblzma/common/block_decoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file block_decoder.h 6 | /// \brief Decodes .xz Blocks 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_BLOCK_DECODER_H 13 | #define LZMA_BLOCK_DECODER_H 14 | 15 | #include "common.h" 16 | 17 | 18 | extern lzma_ret lzma_block_decoder_init(lzma_next_coder *next, 19 | const lzma_allocator *allocator, lzma_block *block); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/liblzma/common/block_encoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file block_encoder.h 6 | /// \brief Encodes .xz Blocks 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_BLOCK_ENCODER_H 13 | #define LZMA_BLOCK_ENCODER_H 14 | 15 | #include "common.h" 16 | 17 | 18 | /// \brief Biggest Compressed Size value that the Block encoder supports 19 | /// 20 | /// The maximum size of a single Block is limited by the maximum size of 21 | /// a Stream, which in theory is 2^63 - 3 bytes (i.e. LZMA_VLI_MAX - 3). 22 | /// While the size is really big and no one should hit it in practice, we 23 | /// take it into account in some places anyway to catch some errors e.g. if 24 | /// application passes insanely big value to some function. 25 | /// 26 | /// We could take into account the headers etc. to determine the exact 27 | /// maximum size of the Compressed Data field, but the complexity would give 28 | /// us nothing useful. Instead, limit the size of Compressed Data so that 29 | /// even with biggest possible Block Header and Check fields the total 30 | /// encoded size of the Block stays as a valid VLI. This doesn't guarantee 31 | /// that the size of the Stream doesn't grow too big, but that problem is 32 | /// taken care outside the Block handling code. 33 | /// 34 | /// ~LZMA_VLI_C(3) is to guarantee that if we need padding at the end of 35 | /// the Compressed Data field, it will still stay in the proper limit. 36 | /// 37 | /// This constant is in this file because it is needed in both 38 | /// block_encoder.c and block_buffer_encoder.c. 39 | #define COMPRESSED_SIZE_MAX ((LZMA_VLI_MAX - LZMA_BLOCK_HEADER_SIZE_MAX \ 40 | - LZMA_CHECK_SIZE_MAX) & ~LZMA_VLI_C(3)) 41 | 42 | 43 | extern lzma_ret lzma_block_encoder_init(lzma_next_coder *next, 44 | const lzma_allocator *allocator, lzma_block *block); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/liblzma/common/easy_buffer_encoder.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file easy_buffer_encoder.c 6 | /// \brief Easy single-call .xz Stream encoder 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "easy_preset.h" 13 | 14 | 15 | extern LZMA_API(lzma_ret) 16 | lzma_easy_buffer_encode(uint32_t preset, lzma_check check, 17 | const lzma_allocator *allocator, const uint8_t *in, 18 | size_t in_size, uint8_t *out, size_t *out_pos, size_t out_size) 19 | { 20 | lzma_options_easy opt_easy; 21 | if (lzma_easy_preset(&opt_easy, preset)) 22 | return LZMA_OPTIONS_ERROR; 23 | 24 | return lzma_stream_buffer_encode(opt_easy.filters, check, 25 | allocator, in, in_size, out, out_pos, out_size); 26 | } 27 | -------------------------------------------------------------------------------- /src/liblzma/common/easy_decoder_memusage.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file easy_decoder_memusage.c 6 | /// \brief Decoder memory usage calculation to match easy encoder presets 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "easy_preset.h" 13 | 14 | 15 | extern LZMA_API(uint64_t) 16 | lzma_easy_decoder_memusage(uint32_t preset) 17 | { 18 | lzma_options_easy opt_easy; 19 | if (lzma_easy_preset(&opt_easy, preset)) 20 | return UINT32_MAX; 21 | 22 | return lzma_raw_decoder_memusage(opt_easy.filters); 23 | } 24 | -------------------------------------------------------------------------------- /src/liblzma/common/easy_encoder.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file easy_encoder.c 6 | /// \brief Easy .xz Stream encoder initialization 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "easy_preset.h" 13 | 14 | 15 | extern LZMA_API(lzma_ret) 16 | lzma_easy_encoder(lzma_stream *strm, uint32_t preset, lzma_check check) 17 | { 18 | lzma_options_easy opt_easy; 19 | if (lzma_easy_preset(&opt_easy, preset)) 20 | return LZMA_OPTIONS_ERROR; 21 | 22 | return lzma_stream_encoder(strm, opt_easy.filters, check); 23 | } 24 | -------------------------------------------------------------------------------- /src/liblzma/common/easy_encoder_memusage.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file easy_encoder_memusage.c 6 | /// \brief Easy .xz Stream encoder memory usage calculation 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "easy_preset.h" 13 | 14 | 15 | extern LZMA_API(uint64_t) 16 | lzma_easy_encoder_memusage(uint32_t preset) 17 | { 18 | lzma_options_easy opt_easy; 19 | if (lzma_easy_preset(&opt_easy, preset)) 20 | return UINT32_MAX; 21 | 22 | return lzma_raw_encoder_memusage(opt_easy.filters); 23 | } 24 | -------------------------------------------------------------------------------- /src/liblzma/common/easy_preset.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file easy_preset.c 6 | /// \brief Preset handling for easy encoder and decoder 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "easy_preset.h" 13 | 14 | 15 | extern bool 16 | lzma_easy_preset(lzma_options_easy *opt_easy, uint32_t preset) 17 | { 18 | if (lzma_lzma_preset(&opt_easy->opt_lzma, preset)) 19 | return true; 20 | 21 | opt_easy->filters[0].id = LZMA_FILTER_LZMA2; 22 | opt_easy->filters[0].options = &opt_easy->opt_lzma; 23 | opt_easy->filters[1].id = LZMA_VLI_UNKNOWN; 24 | 25 | return false; 26 | } 27 | -------------------------------------------------------------------------------- /src/liblzma/common/easy_preset.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file easy_preset.h 6 | /// \brief Preset handling for easy encoder and decoder 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_EASY_PRESET_H 13 | #define LZMA_EASY_PRESET_H 14 | 15 | #include "common.h" 16 | 17 | 18 | typedef struct { 19 | /// We need to keep the filters array available in case 20 | /// LZMA_FULL_FLUSH is used. 21 | lzma_filter filters[LZMA_FILTERS_MAX + 1]; 22 | 23 | /// Options for LZMA2 24 | lzma_options_lzma opt_lzma; 25 | 26 | // Options for more filters can be added later, so this struct 27 | // is not ready to be put into the public API. 28 | 29 | } lzma_options_easy; 30 | 31 | 32 | /// Set *easy to the settings given by the preset. Returns true on error, 33 | /// false on success. 34 | extern bool lzma_easy_preset(lzma_options_easy *easy, uint32_t preset); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/liblzma/common/filter_buffer_encoder.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file filter_buffer_encoder.c 6 | /// \brief Single-call raw encoding 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "filter_encoder.h" 13 | 14 | 15 | extern LZMA_API(lzma_ret) 16 | lzma_raw_buffer_encode( 17 | const lzma_filter *filters, const lzma_allocator *allocator, 18 | const uint8_t *in, size_t in_size, 19 | uint8_t *out, size_t *out_pos, size_t out_size) 20 | { 21 | // Validate what isn't validated later in filter_common.c. 22 | if ((in == NULL && in_size != 0) || out == NULL 23 | || out_pos == NULL || *out_pos > out_size) 24 | return LZMA_PROG_ERROR; 25 | 26 | // Initialize the encoder 27 | lzma_next_coder next = LZMA_NEXT_CODER_INIT; 28 | return_if_error(lzma_raw_encoder_init(&next, allocator, filters)); 29 | 30 | // Store the output position so that we can restore it if 31 | // something goes wrong. 32 | const size_t out_start = *out_pos; 33 | 34 | // Do the actual encoding and free coder's memory. 35 | size_t in_pos = 0; 36 | lzma_ret ret = next.code(next.coder, allocator, in, &in_pos, in_size, 37 | out, out_pos, out_size, LZMA_FINISH); 38 | lzma_next_end(&next, allocator); 39 | 40 | if (ret == LZMA_STREAM_END) { 41 | ret = LZMA_OK; 42 | } else { 43 | if (ret == LZMA_OK) { 44 | // Output buffer was too small. 45 | assert(*out_pos == out_size); 46 | ret = LZMA_BUF_ERROR; 47 | } 48 | 49 | // Restore the output position. 50 | *out_pos = out_start; 51 | } 52 | 53 | return ret; 54 | } 55 | -------------------------------------------------------------------------------- /src/liblzma/common/filter_common.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file filter_common.h 6 | /// \brief Filter-specific stuff common for both encoder and decoder 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_FILTER_COMMON_H 13 | #define LZMA_FILTER_COMMON_H 14 | 15 | #include "common.h" 16 | 17 | 18 | /// Both lzma_filter_encoder and lzma_filter_decoder begin with these members. 19 | typedef struct { 20 | /// Filter ID 21 | lzma_vli id; 22 | 23 | /// Initializes the filter encoder and calls lzma_next_filter_init() 24 | /// for filters + 1. 25 | lzma_init_function init; 26 | 27 | /// Calculates memory usage of the encoder. If the options are 28 | /// invalid, UINT64_MAX is returned. 29 | uint64_t (*memusage)(const void *options); 30 | 31 | } lzma_filter_coder; 32 | 33 | 34 | typedef const lzma_filter_coder *(*lzma_filter_find)(lzma_vli id); 35 | 36 | 37 | extern lzma_ret lzma_validate_chain(const lzma_filter *filters, size_t *count); 38 | 39 | 40 | extern lzma_ret lzma_raw_coder_init( 41 | lzma_next_coder *next, const lzma_allocator *allocator, 42 | const lzma_filter *filters, 43 | lzma_filter_find coder_find, bool is_encoder); 44 | 45 | 46 | extern uint64_t lzma_raw_coder_memusage(lzma_filter_find coder_find, 47 | const lzma_filter *filters); 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/liblzma/common/filter_decoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file filter_decoder.h 6 | /// \brief Filter ID mapping to filter-specific functions 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_FILTER_DECODER_H 13 | #define LZMA_FILTER_DECODER_H 14 | 15 | #include "common.h" 16 | 17 | 18 | extern lzma_ret lzma_raw_decoder_init( 19 | lzma_next_coder *next, const lzma_allocator *allocator, 20 | const lzma_filter *options); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/liblzma/common/filter_encoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file filter_encoder.h 6 | /// \brief Filter ID mapping to filter-specific functions 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_FILTER_ENCODER_H 13 | #define LZMA_FILTER_ENCODER_H 14 | 15 | #include "common.h" 16 | 17 | 18 | extern lzma_ret lzma_raw_encoder_init( 19 | lzma_next_coder *next, const lzma_allocator *allocator, 20 | const lzma_filter *filters); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/liblzma/common/filter_flags_decoder.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file filter_flags_decoder.c 6 | /// \brief Decodes a Filter Flags field 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "filter_decoder.h" 13 | 14 | 15 | extern LZMA_API(lzma_ret) 16 | lzma_filter_flags_decode( 17 | lzma_filter *filter, const lzma_allocator *allocator, 18 | const uint8_t *in, size_t *in_pos, size_t in_size) 19 | { 20 | // Set the pointer to NULL so the caller can always safely free it. 21 | filter->options = NULL; 22 | 23 | // Filter ID 24 | return_if_error(lzma_vli_decode(&filter->id, NULL, 25 | in, in_pos, in_size)); 26 | 27 | if (filter->id >= LZMA_FILTER_RESERVED_START) 28 | return LZMA_DATA_ERROR; 29 | 30 | // Size of Properties 31 | lzma_vli props_size; 32 | return_if_error(lzma_vli_decode(&props_size, NULL, 33 | in, in_pos, in_size)); 34 | 35 | // Filter Properties 36 | if (in_size - *in_pos < props_size) 37 | return LZMA_DATA_ERROR; 38 | 39 | const lzma_ret ret = lzma_properties_decode( 40 | filter, allocator, in + *in_pos, props_size); 41 | 42 | *in_pos += props_size; 43 | 44 | return ret; 45 | } 46 | -------------------------------------------------------------------------------- /src/liblzma/common/filter_flags_encoder.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file filter_flags_encoder.c 6 | /// \brief Encodes a Filter Flags field 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "filter_encoder.h" 13 | 14 | 15 | extern LZMA_API(lzma_ret) 16 | lzma_filter_flags_size(uint32_t *size, const lzma_filter *filter) 17 | { 18 | if (filter->id >= LZMA_FILTER_RESERVED_START) 19 | return LZMA_PROG_ERROR; 20 | 21 | return_if_error(lzma_properties_size(size, filter)); 22 | 23 | *size += lzma_vli_size(filter->id) + lzma_vli_size(*size); 24 | 25 | return LZMA_OK; 26 | } 27 | 28 | 29 | extern LZMA_API(lzma_ret) 30 | lzma_filter_flags_encode(const lzma_filter *filter, 31 | uint8_t *out, size_t *out_pos, size_t out_size) 32 | { 33 | // Filter ID 34 | if (filter->id >= LZMA_FILTER_RESERVED_START) 35 | return LZMA_PROG_ERROR; 36 | 37 | return_if_error(lzma_vli_encode(filter->id, NULL, 38 | out, out_pos, out_size)); 39 | 40 | // Size of Properties 41 | uint32_t props_size; 42 | return_if_error(lzma_properties_size(&props_size, filter)); 43 | return_if_error(lzma_vli_encode(props_size, NULL, 44 | out, out_pos, out_size)); 45 | 46 | // Filter Properties 47 | if (out_size - *out_pos < props_size) 48 | return LZMA_PROG_ERROR; 49 | 50 | return_if_error(lzma_properties_encode(filter, out + *out_pos)); 51 | 52 | *out_pos += props_size; 53 | 54 | return LZMA_OK; 55 | } 56 | -------------------------------------------------------------------------------- /src/liblzma/common/hardware_cputhreads.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file hardware_cputhreads.c 6 | /// \brief Get the number of CPU threads or cores 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "common.h" 13 | 14 | #include "tuklib_cpucores.h" 15 | 16 | 17 | #ifdef HAVE_SYMBOL_VERSIONS_LINUX 18 | // This is for compatibility with binaries linked against liblzma that 19 | // has been patched with xz-5.2.2-compat-libs.patch from RHEL/CentOS 7. 20 | LZMA_SYMVER_API("lzma_cputhreads@XZ_5.2.2", 21 | uint32_t, lzma_cputhreads_522)(void) lzma_nothrow 22 | __attribute__((__alias__("lzma_cputhreads_52"))); 23 | 24 | LZMA_SYMVER_API("lzma_cputhreads@@XZ_5.2", 25 | uint32_t, lzma_cputhreads_52)(void) lzma_nothrow; 26 | 27 | #define lzma_cputhreads lzma_cputhreads_52 28 | #endif 29 | extern LZMA_API(uint32_t) 30 | lzma_cputhreads(void) 31 | { 32 | return tuklib_cpucores(); 33 | } 34 | -------------------------------------------------------------------------------- /src/liblzma/common/hardware_physmem.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file hardware_physmem.c 6 | /// \brief Get the total amount of physical memory (RAM) 7 | // 8 | // Author: Jonathan Nieder 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "common.h" 13 | 14 | #include "tuklib_physmem.h" 15 | 16 | 17 | extern LZMA_API(uint64_t) 18 | lzma_physmem(void) 19 | { 20 | // It is simpler to make lzma_physmem() a wrapper for 21 | // tuklib_physmem() than to hack appropriate symbol visibility 22 | // support for the tuklib modules. 23 | return tuklib_physmem(); 24 | } 25 | -------------------------------------------------------------------------------- /src/liblzma/common/index_decoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file index_decoder.h 6 | /// \brief Decodes the Index field 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_INDEX_DECODER_H 13 | #define LZMA_INDEX_DECODER_H 14 | 15 | #include "common.h" 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 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file index_encoder.h 6 | /// \brief Encodes the Index field 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_INDEX_ENCODER_H 13 | #define LZMA_INDEX_ENCODER_H 14 | 15 | #include "common.h" 16 | 17 | 18 | extern lzma_ret lzma_index_encoder_init(lzma_next_coder *next, 19 | const lzma_allocator *allocator, const lzma_index *i); 20 | 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/liblzma/common/lzip_decoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file lzip_decoder.h 6 | /// \brief Decodes .lz (lzip) files 7 | // 8 | // Author: Michał Górny 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_LZIP_DECODER_H 13 | #define LZMA_LZIP_DECODER_H 14 | 15 | #include "common.h" 16 | 17 | extern lzma_ret lzma_lzip_decoder_init( 18 | lzma_next_coder *next, const lzma_allocator *allocator, 19 | uint64_t memlimit, uint32_t flags); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/liblzma/common/stream_decoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file stream_decoder.h 6 | /// \brief Decodes .xz Streams 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_STREAM_DECODER_H 13 | #define LZMA_STREAM_DECODER_H 14 | 15 | #include "common.h" 16 | 17 | extern lzma_ret lzma_stream_decoder_init( 18 | lzma_next_coder *next, const lzma_allocator *allocator, 19 | uint64_t memlimit, uint32_t flags); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/liblzma/common/stream_flags_common.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file stream_flags_common.c 6 | /// \brief Common stuff for Stream flags coders 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "stream_flags_common.h" 13 | 14 | 15 | const uint8_t lzma_header_magic[6] = { 0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00 }; 16 | const uint8_t lzma_footer_magic[2] = { 0x59, 0x5A }; 17 | 18 | 19 | extern LZMA_API(lzma_ret) 20 | lzma_stream_flags_compare( 21 | const lzma_stream_flags *a, const lzma_stream_flags *b) 22 | { 23 | // We can compare only version 0 structures. 24 | if (a->version != 0 || b->version != 0) 25 | return LZMA_OPTIONS_ERROR; 26 | 27 | // Check type 28 | if ((unsigned int)(a->check) > LZMA_CHECK_ID_MAX 29 | || (unsigned int)(b->check) > LZMA_CHECK_ID_MAX) 30 | return LZMA_PROG_ERROR; 31 | 32 | if (a->check != b->check) 33 | return LZMA_DATA_ERROR; 34 | 35 | // Backward Sizes are compared only if they are known in both. 36 | if (a->backward_size != LZMA_VLI_UNKNOWN 37 | && b->backward_size != LZMA_VLI_UNKNOWN) { 38 | if (!is_backward_size_valid(a) || !is_backward_size_valid(b)) 39 | return LZMA_PROG_ERROR; 40 | 41 | if (a->backward_size != b->backward_size) 42 | return LZMA_DATA_ERROR; 43 | } 44 | 45 | return LZMA_OK; 46 | } 47 | -------------------------------------------------------------------------------- /src/liblzma/common/stream_flags_common.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file stream_flags_common.h 6 | /// \brief Common stuff for Stream flags coders 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_STREAM_FLAGS_COMMON_H 13 | #define LZMA_STREAM_FLAGS_COMMON_H 14 | 15 | #include "common.h" 16 | 17 | /// Size of the Stream Flags field 18 | #define LZMA_STREAM_FLAGS_SIZE 2 19 | 20 | lzma_attr_visibility_hidden 21 | extern const uint8_t lzma_header_magic[6]; 22 | 23 | lzma_attr_visibility_hidden 24 | extern const uint8_t lzma_footer_magic[2]; 25 | 26 | 27 | static inline bool 28 | is_backward_size_valid(const lzma_stream_flags *options) 29 | { 30 | return options->backward_size >= LZMA_BACKWARD_SIZE_MIN 31 | && options->backward_size <= LZMA_BACKWARD_SIZE_MAX 32 | && (options->backward_size & 3) == 0; 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/liblzma/common/stream_flags_encoder.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file stream_flags_encoder.c 6 | /// \brief Encodes Stream Header and Stream Footer for .xz files 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "stream_flags_common.h" 13 | 14 | 15 | static bool 16 | stream_flags_encode(const lzma_stream_flags *options, uint8_t *out) 17 | { 18 | if ((unsigned int)(options->check) > LZMA_CHECK_ID_MAX) 19 | return true; 20 | 21 | out[0] = 0x00; 22 | out[1] = options->check; 23 | 24 | return false; 25 | } 26 | 27 | 28 | extern LZMA_API(lzma_ret) 29 | lzma_stream_header_encode(const lzma_stream_flags *options, uint8_t *out) 30 | { 31 | assert(sizeof(lzma_header_magic) + LZMA_STREAM_FLAGS_SIZE 32 | + 4 == LZMA_STREAM_HEADER_SIZE); 33 | 34 | if (options->version != 0) 35 | return LZMA_OPTIONS_ERROR; 36 | 37 | // Magic 38 | memcpy(out, lzma_header_magic, sizeof(lzma_header_magic)); 39 | 40 | // Stream Flags 41 | if (stream_flags_encode(options, out + sizeof(lzma_header_magic))) 42 | return LZMA_PROG_ERROR; 43 | 44 | // CRC32 of the Stream Header 45 | const uint32_t crc = lzma_crc32(out + sizeof(lzma_header_magic), 46 | LZMA_STREAM_FLAGS_SIZE, 0); 47 | 48 | write32le(out + sizeof(lzma_header_magic) + LZMA_STREAM_FLAGS_SIZE, 49 | crc); 50 | 51 | return LZMA_OK; 52 | } 53 | 54 | 55 | extern LZMA_API(lzma_ret) 56 | lzma_stream_footer_encode(const lzma_stream_flags *options, uint8_t *out) 57 | { 58 | assert(2 * 4 + LZMA_STREAM_FLAGS_SIZE + sizeof(lzma_footer_magic) 59 | == LZMA_STREAM_HEADER_SIZE); 60 | 61 | if (options->version != 0) 62 | return LZMA_OPTIONS_ERROR; 63 | 64 | // Backward Size 65 | if (!is_backward_size_valid(options)) 66 | return LZMA_PROG_ERROR; 67 | 68 | write32le(out + 4, options->backward_size / 4 - 1); 69 | 70 | // Stream Flags 71 | if (stream_flags_encode(options, out + 2 * 4)) 72 | return LZMA_PROG_ERROR; 73 | 74 | // CRC32 75 | const uint32_t crc = lzma_crc32( 76 | out + 4, 4 + LZMA_STREAM_FLAGS_SIZE, 0); 77 | 78 | write32le(out, crc); 79 | 80 | // Magic 81 | memcpy(out + 2 * 4 + LZMA_STREAM_FLAGS_SIZE, 82 | lzma_footer_magic, sizeof(lzma_footer_magic)); 83 | 84 | return LZMA_OK; 85 | } 86 | -------------------------------------------------------------------------------- /src/liblzma/common/vli_encoder.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file vli_encoder.c 6 | /// \brief Encodes variable-length integers 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "common.h" 13 | 14 | 15 | extern LZMA_API(lzma_ret) 16 | lzma_vli_encode(lzma_vli vli, size_t *vli_pos, 17 | uint8_t *restrict out, size_t *restrict out_pos, 18 | size_t out_size) 19 | { 20 | // If we haven't been given vli_pos, work in single-call mode. 21 | size_t vli_pos_internal = 0; 22 | if (vli_pos == NULL) { 23 | vli_pos = &vli_pos_internal; 24 | 25 | // In single-call mode, we expect that the caller has 26 | // reserved enough output space. 27 | if (*out_pos >= out_size) 28 | return LZMA_PROG_ERROR; 29 | } else { 30 | // This never happens when we are called by liblzma, but 31 | // may happen if called directly from an application. 32 | if (*out_pos >= out_size) 33 | return LZMA_BUF_ERROR; 34 | } 35 | 36 | // Validate the arguments. 37 | if (*vli_pos >= LZMA_VLI_BYTES_MAX || vli > LZMA_VLI_MAX) 38 | return LZMA_PROG_ERROR; 39 | 40 | // Shift vli so that the next bits to encode are the lowest. In 41 | // single-call mode this never changes vli since *vli_pos is zero. 42 | vli >>= *vli_pos * 7; 43 | 44 | // Write the non-last bytes in a loop. 45 | while (vli >= 0x80) { 46 | // We don't need *vli_pos during this function call anymore, 47 | // but update it here so that it is ready if we need to 48 | // return before the whole integer has been decoded. 49 | ++*vli_pos; 50 | assert(*vli_pos < LZMA_VLI_BYTES_MAX); 51 | 52 | // Write the next byte. 53 | out[*out_pos] = (uint8_t)(vli) | 0x80; 54 | vli >>= 7; 55 | 56 | if (++*out_pos == out_size) 57 | return vli_pos == &vli_pos_internal 58 | ? LZMA_PROG_ERROR : LZMA_OK; 59 | } 60 | 61 | // Write the last byte. 62 | out[*out_pos] = (uint8_t)(vli); 63 | ++*out_pos; 64 | ++*vli_pos; 65 | 66 | return vli_pos == &vli_pos_internal ? LZMA_OK : LZMA_STREAM_END; 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/liblzma/common/vli_size.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file vli_size.c 6 | /// \brief Calculates the encoded size of a variable-length integer 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "common.h" 13 | 14 | 15 | extern LZMA_API(uint32_t) 16 | lzma_vli_size(lzma_vli vli) 17 | { 18 | if (vli > LZMA_VLI_MAX) 19 | return 0; 20 | 21 | uint32_t i = 0; 22 | do { 23 | vli >>= 7; 24 | ++i; 25 | } while (vli != 0); 26 | 27 | assert(i <= LZMA_VLI_BYTES_MAX); 28 | return i; 29 | } 30 | -------------------------------------------------------------------------------- /src/liblzma/delta/Makefile.inc: -------------------------------------------------------------------------------- 1 | ## SPDX-License-Identifier: 0BSD 2 | ## Author: Lasse Collin 3 | 4 | liblzma_la_SOURCES += \ 5 | delta/delta_common.c \ 6 | delta/delta_common.h \ 7 | delta/delta_private.h 8 | 9 | if COND_ENCODER_DELTA 10 | liblzma_la_SOURCES += \ 11 | delta/delta_encoder.c \ 12 | delta/delta_encoder.h 13 | endif 14 | 15 | if COND_DECODER_DELTA 16 | liblzma_la_SOURCES += \ 17 | delta/delta_decoder.c \ 18 | delta/delta_decoder.h 19 | endif 20 | -------------------------------------------------------------------------------- /src/liblzma/delta/delta_common.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file delta_common.c 6 | /// \brief Common stuff for Delta encoder and decoder 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "delta_common.h" 13 | #include "delta_private.h" 14 | 15 | 16 | static void 17 | delta_coder_end(void *coder_ptr, const lzma_allocator *allocator) 18 | { 19 | lzma_delta_coder *coder = coder_ptr; 20 | lzma_next_end(&coder->next, allocator); 21 | lzma_free(coder, allocator); 22 | return; 23 | } 24 | 25 | 26 | extern lzma_ret 27 | lzma_delta_coder_init(lzma_next_coder *next, const lzma_allocator *allocator, 28 | const lzma_filter_info *filters) 29 | { 30 | // Allocate memory for the decoder if needed. 31 | lzma_delta_coder *coder = next->coder; 32 | if (coder == NULL) { 33 | coder = lzma_alloc(sizeof(lzma_delta_coder), allocator); 34 | if (coder == NULL) 35 | return LZMA_MEM_ERROR; 36 | 37 | next->coder = coder; 38 | 39 | // End function is the same for encoder and decoder. 40 | next->end = &delta_coder_end; 41 | coder->next = LZMA_NEXT_CODER_INIT; 42 | } 43 | 44 | // Validate the options. 45 | if (lzma_delta_coder_memusage(filters[0].options) == UINT64_MAX) 46 | return LZMA_OPTIONS_ERROR; 47 | 48 | // Set the delta distance. 49 | const lzma_options_delta *opt = filters[0].options; 50 | coder->distance = opt->dist; 51 | 52 | // Initialize the rest of the variables. 53 | coder->pos = 0; 54 | memzero(coder->history, LZMA_DELTA_DIST_MAX); 55 | 56 | // Initialize the next decoder in the chain, if any. 57 | return lzma_next_filter_init(&coder->next, allocator, filters + 1); 58 | } 59 | 60 | 61 | extern uint64_t 62 | lzma_delta_coder_memusage(const void *options) 63 | { 64 | const lzma_options_delta *opt = options; 65 | 66 | if (opt == NULL || opt->type != LZMA_DELTA_TYPE_BYTE 67 | || opt->dist < LZMA_DELTA_DIST_MIN 68 | || opt->dist > LZMA_DELTA_DIST_MAX) 69 | return UINT64_MAX; 70 | 71 | return sizeof(lzma_delta_coder); 72 | } 73 | -------------------------------------------------------------------------------- /src/liblzma/delta/delta_common.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file delta_common.h 6 | /// \brief Common stuff for Delta encoder and decoder 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_DELTA_COMMON_H 13 | #define LZMA_DELTA_COMMON_H 14 | 15 | #include "common.h" 16 | 17 | extern uint64_t lzma_delta_coder_memusage(const void *options); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/liblzma/delta/delta_decoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file delta_decoder.h 6 | /// \brief Delta filter decoder 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_DELTA_DECODER_H 13 | #define LZMA_DELTA_DECODER_H 14 | 15 | #include "delta_common.h" 16 | 17 | extern lzma_ret lzma_delta_decoder_init(lzma_next_coder *next, 18 | const lzma_allocator *allocator, 19 | const lzma_filter_info *filters); 20 | 21 | extern lzma_ret lzma_delta_props_decode( 22 | void **options, const lzma_allocator *allocator, 23 | const uint8_t *props, size_t props_size); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/liblzma/delta/delta_encoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file delta_encoder.h 6 | /// \brief Delta filter encoder 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_DELTA_ENCODER_H 13 | #define LZMA_DELTA_ENCODER_H 14 | 15 | #include "delta_common.h" 16 | 17 | extern lzma_ret lzma_delta_encoder_init(lzma_next_coder *next, 18 | const lzma_allocator *allocator, 19 | const lzma_filter_info *filters); 20 | 21 | extern lzma_ret lzma_delta_props_encode(const void *options, uint8_t *out); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/liblzma/delta/delta_private.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file delta_private.h 6 | /// \brief Private common stuff for Delta encoder and decoder 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_DELTA_PRIVATE_H 13 | #define LZMA_DELTA_PRIVATE_H 14 | 15 | #include "delta_common.h" 16 | 17 | typedef struct { 18 | /// Next coder in the chain 19 | lzma_next_coder next; 20 | 21 | /// Delta distance 22 | size_t distance; 23 | 24 | /// Position in history[] 25 | uint8_t pos; 26 | 27 | /// Buffer to hold history of the original data 28 | uint8_t history[LZMA_DELTA_DIST_MAX]; 29 | } lzma_delta_coder; 30 | 31 | 32 | extern lzma_ret lzma_delta_coder_init( 33 | lzma_next_coder *next, const lzma_allocator *allocator, 34 | const lzma_filter_info *filters); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/liblzma/liblzma.pc.in: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | # Author: Lasse Collin 3 | 4 | prefix=@prefix@ 5 | exec_prefix=@exec_prefix@ 6 | libdir=@libdir@ 7 | includedir=@includedir@ 8 | 9 | Name: liblzma 10 | Description: General purpose data compression library 11 | URL: @PACKAGE_URL@ 12 | Version: @PACKAGE_VERSION@ 13 | Cflags: -I${includedir} 14 | Cflags.private: -DLZMA_API_STATIC 15 | Libs: -L${libdir} -llzma 16 | Libs.private: @PTHREAD_CFLAGS@ @LIBS@ 17 | -------------------------------------------------------------------------------- /src/liblzma/liblzma_w32res.rc: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: 0BSD */ 2 | 3 | /* 4 | * Author: Lasse Collin 5 | */ 6 | 7 | #define MY_TYPE VFT_DLL 8 | 9 | #if defined(__MSYS__) 10 | # define MY_NAME "msys-lzma-5" 11 | #elif defined(__CYGWIN__) 12 | # define MY_NAME "cyglzma-5" 13 | #else 14 | # define MY_NAME "liblzma" 15 | #endif 16 | 17 | #define MY_SUFFIX ".dll" 18 | #define MY_DESC "liblzma data compression library" 19 | #include "common_w32res.rc" 20 | -------------------------------------------------------------------------------- /src/liblzma/lz/Makefile.inc: -------------------------------------------------------------------------------- 1 | ## SPDX-License-Identifier: 0BSD 2 | ## Author: Lasse Collin 3 | 4 | if COND_ENCODER_LZ 5 | liblzma_la_SOURCES += \ 6 | lz/lz_encoder.c \ 7 | lz/lz_encoder.h \ 8 | lz/lz_encoder_hash.h \ 9 | lz/lz_encoder_hash_table.h \ 10 | lz/lz_encoder_mf.c 11 | endif 12 | 13 | 14 | if COND_DECODER_LZ 15 | liblzma_la_SOURCES += \ 16 | lz/lz_decoder.c \ 17 | lz/lz_decoder.h 18 | endif 19 | -------------------------------------------------------------------------------- /src/liblzma/lzma/Makefile.inc: -------------------------------------------------------------------------------- 1 | ## SPDX-License-Identifier: 0BSD 2 | ## Author: Lasse Collin 3 | 4 | EXTRA_DIST += lzma/fastpos_tablegen.c 5 | 6 | liblzma_la_SOURCES += \ 7 | lzma/lzma_common.h \ 8 | lzma/lzma_encoder_presets.c 9 | 10 | if COND_ENCODER_LZMA1 11 | liblzma_la_SOURCES += \ 12 | lzma/fastpos.h \ 13 | lzma/lzma_encoder.h \ 14 | lzma/lzma_encoder.c \ 15 | lzma/lzma_encoder_private.h \ 16 | lzma/lzma_encoder_optimum_fast.c \ 17 | lzma/lzma_encoder_optimum_normal.c 18 | 19 | if !COND_SMALL 20 | liblzma_la_SOURCES += lzma/fastpos_table.c 21 | endif 22 | endif 23 | 24 | if COND_DECODER_LZMA1 25 | liblzma_la_SOURCES += \ 26 | lzma/lzma_decoder.c \ 27 | lzma/lzma_decoder.h 28 | endif 29 | 30 | if COND_ENCODER_LZMA2 31 | liblzma_la_SOURCES += \ 32 | lzma/lzma2_encoder.c \ 33 | lzma/lzma2_encoder.h 34 | endif 35 | 36 | if COND_DECODER_LZMA2 37 | liblzma_la_SOURCES += \ 38 | lzma/lzma2_decoder.c \ 39 | lzma/lzma2_decoder.h 40 | endif 41 | -------------------------------------------------------------------------------- /src/liblzma/lzma/fastpos_tablegen.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file fastpos_tablegen.c 6 | /// \brief Generates the lzma_fastpos[] lookup table 7 | /// 8 | // Authors: Igor Pavlov 9 | // Lasse Collin 10 | // 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | #include 14 | #include 15 | 16 | #define lzma_attr_visibility_hidden 17 | #include "fastpos.h" 18 | 19 | 20 | int 21 | main(void) 22 | { 23 | uint8_t fastpos[1 << FASTPOS_BITS]; 24 | 25 | const uint8_t fast_slots = 2 * FASTPOS_BITS; 26 | uint32_t c = 2; 27 | 28 | fastpos[0] = 0; 29 | fastpos[1] = 1; 30 | 31 | for (uint8_t slot_fast = 2; slot_fast < fast_slots; ++slot_fast) { 32 | const uint32_t k = 1 << ((slot_fast >> 1) - 1); 33 | for (uint32_t j = 0; j < k; ++j, ++c) 34 | fastpos[c] = slot_fast; 35 | } 36 | 37 | // Split the SPDX string so that it won't accidentally match 38 | // when tools search for the string. 39 | printf("// SPDX" "-License-Identifier" ": 0BSD\n\n" 40 | "// This file has been generated by fastpos_tablegen.c.\n\n" 41 | "#include \"common.h\"\n" 42 | "#include \"fastpos.h\"\n\n" 43 | "const uint8_t lzma_fastpos[1 << FASTPOS_BITS] = {"); 44 | 45 | for (size_t i = 0; i < (1 << FASTPOS_BITS); ++i) { 46 | if (i % 16 == 0) 47 | printf("\n\t"); 48 | 49 | printf("%3u", (unsigned int)(fastpos[i])); 50 | 51 | if (i != (1 << FASTPOS_BITS) - 1) 52 | printf(","); 53 | } 54 | 55 | printf("\n};\n"); 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /src/liblzma/lzma/lzma2_decoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file lzma2_decoder.h 6 | /// \brief LZMA2 decoder 7 | /// 8 | // Authors: Igor Pavlov 9 | // Lasse Collin 10 | // 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | #ifndef LZMA_LZMA2_DECODER_H 14 | #define LZMA_LZMA2_DECODER_H 15 | 16 | #include "common.h" 17 | 18 | extern lzma_ret lzma_lzma2_decoder_init(lzma_next_coder *next, 19 | const lzma_allocator *allocator, 20 | const lzma_filter_info *filters); 21 | 22 | extern uint64_t lzma_lzma2_decoder_memusage(const void *options); 23 | 24 | extern lzma_ret lzma_lzma2_props_decode( 25 | void **options, const lzma_allocator *allocator, 26 | const uint8_t *props, size_t props_size); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/liblzma/lzma/lzma2_encoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file lzma2_encoder.h 6 | /// \brief LZMA2 encoder 7 | /// 8 | // Authors: Igor Pavlov 9 | // Lasse Collin 10 | // 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | #ifndef LZMA_LZMA2_ENCODER_H 14 | #define LZMA_LZMA2_ENCODER_H 15 | 16 | #include "common.h" 17 | 18 | 19 | /// Maximum number of bytes of actual data per chunk (no headers) 20 | #define LZMA2_CHUNK_MAX (UINT32_C(1) << 16) 21 | 22 | /// Maximum uncompressed size of LZMA chunk (no headers) 23 | #define LZMA2_UNCOMPRESSED_MAX (UINT32_C(1) << 21) 24 | 25 | /// Maximum size of LZMA2 headers 26 | #define LZMA2_HEADER_MAX 6 27 | 28 | /// Size of a header for uncompressed chunk 29 | #define LZMA2_HEADER_UNCOMPRESSED 3 30 | 31 | 32 | extern lzma_ret lzma_lzma2_encoder_init( 33 | lzma_next_coder *next, const lzma_allocator *allocator, 34 | const lzma_filter_info *filters); 35 | 36 | extern uint64_t lzma_lzma2_encoder_memusage(const void *options); 37 | 38 | extern lzma_ret lzma_lzma2_props_encode(const void *options, uint8_t *out); 39 | 40 | extern uint64_t lzma_lzma2_block_size(const void *options); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/liblzma/lzma/lzma_decoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file lzma_decoder.h 6 | /// \brief LZMA decoder API 7 | /// 8 | // Authors: Igor Pavlov 9 | // Lasse Collin 10 | // 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | #ifndef LZMA_LZMA_DECODER_H 14 | #define LZMA_LZMA_DECODER_H 15 | 16 | #include "common.h" 17 | 18 | 19 | /// Allocates and initializes LZMA decoder 20 | extern lzma_ret lzma_lzma_decoder_init(lzma_next_coder *next, 21 | const lzma_allocator *allocator, 22 | const lzma_filter_info *filters); 23 | 24 | extern uint64_t lzma_lzma_decoder_memusage(const void *options); 25 | 26 | extern lzma_ret lzma_lzma_props_decode( 27 | void **options, const lzma_allocator *allocator, 28 | const uint8_t *props, size_t props_size); 29 | 30 | 31 | /// \brief Decodes the LZMA Properties byte (lc/lp/pb) 32 | /// 33 | /// \return true if error occurred, false on success 34 | /// 35 | extern bool lzma_lzma_lclppb_decode( 36 | lzma_options_lzma *options, uint8_t byte); 37 | 38 | 39 | #ifdef LZMA_LZ_DECODER_H 40 | /// Allocate and setup function pointers only. This is used by LZMA1 and 41 | /// LZMA2 decoders. 42 | extern lzma_ret lzma_lzma_decoder_create( 43 | lzma_lz_decoder *lz, const lzma_allocator *allocator, 44 | const lzma_options_lzma *opt, lzma_lz_options *lz_options); 45 | 46 | /// Gets memory usage without validating lc/lp/pb. This is used by LZMA2 47 | /// decoder, because raw LZMA2 decoding doesn't need lc/lp/pb. 48 | extern uint64_t lzma_lzma_decoder_memusage_nocheck(const void *options); 49 | 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/liblzma/lzma/lzma_encoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file lzma_encoder.h 6 | /// \brief LZMA encoder API 7 | /// 8 | // Authors: Igor Pavlov 9 | // Lasse Collin 10 | // 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | #ifndef LZMA_LZMA_ENCODER_H 14 | #define LZMA_LZMA_ENCODER_H 15 | 16 | #include "common.h" 17 | 18 | 19 | typedef struct lzma_lzma1_encoder_s lzma_lzma1_encoder; 20 | 21 | 22 | extern lzma_ret lzma_lzma_encoder_init(lzma_next_coder *next, 23 | const lzma_allocator *allocator, 24 | const lzma_filter_info *filters); 25 | 26 | 27 | extern uint64_t lzma_lzma_encoder_memusage(const void *options); 28 | 29 | extern lzma_ret lzma_lzma_props_encode(const void *options, uint8_t *out); 30 | 31 | 32 | /// Encodes lc/lp/pb into one byte. Returns false on success and true on error. 33 | extern bool lzma_lzma_lclppb_encode( 34 | const lzma_options_lzma *options, uint8_t *byte); 35 | 36 | 37 | #ifdef LZMA_LZ_ENCODER_H 38 | 39 | /// Initializes raw LZMA encoder; this is used by LZMA2. 40 | extern lzma_ret lzma_lzma_encoder_create( 41 | void **coder_ptr, const lzma_allocator *allocator, 42 | lzma_vli id, const lzma_options_lzma *options, 43 | 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/lzma/lzma_encoder_presets.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file lzma_encoder_presets.c 6 | /// \brief Encoder presets 7 | /// \note xz needs this even when only decoding is enabled. 8 | // 9 | // Author: Lasse Collin 10 | // 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | #include "common.h" 14 | 15 | 16 | extern LZMA_API(lzma_bool) 17 | lzma_lzma_preset(lzma_options_lzma *options, uint32_t preset) 18 | { 19 | const uint32_t level = preset & LZMA_PRESET_LEVEL_MASK; 20 | const uint32_t flags = preset & ~LZMA_PRESET_LEVEL_MASK; 21 | const uint32_t supported_flags = LZMA_PRESET_EXTREME; 22 | 23 | if (level > 9 || (flags & ~supported_flags)) 24 | return true; 25 | 26 | options->preset_dict = NULL; 27 | options->preset_dict_size = 0; 28 | 29 | options->lc = LZMA_LC_DEFAULT; 30 | options->lp = LZMA_LP_DEFAULT; 31 | options->pb = LZMA_PB_DEFAULT; 32 | 33 | static const uint8_t dict_pow2[] 34 | = { 18, 20, 21, 22, 22, 23, 23, 24, 25, 26 }; 35 | options->dict_size = UINT32_C(1) << dict_pow2[level]; 36 | 37 | if (level <= 3) { 38 | options->mode = LZMA_MODE_FAST; 39 | options->mf = level == 0 ? LZMA_MF_HC3 : LZMA_MF_HC4; 40 | options->nice_len = level <= 1 ? 128 : 273; 41 | static const uint8_t depths[] = { 4, 8, 24, 48 }; 42 | options->depth = depths[level]; 43 | } else { 44 | options->mode = LZMA_MODE_NORMAL; 45 | options->mf = LZMA_MF_BT4; 46 | options->nice_len = level == 4 ? 16 : level == 5 ? 32 : 64; 47 | options->depth = 0; 48 | } 49 | 50 | if (flags & LZMA_PRESET_EXTREME) { 51 | options->mode = LZMA_MODE_NORMAL; 52 | options->mf = LZMA_MF_BT4; 53 | if (level == 3 || level == 5) { 54 | options->nice_len = 192; 55 | options->depth = 0; 56 | } else { 57 | options->nice_len = 273; 58 | options->depth = 512; 59 | } 60 | } 61 | 62 | return false; 63 | } 64 | -------------------------------------------------------------------------------- /src/liblzma/rangecoder/Makefile.inc: -------------------------------------------------------------------------------- 1 | ## SPDX-License-Identifier: 0BSD 2 | ## Author: Lasse Collin 3 | 4 | EXTRA_DIST += rangecoder/price_tablegen.c 5 | 6 | liblzma_la_SOURCES += rangecoder/range_common.h 7 | 8 | if COND_ENCODER_LZMA1 9 | liblzma_la_SOURCES += \ 10 | rangecoder/range_encoder.h \ 11 | rangecoder/price.h \ 12 | rangecoder/price_table.c 13 | endif 14 | 15 | if COND_DECODER_LZMA1 16 | liblzma_la_SOURCES += rangecoder/range_decoder.h 17 | endif 18 | -------------------------------------------------------------------------------- /src/liblzma/rangecoder/price.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file price.h 6 | /// \brief Probability price calculation 7 | // 8 | // Author: Igor Pavlov 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_PRICE_H 13 | #define LZMA_PRICE_H 14 | 15 | 16 | #define RC_MOVE_REDUCING_BITS 4 17 | #define RC_BIT_PRICE_SHIFT_BITS 4 18 | #define RC_PRICE_TABLE_SIZE (RC_BIT_MODEL_TOTAL >> RC_MOVE_REDUCING_BITS) 19 | 20 | #define RC_INFINITY_PRICE (UINT32_C(1) << 30) 21 | 22 | 23 | /// Lookup table for the inline functions defined in this file. 24 | lzma_attr_visibility_hidden 25 | extern const uint8_t lzma_rc_prices[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[(prob ^ ((UINT32_C(0) - bit) 32 | & (RC_BIT_MODEL_TOTAL - 1))) >> RC_MOVE_REDUCING_BITS]; 33 | } 34 | 35 | 36 | static inline uint32_t 37 | rc_bit_0_price(const probability prob) 38 | { 39 | return lzma_rc_prices[prob >> RC_MOVE_REDUCING_BITS]; 40 | } 41 | 42 | 43 | static inline uint32_t 44 | rc_bit_1_price(const probability prob) 45 | { 46 | return lzma_rc_prices[(prob ^ (RC_BIT_MODEL_TOTAL - 1)) 47 | >> RC_MOVE_REDUCING_BITS]; 48 | } 49 | 50 | 51 | static inline uint32_t 52 | rc_bittree_price(const probability *const probs, 53 | const uint32_t bit_levels, uint32_t symbol) 54 | { 55 | uint32_t price = 0; 56 | symbol += UINT32_C(1) << bit_levels; 57 | 58 | do { 59 | const uint32_t bit = symbol & 1; 60 | symbol >>= 1; 61 | price += rc_bit_price(probs[symbol], bit); 62 | } while (symbol != 1); 63 | 64 | return price; 65 | } 66 | 67 | 68 | static inline uint32_t 69 | rc_bittree_reverse_price(const probability *const probs, 70 | uint32_t bit_levels, uint32_t symbol) 71 | { 72 | uint32_t price = 0; 73 | uint32_t model_index = 1; 74 | 75 | do { 76 | const uint32_t bit = symbol & 1; 77 | symbol >>= 1; 78 | price += rc_bit_price(probs[model_index], bit); 79 | model_index = (model_index << 1) + bit; 80 | } while (--bit_levels != 0); 81 | 82 | return price; 83 | } 84 | 85 | 86 | static inline uint32_t 87 | rc_direct_price(const uint32_t bits) 88 | { 89 | return bits << RC_BIT_PRICE_SHIFT_BITS; 90 | } 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /src/liblzma/rangecoder/price_table.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | // This file has been generated by price_tablegen.c. 4 | 5 | #include "range_encoder.h" 6 | 7 | const uint8_t lzma_rc_prices[RC_PRICE_TABLE_SIZE] = { 8 | 128, 103, 91, 84, 78, 73, 69, 66, 9 | 63, 61, 58, 56, 54, 52, 51, 49, 10 | 48, 46, 45, 44, 43, 42, 41, 40, 11 | 39, 38, 37, 36, 35, 34, 34, 33, 12 | 32, 31, 31, 30, 29, 29, 28, 28, 13 | 27, 26, 26, 25, 25, 24, 24, 23, 14 | 23, 22, 22, 22, 21, 21, 20, 20, 15 | 19, 19, 19, 18, 18, 17, 17, 17, 16 | 16, 16, 16, 15, 15, 15, 14, 14, 17 | 14, 13, 13, 13, 12, 12, 12, 11, 18 | 11, 11, 11, 10, 10, 10, 10, 9, 19 | 9, 9, 9, 8, 8, 8, 8, 7, 20 | 7, 7, 7, 6, 6, 6, 6, 5, 21 | 5, 5, 5, 5, 4, 4, 4, 4, 22 | 3, 3, 3, 3, 3, 2, 2, 2, 23 | 2, 2, 2, 1, 1, 1, 1, 1 24 | }; 25 | -------------------------------------------------------------------------------- /src/liblzma/rangecoder/price_tablegen.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file price_tablegen.c 6 | /// \brief Probability price table generator 7 | /// 8 | /// Compiling: gcc -std=c99 -o price_tablegen price_tablegen.c 9 | /// 10 | // Authors: Igor Pavlov 11 | // Lasse Collin 12 | // 13 | /////////////////////////////////////////////////////////////////////////////// 14 | 15 | #include 16 | #include 17 | 18 | // Make it compile without common.h. 19 | #define BUILDING_PRICE_TABLEGEN 20 | #define lzma_attr_visibility_hidden 21 | 22 | #include "range_common.h" 23 | #include "price.h" 24 | 25 | 26 | static uint32_t rc_prices[RC_PRICE_TABLE_SIZE]; 27 | 28 | 29 | static void 30 | init_price_table(void) 31 | { 32 | for (uint32_t i = (UINT32_C(1) << RC_MOVE_REDUCING_BITS) / 2; 33 | i < RC_BIT_MODEL_TOTAL; 34 | i += (UINT32_C(1) << RC_MOVE_REDUCING_BITS)) { 35 | const uint32_t cycles_bits = RC_BIT_PRICE_SHIFT_BITS; 36 | uint32_t w = i; 37 | uint32_t bit_count = 0; 38 | 39 | for (uint32_t j = 0; j < cycles_bits; ++j) { 40 | w *= w; 41 | bit_count <<= 1; 42 | 43 | while (w >= (UINT32_C(1) << 16)) { 44 | w >>= 1; 45 | ++bit_count; 46 | } 47 | } 48 | 49 | rc_prices[i >> RC_MOVE_REDUCING_BITS] 50 | = (RC_BIT_MODEL_TOTAL_BITS << cycles_bits) 51 | - 15 - bit_count; 52 | } 53 | 54 | return; 55 | } 56 | 57 | 58 | static void 59 | print_price_table(void) 60 | { 61 | // Split the SPDX string so that it won't accidentally match 62 | // when tools search for the string. 63 | printf("// SPDX" "-License-Identifier" ": 0BSD\n\n" 64 | "// This file has been generated by price_tablegen.c.\n\n" 65 | "#include \"range_encoder.h\"\n\n" 66 | "const uint8_t lzma_rc_prices[" 67 | "RC_PRICE_TABLE_SIZE] = {"); 68 | 69 | const size_t array_size = sizeof(lzma_rc_prices) 70 | / sizeof(lzma_rc_prices[0]); 71 | for (size_t i = 0; i < array_size; ++i) { 72 | if (i % 8 == 0) 73 | printf("\n\t"); 74 | 75 | printf("%4" PRIu32, rc_prices[i]); 76 | 77 | if (i != array_size - 1) 78 | printf(","); 79 | } 80 | 81 | printf("\n};\n"); 82 | 83 | return; 84 | } 85 | 86 | 87 | int 88 | main(void) 89 | { 90 | init_price_table(); 91 | print_price_table(); 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /src/liblzma/simple/Makefile.inc: -------------------------------------------------------------------------------- 1 | ## SPDX-License-Identifier: 0BSD 2 | ## Author: Lasse Collin 3 | 4 | liblzma_la_SOURCES += \ 5 | simple/simple_coder.c \ 6 | simple/simple_coder.h \ 7 | simple/simple_private.h 8 | 9 | if COND_ENCODER_SIMPLE 10 | liblzma_la_SOURCES += \ 11 | simple/simple_encoder.c \ 12 | simple/simple_encoder.h 13 | endif 14 | 15 | if COND_DECODER_SIMPLE 16 | liblzma_la_SOURCES += \ 17 | simple/simple_decoder.c \ 18 | simple/simple_decoder.h 19 | endif 20 | 21 | if COND_FILTER_X86 22 | liblzma_la_SOURCES += simple/x86.c 23 | endif 24 | 25 | if COND_FILTER_POWERPC 26 | liblzma_la_SOURCES += simple/powerpc.c 27 | endif 28 | 29 | if COND_FILTER_IA64 30 | liblzma_la_SOURCES += simple/ia64.c 31 | endif 32 | 33 | if COND_FILTER_ARM 34 | liblzma_la_SOURCES += simple/arm.c 35 | endif 36 | 37 | if COND_FILTER_ARMTHUMB 38 | liblzma_la_SOURCES += simple/armthumb.c 39 | endif 40 | 41 | if COND_FILTER_ARM64 42 | liblzma_la_SOURCES += simple/arm64.c 43 | endif 44 | 45 | if COND_FILTER_SPARC 46 | liblzma_la_SOURCES += simple/sparc.c 47 | endif 48 | 49 | if COND_FILTER_RISCV 50 | liblzma_la_SOURCES += simple/riscv.c 51 | endif 52 | -------------------------------------------------------------------------------- /src/liblzma/simple/arm.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file arm.c 6 | /// \brief Filter for ARM binaries 7 | /// 8 | // Authors: Igor Pavlov 9 | // Lasse Collin 10 | // 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | #include "simple_private.h" 14 | 15 | 16 | static size_t 17 | arm_code(void *simple lzma_attribute((__unused__)), 18 | uint32_t now_pos, bool is_encoder, 19 | uint8_t *buffer, size_t size) 20 | { 21 | size_t i; 22 | for (i = 0; i + 4 <= size; i += 4) { 23 | if (buffer[i + 3] == 0xEB) { 24 | uint32_t src = ((uint32_t)(buffer[i + 2]) << 16) 25 | | ((uint32_t)(buffer[i + 1]) << 8) 26 | | (uint32_t)(buffer[i + 0]); 27 | src <<= 2; 28 | 29 | uint32_t dest; 30 | if (is_encoder) 31 | dest = now_pos + (uint32_t)(i) + 8 + src; 32 | else 33 | dest = src - (now_pos + (uint32_t)(i) + 8); 34 | 35 | dest >>= 2; 36 | buffer[i + 2] = (dest >> 16); 37 | buffer[i + 1] = (dest >> 8); 38 | buffer[i + 0] = dest; 39 | } 40 | } 41 | 42 | return i; 43 | } 44 | 45 | 46 | static lzma_ret 47 | arm_coder_init(lzma_next_coder *next, const lzma_allocator *allocator, 48 | const lzma_filter_info *filters, bool is_encoder) 49 | { 50 | return lzma_simple_coder_init(next, allocator, filters, 51 | &arm_code, 0, 4, 4, is_encoder); 52 | } 53 | 54 | 55 | #ifdef HAVE_ENCODER_ARM 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 | #endif 64 | 65 | 66 | #ifdef HAVE_DECODER_ARM 67 | extern lzma_ret 68 | lzma_simple_arm_decoder_init(lzma_next_coder *next, 69 | const lzma_allocator *allocator, 70 | const lzma_filter_info *filters) 71 | { 72 | return arm_coder_init(next, allocator, filters, false); 73 | } 74 | #endif 75 | -------------------------------------------------------------------------------- /src/liblzma/simple/armthumb.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file armthumb.c 6 | /// \brief Filter for ARM-Thumb binaries 7 | /// 8 | // Authors: Igor Pavlov 9 | // Lasse Collin 10 | // 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | #include "simple_private.h" 14 | 15 | 16 | static size_t 17 | armthumb_code(void *simple lzma_attribute((__unused__)), 18 | uint32_t now_pos, bool is_encoder, 19 | uint8_t *buffer, size_t size) 20 | { 21 | size_t i; 22 | for (i = 0; i + 4 <= size; i += 2) { 23 | if ((buffer[i + 1] & 0xF8) == 0xF0 24 | && (buffer[i + 3] & 0xF8) == 0xF8) { 25 | uint32_t src = (((uint32_t)(buffer[i + 1]) & 7) << 19) 26 | | ((uint32_t)(buffer[i + 0]) << 11) 27 | | (((uint32_t)(buffer[i + 3]) & 7) << 8) 28 | | (uint32_t)(buffer[i + 2]); 29 | 30 | src <<= 1; 31 | 32 | uint32_t dest; 33 | if (is_encoder) 34 | dest = now_pos + (uint32_t)(i) + 4 + src; 35 | else 36 | dest = src - (now_pos + (uint32_t)(i) + 4); 37 | 38 | dest >>= 1; 39 | buffer[i + 1] = 0xF0 | ((dest >> 19) & 0x7); 40 | buffer[i + 0] = (dest >> 11); 41 | buffer[i + 3] = 0xF8 | ((dest >> 8) & 0x7); 42 | buffer[i + 2] = (dest); 43 | i += 2; 44 | } 45 | } 46 | 47 | return i; 48 | } 49 | 50 | 51 | static lzma_ret 52 | armthumb_coder_init(lzma_next_coder *next, const lzma_allocator *allocator, 53 | const lzma_filter_info *filters, bool is_encoder) 54 | { 55 | return lzma_simple_coder_init(next, allocator, filters, 56 | &armthumb_code, 0, 4, 2, is_encoder); 57 | } 58 | 59 | 60 | #ifdef HAVE_ENCODER_ARMTHUMB 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 | #endif 69 | 70 | 71 | #ifdef HAVE_DECODER_ARMTHUMB 72 | extern lzma_ret 73 | lzma_simple_armthumb_decoder_init(lzma_next_coder *next, 74 | const lzma_allocator *allocator, 75 | const lzma_filter_info *filters) 76 | { 77 | return armthumb_coder_init(next, allocator, filters, false); 78 | } 79 | #endif 80 | -------------------------------------------------------------------------------- /src/liblzma/simple/powerpc.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file powerpc.c 6 | /// \brief Filter for PowerPC (big endian) binaries 7 | /// 8 | // Authors: Igor Pavlov 9 | // Lasse Collin 10 | // 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | #include "simple_private.h" 14 | 15 | 16 | static size_t 17 | powerpc_code(void *simple lzma_attribute((__unused__)), 18 | uint32_t now_pos, bool is_encoder, 19 | uint8_t *buffer, size_t size) 20 | { 21 | size_t i; 22 | for (i = 0; i + 4 <= size; i += 4) { 23 | // PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link) 24 | if ((buffer[i] >> 2) == 0x12 25 | && ((buffer[i + 3] & 3) == 1)) { 26 | 27 | const uint32_t src 28 | = (((uint32_t)(buffer[i + 0]) & 3) << 24) 29 | | ((uint32_t)(buffer[i + 1]) << 16) 30 | | ((uint32_t)(buffer[i + 2]) << 8) 31 | | ((uint32_t)(buffer[i + 3]) & ~UINT32_C(3)); 32 | 33 | uint32_t dest; 34 | if (is_encoder) 35 | dest = now_pos + (uint32_t)(i) + src; 36 | else 37 | dest = src - (now_pos + (uint32_t)(i)); 38 | 39 | buffer[i + 0] = 0x48 | ((dest >> 24) & 0x03); 40 | buffer[i + 1] = (dest >> 16); 41 | buffer[i + 2] = (dest >> 8); 42 | buffer[i + 3] &= 0x03; 43 | buffer[i + 3] |= dest; 44 | } 45 | } 46 | 47 | return i; 48 | } 49 | 50 | 51 | static lzma_ret 52 | powerpc_coder_init(lzma_next_coder *next, const lzma_allocator *allocator, 53 | const lzma_filter_info *filters, bool is_encoder) 54 | { 55 | return lzma_simple_coder_init(next, allocator, filters, 56 | &powerpc_code, 0, 4, 4, is_encoder); 57 | } 58 | 59 | 60 | #ifdef HAVE_ENCODER_POWERPC 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 | #endif 69 | 70 | 71 | #ifdef HAVE_DECODER_POWERPC 72 | extern lzma_ret 73 | lzma_simple_powerpc_decoder_init(lzma_next_coder *next, 74 | const lzma_allocator *allocator, 75 | const lzma_filter_info *filters) 76 | { 77 | return powerpc_coder_init(next, allocator, filters, false); 78 | } 79 | #endif 80 | -------------------------------------------------------------------------------- /src/liblzma/simple/simple_decoder.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file simple_decoder.c 6 | /// \brief Properties decoder for simple filters 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "simple_decoder.h" 13 | 14 | 15 | extern lzma_ret 16 | lzma_simple_props_decode(void **options, const lzma_allocator *allocator, 17 | const uint8_t *props, size_t props_size) 18 | { 19 | if (props_size == 0) 20 | return LZMA_OK; 21 | 22 | if (props_size != 4) 23 | return LZMA_OPTIONS_ERROR; 24 | 25 | lzma_options_bcj *opt = lzma_alloc( 26 | sizeof(lzma_options_bcj), allocator); 27 | if (opt == NULL) 28 | return LZMA_MEM_ERROR; 29 | 30 | opt->start_offset = read32le(props); 31 | 32 | // Don't leave an options structure allocated if start_offset is zero. 33 | if (opt->start_offset == 0) 34 | lzma_free(opt, allocator); 35 | else 36 | *options = opt; 37 | 38 | return LZMA_OK; 39 | } 40 | -------------------------------------------------------------------------------- /src/liblzma/simple/simple_decoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file simple_decoder.h 6 | /// \brief Properties decoder for simple filters 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_SIMPLE_DECODER_H 13 | #define LZMA_SIMPLE_DECODER_H 14 | 15 | #include "simple_coder.h" 16 | 17 | extern lzma_ret lzma_simple_props_decode( 18 | void **options, const lzma_allocator *allocator, 19 | const uint8_t *props, size_t props_size); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/liblzma/simple/simple_encoder.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file simple_encoder.c 6 | /// \brief Properties encoder for simple filters 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "simple_encoder.h" 13 | 14 | 15 | extern lzma_ret 16 | lzma_simple_props_size(uint32_t *size, const void *options) 17 | { 18 | const lzma_options_bcj *const opt = options; 19 | *size = (opt == NULL || opt->start_offset == 0) ? 0 : 4; 20 | return LZMA_OK; 21 | } 22 | 23 | 24 | extern lzma_ret 25 | lzma_simple_props_encode(const void *options, uint8_t *out) 26 | { 27 | const lzma_options_bcj *const opt = options; 28 | 29 | // The default start offset is zero, so we don't need to store any 30 | // options unless the start offset is non-zero. 31 | if (opt == NULL || opt->start_offset == 0) 32 | return LZMA_OK; 33 | 34 | write32le(out, opt->start_offset); 35 | 36 | return LZMA_OK; 37 | } 38 | -------------------------------------------------------------------------------- /src/liblzma/simple/simple_encoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file simple_encoder.c 6 | /// \brief Properties encoder for simple filters 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_SIMPLE_ENCODER_H 13 | #define LZMA_SIMPLE_ENCODER_H 14 | 15 | #include "simple_coder.h" 16 | 17 | 18 | extern lzma_ret lzma_simple_props_size(uint32_t *size, const void *options); 19 | 20 | extern lzma_ret lzma_simple_props_encode(const void *options, uint8_t *out); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/liblzma/simple/simple_private.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file simple_private.h 6 | /// \brief Private definitions for so called simple filters 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_SIMPLE_PRIVATE_H 13 | #define LZMA_SIMPLE_PRIVATE_H 14 | 15 | #include "simple_coder.h" 16 | 17 | 18 | typedef struct { 19 | /// Next filter in the chain 20 | lzma_next_coder next; 21 | 22 | /// True if the next coder in the chain has returned LZMA_STREAM_END. 23 | bool end_was_reached; 24 | 25 | /// True if filter() should encode the data; false to decode. 26 | /// Currently all simple filters use the same function for encoding 27 | /// and decoding, because the difference between encoders and decoders 28 | /// is very small. 29 | bool is_encoder; 30 | 31 | /// Pointer to filter-specific function, which does 32 | /// the actual filtering. 33 | size_t (*filter)(void *simple, uint32_t now_pos, 34 | bool is_encoder, uint8_t *buffer, size_t size); 35 | 36 | /// Pointer to filter-specific data, or NULL if filter doesn't need 37 | /// any extra data. 38 | void *simple; 39 | 40 | /// The lowest 32 bits of the current position in the data. Most 41 | /// filters need this to do conversions between absolute and relative 42 | /// addresses. 43 | uint32_t now_pos; 44 | 45 | /// Size of the memory allocated for the buffer. 46 | size_t allocated; 47 | 48 | /// Flushing position in the temporary buffer. buffer[pos] is the 49 | /// next byte to be copied to out[]. 50 | size_t pos; 51 | 52 | /// buffer[filtered] is the first unfiltered byte. When pos is smaller 53 | /// than filtered, there is unflushed filtered data in the buffer. 54 | size_t filtered; 55 | 56 | /// Total number of bytes (both filtered and unfiltered) currently 57 | /// in the temporary buffer. 58 | size_t size; 59 | 60 | /// Temporary buffer 61 | uint8_t buffer[]; 62 | } lzma_simple_coder; 63 | 64 | 65 | extern lzma_ret lzma_simple_coder_init(lzma_next_coder *next, 66 | const lzma_allocator *allocator, 67 | const lzma_filter_info *filters, 68 | size_t (*filter)(void *simple, uint32_t now_pos, 69 | bool is_encoder, uint8_t *buffer, size_t size), 70 | size_t simple_size, size_t unfiltered_max, 71 | uint32_t alignment, bool is_encoder); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src/liblzma/simple/sparc.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file sparc.c 6 | /// \brief Filter for SPARC binaries 7 | /// 8 | // Authors: Igor Pavlov 9 | // Lasse Collin 10 | // 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | #include "simple_private.h" 14 | 15 | 16 | static size_t 17 | sparc_code(void *simple lzma_attribute((__unused__)), 18 | uint32_t now_pos, bool is_encoder, 19 | uint8_t *buffer, size_t size) 20 | { 21 | size_t i; 22 | for (i = 0; i + 4 <= size; i += 4) { 23 | 24 | if ((buffer[i] == 0x40 && (buffer[i + 1] & 0xC0) == 0x00) 25 | || (buffer[i] == 0x7F 26 | && (buffer[i + 1] & 0xC0) == 0xC0)) { 27 | 28 | uint32_t src = ((uint32_t)buffer[i + 0] << 24) 29 | | ((uint32_t)buffer[i + 1] << 16) 30 | | ((uint32_t)buffer[i + 2] << 8) 31 | | ((uint32_t)buffer[i + 3]); 32 | 33 | src <<= 2; 34 | 35 | uint32_t dest; 36 | if (is_encoder) 37 | dest = now_pos + (uint32_t)(i) + src; 38 | else 39 | dest = src - (now_pos + (uint32_t)(i)); 40 | 41 | dest >>= 2; 42 | 43 | dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) 44 | | (dest & 0x3FFFFF) 45 | | 0x40000000; 46 | 47 | buffer[i + 0] = (uint8_t)(dest >> 24); 48 | buffer[i + 1] = (uint8_t)(dest >> 16); 49 | buffer[i + 2] = (uint8_t)(dest >> 8); 50 | buffer[i + 3] = (uint8_t)(dest); 51 | } 52 | } 53 | 54 | return i; 55 | } 56 | 57 | 58 | static lzma_ret 59 | sparc_coder_init(lzma_next_coder *next, const lzma_allocator *allocator, 60 | const lzma_filter_info *filters, bool is_encoder) 61 | { 62 | return lzma_simple_coder_init(next, allocator, filters, 63 | &sparc_code, 0, 4, 4, is_encoder); 64 | } 65 | 66 | 67 | #ifdef HAVE_ENCODER_SPARC 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 | #endif 76 | 77 | 78 | #ifdef HAVE_DECODER_SPARC 79 | extern lzma_ret 80 | lzma_simple_sparc_decoder_init(lzma_next_coder *next, 81 | const lzma_allocator *allocator, 82 | const lzma_filter_info *filters) 83 | { 84 | return sparc_coder_init(next, allocator, filters, false); 85 | } 86 | #endif 87 | -------------------------------------------------------------------------------- /src/lzmainfo/Makefile.am: -------------------------------------------------------------------------------- 1 | ## SPDX-License-Identifier: 0BSD 2 | ## Author: Lasse Collin 3 | 4 | bin_PROGRAMS = lzmainfo 5 | 6 | lzmainfo_SOURCES = \ 7 | lzmainfo.c \ 8 | ../common/tuklib_progname.c \ 9 | ../common/tuklib_exit.c 10 | 11 | if COND_W32 12 | lzmainfo_SOURCES += lzmainfo_w32res.rc 13 | endif 14 | 15 | lzmainfo_CPPFLAGS = \ 16 | -DLOCALEDIR=\"$(localedir)\" \ 17 | -I$(top_srcdir)/src/common \ 18 | -I$(top_srcdir)/src/liblzma/api \ 19 | -I$(top_builddir)/lib 20 | 21 | lzmainfo_LDADD = $(top_builddir)/src/liblzma/liblzma.la 22 | 23 | if COND_GNULIB 24 | lzmainfo_LDADD += $(top_builddir)/lib/libgnu.a 25 | endif 26 | 27 | lzmainfo_LDADD += $(LTLIBINTL) 28 | 29 | 30 | dist_man_MANS = lzmainfo.1 31 | 32 | # Windows resource compiler support 33 | .rc.o: 34 | $(RC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ 35 | $(lzmainfo_CPPFLAGS) $(CPPFLAGS) $(RCFLAGS) -i $< -o $@ 36 | 37 | # The installation of translated man pages abuses Automake internals 38 | # by calling "install-man" with redefined dist_man_MANS and man_MANS. 39 | # If this breaks some day, don't blame Automake developers. 40 | install-data-hook: 41 | languages= ; \ 42 | if test "$(USE_NLS)" = yes && test -d "$(top_srcdir)/po4a/man"; then \ 43 | languages=`ls "$(top_srcdir)/po4a/man"`; \ 44 | fi; \ 45 | for lang in . $$languages; do \ 46 | man="$(top_srcdir)/po4a/man/$$lang/lzmainfo.1" ; \ 47 | if test -f "$$man"; then \ 48 | $(MAKE) dist_man_MANS="$$man" man_MANS= \ 49 | mandir="$(mandir)/$$lang" install-man; \ 50 | fi; \ 51 | done 52 | 53 | uninstall-hook: 54 | languages= ; \ 55 | if test "$(USE_NLS)" = yes && test -d "$(top_srcdir)/po4a/man"; then \ 56 | languages=`ls "$(top_srcdir)/po4a/man"`; \ 57 | fi; \ 58 | for lang in . $$languages; do \ 59 | name=`echo lzmainfo | sed '$(transform)'` && \ 60 | rm -f "$(DESTDIR)$(mandir)/$$lang/man1/$$name.1"; \ 61 | done 62 | -------------------------------------------------------------------------------- /src/lzmainfo/lzmainfo.1: -------------------------------------------------------------------------------- 1 | .\" SPDX-License-Identifier: 0BSD 2 | .\" 3 | .\" Author: Lasse Collin 4 | .\" 5 | .TH LZMAINFO 1 "2013-06-30" "Tukaani" "XZ Utils" 6 | .SH NAME 7 | lzmainfo \- show information stored in the .lzma file header 8 | .SH SYNOPSIS 9 | .B lzmainfo 10 | .RB [ \-\-help ] 11 | .RB [ \-\-version ] 12 | .RI [ file... ] 13 | .SH DESCRIPTION 14 | .B lzmainfo 15 | shows information stored in the 16 | .B .lzma 17 | file header. 18 | It reads the first 13 bytes from the specified 19 | .IR file , 20 | decodes the header, and prints it to standard output in human 21 | readable format. 22 | If no 23 | .I files 24 | are given or 25 | .I file 26 | is 27 | .BR \- , 28 | standard input is read. 29 | .PP 30 | Usually the most interesting information is 31 | the uncompressed size and the dictionary size. 32 | Uncompressed size can be shown only if 33 | the file is in the non-streamed 34 | .B .lzma 35 | format variant. 36 | The amount of memory required to decompress the file is 37 | a few dozen kilobytes plus the dictionary size. 38 | .PP 39 | .B lzmainfo 40 | is included in XZ Utils primarily for 41 | backward compatibility with LZMA Utils. 42 | .SH "EXIT STATUS" 43 | .TP 44 | .B 0 45 | All is good. 46 | .TP 47 | .B 1 48 | An error occurred. 49 | .SH BUGS 50 | .B lzmainfo 51 | uses 52 | .B MB 53 | while the correct suffix would be 54 | .B MiB 55 | (2^20 bytes). 56 | This is to keep the output compatible with LZMA Utils. 57 | .SH "SEE ALSO" 58 | .BR xz (1) 59 | -------------------------------------------------------------------------------- /src/lzmainfo/lzmainfo_w32res.rc: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: 0BSD */ 2 | 3 | /* 4 | * Author: Lasse Collin 5 | */ 6 | 7 | #define MY_TYPE VFT_APP 8 | #define MY_NAME "lzmainfo" 9 | #define MY_SUFFIX ".exe" 10 | #define MY_DESC "lzmainfo shows information about .lzma files" 11 | #include "common_w32res.rc" 12 | -------------------------------------------------------------------------------- /src/scripts/xzdiff.1: -------------------------------------------------------------------------------- 1 | .\" SPDX-License-Identifier: 0BSD 2 | .\" 3 | .\" Authors: Lasse Collin 4 | .\" Jia Tan 5 | .\" 6 | .\" (Note that this file is not based on gzip's zdiff.1.) 7 | .\" 8 | .TH XZDIFF 1 "2024-02-13" "Tukaani" "XZ Utils" 9 | .SH NAME 10 | xzcmp, xzdiff, lzcmp, lzdiff \- compare compressed files 11 | . 12 | .SH SYNOPSIS 13 | .B xzcmp 14 | .RI [ option... ] 15 | .I file1 16 | .RI [ file2 ] 17 | .br 18 | .B xzdiff 19 | \&... 20 | .br 21 | .B lzcmp 22 | \&... 23 | .br 24 | .B lzdiff 25 | \&... 26 | . 27 | .SH DESCRIPTION 28 | .B xzcmp 29 | and 30 | .B xzdiff 31 | compare uncompressed contents of two files. 32 | Uncompressed data and options are passed to 33 | .BR cmp (1) 34 | or 35 | .BR diff (1) 36 | unless 37 | .B \-\-help 38 | or 39 | .B \-\-version 40 | is specified. 41 | .PP 42 | If both 43 | .I file1 44 | and 45 | .I file2 46 | are specified, they can be uncompressed files or files in formats that 47 | .BR xz (1), 48 | .BR gzip (1), 49 | .BR bzip2 (1), 50 | .BR lzop (1), 51 | .BR zstd (1), 52 | or 53 | .BR lz4 (1) 54 | can decompress. 55 | The required decompression commands are determined from 56 | the filename suffixes of 57 | .I file1 58 | and 59 | .IR file2 . 60 | A file with an unknown suffix is assumed to be either uncompressed 61 | or in a format that 62 | .BR xz (1) 63 | can decompress. 64 | .PP 65 | If only one filename is provided, 66 | .I file1 67 | must have a suffix of a supported compression format and the name for 68 | .I file2 69 | is assumed to be 70 | .I file1 71 | with the compression format suffix removed. 72 | .PP 73 | The commands 74 | .B lzcmp 75 | and 76 | .B lzdiff 77 | are provided for backward compatibility with LZMA Utils. 78 | . 79 | .SH EXIT STATUS 80 | If a decompression error occurs, the exit status is 81 | .BR 2 . 82 | Otherwise the exit status of 83 | .BR cmp (1) 84 | or 85 | .BR diff (1) 86 | is used. 87 | . 88 | .SH "SEE ALSO" 89 | .BR cmp (1), 90 | .BR diff (1), 91 | .BR xz (1), 92 | .BR gzip (1), 93 | .BR bzip2 (1), 94 | .BR lzop (1), 95 | .BR zstd (1), 96 | .BR lz4 (1) 97 | -------------------------------------------------------------------------------- /src/scripts/xzless.1: -------------------------------------------------------------------------------- 1 | .\" SPDX-License-Identifier: 0BSD 2 | .\" 3 | .\" Authors: Andrew Dudman 4 | .\" Lasse Collin 5 | .\" 6 | .\" (Note that this file is not based on gzip's zless.1.) 7 | .\" 8 | .TH XZLESS 1 "2024-02-12" "Tukaani" "XZ Utils" 9 | .SH NAME 10 | xzless, lzless \- view xz or lzma compressed (text) files 11 | .SH SYNOPSIS 12 | .B xzless 13 | .RI [ file ...] 14 | .br 15 | .B lzless 16 | .RI [ file ...] 17 | .SH DESCRIPTION 18 | .B xzless 19 | is a filter that displays text from compressed files to a terminal. 20 | Files supported by 21 | .BR xz (1) 22 | are decompressed; 23 | other files are assumed to be in uncompressed form already. 24 | If no 25 | .I files 26 | are given, 27 | .B xzless 28 | reads from standard input. 29 | .PP 30 | .B xzless 31 | uses 32 | .BR less (1) 33 | to present its output. 34 | Unlike 35 | .BR xzmore , 36 | its choice of pager cannot be altered by 37 | setting an environment variable. 38 | Commands are based on both 39 | .BR more (1) 40 | and 41 | .BR vi (1) 42 | and allow back and forth movement and searching. 43 | See the 44 | .BR less (1) 45 | manual for more information. 46 | .PP 47 | The command named 48 | .B lzless 49 | is provided for backward compatibility with LZMA Utils. 50 | .SH ENVIRONMENT 51 | .TP 52 | .B LESSMETACHARS 53 | A list of characters special to the shell. 54 | Set by 55 | .B xzless 56 | unless it is already set in the environment. 57 | .TP 58 | .B LESSOPEN 59 | Set to a command line to invoke the 60 | .BR xz (1) 61 | decompressor for preprocessing the input files to 62 | .BR less (1). 63 | .SH "SEE ALSO" 64 | .BR less (1), 65 | .BR xz (1), 66 | .BR xzmore (1), 67 | .BR zless (1) 68 | -------------------------------------------------------------------------------- /src/scripts/xzmore.1: -------------------------------------------------------------------------------- 1 | .\" SPDX-License-Identifier: 0BSD 2 | .\" 3 | .\" Authors: Andrew Dudman 4 | .\" Lasse Collin 5 | .\" 6 | .\" (Note that this file is based on xzless.1 instead of gzip's zmore.1.) 7 | .\" 8 | .TH XZMORE 1 "2024-02-12" "Tukaani" "XZ Utils" 9 | .SH NAME 10 | xzmore, lzmore \- view xz or lzma compressed (text) files 11 | . 12 | .SH SYNOPSIS 13 | .B xzmore 14 | .RI [ file ...] 15 | .br 16 | .B lzmore 17 | .RI [ file ...] 18 | . 19 | .SH DESCRIPTION 20 | .B xzmore 21 | displays text from compressed files to a terminal using 22 | .BR more (1). 23 | Files supported by 24 | .BR xz (1) 25 | are decompressed; 26 | other files are assumed to be in uncompressed form already. 27 | If no 28 | .I files 29 | are given, 30 | .B xzmore 31 | reads from standard input. 32 | See the 33 | .BR more (1) 34 | manual for the keyboard commands. 35 | .PP 36 | Note that scrolling backwards might not be possible 37 | depending on the implementation of 38 | .BR more (1). 39 | This is because 40 | .B xzmore 41 | uses a pipe to pass the decompressed data to 42 | .BR more (1). 43 | .BR xzless (1) 44 | uses 45 | .BR less (1) 46 | which provides more advanced features. 47 | .PP 48 | The command 49 | .B lzmore 50 | is provided for backward compatibility with LZMA Utils. 51 | . 52 | .SH ENVIRONMENT 53 | .TP 54 | .B PAGER 55 | If 56 | .B PAGER 57 | is set, 58 | its value is used as the pager instead of 59 | .BR more (1). 60 | . 61 | .SH "SEE ALSO" 62 | .BR more (1), 63 | .BR xz (1), 64 | .BR xzless (1), 65 | .BR zmore (1) 66 | -------------------------------------------------------------------------------- /src/xz/args.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file args.h 6 | /// \brief Argument parsing 7 | // 8 | // Authors: Lasse Collin 9 | // Jia Tan 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 | const 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 const char stdin_filename[]; 42 | 43 | extern void args_parse(args_info *args, int argc, char **argv); 44 | extern void args_free(void); 45 | -------------------------------------------------------------------------------- /src/xz/list.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file list.h 6 | /// \brief List information about .xz files 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | /// \brief List information about the given .xz file 13 | extern void list_file(const char *filename); 14 | 15 | 16 | /// \brief Show the totals after all files have been listed 17 | extern void list_totals(void); 18 | -------------------------------------------------------------------------------- /src/xz/main.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file main.h 6 | /// \brief Miscellaneous declarations 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | /// Possible exit status values. These are the same as used by gzip and bzip2. 13 | enum exit_status_type { 14 | E_SUCCESS = 0, 15 | E_ERROR = 1, 16 | E_WARNING = 2, 17 | }; 18 | 19 | 20 | /// Sets the exit status after a warning or error has occurred. If new_status 21 | /// is E_WARNING and the old exit status was already E_ERROR, the exit 22 | /// status is not changed. 23 | extern void set_exit_status(enum exit_status_type new_status); 24 | 25 | 26 | /// Use E_SUCCESS instead of E_WARNING if something worth a warning occurs 27 | /// but nothing worth an error has occurred. This is called when --no-warn 28 | /// is specified. 29 | extern void set_exit_no_warn(void); 30 | -------------------------------------------------------------------------------- /src/xz/mytime.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file mytime.h 6 | /// \brief Time handling functions 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | 13 | /// \brief Number of milliseconds to between LZMA_SYNC_FLUSHes 14 | /// 15 | /// If 0, timed flushing is disabled. Otherwise if no more input is available 16 | /// and not at the end of the file and at least opt_flush_timeout milliseconds 17 | /// has elapsed since the start of compression or the previous flushing 18 | /// (LZMA_SYNC_FLUSH or LZMA_FULL_FLUSH), set LZMA_SYNC_FLUSH to flush 19 | /// the pending data. 20 | extern uint64_t opt_flush_timeout; 21 | 22 | 23 | #ifdef USE_SIGTSTP_HANDLER 24 | /// \brief Signal handler for SIGTSTP 25 | extern void mytime_sigtstp_handler(int sig); 26 | #endif 27 | 28 | 29 | /// \brief Store the time when (de)compression was started 30 | /// 31 | /// The start time is also stored as the time of the first flush. 32 | extern void mytime_set_start_time(void); 33 | 34 | 35 | /// \brief Get the number of milliseconds since the operation started 36 | extern uint64_t mytime_get_elapsed(void); 37 | 38 | 39 | /// \brief Store the time of when compressor was flushed 40 | extern void mytime_set_flush_time(void); 41 | 42 | 43 | /// \brief Get the number of milliseconds until the next flush 44 | /// 45 | /// This returns -1 if no timed flushing is used. 46 | /// 47 | /// The return value is intended for use with poll(). 48 | extern int mytime_get_flush_timeout(void); 49 | -------------------------------------------------------------------------------- /src/xz/options.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file options.h 6 | /// \brief Parser for filter-specific options 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | /// \brief Parser for Delta options 13 | /// 14 | /// \return Pointer to allocated options structure. 15 | /// Doesn't return on error. 16 | extern lzma_options_delta *options_delta(const char *str); 17 | 18 | 19 | /// \brief Parser for BCJ options 20 | /// 21 | /// \return Pointer to allocated options structure. 22 | /// Doesn't return on error. 23 | extern lzma_options_bcj *options_bcj(const char *str); 24 | 25 | 26 | /// \brief Parser for LZMA options 27 | /// 28 | /// \return Pointer to allocated options structure. 29 | /// Doesn't return on error. 30 | extern lzma_options_lzma *options_lzma(const char *str); 31 | -------------------------------------------------------------------------------- /src/xz/private.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file private.h 6 | /// \brief Common includes, definitions, and prototypes 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "sysdefs.h" 13 | #include "mythread.h" 14 | 15 | #include "lzma.h" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #ifndef _MSC_VER 25 | # include 26 | #endif 27 | 28 | #include "tuklib_gettext.h" 29 | #include "tuklib_progname.h" 30 | #include "tuklib_exit.h" 31 | #include "tuklib_mbstr.h" 32 | 33 | #if defined(_WIN32) && !defined(__CYGWIN__) 34 | # define WIN32_LEAN_AND_MEAN 35 | # include 36 | #endif 37 | 38 | #ifdef _MSC_VER 39 | # define fileno _fileno 40 | #endif 41 | 42 | #ifndef STDIN_FILENO 43 | # define STDIN_FILENO (fileno(stdin)) 44 | #endif 45 | 46 | #ifndef STDOUT_FILENO 47 | # define STDOUT_FILENO (fileno(stdout)) 48 | #endif 49 | 50 | #ifndef STDERR_FILENO 51 | # define STDERR_FILENO (fileno(stderr)) 52 | #endif 53 | 54 | // Handling SIGTSTP keeps time-keeping for progress indicator correct 55 | // if xz is stopped. It requires use of clock_gettime() as that is 56 | // async-signal safe in POSIX. Require also SIGALRM support since 57 | // on systems where SIGALRM isn't available, progress indicator code 58 | // polls the time and the SIGTSTP handling adds slight overhead to 59 | // that code. Most (all?) systems that have SIGTSTP also have SIGALRM 60 | // so this requirement won't exclude many systems. 61 | #if defined(HAVE_CLOCK_GETTIME) && defined(SIGTSTP) && defined(SIGALRM) 62 | # define USE_SIGTSTP_HANDLER 1 63 | #endif 64 | 65 | #include "main.h" 66 | #include "mytime.h" 67 | #include "coder.h" 68 | #include "message.h" 69 | #include "args.h" 70 | #include "hardware.h" 71 | #include "file_io.h" 72 | #include "options.h" 73 | #include "sandbox.h" 74 | #include "signals.h" 75 | #include "suffix.h" 76 | #include "util.h" 77 | 78 | #ifdef HAVE_DECODERS 79 | # include "list.h" 80 | #endif 81 | -------------------------------------------------------------------------------- /src/xz/sandbox.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file sandbox.h 6 | /// \brief Sandbox support 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #if defined(HAVE_PLEDGE) || defined(HAVE_LINUX_LANDLOCK) \ 13 | || defined(HAVE_CAP_RIGHTS_LIMIT) 14 | # define ENABLE_SANDBOX 1 15 | #endif 16 | 17 | 18 | /// \brief Enables early sandboxing that can always be enabled 19 | /// 20 | /// This requires that tuklib_progname() and io_init() have been called. 21 | extern void sandbox_init(void); 22 | 23 | 24 | /// \brief Enable sandboxing that only allows opening files for reading 25 | extern void sandbox_enable_read_only(void); 26 | 27 | 28 | /// \brief Tell sandboxing code that strict sandboxing can be used 29 | /// 30 | /// This function only sets a flag which will be read by 31 | /// sandbox_enable_strict_if_allowed(). 32 | extern void sandbox_allow_strict(void); 33 | 34 | 35 | /// \brief Enable sandboxing that allows reading from one file 36 | /// 37 | /// This does nothing if sandbox_allow_strict() hasn't been called. 38 | /// 39 | /// \param src_fd File descriptor open for reading 40 | /// \param pipe_event_fd user_abort_pipe[0] from file_io.c 41 | /// \param pipe_write_fd user_abort_pipe[1] from file_io.c 42 | extern void sandbox_enable_strict_if_allowed( 43 | int src_fd, int pipe_event_fd, int pipe_write_fd); 44 | -------------------------------------------------------------------------------- /src/xz/signals.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file signals.h 6 | /// \brief Handling signals to abort operation 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | /// If this is true, we will clean up the possibly incomplete output file, 13 | /// return to main() as soon as practical. That is, the code needs to poll 14 | /// this variable in various places. 15 | extern volatile sig_atomic_t user_abort; 16 | 17 | 18 | /// Initialize the signal handler, which will set user_abort to true when 19 | /// user e.g. presses C-c. 20 | extern void signals_init(void); 21 | 22 | 23 | #if (defined(_WIN32) && !defined(__CYGWIN__)) || defined(__VMS) 24 | # define signals_block() do { } while (0) 25 | # define signals_unblock() do { } while (0) 26 | #else 27 | /// Block the signals which don't have SA_RESTART and which would just set 28 | /// user_abort to true. This is handy when we don't want to handle EINTR 29 | /// and don't want SA_RESTART either. 30 | extern void signals_block(void); 31 | 32 | /// Unblock the signals blocked by signals_block(). 33 | extern void signals_unblock(void); 34 | #endif 35 | 36 | #if defined(_WIN32) && !defined(__CYGWIN__) 37 | # define signals_exit() do { } while (0) 38 | #else 39 | /// If user has sent us a signal earlier to terminate the process, 40 | /// re-raise that signal to actually terminate the process. 41 | extern void signals_exit(void); 42 | #endif 43 | -------------------------------------------------------------------------------- /src/xz/suffix.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file suffix.h 6 | /// \brief Checks filename suffix and creates the destination filename 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | /// \brief Get the name of the destination file 13 | /// 14 | /// Depending on the global variable opt_mode, this tries to find a matching 15 | /// counterpart for src_name. If the name can be constructed, it is allocated 16 | /// and returned (caller must free it). On error, a message is printed and 17 | /// NULL is returned. 18 | extern char *suffix_get_dest_name(const char *src_name); 19 | 20 | 21 | /// \brief Set a custom filename suffix 22 | /// 23 | /// This function calls xstrdup() for the given suffix, thus the caller 24 | /// doesn't need to keep the memory allocated. There can be only one custom 25 | /// suffix, thus if this is called multiple times, the old suffixes are freed 26 | /// and forgotten. 27 | extern void suffix_set(const char *suffix); 28 | 29 | 30 | /// \brief Check if a custom suffix has been set 31 | /// 32 | /// Returns true if the internal tracking of the suffix string has been set 33 | /// and false if the string has not been set. This will keep the suffix 34 | /// string encapsulated instead of extern-ing the variable. 35 | extern bool suffix_is_set(void); 36 | -------------------------------------------------------------------------------- /src/xz/xz_w32res.rc: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: 0BSD */ 2 | 3 | /* 4 | * Author: Lasse Collin 5 | */ 6 | 7 | #define MY_TYPE VFT_APP 8 | #define MY_NAME "xz" 9 | #define MY_SUFFIX ".exe" 10 | #define MY_DESC "xz data compression tool for .xz and .lzma files" 11 | #include "common_w32res.rc" 12 | -------------------------------------------------------------------------------- /src/xzdec/lzmadec_w32res.rc: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: 0BSD */ 2 | 3 | /* 4 | * Author: Lasse Collin 5 | */ 6 | 7 | #define MY_TYPE VFT_APP 8 | #define MY_NAME "lzmadec" 9 | #define MY_SUFFIX ".exe" 10 | #define MY_DESC "lzmadec decompression tool for .lzma files" 11 | #include "common_w32res.rc" 12 | -------------------------------------------------------------------------------- /src/xzdec/xzdec_w32res.rc: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: 0BSD */ 2 | 3 | /* 4 | * Author: Lasse Collin 5 | */ 6 | 7 | #define MY_TYPE VFT_APP 8 | #define MY_NAME "xzdec" 9 | #define MY_SUFFIX ".exe" 10 | #define MY_DESC "xzdec decompression tool for .xz files" 11 | #include "common_w32res.rc" 12 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | ## SPDX-License-Identifier: 0BSD 2 | ## Author: Lasse Collin 3 | 4 | EXTRA_DIST = \ 5 | files \ 6 | ossfuzz \ 7 | tests.cmake \ 8 | tuktest.h \ 9 | tests.h \ 10 | tests_w32res.rc \ 11 | test_files.sh \ 12 | test_compress.sh \ 13 | test_compress_generated_abc \ 14 | test_compress_generated_random \ 15 | test_compress_generated_text \ 16 | test_scripts.sh \ 17 | test_suffix.sh \ 18 | xzgrep_expected_output 19 | 20 | AM_CPPFLAGS = \ 21 | -I$(top_srcdir)/src/common \ 22 | -I$(top_srcdir)/src/liblzma/api \ 23 | -I$(top_srcdir)/src/liblzma 24 | 25 | LDADD = $(top_builddir)/src/liblzma/liblzma.la 26 | 27 | LDADD += $(LTLIBINTL) 28 | 29 | # Windows resource compiler support 30 | .rc.o: 31 | $(RC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ 32 | $(AM_CPPFLAGS) $(CPPFLAGS) $(RCFLAGS) -i $< -o $@ 33 | 34 | if COND_W32 35 | LDADD += tests_w32res.o 36 | endif 37 | 38 | check_PROGRAMS = \ 39 | create_compress_files \ 40 | test_check \ 41 | test_hardware \ 42 | test_stream_flags \ 43 | test_filter_flags \ 44 | test_filter_str \ 45 | test_block_header \ 46 | test_index \ 47 | test_index_hash \ 48 | test_bcj_exact_size \ 49 | test_memlimit \ 50 | test_lzip_decoder \ 51 | test_vli 52 | 53 | TESTS = \ 54 | test_check \ 55 | test_hardware \ 56 | test_stream_flags \ 57 | test_filter_flags \ 58 | test_filter_str \ 59 | test_block_header \ 60 | test_index \ 61 | test_index_hash \ 62 | test_bcj_exact_size \ 63 | test_memlimit \ 64 | test_lzip_decoder \ 65 | test_vli \ 66 | test_files.sh \ 67 | test_suffix.sh \ 68 | test_compress_generated_abc \ 69 | test_compress_generated_random \ 70 | test_compress_generated_text 71 | 72 | if COND_MICROLZMA 73 | check_PROGRAMS += test_microlzma 74 | TESTS += test_microlzma 75 | endif 76 | 77 | if COND_SCRIPTS 78 | TESTS += test_scripts.sh 79 | endif 80 | 81 | clean-local: 82 | -rm -f compress_generated_* \ 83 | xzgrep_test_output xzgrep_test_1.xz xzgrep_test_2.xz 84 | -------------------------------------------------------------------------------- /tests/code_coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SPDX-License-Identifier: 0BSD 3 | 4 | ############################################################################### 5 | # 6 | # This builds xz with special CFLAGS for measuring code coverage and 7 | # uses lcov and genhtml to create coverage reports. 8 | # 9 | # The current directory is used as the build directory so out-of-tree 10 | # builds are possible. The coverage reports are written to the directory 11 | # "coverage" under the current directory. 12 | # 13 | # Any options passed to this script are passed to "make" so to get 14 | # faster builds use, for example, "-j4" as an argument to this script. 15 | # 16 | # Author: Jia Tan 17 | # 18 | ############################################################################### 19 | 20 | set -e 21 | 22 | COVERAGE_DIR="coverage" 23 | 24 | # Test if lcov is installed 25 | if ! command -v lcov > /dev/null 26 | then 27 | echo "Error: lcov not installed" 28 | exit 1 29 | fi 30 | 31 | # Test if genhtml is installed 32 | if ! command -v genhtml > /dev/null 33 | then 34 | echo "Error: genhtml not installed" 35 | exit 1 36 | fi 37 | 38 | top_srcdir=$(cd -- "$(dirname -- "$0")" && cd .. && pwd) 39 | 40 | # Run the autogen.sh script if the configure script has not been generated 41 | if ! test -f "$top_srcdir/configure" 42 | then 43 | ( cd "$top_srcdir" && ./autogen.sh ) 44 | fi 45 | 46 | # Execute the configure script if the Makefile is not present 47 | if ! test -f "Makefile" 48 | then 49 | "$top_srcdir/configure" \ 50 | --disable-xzdec \ 51 | --disable-lzmadec \ 52 | --disable-lzmainfo \ 53 | --disable-shared \ 54 | --enable-silent-rules \ 55 | CFLAGS="$CFLAGS --coverage --no-inline -O0" 56 | fi 57 | 58 | # Run the tests 59 | make "$@" check 60 | 61 | # Re-create the coverage directory 62 | rm -rf "$COVERAGE_DIR" 63 | mkdir -p "$COVERAGE_DIR/liblzma" 64 | mkdir -p "$COVERAGE_DIR/xz" 65 | 66 | # Run lcov with src/liblzma as the input directory and write the 67 | # results out to the coverage directory 68 | lcov -c -d "src/liblzma" -o "$COVERAGE_DIR/liblzma/liblzma.cov" 69 | lcov -c -d "src/xz" -o "$COVERAGE_DIR/xz/xz.cov" 70 | 71 | # Generate the reports 72 | genhtml "$COVERAGE_DIR/liblzma/liblzma.cov" -o "$COVERAGE_DIR/liblzma" 73 | genhtml "$COVERAGE_DIR/xz/xz.cov" -o "$COVERAGE_DIR/xz" 74 | 75 | echo "Success! See:" 76 | echo "file://$PWD/$COVERAGE_DIR/liblzma/index.html" 77 | echo "file://$PWD/$COVERAGE_DIR/xz/index.html" 78 | -------------------------------------------------------------------------------- /tests/files/bad-0-backward_size.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-0-backward_size.xz -------------------------------------------------------------------------------- /tests/files/bad-0-empty-truncated.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-0-empty-truncated.xz -------------------------------------------------------------------------------- /tests/files/bad-0-footer_magic.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-0-footer_magic.xz -------------------------------------------------------------------------------- /tests/files/bad-0-header_magic.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-0-header_magic.xz -------------------------------------------------------------------------------- /tests/files/bad-0-nonempty_index.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-0-nonempty_index.xz -------------------------------------------------------------------------------- /tests/files/bad-0cat-alone.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-0cat-alone.xz -------------------------------------------------------------------------------- /tests/files/bad-0cat-header_magic.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-0cat-header_magic.xz -------------------------------------------------------------------------------- /tests/files/bad-0catpad-empty.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-0catpad-empty.xz -------------------------------------------------------------------------------- /tests/files/bad-0pad-empty.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-0pad-empty.xz -------------------------------------------------------------------------------- /tests/files/bad-1-block_header-1.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-block_header-1.xz -------------------------------------------------------------------------------- /tests/files/bad-1-block_header-2.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-block_header-2.xz -------------------------------------------------------------------------------- /tests/files/bad-1-block_header-3.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-block_header-3.xz -------------------------------------------------------------------------------- /tests/files/bad-1-block_header-4.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-block_header-4.xz -------------------------------------------------------------------------------- /tests/files/bad-1-block_header-5.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-block_header-5.xz -------------------------------------------------------------------------------- /tests/files/bad-1-block_header-6.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-block_header-6.xz -------------------------------------------------------------------------------- /tests/files/bad-1-check-crc32-2.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-check-crc32-2.xz -------------------------------------------------------------------------------- /tests/files/bad-1-check-crc32.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-check-crc32.xz -------------------------------------------------------------------------------- /tests/files/bad-1-check-crc64.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-check-crc64.xz -------------------------------------------------------------------------------- /tests/files/bad-1-check-sha256.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-check-sha256.xz -------------------------------------------------------------------------------- /tests/files/bad-1-lzma2-1.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-lzma2-1.xz -------------------------------------------------------------------------------- /tests/files/bad-1-lzma2-10.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-lzma2-10.xz -------------------------------------------------------------------------------- /tests/files/bad-1-lzma2-11.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-lzma2-11.xz -------------------------------------------------------------------------------- /tests/files/bad-1-lzma2-2.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-lzma2-2.xz -------------------------------------------------------------------------------- /tests/files/bad-1-lzma2-3.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-lzma2-3.xz -------------------------------------------------------------------------------- /tests/files/bad-1-lzma2-4.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-lzma2-4.xz -------------------------------------------------------------------------------- /tests/files/bad-1-lzma2-5.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-lzma2-5.xz -------------------------------------------------------------------------------- /tests/files/bad-1-lzma2-6.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-lzma2-6.xz -------------------------------------------------------------------------------- /tests/files/bad-1-lzma2-7.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-lzma2-7.xz -------------------------------------------------------------------------------- /tests/files/bad-1-lzma2-8.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-lzma2-8.xz -------------------------------------------------------------------------------- /tests/files/bad-1-lzma2-9.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-lzma2-9.xz -------------------------------------------------------------------------------- /tests/files/bad-1-stream_flags-1.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-stream_flags-1.xz -------------------------------------------------------------------------------- /tests/files/bad-1-stream_flags-2.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-stream_flags-2.xz -------------------------------------------------------------------------------- /tests/files/bad-1-stream_flags-3.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-stream_flags-3.xz -------------------------------------------------------------------------------- /tests/files/bad-1-v0-uncomp-size.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-v0-uncomp-size.lz -------------------------------------------------------------------------------- /tests/files/bad-1-v1-crc32.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-v1-crc32.lz -------------------------------------------------------------------------------- /tests/files/bad-1-v1-dict-1.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-v1-dict-1.lz -------------------------------------------------------------------------------- /tests/files/bad-1-v1-dict-2.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-v1-dict-2.lz -------------------------------------------------------------------------------- /tests/files/bad-1-v1-magic-1.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-v1-magic-1.lz -------------------------------------------------------------------------------- /tests/files/bad-1-v1-magic-2.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-v1-magic-2.lz -------------------------------------------------------------------------------- /tests/files/bad-1-v1-member-size.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-v1-member-size.lz -------------------------------------------------------------------------------- /tests/files/bad-1-v1-trailing-magic.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-v1-trailing-magic.lz -------------------------------------------------------------------------------- /tests/files/bad-1-v1-uncomp-size.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-v1-uncomp-size.lz -------------------------------------------------------------------------------- /tests/files/bad-1-vli-1.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-vli-1.xz -------------------------------------------------------------------------------- /tests/files/bad-1-vli-2.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-1-vli-2.xz -------------------------------------------------------------------------------- /tests/files/bad-2-compressed_data_padding.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-2-compressed_data_padding.xz -------------------------------------------------------------------------------- /tests/files/bad-2-index-1.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-2-index-1.xz -------------------------------------------------------------------------------- /tests/files/bad-2-index-2.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-2-index-2.xz -------------------------------------------------------------------------------- /tests/files/bad-2-index-3.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-2-index-3.xz -------------------------------------------------------------------------------- /tests/files/bad-2-index-4.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-2-index-4.xz -------------------------------------------------------------------------------- /tests/files/bad-2-index-5.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-2-index-5.xz -------------------------------------------------------------------------------- /tests/files/bad-3-index-uncomp-overflow.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-3-index-uncomp-overflow.xz -------------------------------------------------------------------------------- /tests/files/bad-too_big_size-with_eopm.lzma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-too_big_size-with_eopm.lzma -------------------------------------------------------------------------------- /tests/files/bad-too_small_size-without_eopm-1.lzma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-too_small_size-without_eopm-1.lzma -------------------------------------------------------------------------------- /tests/files/bad-too_small_size-without_eopm-2.lzma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-too_small_size-without_eopm-2.lzma -------------------------------------------------------------------------------- /tests/files/bad-too_small_size-without_eopm-3.lzma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-too_small_size-without_eopm-3.lzma -------------------------------------------------------------------------------- /tests/files/bad-unknown_size-without_eopm.lzma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/bad-unknown_size-without_eopm.lzma -------------------------------------------------------------------------------- /tests/files/good-0-empty.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-0-empty.xz -------------------------------------------------------------------------------- /tests/files/good-0cat-empty.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-0cat-empty.xz -------------------------------------------------------------------------------- /tests/files/good-0catpad-empty.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-0catpad-empty.xz -------------------------------------------------------------------------------- /tests/files/good-0pad-empty.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-0pad-empty.xz -------------------------------------------------------------------------------- /tests/files/good-1-3delta-lzma2.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-3delta-lzma2.xz -------------------------------------------------------------------------------- /tests/files/good-1-arm64-lzma2-1.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-arm64-lzma2-1.xz -------------------------------------------------------------------------------- /tests/files/good-1-arm64-lzma2-2.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-arm64-lzma2-2.xz -------------------------------------------------------------------------------- /tests/files/good-1-block_header-1.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-block_header-1.xz -------------------------------------------------------------------------------- /tests/files/good-1-block_header-2.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-block_header-2.xz -------------------------------------------------------------------------------- /tests/files/good-1-block_header-3.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-block_header-3.xz -------------------------------------------------------------------------------- /tests/files/good-1-check-crc32.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-check-crc32.xz -------------------------------------------------------------------------------- /tests/files/good-1-check-crc64.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-check-crc64.xz -------------------------------------------------------------------------------- /tests/files/good-1-check-none.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-check-none.xz -------------------------------------------------------------------------------- /tests/files/good-1-check-sha256.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-check-sha256.xz -------------------------------------------------------------------------------- /tests/files/good-1-delta-lzma2.tiff.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-delta-lzma2.tiff.xz -------------------------------------------------------------------------------- /tests/files/good-1-empty-bcj-lzma2.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-empty-bcj-lzma2.xz -------------------------------------------------------------------------------- /tests/files/good-1-lzma2-1.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-lzma2-1.xz -------------------------------------------------------------------------------- /tests/files/good-1-lzma2-2.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-lzma2-2.xz -------------------------------------------------------------------------------- /tests/files/good-1-lzma2-3.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-lzma2-3.xz -------------------------------------------------------------------------------- /tests/files/good-1-lzma2-4.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-lzma2-4.xz -------------------------------------------------------------------------------- /tests/files/good-1-lzma2-5.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-lzma2-5.xz -------------------------------------------------------------------------------- /tests/files/good-1-v0-trailing-1.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-v0-trailing-1.lz -------------------------------------------------------------------------------- /tests/files/good-1-v0.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-v0.lz -------------------------------------------------------------------------------- /tests/files/good-1-v1-trailing-1.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-v1-trailing-1.lz -------------------------------------------------------------------------------- /tests/files/good-1-v1-trailing-2.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-v1-trailing-2.lz -------------------------------------------------------------------------------- /tests/files/good-1-v1.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-1-v1.lz -------------------------------------------------------------------------------- /tests/files/good-2-lzma2.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-2-lzma2.xz -------------------------------------------------------------------------------- /tests/files/good-2-v0-v1.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-2-v0-v1.lz -------------------------------------------------------------------------------- /tests/files/good-2-v1-v0.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-2-v1-v0.lz -------------------------------------------------------------------------------- /tests/files/good-2-v1-v1.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-2-v1-v1.lz -------------------------------------------------------------------------------- /tests/files/good-known_size-with_eopm.lzma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-known_size-with_eopm.lzma -------------------------------------------------------------------------------- /tests/files/good-known_size-without_eopm.lzma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-known_size-without_eopm.lzma -------------------------------------------------------------------------------- /tests/files/good-unknown_size-with_eopm.lzma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/good-unknown_size-with_eopm.lzma -------------------------------------------------------------------------------- /tests/files/unsupported-1-v234.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/unsupported-1-v234.lz -------------------------------------------------------------------------------- /tests/files/unsupported-block_header.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/unsupported-block_header.xz -------------------------------------------------------------------------------- /tests/files/unsupported-check.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/unsupported-check.xz -------------------------------------------------------------------------------- /tests/files/unsupported-filter_flags-1.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/unsupported-filter_flags-1.xz -------------------------------------------------------------------------------- /tests/files/unsupported-filter_flags-2.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/unsupported-filter_flags-2.xz -------------------------------------------------------------------------------- /tests/files/unsupported-filter_flags-3.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/liblzma/8565799d188b66b2f4a324b04c8e16079e34b289/tests/files/unsupported-filter_flags-3.xz -------------------------------------------------------------------------------- /tests/ossfuzz/Makefile: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | 3 | FUZZ_TARGET_SRCS = $(wildcard *.c) 4 | FUZZ_TARGET_BINS = $(FUZZ_TARGET_SRCS:.c=) 5 | 6 | all: $(FUZZ_TARGET_BINS) 7 | 8 | %: %.c 9 | $(CC) $(CFLAGS) -c $< -I ../../src/liblzma/api/ ; 10 | $(CXX) $(CXXFLAGS) $(LIB_FUZZING_ENGINE) $(<:.c=.o) -o $(OUT)/$@ \ 11 | ../../src/liblzma/.libs/liblzma.a ; 12 | 13 | # The generated binaries are not removed, just the object files. The 14 | # binaries are created to the $(OUT) directory and must be removed by the 15 | # fuzzing framework. 16 | clean: 17 | rm -f *.o 18 | -------------------------------------------------------------------------------- /tests/ossfuzz/config/fuzz_decode_alone.options: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | 3 | [libfuzzer] 4 | max_len = 4096 5 | dict = fuzz_lzma.dict 6 | -------------------------------------------------------------------------------- /tests/ossfuzz/config/fuzz_decode_stream.options: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | 3 | [libfuzzer] 4 | dict = fuzz_xz.dict 5 | -------------------------------------------------------------------------------- /tests/ossfuzz/config/fuzz_encode_stream.options: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | 3 | [libfuzzer] 4 | max_len = 4096 5 | -------------------------------------------------------------------------------- /tests/ossfuzz/config/fuzz_lzma.dict: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | 3 | # first 5 header bytes of .lzma archives based on the info from 4 | # /doc/lzma-file-format.txt 5 | 6 | # byte 0 is created by encoding LZMA property values (lc, lp, pb) 7 | # using the algorithm described in the documentation above. 8 | 9 | # lc=3, lp=0, pb=2 and dictionary size = 0x00100000 10 | "\x5d\x00\x00\x10\x00" 11 | 12 | # lc=3, lp=1, pb=3 and dictionary size = 0x00100000 13 | "\x93\x00\x00\x10\x00" 14 | 15 | # lc=2, lp=2, pb=4 and dictionary size = 0x00100000 16 | "\xc8\x00\x00\x10\x00" 17 | 18 | # lc=1, lp=3, pb=1 and dictionary size = 0x00200000 19 | "\x49\x00\x00\x20\x00" 20 | 21 | # lc=0, lp=4, pb=0 and dictionary size = 0x00200000 22 | "\x24\x00\x00\x20\x00" 23 | -------------------------------------------------------------------------------- /tests/ossfuzz/config/fuzz_xz.dict: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | 3 | "\xFD7zXZ\x00" 4 | "YZ" 5 | -------------------------------------------------------------------------------- /tests/ossfuzz/fuzz_common.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file fuzz_common.h 6 | /// \brief Common macros and functions needed by the fuzz targets 7 | // 8 | // Authors: Maksym Vatsyk 9 | // Lasse Collin 10 | // 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | #include 14 | #include 15 | #include 16 | #include "lzma.h" 17 | 18 | // Some header values can make liblzma allocate a lot of RAM 19 | // (up to about 4 GiB with liblzma 5.2.x). We set a limit here to 20 | // prevent extreme allocations when fuzzing. 21 | #define MEM_LIMIT (300 << 20) // 300 MiB 22 | 23 | 24 | static void 25 | fuzz_code(lzma_stream *stream, const uint8_t *inbuf, size_t inbuf_size) { 26 | // Output buffer for decompressed data. This is write only; nothing 27 | // cares about the actual data written here. 28 | uint8_t outbuf[4096]; 29 | 30 | // Give the whole input buffer at once to liblzma. 31 | // Output buffer isn't initialized as liblzma only writes to it. 32 | stream->next_in = inbuf; 33 | stream->avail_in = inbuf_size; 34 | stream->next_out = outbuf; 35 | stream->avail_out = sizeof(outbuf); 36 | 37 | lzma_ret ret; 38 | while ((ret = lzma_code(stream, LZMA_FINISH)) == LZMA_OK) { 39 | if (stream->avail_out == 0) { 40 | // outbuf became full. We don't care about the 41 | // uncompressed data there, so we simply reuse 42 | // the outbuf and overwrite the old data. 43 | stream->next_out = outbuf; 44 | stream->avail_out = sizeof(outbuf); 45 | } 46 | } 47 | 48 | // LZMA_PROG_ERROR should never happen as long as the code calling 49 | // the liblzma functions is correct. Thus LZMA_PROG_ERROR is a sign 50 | // of a bug in either this function or in liblzma. 51 | if (ret == LZMA_PROG_ERROR) { 52 | fprintf(stderr, "lzma_code() returned LZMA_PROG_ERROR\n"); 53 | abort(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/ossfuzz/fuzz_decode_alone.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file fuzz_decode_alone.c 6 | /// \brief Fuzz test program for liblzma .lzma decoding 7 | // 8 | // Authors: Maksym Vatsyk 9 | // Lasse Collin 10 | // 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | #include 14 | #include 15 | #include 16 | #include "lzma.h" 17 | #include "fuzz_common.h" 18 | 19 | 20 | extern int 21 | LLVMFuzzerTestOneInput(const uint8_t *inbuf, size_t inbuf_size) 22 | { 23 | lzma_stream strm = LZMA_STREAM_INIT; 24 | // Initialize a LZMA alone decoder using the memory usage limit 25 | // defined in fuzz_common.h 26 | lzma_ret ret = lzma_alone_decoder(&strm, MEM_LIMIT); 27 | 28 | if (ret != LZMA_OK) { 29 | // This should never happen unless the system has 30 | // no free memory or address space to allow the small 31 | // allocations that the initialization requires. 32 | fprintf(stderr, "lzma_alone_decoder() failed (%d)\n", ret); 33 | abort(); 34 | } 35 | 36 | fuzz_code(&strm, inbuf, inbuf_size); 37 | 38 | // Free the allocated memory. 39 | lzma_end(&strm); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /tests/ossfuzz/fuzz_decode_stream.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file fuzz_decode_stream.c 6 | /// \brief Fuzz test program for single threaded .xz decoding 7 | // 8 | // Authors: Lasse Collin 9 | // Maksym Vatsyk 10 | // 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | #include 14 | #include 15 | #include 16 | #include "lzma.h" 17 | #include "fuzz_common.h" 18 | 19 | 20 | extern int 21 | LLVMFuzzerTestOneInput(const uint8_t *inbuf, size_t inbuf_size) 22 | { 23 | lzma_stream strm = LZMA_STREAM_INIT; 24 | // Initialize a .xz decoder using the memory usage limit 25 | // defined in fuzz_common.h 26 | // 27 | // Enable support for concatenated .xz files which is used when 28 | // decompressing regular .xz files (instead of data embedded inside 29 | // some other file format). Integrity checks on the uncompressed 30 | // data are ignored to make fuzzing more effective (incorrect check 31 | // values won't prevent the decoder from processing more input). 32 | // 33 | // The flag LZMA_IGNORE_CHECK doesn't disable verification of 34 | // header CRC32 values. Those checks are disabled when liblzma is 35 | // built with the #define FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION. 36 | lzma_ret ret = lzma_stream_decoder(&strm, MEM_LIMIT, 37 | LZMA_CONCATENATED | LZMA_IGNORE_CHECK); 38 | 39 | if (ret != LZMA_OK) { 40 | // This should never happen unless the system has 41 | // no free memory or address space to allow the small 42 | // allocations that the initialization requires. 43 | fprintf(stderr, "lzma_stream_decoder() failed (%d)\n", ret); 44 | abort(); 45 | } 46 | 47 | fuzz_code(&strm, inbuf, inbuf_size); 48 | 49 | // Free the allocated memory. 50 | lzma_end(&strm); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /tests/ossfuzz/fuzz_encode_stream.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file fuzz_encode_stream.c 6 | /// \brief Fuzz test program for .xz encoding 7 | // 8 | // Authors: Maksym Vatsyk 9 | // Lasse Collin 10 | // 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | #include 14 | #include 15 | #include 16 | #include "lzma.h" 17 | #include "fuzz_common.h" 18 | 19 | 20 | extern int 21 | LLVMFuzzerTestOneInput(const uint8_t *inbuf, size_t inbuf_size) 22 | { 23 | if (inbuf_size == 0) { 24 | fprintf(stderr, "no input data provided\n"); 25 | return 0; 26 | } 27 | 28 | // Set the LZMA options based on the first input byte. The fuzzer 29 | // will learn through its mutational genetic algorithm with the 30 | // code coverage feedback that the first byte must be one of the 31 | // values with a switch case label. This allows us to have one fuzz 32 | // target cover many critical code paths so the fuzz resources can 33 | // be used efficiently. 34 | uint32_t preset_level; 35 | const uint8_t decider = inbuf[0]; 36 | 37 | switch (decider) { 38 | case 0: 39 | case 1: 40 | case 5: 41 | preset_level = (uint32_t)decider; 42 | break; 43 | case 6: 44 | preset_level = 0 | LZMA_PRESET_EXTREME; 45 | break; 46 | case 7: 47 | preset_level = 3 | LZMA_PRESET_EXTREME; 48 | break; 49 | default: 50 | return 0; 51 | } 52 | 53 | // Initialize lzma_options with the above preset level 54 | lzma_options_lzma opt_lzma; 55 | if (lzma_lzma_preset(&opt_lzma, preset_level)){ 56 | fprintf(stderr, "lzma_lzma_preset() failed\n"); 57 | abort(); 58 | } 59 | 60 | // Set the filter chain as only LZMA2. 61 | lzma_filter filters[2] = { 62 | { 63 | .id = LZMA_FILTER_LZMA2, 64 | .options = &opt_lzma, 65 | }, { 66 | .id = LZMA_VLI_UNKNOWN, 67 | } 68 | }; 69 | 70 | // initialize empty LZMA stream 71 | lzma_stream strm = LZMA_STREAM_INIT; 72 | 73 | // Initialize the stream encoder using the above 74 | // stream, filter chain and CRC64. 75 | lzma_ret ret = lzma_stream_encoder(&strm, filters, LZMA_CHECK_CRC64); 76 | if (ret != LZMA_OK) { 77 | fprintf(stderr, "lzma_stream_encoder() failed (%d)\n", ret); 78 | abort(); 79 | } 80 | 81 | fuzz_code(&strm, inbuf + 1, inbuf_size - 1); 82 | 83 | // Free the allocated memory. 84 | lzma_end(&strm); 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /tests/test_compress_generated_abc: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SPDX-License-Identifier: 0BSD 3 | 4 | exec "$srcdir/test_compress.sh" compress_generated_abc 5 | -------------------------------------------------------------------------------- /tests/test_compress_generated_random: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SPDX-License-Identifier: 0BSD 3 | 4 | exec "$srcdir/test_compress.sh" compress_generated_random 5 | -------------------------------------------------------------------------------- /tests/test_compress_generated_text: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SPDX-License-Identifier: 0BSD 3 | 4 | exec "$srcdir/test_compress.sh" compress_generated_text 5 | -------------------------------------------------------------------------------- /tests/test_hardware.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file test_hardware.c 6 | /// \brief Tests src/liblzma/api/lzma/hardware.h API functions 7 | /// 8 | /// Since the output values of these functions are hardware dependent, these 9 | /// tests are trivial. They are simply used to detect errors and machines 10 | /// that these function are not supported on. 11 | // 12 | // Author: Jia Tan 13 | // 14 | /////////////////////////////////////////////////////////////////////////////// 15 | 16 | #include "tests.h" 17 | #include "mythread.h" 18 | 19 | 20 | static void 21 | test_lzma_physmem(void) 22 | { 23 | // NOTE: Use _skip instead of _fail because 0 can also mean that we 24 | // don't know how to get this information on this operating system. 25 | if (lzma_physmem() == 0) 26 | assert_skip("Could not determine amount of physical memory"); 27 | } 28 | 29 | 30 | static void 31 | test_lzma_cputhreads(void) 32 | { 33 | #ifndef MYTHREAD_ENABLED 34 | assert_skip("Threading support disabled"); 35 | #else 36 | if (lzma_cputhreads() == 0) 37 | assert_skip("Could not determine cpu core count"); 38 | #endif 39 | } 40 | 41 | 42 | extern int 43 | main(int argc, char **argv) 44 | { 45 | tuktest_start(argc, argv); 46 | tuktest_run(test_lzma_physmem); 47 | tuktest_run(test_lzma_cputhreads); 48 | return tuktest_end(); 49 | } 50 | -------------------------------------------------------------------------------- /tests/tests.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: 0BSD 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | // 5 | /// \file tests.h 6 | /// \brief Common definitions for test applications 7 | // 8 | // Author: Lasse Collin 9 | // 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef LZMA_TESTS_H 13 | #define LZMA_TESTS_H 14 | 15 | #include "sysdefs.h" 16 | #include "tuklib_integer.h" 17 | #include "lzma.h" 18 | #include "tuktest.h" 19 | 20 | 21 | // Invalid value for the lzma_check enumeration. This must be positive 22 | // but small enough to fit into signed char since the underlying type might 23 | // one some platform be a signed char. 24 | // 25 | // Don't put LZMA_ at the beginning of the name so that it is obvious that 26 | // this constant doesn't come from the API headers. 27 | #define INVALID_LZMA_CHECK_ID ((lzma_check)(LZMA_CHECK_ID_MAX + 1)) 28 | 29 | 30 | // This table and macro allow getting more readable error messages when 31 | // comparing the lzma_ret enumeration values. 32 | static const char enum_strings_lzma_ret[][24] = { 33 | "LZMA_OK", 34 | "LZMA_STREAM_END", 35 | "LZMA_NO_CHECK", 36 | "LZMA_UNSUPPORTED_CHECK", 37 | "LZMA_GET_CHECK", 38 | "LZMA_MEM_ERROR", 39 | "LZMA_MEMLIMIT_ERROR", 40 | "LZMA_FORMAT_ERROR", 41 | "LZMA_OPTIONS_ERROR", 42 | "LZMA_DATA_ERROR", 43 | "LZMA_BUF_ERROR", 44 | "LZMA_PROG_ERROR", 45 | "LZMA_SEEK_NEEDED", 46 | }; 47 | 48 | #define assert_lzma_ret(test_expr, ref_val) \ 49 | assert_enum_eq(test_expr, ref_val, enum_strings_lzma_ret) 50 | 51 | 52 | static const char enum_strings_lzma_check[][24] = { 53 | "LZMA_CHECK_NONE", 54 | "LZMA_CHECK_CRC32", 55 | "LZMA_CHECK_UNKNOWN_2", 56 | "LZMA_CHECK_UNKNOWN_3", 57 | "LZMA_CHECK_CRC64", 58 | "LZMA_CHECK_UNKNOWN_5", 59 | "LZMA_CHECK_UNKNOWN_6", 60 | "LZMA_CHECK_UNKNOWN_7", 61 | "LZMA_CHECK_UNKNOWN_8", 62 | "LZMA_CHECK_UNKNOWN_9", 63 | "LZMA_CHECK_SHA256", 64 | "LZMA_CHECK_UNKNOWN_11", 65 | "LZMA_CHECK_UNKNOWN_12", 66 | "LZMA_CHECK_UNKNOWN_13", 67 | "LZMA_CHECK_UNKNOWN_14", 68 | "LZMA_CHECK_UNKNOWN_15", 69 | }; 70 | 71 | #define assert_lzma_check(test_expr, ref_val) \ 72 | assert_enum_eq(test_expr, ref_val, enum_strings_lzma_check) 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /tests/tests_w32res.rc: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: 0BSD */ 2 | 3 | /* 4 | * Author: Lasse Collin 5 | */ 6 | 7 | /* 8 | * It's silly to add version info to test programs but GNU windres fails 9 | * if there are no resources to build, which happens with Autotools on 10 | * Cygwin and MSYS2 because otherwise one more Automake conditional would 11 | * be needed. 12 | */ 13 | 14 | #define MY_TYPE VFT_APP 15 | #define MY_NAME "test" 16 | #define MY_SUFFIX ".exe" 17 | #define MY_DESC "Test program" 18 | #include "common_w32res.rc" 19 | -------------------------------------------------------------------------------- /tests/xzgrep_expected_output: -------------------------------------------------------------------------------- 1 | => xzgrep 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 | => xzgrep -l el <= 7 | xzgrep_test_1.xz 8 | xzgrep_test_2.xz 9 | retval 0 10 | => xzgrep -h el <= 11 | elit, sed do eiusmod tempor incididunt ut 12 | in voluptate velit esse cillum dolore eu 13 | Hello 14 | retval 0 15 | => xzgrep -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 | => xzgrep Hello <= 21 | xzgrep_test_2.xz:Hello 22 | retval 0 23 | => xzgrep -l Hello <= 24 | xzgrep_test_2.xz 25 | retval 0 26 | => xzgrep -h Hello <= 27 | Hello 28 | retval 0 29 | => xzgrep -H Hello <= 30 | xzgrep_test_2.xz:Hello 31 | retval 0 32 | => xzgrep NOMATCH <= 33 | retval 1 34 | => xzgrep -l NOMATCH <= 35 | retval 1 36 | => xzgrep -h NOMATCH <= 37 | retval 1 38 | => xzgrep -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 | liblzma got MSVC support in XZ Utils 5.2.0, and the xz, xzdec, 9 | lzmadec, and lzmainfo command line tools in XZ Utils 5.6.0. 10 | 11 | NOTE: The *.exe files are linked against GNU getopt_long from 12 | the "lib" directory. That code is under the GNU LGPLv2.1 13 | and thus the matching source code must be provided when 14 | distributing the *.exe files. The simplest way to comply with 15 | the license requirements is to distribute the matching XZ Utils 16 | source package alongside the *.exe files. 17 | 18 | MSVC 2013 update 2 and later have enough C99 support to build 19 | liblzma from XZ Utils 5.2.0 and later without modifications. 20 | 21 | Visual Studio 2015 or later is required to build the command line 22 | tools. 23 | 24 | 25 | Building 26 | -------- 27 | 28 | Use CMake to generate build files for MSVC. Visual Studio project 29 | files are no longer provided (XZ Utils 5.4.x were the last versions 30 | to include the project files). 31 | 32 | NOTE: GCC and Clang compatible inline assembly isn't supported by 33 | the MSVC compiler. Using clang-cl under MSVC should make inline 34 | assembly work (untested). 35 | 36 | 37 | Notes 38 | ----- 39 | 40 | liblzma API headers declare the functions with __declspec(dllimport) 41 | by default. To avoid this when using static liblzma from your code, 42 | #define LZMA_API_STATIC before #including . 43 | 44 | MSVC gives a bunch of compiler warnings. Some warnings are specific 45 | to 32-bit or 64-bit build and some appear for both builds. These 46 | are known and shouldn't be a problem. Some of them will probably 47 | be fixed in the future. 48 | 49 | -------------------------------------------------------------------------------- /windows/INSTALL-MinGW-w64_with_Autotools.txt: -------------------------------------------------------------------------------- 1 | 2 | Creating XZ Utils Windows package with build.bash 3 | ================================================= 4 | 5 | Introduction 6 | ------------ 7 | 8 | The script build.bash can be used for building XZ Utils with 9 | GCC + MinGW-w64 under MSYS2, under the ancient MSYS, or 10 | cross-compiling from GNU/Linux. The script will create a package 11 | with binaries and documentation in a hopefully-convenient bundle. 12 | 13 | NOTE: build.bash requires files that are only included 14 | in release tarballs. If building from xz.git, a distribution 15 | tarball should be created first. 16 | 17 | For native builds on Windows, the CMake-based build described 18 | in the file INSTALL-MinGW-w64_with_CMake.txt is simpler to do as 19 | it has no need for MSYS2 and it works from xz.git without extra 20 | steps. For cross-compilation and package creation the script can 21 | be convenient though. 22 | 23 | These instructions are for making a package with build.bash and thus 24 | don't apply to normal Autotool-based builds under Cygwin or MSYS2. 25 | 26 | 27 | Usage 28 | ----- 29 | 30 | First copy the file COPYING.MinGW-w64-runtime.txt from MinGW-w64 31 | to this directory. It contains copyright and license notices that 32 | apply to the MinGW-w64 runtime that gets statically linked into 33 | the XZ Utils binaries being built. build.bash will include the file 34 | in the final package. 35 | 36 | Put i686 and/or x86_64 GCC-based toolchain in PATH depending on 37 | which builds are wanted. 38 | 39 | Optional: Put the 7z tool from 7-Zip or p7zip in PATH. Without 40 | this, .zip and .7z files won't be created from the finished "pkg" 41 | directory contents. 42 | 43 | Run build.bash: 44 | 45 | bash windows/build.bash 46 | 47 | Note that it does an in-tree build so the build files will be mixed 48 | with the source files in the same directory tree. 49 | 50 | -------------------------------------------------------------------------------- /windows/build-with-cmake.bat: -------------------------------------------------------------------------------- 1 | @rem # SPDX-License-Identifier: 0BSD 2 | @rem # Author: Lasse Collin 3 | @rem # 4 | @rem ######################################################################## 5 | @rem # 6 | @rem # This builds XZ Utils with CMake + MinGW-w64 (GCC or Clang/LLVM). 7 | @rem # See INSTALL-MinGW-w64_with_CMake.txt for detailed instructions. 8 | @rem # 9 | @rem # Summary of command line arguments: 10 | @rem # 11 | @rem # %1 = Path to CMake's bin directory. Example: 12 | @rem # C:\devel\cmake\bin 13 | @rem # 14 | @rem # %2 = Path to MinGW-w64's bin directory. Example: 15 | @rem # C:\devel\mingw64\bin 16 | @rem # 17 | @rem # %3 = ON or OFF: Set to ON to build liblzma.dll or OFF for 18 | @rem # static liblzma.a. With OFF, the *.exe files won't 19 | @rem # depend on liblzma.dll. 20 | @rem # 21 | @rem ######################################################################## 22 | 23 | setlocal 24 | set PATH=%1;%2;%PATH% 25 | 26 | md build || exit /b 27 | cd build || exit /b 28 | 29 | cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DENABLE_NLS=OFF -DBUILD_SHARED_LIBS=%3 ..\.. || exit /b 30 | mingw32-make || exit /b 31 | mingw32-make test || exit /b 32 | 33 | @rem liblzma.dll might not exist so ignore errors. 34 | strip xz.exe xzdec.exe lzmadec.exe lzmainfo.exe liblzma.dll 35 | exit /b 0 36 | --------------------------------------------------------------------------------