From: Peter Avalos Date: Sun, 8 Jan 2012 21:32:05 +0000 (-0800) Subject: Import xz-5.0.3. X-Git-Tag: v3.0.0~151^2 X-Git-Url: https://gitweb.dragonflybsd.org/~nant/dragonfly.git/commitdiff_plain/114db65b7d1a106752c685a14803bdf7b4ce5594 Import xz-5.0.3. * xz --force now (de)compresses files that have setuid, setgid, or sticky bit set and files that have multiple hard links. The man page had it documented this way already, but the code had a bug. * LZMA2 decompressor now correctly accepts LZMA2 streams with no uncompressed data. Previously it considered them corrupt. The bug can affect applications that use raw LZMA2 streams. It is very unlikely to affect .xz files because no compressor creates .xz files with empty LZMA2 streams. (Empty .xz files are a different thing than empty LZMA2 streams.) * "xz --suffix=.foo filename.foo" now refuses to compress the file due to it already having the suffix .foo. It was already documented on the man page, but the code lacked the test. * liblzma fixes: - A memory leak was fixed. - lzma_stream_buffer_encode() no longer creates an empty .xz Block if encoding an empty buffer. Such an empty Block with LZMA2 data would trigger a bug. - Validate function arguments better in a few functions. Most importantly, specifying an unsupported integrity check to lzma_stream_buffer_encode() no longer creates a corrupt .xz file. Probably no application tries to do that, so this shouldn't be a big problem in practice. - Document that lzma_block_buffer_encode(), lzma_easy_buffer_encode(), lzma_stream_encoder(), and lzma_stream_buffer_encode() may return LZMA_UNSUPPORTED_CHECK. - The return values of the _memusage() functions are now documented better. --- diff --git a/contrib/xz/NEWS b/contrib/xz/NEWS index d9a2f3cfc0..e3ea498944 100644 --- a/contrib/xz/NEWS +++ b/contrib/xz/NEWS @@ -1,6 +1,70 @@ -XZ Utils User-Visible Changes -============================= +XZ Utils Release Notes +====================== + +5.0.3 (2011-05-21) + + * liblzma fixes: + + - A memory leak was fixed. + + - lzma_stream_buffer_encode() no longer creates an empty .xz + Block if encoding an empty buffer. Such an empty Block with + LZMA2 data would trigger a bug in 5.0.1 and older (see the + first bullet point in 5.0.2 notes). When releasing 5.0.2, + I thought that no encoder creates this kind of files but + I was wrong. + + - Validate function arguments better in a few functions. Most + importantly, specifying an unsupported integrity check to + lzma_stream_buffer_encode() no longer creates a corrupt .xz + file. Probably no application tries to do that, so this + shouldn't be a big problem in practice. + + - Document that lzma_block_buffer_encode(), + lzma_easy_buffer_encode(), lzma_stream_encoder(), and + lzma_stream_buffer_encode() may return LZMA_UNSUPPORTED_CHECK. + + - The return values of the _memusage() functions are now + documented better. + + * Fix command name detection in xzgrep. xzegrep and xzfgrep now + correctly use egrep and fgrep instead of grep. + + * French translation was added. + + +5.0.2 (2011-04-01) + + * LZMA2 decompressor now correctly accepts LZMA2 streams with no + uncompressed data. Previously it considered them corrupt. The + bug can affect applications that use raw LZMA2 streams. It is + very unlikely to affect .xz files because no compressor creates + .xz files with empty LZMA2 streams. (Empty .xz files are a + different thing than empty LZMA2 streams.) + + * "xz --suffix=.foo filename.foo" now refuses to compress the + file due to it already having the suffix .foo. It was already + documented on the man page, but the code lacked the test. + + * "xzgrep -l foo bar.xz" works now. + + * Polish translation was added. + + +5.0.1 (2011-01-29) + + * xz --force now (de)compresses files that have setuid, setgid, + or sticky bit set and files that have multiple hard links. + The man page had it documented this way already, but the code + had a bug. + + * gzip and bzip2 support in xzdiff was fixed. + + * Portability fixes + + * Minor fix to Czech translation + 5.0.0 (2010-10-23) diff --git a/contrib/xz/src/common/sysdefs.h b/contrib/xz/src/common/sysdefs.h index c74c6212cf..69370ba421 100644 --- a/contrib/xz/src/common/sysdefs.h +++ b/contrib/xz/src/common/sysdefs.h @@ -65,6 +65,9 @@ #ifndef PRIu32 # define PRIu32 "u" #endif +#ifndef PRIx32 +# define PRIx32 "x" +#endif #ifndef PRIX32 # define PRIX32 "X" #endif @@ -76,6 +79,9 @@ # ifndef PRIu64 # define PRIu64 "llu" # endif +# ifndef PRIx64 +# define PRIx64 "llx" +# endif # ifndef PRIX64 # define PRIX64 "llX" # endif @@ -86,6 +92,9 @@ # ifndef PRIu64 # define PRIu64 "lu" # endif +# ifndef PRIx64 +# define PRIx64 "lx" +# endif # ifndef PRIX64 # define PRIX64 "lX" # endif @@ -171,4 +180,10 @@ typedef unsigned char _Bool; # define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) #endif +#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4 +# define lzma_attr_alloc_size(x) __attribute__((__alloc_size__(x))) +#else +# define lzma_attr_alloc_size(x) +#endif + #endif diff --git a/contrib/xz/src/liblzma/api/lzma/block.h b/contrib/xz/src/liblzma/api/lzma/block.h index 3019bf916f..8a4bf2323c 100644 --- a/contrib/xz/src/liblzma/api/lzma/block.h +++ b/contrib/xz/src/liblzma/api/lzma/block.h @@ -483,6 +483,7 @@ extern LZMA_API(size_t) lzma_block_buffer_bound(size_t uncompressed_size) * * \return - LZMA_OK: Encoding was successful. * - LZMA_BUF_ERROR: Not enough output buffer space. + * - LZMA_UNSUPPORTED_CHECK * - LZMA_OPTIONS_ERROR * - LZMA_MEM_ERROR * - LZMA_DATA_ERROR diff --git a/contrib/xz/src/liblzma/api/lzma/container.h b/contrib/xz/src/liblzma/api/lzma/container.h index 83e70b44f2..7a9ffc6457 100644 --- a/contrib/xz/src/liblzma/api/lzma/container.h +++ b/contrib/xz/src/liblzma/api/lzma/container.h @@ -66,6 +66,10 @@ * This function is a wrapper for lzma_raw_encoder_memusage(). * * \param preset Compression preset (level and possible flags) + * + * \return Number of bytes of memory required for the given + * preset when encoding. If an error occurs, for example + * due to unsupported preset, UINT64_MAX is returned. */ extern LZMA_API(uint64_t) lzma_easy_encoder_memusage(uint32_t preset) lzma_nothrow lzma_attr_pure; @@ -77,6 +81,11 @@ extern LZMA_API(uint64_t) lzma_easy_encoder_memusage(uint32_t preset) * This function is a wrapper for lzma_raw_decoder_memusage(). * * \param preset Compression preset (level and possible flags) + * + * \return Number of bytes of memory required to decompress a file + * that was compressed using the given preset. If an error + * occurs, for example due to unsupported preset, UINT64_MAX + * is returned. */ extern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset) lzma_nothrow lzma_attr_pure; @@ -148,6 +157,7 @@ extern LZMA_API(lzma_ret) lzma_easy_encoder( * * \return - LZMA_OK: Encoding was successful. * - LZMA_BUF_ERROR: Not enough output buffer space. + * - LZMA_UNSUPPORTED_CHECK * - LZMA_OPTIONS_ERROR * - LZMA_MEM_ERROR * - LZMA_DATA_ERROR @@ -171,6 +181,7 @@ extern LZMA_API(lzma_ret) lzma_easy_buffer_encode( * * \return - LZMA_OK: Initialization was successful. * - LZMA_MEM_ERROR + * - LZMA_UNSUPPORTED_CHECK * - LZMA_OPTIONS_ERROR * - LZMA_PROG_ERROR */ @@ -250,6 +261,7 @@ extern LZMA_API(size_t) lzma_stream_buffer_bound(size_t uncompressed_size) * * \return - LZMA_OK: Encoding was successful. * - LZMA_BUF_ERROR: Not enough output buffer space. + * - LZMA_UNSUPPORTED_CHECK * - LZMA_OPTIONS_ERROR * - LZMA_MEM_ERROR * - LZMA_DATA_ERROR diff --git a/contrib/xz/src/liblzma/api/lzma/filter.h b/contrib/xz/src/liblzma/api/lzma/filter.h index efd036f7f0..e0bc163ad3 100644 --- a/contrib/xz/src/liblzma/api/lzma/filter.h +++ b/contrib/xz/src/liblzma/api/lzma/filter.h @@ -131,7 +131,9 @@ extern LZMA_API(lzma_ret) lzma_filters_copy(const lzma_filter *src, * .id == LZMA_VLI_UNKNOWN. * * \return Number of bytes of memory required for the given - * filter chain when encoding. + * filter chain when encoding. If an error occurs, + * for example due to unsupported filter chain, + * UINT64_MAX is returned. */ extern LZMA_API(uint64_t) lzma_raw_encoder_memusage(const lzma_filter *filters) lzma_nothrow lzma_attr_pure; @@ -148,7 +150,9 @@ extern LZMA_API(uint64_t) lzma_raw_encoder_memusage(const lzma_filter *filters) * .id == LZMA_VLI_UNKNOWN. * * \return Number of bytes of memory required for the given - * filter chain when decoding. + * filter chain when decoding. If an error occurs, + * for example due to unsupported filter chain, + * UINT64_MAX is returned. */ extern LZMA_API(uint64_t) lzma_raw_decoder_memusage(const lzma_filter *filters) lzma_nothrow lzma_attr_pure; diff --git a/contrib/xz/src/liblzma/api/lzma/lzma.h b/contrib/xz/src/liblzma/api/lzma/lzma.h index 8d5fdb6e5c..3f8e095f70 100644 --- a/contrib/xz/src/liblzma/api/lzma/lzma.h +++ b/contrib/xz/src/liblzma/api/lzma/lzma.h @@ -412,6 +412,9 @@ typedef struct { * * This function is available only if LZMA1 or LZMA2 encoder has been enabled * when building liblzma. + * + * \return On success, false is returned. If the preset is not + * supported, true is returned. */ extern LZMA_API(lzma_bool) lzma_lzma_preset( lzma_options_lzma *options, uint32_t preset) lzma_nothrow; diff --git a/contrib/xz/src/liblzma/api/lzma/version.h b/contrib/xz/src/liblzma/api/lzma/version.h index 25e8a8201f..9226663776 100644 --- a/contrib/xz/src/liblzma/api/lzma/version.h +++ b/contrib/xz/src/liblzma/api/lzma/version.h @@ -22,7 +22,7 @@ */ #define LZMA_VERSION_MAJOR 5 #define LZMA_VERSION_MINOR 0 -#define LZMA_VERSION_PATCH 0 +#define LZMA_VERSION_PATCH 3 #define LZMA_VERSION_STABILITY LZMA_VERSION_STABILITY_STABLE #ifndef LZMA_VERSION_COMMIT diff --git a/contrib/xz/src/liblzma/common/alone_decoder.c b/contrib/xz/src/liblzma/common/alone_decoder.c index 039b428595..678c79e654 100644 --- a/contrib/xz/src/liblzma/common/alone_decoder.c +++ b/contrib/xz/src/liblzma/common/alone_decoder.c @@ -46,7 +46,7 @@ struct lzma_coder_s { static lzma_ret alone_decode(lzma_coder *coder, - lzma_allocator *allocator lzma_attribute((unused)), + lzma_allocator *allocator lzma_attribute((__unused__)), const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size, diff --git a/contrib/xz/src/liblzma/common/alone_encoder.c b/contrib/xz/src/liblzma/common/alone_encoder.c index d8c0170f02..eb1697e997 100644 --- a/contrib/xz/src/liblzma/common/alone_encoder.c +++ b/contrib/xz/src/liblzma/common/alone_encoder.c @@ -32,7 +32,7 @@ struct lzma_coder_s { static lzma_ret alone_encode(lzma_coder *coder, - lzma_allocator *allocator lzma_attribute((unused)), + lzma_allocator *allocator lzma_attribute((__unused__)), const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size, @@ -103,7 +103,7 @@ alone_encoder_init(lzma_next_coder *next, lzma_allocator *allocator, if (options->dict_size < LZMA_DICT_SIZE_MIN) return LZMA_OPTIONS_ERROR; - // Round up to to the next 2^n or 2^n + 2^(n - 1) depending on which + // Round up to the next 2^n or 2^n + 2^(n - 1) depending on which // one is the next unless it is UINT32_MAX. While the header would // allow any 32-bit integer, we do this to keep the decoder of liblzma // accepting the resulting files. diff --git a/contrib/xz/src/liblzma/common/block_buffer_encoder.c b/contrib/xz/src/liblzma/common/block_buffer_encoder.c index a8f71c2140..519c6a684d 100644 --- a/contrib/xz/src/liblzma/common/block_buffer_encoder.c +++ b/contrib/xz/src/liblzma/common/block_buffer_encoder.c @@ -226,16 +226,23 @@ lzma_block_buffer_encode(lzma_block *block, lzma_allocator *allocator, const uint8_t *in, size_t in_size, uint8_t *out, size_t *out_pos, size_t out_size) { - // Sanity checks - if (block == NULL || block->filters == NULL - || (in == NULL && in_size != 0) || out == NULL + // Validate the arguments. + if (block == NULL || (in == NULL && in_size != 0) || out == NULL || out_pos == NULL || *out_pos > out_size) return LZMA_PROG_ERROR; - // Check the version field. + // The contents of the structure may depend on the version so + // check the version before validating the contents of *block. if (block->version != 0) return LZMA_OPTIONS_ERROR; + if ((unsigned int)(block->check) > LZMA_CHECK_ID_MAX + || block->filters == NULL) + return LZMA_PROG_ERROR; + + if (!lzma_check_is_supported(block->check)) + return LZMA_UNSUPPORTED_CHECK; + // Size of a Block has to be a multiple of four, so limit the size // here already. This way we don't need to check it again when adding // Block Padding. @@ -243,8 +250,7 @@ lzma_block_buffer_encode(lzma_block *block, lzma_allocator *allocator, // Get the size of the Check field. const size_t check_size = lzma_check_size(block->check); - if (check_size == UINT32_MAX) - return LZMA_PROG_ERROR; + assert(check_size != UINT32_MAX); // Reserve space for the Check field. if (out_size - *out_pos <= check_size) diff --git a/contrib/xz/src/liblzma/common/block_encoder.c b/contrib/xz/src/liblzma/common/block_encoder.c index ca5152357e..1eeb502b7f 100644 --- a/contrib/xz/src/liblzma/common/block_encoder.c +++ b/contrib/xz/src/liblzma/common/block_encoder.c @@ -144,7 +144,7 @@ block_encoder_end(lzma_coder *coder, lzma_allocator *allocator) static lzma_ret block_encoder_update(lzma_coder *coder, lzma_allocator *allocator, - const lzma_filter *filters lzma_attribute((unused)), + const lzma_filter *filters lzma_attribute((__unused__)), const lzma_filter *reversed_filters) { if (coder->sequence != SEQ_CODE) @@ -161,6 +161,11 @@ lzma_block_encoder_init(lzma_next_coder *next, lzma_allocator *allocator, { lzma_next_coder_init(&lzma_block_encoder_init, next, allocator); + if (block == NULL) + return LZMA_PROG_ERROR; + + // The contents of the structure may depend on the version so + // check the version first. if (block->version != 0) return LZMA_OPTIONS_ERROR; diff --git a/contrib/xz/src/liblzma/common/common.c b/contrib/xz/src/liblzma/common/common.c index 0408e15328..b9e3860273 100644 --- a/contrib/xz/src/liblzma/common/common.c +++ b/contrib/xz/src/liblzma/common/common.c @@ -35,7 +35,7 @@ lzma_version_string(void) // Memory allocation // /////////////////////// -extern void * lzma_attribute((malloc)) +extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1) lzma_alloc(size_t size, lzma_allocator *allocator) { // Some malloc() variants return NULL if called with size == 0. diff --git a/contrib/xz/src/liblzma/common/common.h b/contrib/xz/src/liblzma/common/common.h index 3a85168f13..45aba4f06b 100644 --- a/contrib/xz/src/liblzma/common/common.h +++ b/contrib/xz/src/liblzma/common/common.h @@ -205,7 +205,7 @@ struct lzma_internal_s { /// Allocates memory extern void *lzma_alloc(size_t size, lzma_allocator *allocator) - lzma_attribute((malloc)); + lzma_attribute((__malloc__)) lzma_attr_alloc_size(1); /// Frees memory extern void lzma_free(void *ptr, lzma_allocator *allocator); diff --git a/contrib/xz/src/liblzma/common/filter_common.c b/contrib/xz/src/liblzma/common/filter_common.c index b157c6280f..7c95b05f2a 100644 --- a/contrib/xz/src/liblzma/common/filter_common.c +++ b/contrib/xz/src/liblzma/common/filter_common.c @@ -43,7 +43,7 @@ static const struct { .changes_size = true, }, #endif -#ifdef HAVE_DECODER_LZMA2 +#if defined(HAVE_ENCODER_LZMA2) || defined(HAVE_DECODER_LZMA2) { .id = LZMA_FILTER_LZMA2, .options_size = sizeof(lzma_options_lzma), @@ -52,7 +52,7 @@ static const struct { .changes_size = true, }, #endif -#ifdef HAVE_DECODER_X86 +#if defined(HAVE_ENCODER_X86) || defined(HAVE_DECODER_X86) { .id = LZMA_FILTER_X86, .options_size = sizeof(lzma_options_bcj), @@ -70,7 +70,7 @@ static const struct { .changes_size = false, }, #endif -#ifdef HAVE_DECODER_IA64 +#if defined(HAVE_ENCODER_IA64) || defined(HAVE_DECODER_IA64) { .id = LZMA_FILTER_IA64, .options_size = sizeof(lzma_options_bcj), diff --git a/contrib/xz/src/liblzma/common/index_decoder.c b/contrib/xz/src/liblzma/common/index_decoder.c index a6bc650e04..83c8a3af1d 100644 --- a/contrib/xz/src/liblzma/common/index_decoder.c +++ b/contrib/xz/src/liblzma/common/index_decoder.c @@ -56,10 +56,11 @@ struct lzma_coder_s { static lzma_ret index_decode(lzma_coder *coder, lzma_allocator *allocator, const uint8_t *restrict in, size_t *restrict in_pos, - size_t in_size, uint8_t *restrict out lzma_attribute((unused)), - size_t *restrict out_pos lzma_attribute((unused)), - size_t out_size lzma_attribute((unused)), - lzma_action action lzma_attribute((unused))) + size_t in_size, + uint8_t *restrict out lzma_attribute((__unused__)), + size_t *restrict out_pos lzma_attribute((__unused__)), + size_t out_size lzma_attribute((__unused__)), + lzma_action action lzma_attribute((__unused__))) { // Similar optimization as in index_encoder.c const size_t in_start = *in_pos; diff --git a/contrib/xz/src/liblzma/common/index_encoder.c b/contrib/xz/src/liblzma/common/index_encoder.c index c10d7afa06..45919f094c 100644 --- a/contrib/xz/src/liblzma/common/index_encoder.c +++ b/contrib/xz/src/liblzma/common/index_encoder.c @@ -42,12 +42,13 @@ struct lzma_coder_s { static lzma_ret index_encode(lzma_coder *coder, - lzma_allocator *allocator lzma_attribute((unused)), - const uint8_t *restrict in lzma_attribute((unused)), - size_t *restrict in_pos lzma_attribute((unused)), - size_t in_size lzma_attribute((unused)), + lzma_allocator *allocator lzma_attribute((__unused__)), + const uint8_t *restrict in lzma_attribute((__unused__)), + size_t *restrict in_pos lzma_attribute((__unused__)), + size_t in_size lzma_attribute((__unused__)), uint8_t *restrict out, size_t *restrict out_pos, - size_t out_size, lzma_action action lzma_attribute((unused))) + size_t out_size, + lzma_action action lzma_attribute((__unused__))) { // Position where to start calculating CRC32. The idea is that we // need to call lzma_crc32() only once per call to index_encode(). diff --git a/contrib/xz/src/liblzma/common/stream_buffer_encoder.c b/contrib/xz/src/liblzma/common/stream_buffer_encoder.c index f727d8542b..2450ee2e1f 100644 --- a/contrib/xz/src/liblzma/common/stream_buffer_encoder.c +++ b/contrib/xz/src/liblzma/common/stream_buffer_encoder.c @@ -51,6 +51,9 @@ lzma_stream_buffer_encode(lzma_filter *filters, lzma_check check, || out_pos_ptr == NULL || *out_pos_ptr > out_size) return LZMA_PROG_ERROR; + if (!lzma_check_is_supported(check)) + return LZMA_UNSUPPORTED_CHECK; + // Note for the paranoids: Index encoder prevents the Stream from // getting too big and still being accepted with LZMA_OK, and Block // encoder catches if the input is too big. So we don't need to @@ -81,26 +84,32 @@ lzma_stream_buffer_encode(lzma_filter *filters, lzma_check check, out_pos += LZMA_STREAM_HEADER_SIZE; - // Block + // Encode a Block but only if there is at least one byte of input. lzma_block block = { .version = 0, .check = check, .filters = filters, }; - return_if_error(lzma_block_buffer_encode(&block, allocator, - in, in_size, out, &out_pos, out_size)); + if (in_size > 0) + return_if_error(lzma_block_buffer_encode(&block, allocator, + in, in_size, out, &out_pos, out_size)); // Index { - // Create an Index with one Record. + // Create an Index. It will have one Record if there was + // at least one byte of input to encode. Otherwise the + // Index will be empty. lzma_index *i = lzma_index_init(allocator); if (i == NULL) return LZMA_MEM_ERROR; - lzma_ret ret = lzma_index_append(i, allocator, - lzma_block_unpadded_size(&block), - block.uncompressed_size); + lzma_ret ret = LZMA_OK; + + if (in_size > 0) + ret = lzma_index_append(i, allocator, + lzma_block_unpadded_size(&block), + block.uncompressed_size); // If adding the Record was successful, encode the Index // and get its size which will be stored into Stream Footer. diff --git a/contrib/xz/src/liblzma/common/stream_encoder.c b/contrib/xz/src/liblzma/common/stream_encoder.c index 48d91da793..97a7a23a81 100644 --- a/contrib/xz/src/liblzma/common/stream_encoder.c +++ b/contrib/xz/src/liblzma/common/stream_encoder.c @@ -280,6 +280,7 @@ lzma_stream_encoder_init(lzma_next_coder *next, lzma_allocator *allocator, next->end = &stream_encoder_end; next->update = &stream_encoder_update; + next->coder->filters[0].id = LZMA_VLI_UNKNOWN; next->coder->block_encoder = LZMA_NEXT_CODER_INIT; next->coder->index_encoder = LZMA_NEXT_CODER_INIT; next->coder->index = NULL; @@ -289,7 +290,6 @@ lzma_stream_encoder_init(lzma_next_coder *next, lzma_allocator *allocator, next->coder->sequence = SEQ_STREAM_HEADER; next->coder->block_options.version = 0; next->coder->block_options.check = check; - next->coder->filters[0].id = LZMA_VLI_UNKNOWN; // Initialize the Index lzma_index_end(next->coder->index, allocator); diff --git a/contrib/xz/src/liblzma/delta/delta_encoder.c b/contrib/xz/src/liblzma/delta/delta_encoder.c index ea1cc2cb02..15c7951e10 100644 --- a/contrib/xz/src/liblzma/delta/delta_encoder.c +++ b/contrib/xz/src/liblzma/delta/delta_encoder.c @@ -85,7 +85,7 @@ delta_encode(lzma_coder *coder, lzma_allocator *allocator, static lzma_ret delta_encoder_update(lzma_coder *coder, lzma_allocator *allocator, - const lzma_filter *filters_null lzma_attribute((unused)), + const lzma_filter *filters_null lzma_attribute((__unused__)), const lzma_filter *reversed_filters) { // Delta doesn't and will never support changing the options in diff --git a/contrib/xz/src/liblzma/lz/lz_decoder.c b/contrib/xz/src/liblzma/lz/lz_decoder.c index 2c57355125..d74085cf44 100644 --- a/contrib/xz/src/liblzma/lz/lz_decoder.c +++ b/contrib/xz/src/liblzma/lz/lz_decoder.c @@ -126,7 +126,7 @@ decode_buffer(lzma_coder *coder, static lzma_ret lz_decode(lzma_coder *coder, - lzma_allocator *allocator lzma_attribute((unused)), + lzma_allocator *allocator lzma_attribute((__unused__)), const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size, diff --git a/contrib/xz/src/liblzma/lz/lz_encoder.c b/contrib/xz/src/liblzma/lz/lz_encoder.c index 273f577b69..e240696588 100644 --- a/contrib/xz/src/liblzma/lz/lz_encoder.c +++ b/contrib/xz/src/liblzma/lz/lz_encoder.c @@ -480,7 +480,7 @@ lz_encoder_end(lzma_coder *coder, lzma_allocator *allocator) static lzma_ret lz_encoder_update(lzma_coder *coder, lzma_allocator *allocator, - const lzma_filter *filters_null lzma_attribute((unused)), + const lzma_filter *filters_null lzma_attribute((__unused__)), const lzma_filter *reversed_filters) { if (coder->lz.options_update == NULL) diff --git a/contrib/xz/src/liblzma/lzma/lzma2_decoder.c b/contrib/xz/src/liblzma/lzma/lzma2_decoder.c index f38879ce17..3e42575d5b 100644 --- a/contrib/xz/src/liblzma/lzma/lzma2_decoder.c +++ b/contrib/xz/src/liblzma/lzma/lzma2_decoder.c @@ -67,6 +67,10 @@ lzma2_decode(lzma_coder *restrict coder, lzma_dict *restrict dict, const uint32_t control = in[*in_pos]; ++*in_pos; + // End marker + if (control == 0x00) + return LZMA_STREAM_END; + if (control >= 0xE0 || control == 1) { // Dictionary reset implies that next LZMA chunk has // to set new properties. @@ -104,10 +108,6 @@ lzma2_decode(lzma_coder *restrict coder, lzma_dict *restrict dict, &coder->options); } } else { - // End marker - if (control == 0x00) - return LZMA_STREAM_END; - // Invalid control values if (control > 2) return LZMA_DATA_ERROR; diff --git a/contrib/xz/src/liblzma/lzma/lzma2_encoder.c b/contrib/xz/src/liblzma/lzma/lzma2_encoder.c index b48e0d6894..992720ca6d 100644 --- a/contrib/xz/src/liblzma/lzma/lzma2_encoder.c +++ b/contrib/xz/src/liblzma/lzma/lzma2_encoder.c @@ -374,7 +374,7 @@ lzma_lzma2_props_encode(const void *options, uint8_t *out) const lzma_options_lzma *const opt = options; uint32_t d = my_max(opt->dict_size, LZMA_DICT_SIZE_MIN); - // Round up to to the next 2^n - 1 or 2^n + 2^(n - 1) - 1 depending + // Round up to the next 2^n - 1 or 2^n + 2^(n - 1) - 1 depending // on which one is the next: --d; d |= d >> 2; diff --git a/contrib/xz/src/liblzma/simple/arm.c b/contrib/xz/src/liblzma/simple/arm.c index 8fcf643749..a84702ac62 100644 --- a/contrib/xz/src/liblzma/simple/arm.c +++ b/contrib/xz/src/liblzma/simple/arm.c @@ -15,7 +15,7 @@ static size_t -arm_code(lzma_simple *simple lzma_attribute((unused)), +arm_code(lzma_simple *simple lzma_attribute((__unused__)), uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size) { diff --git a/contrib/xz/src/liblzma/simple/armthumb.c b/contrib/xz/src/liblzma/simple/armthumb.c index eb6a69d128..4b49175fec 100644 --- a/contrib/xz/src/liblzma/simple/armthumb.c +++ b/contrib/xz/src/liblzma/simple/armthumb.c @@ -15,7 +15,7 @@ static size_t -armthumb_code(lzma_simple *simple lzma_attribute((unused)), +armthumb_code(lzma_simple *simple lzma_attribute((__unused__)), uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size) { diff --git a/contrib/xz/src/liblzma/simple/ia64.c b/contrib/xz/src/liblzma/simple/ia64.c index fd263d4aea..ce3692b98f 100644 --- a/contrib/xz/src/liblzma/simple/ia64.c +++ b/contrib/xz/src/liblzma/simple/ia64.c @@ -15,7 +15,7 @@ static size_t -ia64_code(lzma_simple *simple lzma_attribute((unused)), +ia64_code(lzma_simple *simple lzma_attribute((__unused__)), uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size) { diff --git a/contrib/xz/src/liblzma/simple/powerpc.c b/contrib/xz/src/liblzma/simple/powerpc.c index aaa14f2219..6f8351176c 100644 --- a/contrib/xz/src/liblzma/simple/powerpc.c +++ b/contrib/xz/src/liblzma/simple/powerpc.c @@ -15,7 +15,7 @@ static size_t -powerpc_code(lzma_simple *simple lzma_attribute((unused)), +powerpc_code(lzma_simple *simple lzma_attribute((__unused__)), uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size) { diff --git a/contrib/xz/src/liblzma/simple/simple_coder.c b/contrib/xz/src/liblzma/simple/simple_coder.c index 06db86ec2d..37de7fa1a0 100644 --- a/contrib/xz/src/liblzma/simple/simple_coder.c +++ b/contrib/xz/src/liblzma/simple/simple_coder.c @@ -212,7 +212,7 @@ simple_coder_end(lzma_coder *coder, lzma_allocator *allocator) static lzma_ret simple_coder_update(lzma_coder *coder, lzma_allocator *allocator, - const lzma_filter *filters_null lzma_attribute((unused)), + const lzma_filter *filters_null lzma_attribute((__unused__)), const lzma_filter *reversed_filters) { // No update support, just call the next filter in the chain. diff --git a/contrib/xz/src/liblzma/simple/sparc.c b/contrib/xz/src/liblzma/simple/sparc.c index 808a59aaac..8270d6ab19 100644 --- a/contrib/xz/src/liblzma/simple/sparc.c +++ b/contrib/xz/src/liblzma/simple/sparc.c @@ -15,7 +15,7 @@ static size_t -sparc_code(lzma_simple *simple lzma_attribute((unused)), +sparc_code(lzma_simple *simple lzma_attribute((__unused__)), uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size) { diff --git a/contrib/xz/src/lzmainfo/lzmainfo.c b/contrib/xz/src/lzmainfo/lzmainfo.c index 3100dc631a..b0ccdfb430 100644 --- a/contrib/xz/src/lzmainfo/lzmainfo.c +++ b/contrib/xz/src/lzmainfo/lzmainfo.c @@ -26,7 +26,7 @@ #endif -static void lzma_attribute((noreturn)) +static void lzma_attribute((__noreturn__)) help(void) { printf( @@ -45,7 +45,7 @@ _("Usage: %s [--help] [--version] [FILE]...\n" } -static void lzma_attribute((noreturn)) +static void lzma_attribute((__noreturn__)) version(void) { puts("lzmainfo (" PACKAGE_NAME ") " LZMA_VERSION_STRING); diff --git a/contrib/xz/src/scripts/xzdiff.1 b/contrib/xz/src/scripts/xzdiff.1 new file mode 100644 index 0000000000..d97f3cb810 --- /dev/null +++ b/contrib/xz/src/scripts/xzdiff.1 @@ -0,0 +1,75 @@ +.\" +.\" Original zdiff.1 for gzip: Jean-loup Gailly +.\" +.\" Modifications for XZ Utils: Lasse Collin +.\" Andrew Dudman +.\" +.\" License: GNU GPLv2+ +.\" +.TH XZDIFF 1 "2010-09-27" "Tukaani" "XZ Utils" +.SH NAME +xzcmp, xzdiff, lzcmp, lzdiff \- compare compressed files +.SH SYNOPSIS +.B xzcmp +.RI [ cmp_options "] " file1 " [" file2 ] +.br +.B xzdiff +.RI [ diff_options "] " file1 " [" file2 ] +.br +.B lzcmp +.RI [ cmp_options "] " file1 " [" file2 ] +.br +.B lzdiff +.RI [ diff_options "] " file1 " [" file2 ] +.SH DESCRIPTION +.B xzcmp +and +.B xzdiff +invoke +.BR cmp (1) +or +.BR diff (1) +on files compressed with +.BR xz (1), +.BR lzma (1), +.BR gzip (1), +or +.BR bzip2 (1). +All options specified are passed directly to +.BR cmp (1) +or +.BR diff (1). +If only one file is specified, then the files compared are +.I file1 +(which must have a suffix of a supported compression format) and +.I file1 +from which the compression format suffix has been stripped. +If two files are specified, +then they are uncompressed if necessary and fed to +.BR cmp (1) +or +.BR diff (1). +The exit status from +.BR cmp (1) +or +.BR diff (1) +is preserved. +.PP +The names +.B lzcmp +and +.B lzdiff +are provided for backward compatibility with LZMA Utils. +.SH "SEE ALSO" +.BR cmp (1), +.BR diff (1), +.BR xz (1), +.BR gzip (1), +.BR bzip2 (1), +.BR zdiff (1) +.SH BUGS +Messages from the +.BR cmp (1) +or +.BR diff (1) +programs refer to temporary filenames instead of those specified. diff --git a/contrib/xz/src/scripts/xzdiff.in b/contrib/xz/src/scripts/xzdiff.in new file mode 100644 index 0000000000..45633e0a86 --- /dev/null +++ b/contrib/xz/src/scripts/xzdiff.in @@ -0,0 +1,172 @@ +#!@POSIX_SHELL@ + +# Copyright (C) 1998, 2002, 2006, 2007 Free Software Foundation +# Copyright (C) 1993 Jean-loup Gailly + +# Modified for XZ Utils by Andrew Dudman and Lasse Collin. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +#SET_PATH - This line is a placeholder to ease patching this script. + +# Instead of unsetting XZ_OPT, just make sure that xz will use file format +# autodetection. This way memory usage limit and thread limit can be +# specified via XZ_OPT. With gzip and bzip2 it's OK to just unset the +# environment variables. +xz='@xz@ --format=auto' +unset GZIP BZIP BZIP2 + +case ${0##*/} in + *cmp*) prog=xzcmp; cmp=${CMP:-cmp};; + *) prog=xzdiff; cmp=${DIFF:-diff};; +esac + +version="$prog (@PACKAGE_NAME@) @VERSION@" + +usage="Usage: ${0##*/} [OPTION]... FILE1 [FILE2] +Compare FILE1 to FILE2, using their uncompressed contents if they are +compressed. If FILE2 is omitted, then the files compared are FILE1 and +FILE1 from which the compression format suffix has been stripped. + +Do comparisons like '$cmp' does. OPTIONs are the same as for '$cmp'. + +Report bugs to <@PACKAGE_BUGREPORT@>." + +# sed script to escape all ' for the shell, and then (to handle trailing +# newlines correctly) turn trailing X on last line into '. +escape=' + s/'\''/'\''\\'\'''\''/g + $s/X$/'\''/ +' + +while :; do + case $1 in + --h*) printf '%s\n' "$usage" || exit 2; exit;; + --v*) echo "$version" || exit 2; exit;; + --) shift; break;; + -*\'*) cmp="$cmp '"`printf '%sX\n' "$1" | sed "$escape"`;; + -?*) cmp="$cmp '$1'";; + *) break;; + esac + shift +done +cmp="$cmp --" + +for file; do + test "X$file" = X- || <"$file" || exit 2 +done + +xz1=$xz +xz2=$xz +xz_status=0 +exec 3>&1 + +if test $# -eq 1; then + case $1 in + *[-.]xz | *[-.]lzma | *.t[lx]z) + ;; + *[-.]bz2 | *.tbz | *.tbz2) + xz1=bzip2;; + *[-.][zZ] | *_z | *[-.]gz | *.t[ag]z) + xz1=gzip;; + *) + echo >&2 "$0: $1: Unknown compressed file name suffix" + exit 2;; + esac + case $1 in + *[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma) + FILE=`expr "X$1" : 'X\(.*\)[-.][abglmxzZ2]*$'`;; + *.t[abglx]z) + FILE=`expr "X$1" : 'X\(.*[-.]t\)[abglx]z$'`ar;; + *.tbz2) + FILE=`expr "X$1" : 'X\(.*[-.]t\)bz2$'`ar;; + esac + xz_status=$( + exec 4>&1 + ($xz1 -cd -- "$1" 4>&-; echo $? >&4) 3>&- | eval "$cmp" - '"$FILE"' >&3 + ) +elif test $# -eq 2; then + case $1 in + *[-.]bz2 | *.tbz | *.tbz2) xz1=bzip2;; + *[-.][zZ] | *_z | *[-.]gz | *.t[ag]z) xz1=gzip;; + esac + case $2 in + *[-.]bz2 | *.tbz | *.tbz2) xz2=bzip2;; + *[-.][zZ] | *_z | *[-.]gz | *.t[ag]z) xz2=gzip;; + esac + case $1 in + *[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *.t[abglx]z | *.tbz2 | -) + case "$2" in + *[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *.t[abglx]z | *.tbz2 | -) + if test "$1$2" = --; then + xz_status=$( + exec 4>&1 + ($xz1 -cdfq - 4>&-; echo $? >&4) 3>&- | + eval "$cmp" - - >&3 + ) + elif # Reject Solaris 8's buggy /bin/bash 2.03. + echo X | (echo X | eval "$cmp" /dev/fd/5 - >/dev/null 2>&1) 5<&0; then + xz_status=$( + exec 4>&1 + ($xz1 -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- | + ( ($xz2 -cdfq -- "$2" 4>&-; echo $? >&4) 3>&- 5<&- &3) 5<&0 + ) + case $xz_status in + *[1-9]*) xz_status=1;; + *) xz_status=0;; + esac + else + F=`expr "/$2" : '.*/\(.*\)[-.][ablmtxz2]*$'` || F=$prog + tmp= + trap ' + test -n "$tmp" && rm -f "$tmp" + (exit 2); exit 2 + ' HUP INT PIPE TERM 0 + tmp=`mktemp -t -- "$F.XXXXXX"` || exit 2 + $xz2 -cdfq -- "$2" > "$tmp" || exit 2 + xz_status=$( + exec 4>&1 + ($xz1 -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- | + eval "$cmp" - '"$tmp"' >&3 + ) + cmp_status=$? + rm -f "$tmp" || xz_status=$? + trap - HUP INT PIPE TERM 0 + (exit $cmp_status) + fi;; + *) + xz_status=$( + exec 4>&1 + ($xz1 -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- | + eval "$cmp" - '"$2"' >&3 + );; + esac;; + *) + case "$2" in + *[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *.t[abglx]z | *.tbz2 | -) + xz_status=$( + exec 4>&1 + ($xz2 -cdfq -- "$2" 4>&-; echo $? >&4) 3>&- | + eval "$cmp" '"$1"' - >&3 + );; + *) + eval "$cmp" '"$1"' '"$2"';; + esac;; + esac +else + echo >&2 "$0: Invalid number of operands; try \`${0##*/} --help' for help" + exit 2 +fi + +cmp_status=$? +test "$xz_status" -eq 0 || exit 2 +exit $cmp_status diff --git a/contrib/xz/src/scripts/xzgrep.1 b/contrib/xz/src/scripts/xzgrep.1 new file mode 100644 index 0000000000..a96f1b89db --- /dev/null +++ b/contrib/xz/src/scripts/xzgrep.1 @@ -0,0 +1,95 @@ +.\" +.\" Original zgrep.1 for gzip: Jean-loup Gailly +.\" Charles Levert +.\" +.\" Modifications for XZ Utils: Lasse Collin +.\" +.\" License: GNU GPLv2+ +.\" +.TH XZGREP 1 "2010-09-27" "Tukaani" "XZ Utils" +.SH NAME +xzgrep \- search compressed files for a regular expression +.SH SYNOPSIS +.B xzgrep +.RI [ grep_options ] +.RB [ \-e ] +.I pattern +.IR file "..." +.br +.B xzegrep +.RB ... +.br +.B xzfgrep +.RB ... +.br +.B lzgrep +.RB ... +.br +.B lzegrep +.RB ... +.br +.B lzfgrep +.RB ... +.SH DESCRIPTION +.B xzgrep +invokes +.BR grep (1) +on +.I files +which may be either uncompressed or compressed with +.BR xz (1), +.BR lzma (1), +.BR gzip (1), +or +.BR bzip2 (1). +All options specified are passed directly to +.BR grep (1). +.PP +If no +.I file +is specified, then standard input is decompressed if necessary +and fed to +.BR grep (1). +When reading from standard input, +.BR gzip (1) +and +.BR bzip2 (1) +compressed files are not supported. +.PP +If +.B xzgrep +is invoked as +.B xzegrep +or +.B xzfgrep +then +.BR egrep (1) +or +.BR fgrep (1) +is used instead of +.BR grep (1). +The same applies to names +.BR lzgrep , +.BR lzegrep , +and +.BR lzfgrep , +which are provided for backward compatibility with LZMA Utils. +.PP +.SH ENVIRONMENT +.TP +.B GREP +If the +.B GREP +environment variable is set, +.B xzgrep +uses it instead of +.BR grep (1), +.BR egrep (1), +or +.BR fgrep (1). +.SH "SEE ALSO" +.BR grep (1), +.BR xz (1), +.BR gzip (1), +.BR bzip2 (1), +.BR zgrep (1) diff --git a/contrib/xz/src/scripts/xzgrep.in b/contrib/xz/src/scripts/xzgrep.in new file mode 100644 index 0000000000..ae30725c69 --- /dev/null +++ b/contrib/xz/src/scripts/xzgrep.in @@ -0,0 +1,200 @@ +#!@POSIX_SHELL@ + +# xzgrep -- a wrapper around a grep program that decompresses files as needed +# Adapted from a version sent by Charles Levert + +# Copyright (C) 1998, 2001, 2002, 2006, 2007 Free Software Foundation +# Copyright (C) 1993 Jean-loup Gailly + +# Modified for XZ Utils by Andrew Dudman and Lasse Collin. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +#SET_PATH - This line is a placeholder to ease patching this script. + +# Instead of unsetting XZ_OPT, just make sure that xz will use file format +# autodetection. This way memory usage limit and thread limit can be +# specified via XZ_OPT. With gzip and bzip2 it's OK to just unset the +# environment variables. +xz='@xz@ --format=auto' +unset GZIP BZIP BZIP2 + +case ${0##*/} in + *egrep*) prog=xzegrep; grep=${GREP:-egrep};; + *fgrep*) prog=xzfgrep; grep=${GREP:-fgrep};; + *) prog=xzgrep; grep=${GREP:-grep};; +esac + +version="$prog (@PACKAGE_NAME@) @VERSION@" + +usage="Usage: ${0##*/} [OPTION]... [-e] PATTERN [FILE]... +Look for instances of PATTERN in the input FILEs, using their +uncompressed contents if they are compressed. + +OPTIONs are the same as for '$grep'. + +Report bugs to <@PACKAGE_BUGREPORT@>." + +# sed script to escape all ' for the shell, and then (to handle trailing +# newlines correctly) turn trailing X on last line into '. +escape=' + s/'\''/'\''\\'\'''\''/g + $s/X$/'\''/ +' +operands= +have_pat=0 +files_with_matches=0 +files_without_matches=0 +no_filename=0 +with_filename=0 + +while test $# -ne 0; do + option=$1 + shift + optarg= + + case $option in + (-[0123456789abcdhHiIKLlnoqrRsTuUvVwxyzZ]?*) + arg2=-\'$(expr "X${option}X" : 'X-.[0-9]*\(.*\)' | sed "$escape") + eval "set -- $arg2 "'${1+"$@"}' + option=$(expr "X$option" : 'X\(-.[0-9]*\)');; + (--binary-*=* | --[lm]a*=* | --reg*=*) + ;; + (-[ABCDefm] | --binary-* | --file | --[lm]a* | --reg*) + case ${1?"$option option requires an argument"} in + (*\'*) + optarg=" '"$(printf '%sX\n' "$1" | sed "$escape");; + (*) + optarg=" '$1'";; + esac + shift;; + (--) + break;; + (-?*) + ;; + (*) + case $option in + (*\'*) + operands="$operands '"$(printf '%sX\n' "$option" | sed "$escape");; + (*) + operands="$operands '$option'";; + esac + ${POSIXLY_CORRECT+break} + continue;; + esac + + case $option in + (-[drRzZ] | --di* | --exc* | --inc* | --rec* | --nu*) + printf >&2 '%s: %s: Option not supported\n' "$0" "$option" + exit 2;; + (-[ef]* | --file | --file=* | --reg*) + have_pat=1;; + (--h | --he | --hel | --help) + echo "$usage" || exit 2 + exit;; + (-H | --wi | --wit | --with | --with- | --with-f | --with-fi \ + | --with-fil | --with-file | --with-filen | --with-filena | --with-filenam \ + | --with-filename) + with_filename=1 + continue;; + (-l | --files-with-*) + files_with_matches=1;; + (-L | --files-witho*) + files_without_matches=1;; + (--no-f*) + no_filename=1;; + (-V | --v | --ve | --ver | --vers | --versi | --versio | --version) + echo "$version" || exit 2 + exit;; + esac + + case $option in + (*\'?*) + option=\'$(expr "X${option}X" : 'X\(.*\)' | sed "$escape");; + (*) + option="'$option'";; + esac + + grep="$grep $option$optarg" +done + +if test $files_with_matches -eq 1 || test $files_without_matches -eq 1; then + grep="$grep -q" +fi + +eval "set -- $operands "'${1+"$@"}' + +if test $have_pat -eq 0; then + case ${1?"Missing pattern; try \`${0##*/} --help' for help"} in + (*\'*) + grep="$grep -- '"$(printf '%sX\n' "$1" | sed "$escape");; + (*) + grep="$grep -- '$1'";; + esac + shift +fi + +if test $# -eq 0; then + set -- - +fi + +exec 3>&1 +res=0 + +for i; do + case $i in + *[-.][zZ] | *_z | *[-.]gz | *.t[ag]z) uncompress="gzip -cdfq";; + *[-.]bz2 | *[-.]tbz | *.tbz2) uncompress="bzip2 -cdfq";; + *) uncompress="$xz -cdfq";; + esac + # Fail if xz or grep (or sed) fails. + xz_status=$( + exec 5>&1 + ($uncompress -- "$i" 5>&-; echo $? >&5) 3>&- | + if test $files_with_matches -eq 1; then + eval "$grep" && { printf '%s\n' "$i" || exit 2; } + elif test $files_without_matches -eq 1; then + eval "$grep" || { + r=$? + if test $r -eq 1; then + printf '%s\n' "$i" || r=2 + fi + exit $r + } + elif test $with_filename -eq 0 && + { test $# -eq 1 || test $no_filename -eq 1; }; then + eval "$grep" + else + case $i in + (*' +'* | *'&'* | *'\'* | *'|'*) + i=$(printf '%s\n' "$i" | + sed ' + $!N + $s/[&\|]/\\&/g + $s/\n/\\n/g + ');; + esac + sed_script="s|^|$i:|" + + # Fail if grep or sed fails. + r=$( + exec 4>&1 + (eval "$grep" 4>&-; echo $? >&4) 3>&- | sed "$sed_script" >&3 4>&- + ) || r=2 + exit $r + fi >&3 5>&- + ) + r=$? + test "$xz_status" -eq 0 || test "$xz_status" -eq 2 || r=2 + test $res -lt $r && res=$r +done +exit $res diff --git a/contrib/xz/src/scripts/xzless.1 b/contrib/xz/src/scripts/xzless.1 new file mode 100644 index 0000000000..2d05459d00 --- /dev/null +++ b/contrib/xz/src/scripts/xzless.1 @@ -0,0 +1,69 @@ +.\" +.\" Authors: Andrew Dudman +.\" Lasse Collin +.\" +.\" This file has been put into the public domain. +.\" You can do whatever you want with this file. +.\" +.\" (Note that this file is not based on gzip's zless.1.) +.\" +.TH XZLESS 1 "2010-09-27" "Tukaani" "XZ Utils" +.SH NAME +xzless, lzless \- view xz or lzma compressed (text) files +.SH SYNOPSIS +.B xzless +.RI [ file ...] +.br +.B lzless +.RI [ file ...] +.SH DESCRIPTION +.B xzless +is a filter that displays text from compressed files to a terminal. +It works on files compressed with +.BR xz (1) +or +.BR lzma (1). +If no +.I files +are given, +.B xzless +reads from standard input. +.PP +.B xzless +uses +.BR less (1) +to present its output. +Unlike +.BR xzmore , +its choice of pager cannot be altered by +setting an environment variable. +Commands are based on both +.BR more (1) +and +.BR vi (1) +and allow back and forth movement and searching. +See the +.BR less (1) +manual for more information. +.PP +The command named +.B lzless +is provided for backward compatibility with LZMA Utils. +.SH ENVIRONMENT +.TP +.B LESSMETACHARS +A list of characters special to the shell. +Set by +.B xzless +unless it is already set in the environment. +.TP +.B LESSOPEN +Set to a command line to invoke the +.BR xz (1) +decompressor for preprocessing the input files to +.BR less (1). +.SH "SEE ALSO" +.BR less (1), +.BR xz (1), +.BR xzmore (1), +.BR zless (1) diff --git a/contrib/xz/src/scripts/xzless.in b/contrib/xz/src/scripts/xzless.in new file mode 100644 index 0000000000..a3da697c59 --- /dev/null +++ b/contrib/xz/src/scripts/xzless.in @@ -0,0 +1,58 @@ +#!@POSIX_SHELL@ + +# Copyright (C) 1998, 2002, 2006, 2007 Free Software Foundation + +# The original version for gzip was written by Paul Eggert. +# Modified for XZ Utils by Andrew Dudman and Lasse Collin. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +#SET_PATH - This line is a placeholder to ease patching this script. + +# Instead of unsetting XZ_OPT, just make sure that xz will use file format +# autodetection. This way memory usage limit and thread limit can be +# specified via XZ_OPT. +xz='@xz@ --format=auto' + +version='xzless (@PACKAGE_NAME@) @VERSION@' + +usage="Usage: ${0##*/} [OPTION]... [FILE]... +Like 'less', but operate on the uncompressed contents of xz compressed FILEs. + +Options are the same as for 'less'. + +Report bugs to <@PACKAGE_BUGREPORT@>." + +case $1 in + --help) echo "$usage" || exit 2; exit;; + --version) echo "$version" || exit 2; exit;; +esac + +if test "${LESSMETACHARS+set}" != set; then + # Work around a bug in less 394 and earlier; + # it mishandles the metacharacters '$%=~'. + space=' ' + tab=' ' + nl=' +' + LESSMETACHARS="$space$tab$nl'"';*?"()<>[|&^`#\$%=~' +fi + +if test "$(less -V | { read ver && echo ${ver#less }; })" -ge 429; then + # less 429 or later: LESSOPEN pipe will be used on + # standard input if $LESSOPEN begins with |-. + LESSOPEN="|-$xz -cdfq -- %s" +else + LESSOPEN="|$xz -cdfq -- %s" +fi +export LESSMETACHARS LESSOPEN + +exec less "$@" diff --git a/contrib/xz/src/scripts/xzmore.1 b/contrib/xz/src/scripts/xzmore.1 new file mode 100644 index 0000000000..30dad6871a --- /dev/null +++ b/contrib/xz/src/scripts/xzmore.1 @@ -0,0 +1,55 @@ +.\" +.\" Original zdiff.1 for gzip: Jean-loup Gailly +.\" Modifications for XZ Utils: Lasse Collin +.\" +.\" License: GNU GPLv2+ +.\" +.TH XZMORE 1 "2010-09-27" "Tukaani" "XZ Utils" +.SH NAME +xzmore, lzmore \- view xz or lzma compressed (text) files +.SH SYNOPSIS +.B xzmore +.RI [ "filename ..." ] +.br +.B lzmore +.RI [ "filename ..." ] +.SH DESCRIPTION +.B xzmore +is a filter which allows examination of +.BR xz (1) +or +.BR lzma (1) +compressed text files one screenful at a time +on a soft-copy terminal. +.PP +To use a pager other than the default +.B more, +set environment variable +.B PAGER +to the name of the desired program. +The name +.B lzmore +is provided for backward compatibility with LZMA Utils. +.TP +.BR e " or " q +When the prompt \-\-More\-\-(Next file: +.IR file ) +is printed, this command causes +.B xzmore +to exit. +.TP +.B s +When the prompt \-\-More\-\-(Next file: +.IR file ) +is printed, this command causes +.B xzmore +to skip the next file and continue. +.PP +For list of keyboard commands supported while actually viewing the +content of a file, refer to manual of the pager you use, usually +.BR more (1). +.SH "SEE ALSO" +.BR more (1), +.BR xz (1), +.BR xzless (1), +.BR zmore (1) diff --git a/contrib/xz/src/scripts/xzmore.in b/contrib/xz/src/scripts/xzmore.in new file mode 100644 index 0000000000..940d661446 --- /dev/null +++ b/contrib/xz/src/scripts/xzmore.in @@ -0,0 +1,78 @@ +#!@POSIX_SHELL@ + +# Copyright (C) 2001, 2002, 2007 Free Software Foundation +# Copyright (C) 1992, 1993 Jean-loup Gailly + +# Modified for XZ Utils by Andrew Dudman and Lasse Collin. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +#SET_PATH - This line is a placeholder to ease patching this script. + +# Instead of unsetting XZ_OPT, just make sure that xz will use file format +# autodetection. This way memory usage limit and thread limit can be +# specified via XZ_OPT. +xz='@xz@ --format=auto' + +version='xzmore (@PACKAGE_NAME@) @VERSION@' + +usage="Usage: ${0##*/} [OPTION]... [FILE]... +Like 'more', but operate on the uncompressed contents of xz compressed FILEs. + +Report bugs to <@PACKAGE_BUGREPORT@>." + +case $1 in + --help) echo "$usage" || exit 2; exit;; + --version) echo "$version" || exit 2; exit;; +esac + +oldtty=`stty -g 2>/dev/null` +if stty -cbreak 2>/dev/null; then + cb='cbreak'; ncb='-cbreak' +else + # 'stty min 1' resets eof to ^a on both SunOS and SysV! + cb='min 1 -icanon'; ncb='icanon eof ^d' +fi +if test $? -eq 0 && test -n "$oldtty"; then + trap 'stty $oldtty 2>/dev/null; exit' 0 2 3 5 10 13 15 +else + trap 'stty $ncb echo 2>/dev/null; exit' 0 2 3 5 10 13 15 +fi + +if test $# = 0; then + if test -t 0; then + echo "$usage"; exit 1 + else + $xz -cdfq | eval "${PAGER:-more}" + fi +else + FIRST=1 + for FILE; do + < "$FILE" || continue + if test $FIRST -eq 0; then + printf "%s--More--(Next file: %s)" "" "$FILE" + stty $cb -echo 2>/dev/null + ANS=`dd bs=1 count=1 2>/dev/null` + stty $ncb echo 2>/dev/null + echo " " + case "$ANS" in + [eq]) exit;; + esac + fi + if test "$ANS" != 's'; then + echo "------> $FILE <------" + $xz -cdfq -- "$FILE" | eval "${PAGER:-more}" + fi + if test -t 1; then + FIRST=0 + fi + done +fi diff --git a/contrib/xz/src/xz/coder.c b/contrib/xz/src/xz/coder.c index 5182dddc3f..b123ec5bf2 100644 --- a/contrib/xz/src/xz/coder.c +++ b/contrib/xz/src/xz/coder.c @@ -102,7 +102,7 @@ coder_add_filter(lzma_vli id, void *options) } -static void lzma_attribute((noreturn)) +static void lzma_attribute((__noreturn__)) memlimit_too_small(uint64_t memory_usage) { message(V_ERROR, _("Memory usage limit is too low for the given " diff --git a/contrib/xz/src/xz/file_io.c b/contrib/xz/src/xz/file_io.c index 6e24c58a94..f9b7f305e0 100644 --- a/contrib/xz/src/xz/file_io.c +++ b/contrib/xz/src/xz/file_io.c @@ -53,7 +53,7 @@ static bool io_write_buf(file_pair *pair, const uint8_t *buf, size_t size); extern void io_init(void) { - // Make sure that stdin, stdout, and and stderr are connected to + // Make sure that stdin, stdout, and stderr are connected to // a valid file descriptor. Exit immediately with exit code ERROR // if we cannot make the file descriptors valid. Maybe we should // print an error message, but our stderr could be screwed anyway. @@ -457,15 +457,14 @@ io_open_src_real(file_pair *pair) goto error; } - if (reg_files_only) { - if (!S_ISREG(pair->src_st.st_mode)) { - message_warning(_("%s: Not a regular file, " - "skipping"), pair->src_name); - goto error; - } + if (reg_files_only && !S_ISREG(pair->src_st.st_mode)) { + message_warning(_("%s: Not a regular file, skipping"), + pair->src_name); + goto error; + } - // These are meaningless on Windows. #ifndef TUKLIB_DOSLIKE + if (reg_files_only && !opt_force) { if (pair->src_st.st_mode & (S_ISUID | S_ISGID)) { // gzip rejects setuid and setgid files even // when --force was used. bzip2 doesn't check @@ -495,8 +494,8 @@ io_open_src_real(file_pair *pair) "skipping"), pair->src_name); goto error; } -#endif } +#endif return false; diff --git a/contrib/xz/src/xz/hardware.h b/contrib/xz/src/xz/hardware.h index bed952b07d..ad526f260b 100644 --- a/contrib/xz/src/xz/hardware.h +++ b/contrib/xz/src/xz/hardware.h @@ -35,4 +35,4 @@ extern void hardware_memlimit_set(uint64_t new_memlimit, extern uint64_t hardware_memlimit_get(enum operation_mode mode); /// Display the amount of RAM and memory usage limits and exit. -extern void hardware_memlimit_show(void) lzma_attribute((noreturn)); +extern void hardware_memlimit_show(void) lzma_attribute((__noreturn__)); diff --git a/contrib/xz/src/xz/message.c b/contrib/xz/src/xz/message.c index 38cce4a1b0..80c86a49c3 100644 --- a/contrib/xz/src/xz/message.c +++ b/contrib/xz/src/xz/message.c @@ -94,7 +94,7 @@ static volatile sig_atomic_t progress_needs_updating = false; /// Signal handler for SIGALRM static void -progress_signal_handler(int sig lzma_attribute((unused))) +progress_signal_handler(int sig lzma_attribute((__unused__))) { progress_needs_updating = true; return; @@ -726,7 +726,11 @@ vmessage(enum message_verbosity v, const char *fmt, va_list ap) progress_flush(false); - fprintf(stderr, "%s: ", progname); + // TRANSLATORS: This is the program name in the beginning + // of the line in messages. Usually it becomes "xz: ". + // This is a translatable string because French needs + // a space before a colon. + fprintf(stderr, _("%s: "), progname); vfprintf(stderr, fmt, ap); fputc('\n', stderr); diff --git a/contrib/xz/src/xz/message.h b/contrib/xz/src/xz/message.h index e3fca3cc42..74599bd978 100644 --- a/contrib/xz/src/xz/message.h +++ b/contrib/xz/src/xz/message.h @@ -45,7 +45,7 @@ extern enum message_verbosity message_verbosity_get(void); /// /// This doesn't touch the exit status. extern void message(enum message_verbosity verbosity, const char *fmt, ...) - lzma_attribute((format(printf, 2, 3))); + lzma_attribute((__format__(__printf__, 2, 3))); /// \brief Prints a warning and possibly sets exit status @@ -53,7 +53,7 @@ extern void message(enum message_verbosity verbosity, const char *fmt, ...) /// The message is printed only if verbosity level is at least V_WARNING. /// The exit status is set to WARNING unless it was already at ERROR. extern void message_warning(const char *fmt, ...) - lzma_attribute((format(printf, 1, 2))); + lzma_attribute((__format__(__printf__, 1, 2))); /// \brief Prints an error message and sets exit status @@ -61,25 +61,25 @@ extern void message_warning(const char *fmt, ...) /// The message is printed only if verbosity level is at least V_ERROR. /// The exit status is set to ERROR. extern void message_error(const char *fmt, ...) - lzma_attribute((format(printf, 1, 2))); + lzma_attribute((__format__(__printf__, 1, 2))); /// \brief Prints an error message and exits with EXIT_ERROR /// /// The message is printed only if verbosity level is at least V_ERROR. extern void message_fatal(const char *fmt, ...) - lzma_attribute((format(printf, 1, 2))) - lzma_attribute((noreturn)); + lzma_attribute((__format__(__printf__, 1, 2))) + lzma_attribute((__noreturn__)); /// Print an error message that an internal error occurred and exit with /// EXIT_ERROR. -extern void message_bug(void) lzma_attribute((noreturn)); +extern void message_bug(void) lzma_attribute((__noreturn__)); /// Print a message that establishing signal handlers failed, and exit with /// exit status ERROR. -extern void message_signal_handler(void) lzma_attribute((noreturn)); +extern void message_signal_handler(void) lzma_attribute((__noreturn__)); /// Convert lzma_ret to a string. @@ -116,11 +116,11 @@ extern void message_try_help(void); /// Prints the version number to stdout and exits with exit status SUCCESS. -extern void message_version(void) lzma_attribute((noreturn)); +extern void message_version(void) lzma_attribute((__noreturn__)); /// Print the help message. -extern void message_help(bool long_help) lzma_attribute((noreturn)); +extern void message_help(bool long_help) lzma_attribute((__noreturn__)); /// \brief Set the total number of files to be processed diff --git a/contrib/xz/src/xz/options.c b/contrib/xz/src/xz/options.c index 379a2e46dc..f21a0ba510 100644 --- a/contrib/xz/src/xz/options.c +++ b/contrib/xz/src/xz/options.c @@ -150,7 +150,7 @@ enum { static void set_delta(void *options, uint32_t key, uint64_t value, - const char *valuestr lzma_attribute((unused))) + const char *valuestr lzma_attribute((__unused__))) { lzma_options_delta *opt = options; switch (key) { @@ -194,7 +194,7 @@ enum { static void set_bcj(void *options, uint32_t key, uint64_t value, - const char *valuestr lzma_attribute((unused))) + const char *valuestr lzma_attribute((__unused__))) { lzma_options_bcj *opt = options; switch (key) { @@ -241,7 +241,7 @@ enum { }; -static void lzma_attribute((noreturn)) +static void lzma_attribute((__noreturn__)) error_lzma_preset(const char *valuestr) { message_fatal(_("Unsupported LZMA1/LZMA2 preset: %s"), valuestr); diff --git a/contrib/xz/src/xz/signals.c b/contrib/xz/src/xz/signals.c index 4d6a9da316..de213644d0 100644 --- a/contrib/xz/src/xz/signals.c +++ b/contrib/xz/src/xz/signals.c @@ -179,7 +179,7 @@ signals_exit(void) // console window. static BOOL WINAPI -signal_handler(DWORD type lzma_attribute((unused))) +signal_handler(DWORD type lzma_attribute((__unused__))) { // Since we don't get a signal number which we could raise() at // signals_exit() like on POSIX, just set the exit status to diff --git a/contrib/xz/src/xz/suffix.c b/contrib/xz/src/xz/suffix.c index f2a2da2749..c89f67fe85 100644 --- a/contrib/xz/src/xz/suffix.c +++ b/contrib/xz/src/xz/suffix.c @@ -21,10 +21,28 @@ static char *custom_suffix = NULL; -struct suffix_pair { - const char *compressed; - const char *uncompressed; -}; +/// \brief Test if the char is a directory separator +static bool +is_dir_sep(char c) +{ +#ifdef TUKLIB_DOSLIKE + return c == '/' || c == '\\' || c == ':'; +#else + return c == '/'; +#endif +} + + +/// \brief Test if the string contains a directory separator +static bool +has_dir_sep(const char *str) +{ +#ifdef TUKLIB_DOSLIKE + return strpbrk(str, "/\\:") != NULL; +#else + return strchr(str, '/') != NULL; +#endif +} /// \brief Checks if src_name has given compressed_suffix @@ -44,7 +62,8 @@ test_suffix(const char *suffix, const char *src_name, size_t src_len) // The filename must have at least one character in addition to // the suffix. src_name may contain path to the filename, so we // need to check for directory separator too. - if (src_len <= suffix_len || src_name[src_len - suffix_len - 1] == '/') + if (src_len <= suffix_len + || is_dir_sep(src_name[src_len - suffix_len - 1])) return 0; if (strcmp(suffix, src_name + src_len - suffix_len) == 0) @@ -61,7 +80,10 @@ test_suffix(const char *suffix, const char *src_name, size_t src_len) static char * uncompressed_name(const char *src_name, const size_t src_len) { - static const struct suffix_pair suffixes[] = { + static const struct { + const char *compressed; + const char *uncompressed; + } suffixes[] = { { ".xz", "" }, { ".txz", ".tar" }, // .txz abbreviation for .txt.gz is rare. { ".lzma", "" }, @@ -120,25 +142,25 @@ static char * compressed_name(const char *src_name, const size_t src_len) { // The order of these must match the order in args.h. - static const struct suffix_pair all_suffixes[][3] = { + static const char *const all_suffixes[][3] = { { - { ".xz", "" }, - { ".txz", ".tar" }, - { NULL, NULL } + ".xz", + ".txz", + NULL }, { - { ".lzma", "" }, - { ".tlz", ".tar" }, - { NULL, NULL } + ".lzma", + ".tlz", + NULL /* }, { - { ".gz", "" }, - { ".tgz", ".tar" }, - { NULL, NULL } + ".gz", + ".tgz", + NULL */ }, { // --format=raw requires specifying the suffix // manually or using stdout. - { NULL, NULL } + NULL } }; @@ -146,14 +168,22 @@ compressed_name(const char *src_name, const size_t src_len) assert(opt_format != FORMAT_AUTO); const size_t format = opt_format - 1; - const struct suffix_pair *const suffixes = all_suffixes[format]; + const char *const *suffixes = all_suffixes[format]; + + for (size_t i = 0; suffixes[i] != NULL; ++i) { + if (test_suffix(suffixes[i], src_name, src_len) != 0) { + message_warning(_("%s: File already has `%s' " + "suffix, skipping"), src_name, + suffixes[i]); + return NULL; + } + } - for (size_t i = 0; suffixes[i].compressed != NULL; ++i) { - if (test_suffix(suffixes[i].compressed, src_name, src_len) - != 0) { + if (custom_suffix != NULL) { + if (test_suffix(custom_suffix, src_name, src_len) != 0) { message_warning(_("%s: File already has `%s' " "suffix, skipping"), src_name, - suffixes[i].compressed); + custom_suffix); return NULL; } } @@ -168,7 +198,7 @@ compressed_name(const char *src_name, const size_t src_len) } const char *suffix = custom_suffix != NULL - ? custom_suffix : suffixes[0].compressed; + ? custom_suffix : suffixes[0]; const size_t suffix_len = strlen(suffix); char *dest_name = xmalloc(src_len + suffix_len + 1); @@ -199,9 +229,9 @@ suffix_get_dest_name(const char *src_name) extern void suffix_set(const char *suffix) { - // Empty suffix and suffixes having a slash are rejected. Such - // suffixes would break things later. - if (suffix[0] == '\0' || strchr(suffix, '/') != NULL) + // Empty suffix and suffixes having a directory separator are + // rejected. Such suffixes would break things later. + if (suffix[0] == '\0' || has_dir_sep(suffix)) message_fatal(_("%s: Invalid filename suffix"), optarg); // Replace the old custom_suffix (if any) with the new suffix. diff --git a/contrib/xz/src/xz/util.h b/contrib/xz/src/xz/util.h index fea8cc6695..a2516bf968 100644 --- a/contrib/xz/src/xz/util.h +++ b/contrib/xz/src/xz/util.h @@ -19,11 +19,12 @@ /// \brief Safe realloc() that never returns NULL -extern void *xrealloc(void *ptr, size_t size); +extern void *xrealloc(void *ptr, size_t size) + lzma_attribute((__malloc__)) lzma_attr_alloc_size(2); /// \brief Safe strdup() that never returns NULL -extern char *xstrdup(const char *src); +extern char *xstrdup(const char *src) lzma_attribute((__malloc__)); /// \brief Fancy version of strtoull() @@ -101,7 +102,7 @@ extern const char *uint64_to_nicestr(uint64_t value, /// A maximum of *left bytes is written starting from *pos. *pos and *left /// are updated accordingly. extern void my_snprintf(char **pos, size_t *left, const char *fmt, ...) - lzma_attribute((format(printf, 3, 4))); + lzma_attribute((__format__(__printf__, 3, 4))); /// \brief Check if filename is empty and print an error message diff --git a/contrib/xz/src/xz/xz.1 b/contrib/xz/src/xz/xz.1 index cba1d077c2..f1c9135d15 100644 --- a/contrib/xz/src/xz/xz.1 +++ b/contrib/xz/src/xz/xz.1 @@ -866,7 +866,7 @@ This is equivalent to specifying \fB\-\-memlimit\-compress=\fIlimit \fB\-\-memlimit\-decompress=\fIlimit\fR. .TP .B \-\-no\-adjust -Display an error and exit if the compression settings exceed the +Display an error and exit if the compression settings exceed the memory usage limit. The default is to adjust the settings downwards so that the memory usage limit is not exceeded. diff --git a/contrib/xz/src/xzdec/xzdec.c b/contrib/xz/src/xzdec/xzdec.c index fd015076de..b7830db4b5 100644 --- a/contrib/xz/src/xzdec/xzdec.c +++ b/contrib/xz/src/xzdec/xzdec.c @@ -40,7 +40,7 @@ static unsigned int display_errors = 2; -static void lzma_attribute((format(printf, 1, 2))) +static void lzma_attribute((__format__(__printf__, 1, 2))) my_errorf(const char *fmt, ...) { va_list ap; @@ -57,7 +57,7 @@ my_errorf(const char *fmt, ...) } -static void lzma_attribute((noreturn)) +static void lzma_attribute((__noreturn__)) help(void) { printf( @@ -81,7 +81,7 @@ PACKAGE_NAME " home page: <" PACKAGE_URL ">\n", progname); } -static void lzma_attribute((noreturn)) +static void lzma_attribute((__noreturn__)) version(void) { printf(TOOL_FORMAT "dec (" PACKAGE_NAME ") " LZMA_VERSION_STRING "\n"