[Spice-devel] [PATCH 4/5] LZ4: Implement htonl to remove dependency on arpa/inte.h

Javier Celaya javier.celaya at flexvm.es
Thu Jan 22 08:21:07 PST 2015


---
 server/lz4_encoder.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/server/lz4_encoder.c b/server/lz4_encoder.c
index 2327e9a..4f0f3c8 100644
--- a/server/lz4_encoder.c
+++ b/server/lz4_encoder.c
@@ -22,7 +22,6 @@
 
 #define SPICE_LOG_DOMAIN "SpiceLz4Encoder"
 
-#include <arpa/inet.h>
 #include <lz4.h>
 #include "red_common.h"
 #include "lz4_encoder.h"
@@ -31,6 +30,16 @@ typedef struct Lz4Encoder {
     Lz4EncoderUsrContext *usr;
 } Lz4Encoder;
 
+static inline void encode32(uint8_t *buffer, uint32_t value)
+{
+    // Network order -> big endian
+    int i;
+    for (i = 3; i > -1; --i) {
+        buffer[i] = value & 0xFF;
+        value >>= 8;
+    }
+}
+
 Lz4EncoderContext* lz4_encoder_create(Lz4EncoderUsrContext *usr)
 {
     Lz4Encoder *enc;
@@ -85,7 +94,7 @@ int lz4_encode(Lz4EncoderContext *lz4, int height, int stride, uint8_t *io_ptr,
             LZ4_freeStream(stream);
             return 0;
         }
-        *((uint32_t *)compressed_lines) = htonl(enc_size);
+        encode32(compressed_lines, enc_size);
 
         out_size += enc_size += 4;
         already_copied = 0;
-- 
1.9.3



More information about the Spice-devel mailing list