diff options
author | dosomder <dosomder@users.noreply.github.com> | 2016-03-12 20:35:06 +0100 |
---|---|---|
committer | dosomder <dosomder@users.noreply.github.com> | 2016-03-12 23:57:34 +0100 |
commit | cc204c3e7b32c9ffc280590bb86cfeea8dba30a5 (patch) | |
tree | 461d50c624d265d3dbf86ffa0d912740c4e58fa6 /libarchive/archive_write_add_filter_lz4.c | |
parent | bcfa1f80be128ecd24e78774db3abed85180f99d (diff) | |
download | libarchive-cc204c3e7b32c9ffc280590bb86cfeea8dba30a5.tar.gz |
Make LZ4 HC optional
Diffstat (limited to 'libarchive/archive_write_add_filter_lz4.c')
-rw-r--r-- | libarchive/archive_write_add_filter_lz4.c | 63 |
1 files changed, 41 insertions, 22 deletions
diff --git a/libarchive/archive_write_add_filter_lz4.c b/libarchive/archive_write_add_filter_lz4.c index 426e140a..2f08ff40 100644 --- a/libarchive/archive_write_add_filter_lz4.c +++ b/libarchive/archive_write_add_filter_lz4.c @@ -160,10 +160,20 @@ archive_filter_lz4_options(struct archive_write_filter *f, struct private_data *data = (struct private_data *)f->data; if (strcmp(key, "compression-level") == 0) { - if (value == NULL || !(value[0] >= '1' && value[0] <= '9') || + int val; + if (value == NULL || !((val = value[0] - '0') >= 1 && val <= 9) || value[1] != '\0') return (ARCHIVE_WARN); - data->compression_level = value[0] - '0'; + +#ifndef HAVE_LZ4HC_H + if(val >= 3) + { + archive_set_error(f->archive, ARCHIVE_ERRNO_PROGRAMMER, + "High compression not included in this build"); + return (ARCHIVE_FATAL); + } +#endif + data->compression_level = val; return (ARCHIVE_OK); } if (strcmp(key, "stream-checksum") == 0) { @@ -367,14 +377,16 @@ archive_filter_lz4_free(struct archive_write_filter *f) struct private_data *data = (struct private_data *)f->data; if (data->lz4_stream != NULL) { - if (data->compression_level < 3) +#ifdef HAVE_LZ4HC_H + if (data->compression_level >= 3) + LZ4_freeHC(data->lz4_stream); + else +#endif #if LZ4_VERSION_MINOR >= 3 LZ4_freeStream(data->lz4_stream); #else LZ4_free(data->lz4_stream); #endif - else - LZ4_freeHC(data->lz4_stream); } free(data->out_buffer); free(data->in_buffer_allocated); @@ -481,13 +493,15 @@ drive_compressor_independence(struct archive_write_filter *f, const char *p, struct private_data *data = (struct private_data *)f->data; unsigned int outsize; - if (data->compression_level < 4) - outsize = LZ4_compress_limitedOutput(p, data->out + 4, - (int)length, (int)data->block_size); - else +#ifdef HAVE_LZ4HC_H + if (data->compression_level >= 4) outsize = LZ4_compressHC2_limitedOutput(p, data->out + 4, (int)length, (int)data->block_size, data->compression_level); + else +#endif + outsize = LZ4_compress_limitedOutput(p, data->out + 4, + (int)length, (int)data->block_size); if (outsize) { /* The buffer is compressed. */ @@ -518,9 +532,11 @@ drive_compressor_dependence(struct archive_write_filter *f, const char *p, struct private_data *data = (struct private_data *)f->data; int outsize; - if (data->compression_level < 3) { +#ifdef HAVE_LZ4HC_H + if (data->compression_level >= 3) { if (data->lz4_stream == NULL) { - data->lz4_stream = LZ4_createStream(); + data->lz4_stream = + LZ4_createHC(data->in_buffer_allocated); if (data->lz4_stream == NULL) { archive_set_error(f->archive, ENOMEM, "Can't allocate data for compression" @@ -528,13 +544,14 @@ drive_compressor_dependence(struct archive_write_filter *f, const char *p, return (ARCHIVE_FATAL); } } - outsize = LZ4_compress_limitedOutput_continue( + outsize = LZ4_compressHC2_limitedOutput_continue( data->lz4_stream, p, data->out + 4, (int)length, - (int)data->block_size); - } else { + (int)data->block_size, data->compression_level); + } else +#endif + { if (data->lz4_stream == NULL) { - data->lz4_stream = - LZ4_createHC(data->in_buffer_allocated); + data->lz4_stream = LZ4_createStream(); if (data->lz4_stream == NULL) { archive_set_error(f->archive, ENOMEM, "Can't allocate data for compression" @@ -542,9 +559,9 @@ drive_compressor_dependence(struct archive_write_filter *f, const char *p, return (ARCHIVE_FATAL); } } - outsize = LZ4_compressHC2_limitedOutput_continue( + outsize = LZ4_compress_limitedOutput_continue( data->lz4_stream, p, data->out + 4, (int)length, - (int)data->block_size, data->compression_level); + (int)data->block_size); } if (outsize) { @@ -569,13 +586,15 @@ drive_compressor_dependence(struct archive_write_filter *f, const char *p, if (length == data->block_size) { #define DICT_SIZE (64 * 1024) - if (data->compression_level < 3) - LZ4_saveDict(data->lz4_stream, - data->in_buffer_allocated, DICT_SIZE); - else { +#ifdef HAVE_LZ4HC_H + if (data->compression_level >= 3) { LZ4_slideInputBufferHC(data->lz4_stream); data->in_buffer = data->in_buffer_allocated + DICT_SIZE; } + else +#endif + LZ4_saveDict(data->lz4_stream, + data->in_buffer_allocated, DICT_SIZE); #undef DICT_SIZE } return (ARCHIVE_OK); |