Portable generic byteswap for BE.

This commit is contained in:
Con Kolivas 2011-03-22 00:13:29 +11:00
parent c533b031bc
commit a30efcaa55
5 changed files with 30 additions and 4 deletions

View file

@ -37,7 +37,6 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/time.h> #include <sys/time.h>
#include <termios.h> #include <termios.h>
#include <endian.h>
#include "md5.h" #include "md5.h"
#include "rzip.h" #include "rzip.h"

View file

@ -99,6 +99,36 @@ typedef struct md5_ctx md5_ctx;
# define mremap fake_mremap # define mremap fake_mremap
#endif #endif
#define bswap_32(x) \
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
# define bswap_64(x) \
((((x) & 0xff00000000000000ull) >> 56) \
| (((x) & 0x00ff000000000000ull) >> 40) \
| (((x) & 0x0000ff0000000000ull) >> 24) \
| (((x) & 0x000000ff00000000ull) >> 8) \
| (((x) & 0x00000000ff000000ull) << 8) \
| (((x) & 0x0000000000ff0000ull) << 24) \
| (((x) & 0x000000000000ff00ull) << 40) \
| (((x) & 0x00000000000000ffull) << 56))
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define htole32(x) (x)
# define le32toh(x) (x)
# define htole64(x) (x)
# define le64toh(x) (x)
# elif __BYTE_ORDER == __BIG_ENDIAN
# define htole32(x) bswap_32 (x)
# define le32toh(x) bswap_32 (x)
# define htole64(x) bswap_64 (x)
# define le64toh(x) bswap_64 (x)
#else
#error UNKNOWN BYTE ORDER
#endif
#define FLAG_SHOW_PROGRESS (1 << 0) #define FLAG_SHOW_PROGRESS (1 << 0)
#define FLAG_KEEP_FILES (1 << 1) #define FLAG_KEEP_FILES (1 << 1)
#define FLAG_TEST_ONLY (1 << 2) #define FLAG_TEST_ONLY (1 << 2)

View file

@ -31,7 +31,6 @@
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
#endif #endif
#include <endian.h>
#include "md5.h" #include "md5.h"
#include "runzip.h" #include "runzip.h"

1
rzip.c
View file

@ -42,7 +42,6 @@
#ifdef HAVE_ERRNO_H #ifdef HAVE_ERRNO_H
# include <errno.h> # include <errno.h>
#endif #endif
#include <endian.h>
#include "md5.h" #include "md5.h"
#include "stream.h" #include "stream.h"

View file

@ -39,7 +39,6 @@
#ifdef HAVE_ERRNO_H #ifdef HAVE_ERRNO_H
# include <errno.h> # include <errno.h>
#endif #endif
#include <endian.h>
/* LZMA C Wrapper */ /* LZMA C Wrapper */
#include "lzma/C/LzmaLib.h" #include "lzma/C/LzmaLib.h"