From: John Darrington Date: Sun, 19 Feb 2012 18:26:23 +0000 (+0100) Subject: Attempt to cope with endian issues in zip reader. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fbuilds%2F20120220030501%2Fpspp;p=pspp Attempt to cope with endian issues in zip reader. --- 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