Attempt to cope with endian issues in zip reader. 20120220030501/pspp 20120221030502/pspp
authorJohn Darrington <john@darrington.wattle.id.au>
Sun, 19 Feb 2012 18:26:23 +0000 (19:26 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Sun, 19 Feb 2012 18:26:23 +0000 (19:26 +0100)
src/libpspp/zip-reader.c

index bee7e2f240ff2affad679c5a50f1bef916d638a6..4672a1079f96ae12367670c7a1d4a760425c251b 100644 (file)
@@ -26,6 +26,7 @@
 #include <xalloc.h>
 #include <libpspp/assertion.h>
 
+#include <byteswap.h>
 #include <crc.h>
 
 #include "inflate.h"
@@ -160,9 +161,28 @@ get_bytes (FILE *f, void *x, size_t n)
 
 /* Read a 32 bit value from F */
 static void
-get_u32 (FILE *f, uint32_t *x)
+get_u32 (FILE *f, uint32_t *v)
 {
-  get_bytes (f, x, sizeof *x);
+  uint32_t x;
+  get_bytes (f, &x, sizeof x);
+#ifdef WORDS_BIGENDIAN
+  *v = bswap_32 (x);
+#else
+  *v = x;
+#endif
+}
+
+/* Read a 16 bit value from F */
+static void
+get_u16 (FILE *f, uint16_t *v)
+{
+  uint16_t x;
+  get_bytes (f, &x, sizeof x);
+#ifdef WORDS_BIGENDIAN
+  *v = bswap_16 (x);
+#else
+  *v = x;
+#endif
 }
 
 
@@ -187,13 +207,6 @@ check_magic (FILE *f, uint32_t expected, struct string *err)
 }
 
 
-/* Read a 16 bit value from F */
-static void
-get_u16 (FILE *f, uint16_t *x)
-{
-  get_bytes (f, x, sizeof *x);
-}
-
 /* Reads upto BYTES bytes from ZM and puts them in BUF.
    Returns the number of bytes read, or -1 on error */
 int