cutil/endian.c
2022-04-28 18:26:15 +03:00

27 lines
691 B
C

#include "endian.h"
enum cu_endian_e cu_endian;
static const union {
uint8_t bytes[4];
uint32_t value;
} host_order = {
{0, 1, 2, 3}
};
#define ORDER_LITTLE_ENDIAN 0x03020100
#define ORDER_BIG_ENDIAN 0x00010203
#define ORDER_PDP_ENDIAN 0x01000302
#define ORDER_HONEYWELL_ENDIAN 0x02030001
void cu_endian_init()
{
if (host_order.value == ORDER_LITTLE_ENDIAN)
cu_endian = LittleEndian;
else if (host_order.value == ORDER_BIG_ENDIAN)
cu_endian = BigEndian;
else if (host_order.value == ORDER_PDP_ENDIAN)
cu_endian = PDPEndian;
else if (host_order.value == ORDER_HONEYWELL_ENDIAN)
cu_endian = HoneywellEndian;
}