X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fxpress-compress.c;h=ec63eb18a8206b06d39dbdf032a1080809f962bb;hb=e1aaba78f1608adf6fcb8d1650144789755940fd;hp=466dd7553811c73b7efe028a56e81b3d24ae78d1;hpb=4c7c5fee0bde9efa0529e0eb22cd8f6a36a6eb6b;p=wimlib diff --git a/src/xpress-compress.c b/src/xpress-compress.c index 466dd755..ec63eb18 100644 --- a/src/xpress-compress.c +++ b/src/xpress-compress.c @@ -26,7 +26,9 @@ */ #include "xpress.h" +#include "wimlib.h" #include "compress.h" + #include #include @@ -139,20 +141,11 @@ static const struct lz_params xpress_lz_params = { .too_far = 4096, }; -/* - * Performs XPRESS compression on a block of data. - * - * Please see the documentation for the 'compress_func_t' type in write.c for - * the exact behavior of this function and how to call it. - */ -#ifdef EXPORT_COMPRESSION_FUNCTIONS -WIMLIBAPI -#endif -unsigned -xpress_compress(const void *__uncompressed_data, unsigned uncompressed_len, - void *__compressed_data) +/* Documented in wimlib.h */ +WIMLIBAPI unsigned +wimlib_xpress_compress(const void *__uncompressed_data, + unsigned uncompressed_len, void *__compressed_data) { - const u8 *uncompressed_data = __uncompressed_data; u8 *compressed_data = __compressed_data; struct output_bitstream ostream; u32 match_tab[uncompressed_len]; @@ -163,6 +156,10 @@ xpress_compress(const void *__uncompressed_data, unsigned uncompressed_len, unsigned compressed_len; unsigned i; int ret; + u8 uncompressed_data[uncompressed_len + 8]; + + memcpy(uncompressed_data, __uncompressed_data, uncompressed_len); + memset(uncompressed_data + uncompressed_len, 0, 8); wimlib_assert(uncompressed_len <= 32768); @@ -242,23 +239,25 @@ xpress_compress(const void *__uncompressed_data, unsigned uncompressed_len, wimlib_assert(compressed_len <= uncompressed_len - 1); -#ifdef ENABLE_VERIFY_COMPRESSION +#if defined(ENABLE_VERIFY_COMPRESSION) /* Verify that we really get the same thing back when decompressing. */ - u8 buf[uncompressed_len]; - ret = xpress_decompress(__compressed_data, compressed_len, buf, - uncompressed_len); - if (ret) { - ERROR("xpress_compress(): Failed to decompress data we " - "compressed"); - abort(); - } - for (i = 0; i < uncompressed_len; i++) { - if (buf[i] != uncompressed_data[i]) { - ERROR("xpress_compress(): Data we compressed didn't " - "decompress to the original data (difference at " - "byte %u of %u)", i + 1, uncompressed_len); + { + u8 buf[uncompressed_len]; + ret = wimlib_xpress_decompress(__compressed_data, compressed_len, + buf, uncompressed_len); + if (ret) { + ERROR("xpress_compress(): Failed to decompress data we " + "compressed"); abort(); } + for (i = 0; i < uncompressed_len; i++) { + if (buf[i] != uncompressed_data[i]) { + ERROR("xpress_compress(): Data we compressed didn't " + "decompress to the original data (difference at " + "byte %u of %u)", i + 1, uncompressed_len); + abort(); + } + } } #endif return compressed_len;