summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/ext/compressors/lz4/lz4_compress.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/third_party/wiredtiger/ext/compressors/lz4/lz4_compress.c')
-rw-r--r--src/third_party/wiredtiger/ext/compressors/lz4/lz4_compress.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/third_party/wiredtiger/ext/compressors/lz4/lz4_compress.c b/src/third_party/wiredtiger/ext/compressors/lz4/lz4_compress.c
index d070dc3fb79..062307b721a 100644
--- a/src/third_party/wiredtiger/ext/compressors/lz4/lz4_compress.c
+++ b/src/third_party/wiredtiger/ext/compressors/lz4/lz4_compress.c
@@ -26,23 +26,13 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+#include <wt_internal.h>
+
#include <lz4.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
-#include <wiredtiger.h>
-#include <wiredtiger_ext.h>
-
-/*
- * We need to include the configuration file to detect whether this extension
- * is being built into the WiredTiger library.
- */
-#include "wiredtiger_config.h"
-#ifdef _MSC_VER
-#define inline __inline
-#endif
-
/* Local compressor structure. */
typedef struct {
WT_COMPRESSOR compressor; /* Must come first */
@@ -73,6 +63,24 @@ typedef struct {
} LZ4_PREFIX;
/*
+ * lz4_prefix_swap --
+ * The additional information is written in little-endian format, handle
+ * the conversion.
+ */
+static inline void
+lz4_prefix_swap(LZ4_PREFIX *prefix)
+{
+#ifdef WORDS_BIGENDIAN
+ prefix->compressed_len = __wt_bswap32(prefix->compressed_len);
+ prefix->uncompressed_len = __wt_bswap32(prefix->uncompressed_len);
+ prefix->useful_len = __wt_bswap32(prefix->useful_len);
+ prefix->unused = __wt_bswap32(prefix->unused);
+#else
+ WT_UNUSED(prefix);
+#endif
+}
+
+/*
* lz4_error --
* Output an error message, and return a standard error code.
*/
@@ -119,6 +127,7 @@ lz4_compress(WT_COMPRESSOR *compressor, WT_SESSION *session,
prefix.uncompressed_len = (uint32_t)src_len;
prefix.useful_len = (uint32_t)src_len;
prefix.unused = 0;
+ lz4_prefix_swap(&prefix);
memcpy(dst, &prefix, sizeof(LZ4_PREFIX));
*result_lenp = (size_t)lz4_len + sizeof(LZ4_PREFIX);
@@ -154,6 +163,7 @@ lz4_decompress(WT_COMPRESSOR *compressor, WT_SESSION *session,
* decompressed bytes to return from the start of the source buffer.
*/
memcpy(&prefix, src, sizeof(LZ4_PREFIX));
+ lz4_prefix_swap(&prefix);
/*
* Decompress, starting after the prefix bytes. Use safe decompression:
@@ -268,6 +278,7 @@ lz4_compress_raw(WT_COMPRESSOR *compressor, WT_SESSION *session,
prefix.uncompressed_len = (uint32_t)sourceSize;
prefix.useful_len = offsets[slot];
prefix.unused = 0;
+ lz4_prefix_swap(&prefix);
memcpy(dst, &prefix, sizeof(LZ4_PREFIX));
*result_slotsp = slot;