From 746cecf4b79de2d58bd56225f79d7dfaa4e56322 Mon Sep 17 00:00:00 2001 From: John Johansen Date: Wed, 23 Apr 2014 11:07:49 -0700 Subject: [PATCH] Convert to htoleXX fns instead of ifdef on endian This patch makes use of the htoleXX() functions (see endian(3)) defined as part of endian.h (already included in parser_interface.c), instead of defining a function differently based on the detection of endian related macros. This fixes a build failure experienced on powerpc with John's patch set applied. This patch has been updated with John's feedback to use letoh16() in the le16_to_cpu() macro. Signed-off-by: Steve Beattie Acked-by: John Johansen Acked-by: Seth Arnold --- parser/parser.h | 15 ++++++--------- parser/parser_interface.c | 3 --- parser/parser_main.c | 6 +----- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/parser/parser.h b/parser/parser.h index f9338236f..32ab1dfda 100644 --- a/parser/parser.h +++ b/parser/parser.h @@ -23,9 +23,11 @@ #define __AA_PARSER_H +#include #include #include #include + #include "immunix.h" #include "libapparmor_re/apparmor_re.h" #include "libapparmor_re/aare_rules.h" @@ -258,15 +260,10 @@ do { \ #define u16 uint16_t #define u32 uint32_t #define u64 uint64_t -#if __BYTE_ORDER == __BIG_ENDIAN -# define cpu_to_le16(x) ((u16)(bswap_16 ((u16) x))) -# define cpu_to_le32(x) ((u32)(bswap_32 ((u32) x))) -# define cpu_to_le64(x) ((u64)(bswap_64 ((u64) x))) -#else -# define cpu_to_le16(x) ((u16)(x)) -# define cpu_to_le32(x) ((u32)(x)) -# define cpu_to_le64(x) ((u64)(x)) -#endif + +#define cpu_to_le16(x) ((u16)(htole16 ((u16) x))) +#define cpu_to_le32(x) ((u32)(htole32 ((u32) x))) +#define cpu_to_le64(x) ((u64)(htole64 ((u64) x))) /* The encoding for kernal abi > 5 is * 28-31: reserved diff --git a/parser/parser_interface.c b/parser/parser_interface.c index 0e2db0f3d..4da57f6bf 100644 --- a/parser/parser_interface.c +++ b/parser/parser_interface.c @@ -37,9 +37,6 @@ #include #include -/* only for x86 at the moment */ -#include -#include #include #define _(s) gettext(s) diff --git a/parser/parser_main.c b/parser/parser_main.c index f06a143da..d2b270b51 100644 --- a/parser/parser_main.c +++ b/parser/parser_main.c @@ -946,11 +946,7 @@ int test_for_dir_mode(const char *basename, const char *linkdir) return rc; } -#if __BYTE_ORDER == __BIG_ENDIAN -# define le16_to_cpu(x) ((uint16_t)(bswap_16 (*(uint16_t *) x))) -#else -# define le16_to_cpu(x) (*(uint16_t *)(x)) -#endif +#define le16_to_cpu(x) ((uint16_t)(le16toh (*(uint16_t *) x))) const char header_string[] = "\004\010\000version\000\002"; #define HEADER_STRING_SIZE 12