summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>2011-12-16 23:41:46 (GMT)
committeryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>2011-12-16 23:41:46 (GMT)
commit8ee579983ae3abd82efab86915cf0d42a6a185db (patch)
tree7cef2bfb18704b272258afb9b6391da9dedd1815
parent39630716d78c27714aa1827a92f12c29f2ab66fd (diff)
downloadlz4-8ee579983ae3abd82efab86915cf0d42a6a185db.zip
lz4-8ee579983ae3abd82efab86915cf0d42a6a185db.tar.gz
lz4-8ee579983ae3abd82efab86915cf0d42a6a185db.tar.bz2
Endianess correction
git-svn-id: https://lz4.googlecode.com/svn/trunk@43 650e7d94-2a16-8b24-b05c-7c0b3f6821cd
-rw-r--r--lz4.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/lz4.c b/lz4.c
index 8041552..2c522f1 100644
--- a/lz4.c
+++ b/lz4.c
@@ -160,7 +160,9 @@ int LZ4_compressCtx(void** ctx,
BYTE* op = (BYTE*) dest;
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
const size_t DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, 3, 2, 2, 1, 3, 2, 0, 1, 3, 3, 1, 2, 2, 2, 2, 0, 3, 1, 2, 0, 1, 0, 1, 1 };
+#endif
int len, length;
const int skipStrength = SKIPSTRENGTH;
U32 forwardH;
@@ -223,7 +225,11 @@ int LZ4_compressCtx(void** ctx,
_next_match:
// Encode Offset
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
A16(op) = (ip-ref); op+=2;
+#else
+ { int delta = ip-ref; *op++ = delta; *op++ = delta>>8; }
+#endif
// Start Counting
ip+=MINMATCH; ref+=MINMATCH; // MinMatch verified
@@ -308,7 +314,9 @@ int LZ4_compress64kCtx(void** ctx,
BYTE* op = (BYTE*) dest;
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
const size_t DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, 3, 2, 2, 1, 3, 2, 0, 1, 3, 3, 1, 2, 2, 2, 2, 0, 3, 1, 2, 0, 1, 0, 1, 1 };
+#endif
int len, length;
const int skipStrength = SKIPSTRENGTH;
U32 forwardH;
@@ -370,7 +378,11 @@ int LZ4_compress64kCtx(void** ctx,
_next_match:
// Encode Offset
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
A16(op) = (ip-ref); op+=2;
+#else
+ { int delta = ip-ref; *op++ = delta; *op++ = delta>>8; }
+#endif
// Start Counting
ip+=MINMATCH; ref+=MINMATCH; // MinMatch verified
@@ -495,7 +507,11 @@ int LZ4_uncompress(char* source,
// get offset
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
ref = cpy - A16(ip); ip+=2;
+#else
+ { int delta = *ip++; delta += *ip++ << 8; ref = cpy - delta; }
+#endif
// get matchlength
if ((length=(token&ML_MASK)) == ML_MASK) { for (;*ip==255;length+=255) {ip++;} length += *ip++; }
@@ -573,9 +589,12 @@ int LZ4_uncompress_unknownOutputSize(
LZ4_WILDCOPY(ip, op, cpy); ip -= (op-cpy); op = cpy;
if (ip>=iend) break; // check EOF
-
// get offset
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
ref = cpy - A16(ip); ip+=2;
+#else
+ { int delta = *ip++; delta += *ip++ << 8; ref = cpy - delta; }
+#endif
// get matchlength
if ((length=(token&ML_MASK)) == ML_MASK) { for (;(len=*ip++)==255;length+=255){} length += len; }