endian.c revision cc366bfc297550eb10cd5f677d98c8d206eca4f1
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
*/
/*
* Copyright 2016 Joyent, Inc.
*/
/*
* Test endian(3C).
*/
#include <endian.h>
#ifndef BIG_ENDIAN
#error "Missing BIG_ENDIAN definition"
#endif
#ifndef LITTLE_ENDIAN
#error "Missing LITTLE_ENDIAN definition"
#endif
static void
endian_fromhost(void)
{
#if defined(_LITTLE_ENDIAN)
ebe16 = 0x2211;
ebe32 = 0x44332211UL;
ebe64 = 0x8877665544332211ULL;
ele16 = 0x1122;
ele32 = 0x11223344UL;
ele64 = 0x1122334455667788ULL;
#elif defined(_BIG_ENDIAN)
ele16 = 0x2211;
ele32 = 0x44332211UL;
ele64 = 0x8877665544332211ULL;
ebe16 = 0x1122;
ebe32 = 0x11223344UL;
ebe64 = 0x1122334455667788ULL;
#else
#error "Unknown byte order"
#endif /* _LITTLE_ENDIAN */
}
static void
endian_frombig(void)
{
#if defined(_LITTLE_ENDIAN)
e16 = 0x2211;
e32 = 0x44332211UL;
e64 = 0x8877665544332211ULL;
#elif defined(_BIG_ENDIAN)
e16 = 0x1122;
e32 = 0x11223344UL;
e64 = 0x1122334455667788ULL;
#else
#error "Unknown byte order"
#endif /* _LITTLE_ENDIAN */
}
static void
endian_fromlittle(void)
{
#if defined(_LITTLE_ENDIAN)
e16 = 0x1122;
e32 = 0x11223344UL;
e64 = 0x1122334455667788ULL;
#elif defined(_BIG_ENDIAN)
e16 = 0x2211;
e32 = 0x44332211UL;
e64 = 0x8877665544332211ULL;
#else
#error "Unknown byte order"
#endif /* _LITTLE_ENDIAN */
}
int
main(void)
{
return (0);
}