Fixes for non little endian machines.

This commit is contained in:
Con Kolivas 2011-03-20 16:16:38 +11:00
parent 1ade3bcc2f
commit 30b70dc884
2 changed files with 11 additions and 4 deletions

View file

@ -37,6 +37,7 @@
#include <sys/mman.h>
#include <sys/time.h>
#include <termios.h>
#include <endian.h>
#include "md5.h"
#include "rzip.h"
@ -75,8 +76,10 @@ void write_magic(rzip_control *control)
* and instead the salt is stored here to preserve space. */
if (ENCRYPT)
memcpy(&magic[6], &control->salt, 8);
else if (!STDIN || !STDOUT || control->eof)
else if (!STDIN || !STDOUT || control->eof) {
memcpy(&magic[6], &control->st_size, 8);
control->st_size = le64toh(control->st_size);
}
/* save LZMA compression flags */
if (LZMA_COMPRESS) {
@ -130,8 +133,10 @@ static void get_magic(rzip_control *control, char *magic)
expected_size = ntohl(v);
memcpy(&v, &magic[10], 4);
expected_size |= ((i64)ntohl(v)) << 32;
} else
} else {
memcpy(&expected_size, &magic[6], 8);
expected_size = le64toh(expected_size);
}
control->st_size = expected_size;
/* restore LZMA compression flags only if stored */

View file

@ -38,6 +38,7 @@
#ifdef HAVE_ERRNO_H
# include <errno.h>
#endif
#include <endian.h>
/* LZMA C Wrapper */
#include "lzma/C/LzmaLib.h"
@ -783,6 +784,7 @@ static inline int write_u8(rzip_control *control, int f, uchar v)
static inline int write_val(rzip_control *control, int f, i64 v, int len)
{
v = htole64(v);
return write_buf(control, f, (uchar *)&v, len);
}
@ -809,12 +811,12 @@ static inline int read_u8(rzip_control *control, int f, uchar *v)
static inline int read_u32(rzip_control *control, int f, u32 *v)
{
return read_buf(control, f, (uchar *)v, 4);
return le32toh(read_buf(control, f, (uchar *)v, 4));
}
static inline int read_i64(rzip_control *control, int f, i64 *v)
{
return read_buf(control, f, (uchar *)v, 8);
return le64toh(read_buf(control, f, (uchar *)v, 8));
}
static inline int read_val(rzip_control *control, int f, i64 *v, int len)