blob: 82e48f0bc48d236105fee108d32ef0ea089240b4 [file] [log] [blame]
Alexandre Lision51140e12013-12-02 10:54:09 -05001/*
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05002---------------------------------------------------------------------------
3Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved.
Alexandre Lision51140e12013-12-02 10:54:09 -05004
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05005The redistribution and use of this software (with or without changes)
6is allowed without the payment of fees or royalties provided that:
Alexandre Lision51140e12013-12-02 10:54:09 -05007
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05008 source code distributions include the above copyright notice, this
9 list of conditions and the following disclaimer;
Alexandre Lision51140e12013-12-02 10:54:09 -050010
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050011 binary distributions include the above copyright notice, this list
12 of conditions and the following disclaimer in their documentation.
Alexandre Lision51140e12013-12-02 10:54:09 -050013
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050014This software is provided 'as is' with no explicit or implied warranties
15in respect of its operation, including, but not limited to, correctness
16and fitness for purpose.
17---------------------------------------------------------------------------
18Issue Date: 20/12/2007
Alexandre Lision51140e12013-12-02 10:54:09 -050019*/
20
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050021#ifndef _BRG_ENDIAN_H
22#define _BRG_ENDIAN_H
Alexandre Lision51140e12013-12-02 10:54:09 -050023
24#define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */
25#define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */
26
27/* Include files where endian defines and byteswap functions may reside */
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050028#if defined( __sun )
29# include <sys/isa_defs.h>
30#elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ )
Alexandre Lision51140e12013-12-02 10:54:09 -050031# include <sys/endian.h>
32#elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \
33 defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ )
34# include <machine/endian.h>
35#elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ )
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050036# if !defined( __MINGW32__ ) && !defined( _AIX )
Alexandre Lision51140e12013-12-02 10:54:09 -050037# include <endian.h>
38# if !defined( __BEOS__ )
39# include <byteswap.h>
40# endif
41# endif
42#endif
43
44/* Now attempt to set the define for platform byte order using any */
45/* of the four forms SYMBOL, _SYMBOL, __SYMBOL & __SYMBOL__, which */
46/* seem to encompass most endian symbol definitions */
47
48#if defined( BIG_ENDIAN ) && defined( LITTLE_ENDIAN )
49# if defined( BYTE_ORDER ) && BYTE_ORDER == BIG_ENDIAN
50# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
51# elif defined( BYTE_ORDER ) && BYTE_ORDER == LITTLE_ENDIAN
52# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
53# endif
54#elif defined( BIG_ENDIAN )
55# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
56#elif defined( LITTLE_ENDIAN )
57# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
58#endif
59
60#if defined( _BIG_ENDIAN ) && defined( _LITTLE_ENDIAN )
61# if defined( _BYTE_ORDER ) && _BYTE_ORDER == _BIG_ENDIAN
62# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
63# elif defined( _BYTE_ORDER ) && _BYTE_ORDER == _LITTLE_ENDIAN
64# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
65# endif
66#elif defined( _BIG_ENDIAN )
67# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
68#elif defined( _LITTLE_ENDIAN )
69# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
70#endif
71
72#if defined( __BIG_ENDIAN ) && defined( __LITTLE_ENDIAN )
73# if defined( __BYTE_ORDER ) && __BYTE_ORDER == __BIG_ENDIAN
74# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
75# elif defined( __BYTE_ORDER ) && __BYTE_ORDER == __LITTLE_ENDIAN
76# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
77# endif
78#elif defined( __BIG_ENDIAN )
79# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
80#elif defined( __LITTLE_ENDIAN )
81# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
82#endif
83
84#if defined( __BIG_ENDIAN__ ) && defined( __LITTLE_ENDIAN__ )
85# if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __BIG_ENDIAN__
86# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
87# elif defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __LITTLE_ENDIAN__
88# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
89# endif
90#elif defined( __BIG_ENDIAN__ )
91# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
92#elif defined( __LITTLE_ENDIAN__ )
93# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
94#endif
95
96/* if the platform byte order could not be determined, then try to */
97/* set this define using common machine defines */
98#if !defined(PLATFORM_BYTE_ORDER)
99
100#if defined( __alpha__ ) || defined( __alpha ) || defined( i386 ) || \
101 defined( __i386__ ) || defined( _M_I86 ) || defined( _M_IX86 ) || \
102 defined( __OS2__ ) || defined( sun386 ) || defined( __TURBOC__ ) || \
103 defined( vax ) || defined( vms ) || defined( VMS ) || \
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500104 defined( __VMS ) || defined( _M_X64 )
Alexandre Lision51140e12013-12-02 10:54:09 -0500105# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
106
107#elif defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \
108 defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \
109 defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \
110 defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \
111 defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \
112 defined( __VOS__ ) || defined( __TIGCC__ ) || defined( __TANDEM ) || \
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500113 defined( THINK_C ) || defined( __VMCMS__ ) || defined( _AIX )
Alexandre Lision51140e12013-12-02 10:54:09 -0500114# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
115
116#elif 0 /* **** EDIT HERE IF NECESSARY **** */
117# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
118#elif 0 /* **** EDIT HERE IF NECESSARY **** */
119# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
120#else
121# error Please edit lines 126 or 128 in brg_endian.h to set the platform byte order
122#endif
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500123
Alexandre Lision51140e12013-12-02 10:54:09 -0500124#endif
125
Alexandre Lision51140e12013-12-02 10:54:09 -0500126#endif