From 332795cc5951c6d65badd2bbf3c79f6b63dbdbc2 Mon Sep 17 00:00:00 2001 From: Hung-Te Lin Date: Mon, 28 Jan 2013 15:53:34 +0800 Subject: cbfstool: Make endian detection functions to work without prior setup. The 'host_bigendian' variable (and functions relying on it like ntohl/htonl) requires host detection by calling static which_endian() first -- which may be easily forgotten by developers. It's now a public function in common.c and doesn't need initialization anymore. Change-Id: I13dabd1ad15d2d6657137d29138e0878040cb205 Signed-off-by: Hung-Te Lin Reviewed-on: http://review.coreboot.org/2199 Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel --- util/cbfstool/common.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'util/cbfstool/common.h') diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h index bd5ef65f16..5315e69bed 100644 --- a/util/cbfstool/common.h +++ b/util/cbfstool/common.h @@ -21,13 +21,16 @@ #define __CBFSTOOL_COMMON_H #include + +/* Endianess */ #include "swab.h" #ifndef __APPLE__ -#define ntohl(x) (host_bigendian?(x):swab32(x)) -#define htonl(x) (host_bigendian?(x):swab32(x)) +#define ntohl(x) (is_big_endian() ? (x) : swab32(x)) +#define htonl(x) (is_big_endian() ? (x) : swab32(x)) #endif -#define ntohll(x) (host_bigendian?(x):swab64(x)) -#define htonll(x) (host_bigendian?(x):swab64(x)) +#define ntohll(x) (is_big_endian() ? (x) : swab64(x)) +#define htonll(x) (is_big_endian() ? (x) : swab64(x)) +extern int is_big_endian(void); /* Message output */ extern int verbose; -- cgit v1.2.3