From 95946055e3d02444fb8fd4cbdf48b78ecd212936 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sun, 19 Feb 2012 19:26:23 +0100 Subject: [PATCH] Attempt to cope with endian issues in zip reader. --- src/libpspp/zip-reader.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/libpspp/zip-reader.c b/src/libpspp/zip-reader.c index bee7e2f240..4672a1079f 100644 --- a/src/libpspp/zip-reader.c +++ b/src/libpspp/zip-reader.c @@ -26,6 +26,7 @@ #include #include +#include #include #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 -- 2.30.2