From 57ea37a8fad405df23256144367b6a18a5ab1580 Mon Sep 17 00:00:00 2001 From: Christopher Peplin Date: Sat, 4 Jan 2014 11:12:11 -0500 Subject: [PATCH] Use more portable endinaness macros to check architecture. --- src/bitfield/bitfield.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bitfield/bitfield.c b/src/bitfield/bitfield.c index 52f368f5..dddb0ee2 100644 --- a/src/bitfield/bitfield.c +++ b/src/bitfield/bitfield.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include uint64_t bitmask(const uint8_t bit_count) { return (((uint64_t)0x1) << bit_count) - 1; @@ -40,7 +40,10 @@ uint64_t get_bitfield(const uint8_t source[], const uint8_t source_length, } combined; copy_bits_right_aligned(source, source_length, offset, bit_count, combined.bytes, sizeof(combined.bytes)); - return htobe64(combined.whole); + if(BYTE_ORDER == LITTLE_ENDIAN) { + combined.whole = __builtin_bswap64(combined.whole); + } + return combined.whole; } bool set_nibble(const uint16_t nibble_index, const uint8_t value, -- 2.16.6