IBR-DTNSuite  0.10
brg_endian.h
Go to the documentation of this file.
1 /*
2  ---------------------------------------------------------------------------
3  Copyright (c) 1998-2006, Brian Gladman, Worcester, UK. All rights reserved.
4 
5  LICENSE TERMS
6 
7  The free distribution and use of this software in both source and binary
8  form is allowed (with or without changes) provided that:
9 
10  1. distributions of this source code include the above copyright
11  notice, this list of conditions and the following disclaimer;
12 
13  2. distributions in binary form include the above copyright
14  notice, this list of conditions and the following disclaimer
15  in the documentation and/or other associated materials;
16 
17  3. the copyright holder's name is not used to endorse products
18  built using this software without specific written permission.
19 
20  ALTERNATIVELY, provided that this notice is retained in full, this product
21  may be distributed under the terms of the GNU General Public License (GPL),
22  in which case the provisions of the GPL apply INSTEAD OF those given above.
23 
24  DISCLAIMER
25 
26  This software is provided 'as is' with no explicit or implied warranties
27  in respect of its properties, including, but not limited to, correctness
28  and/or fitness for purpose.
29  ---------------------------------------------------------------------------
30  Issue 20/10/2006
31 */
32 
33 #ifndef BRG_ENDIAN_H
34 #define BRG_ENDIAN_H
35 
36 #define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */
37 #define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */
38 
39 /* Include files where endian defines and byteswap functions may reside */
40 #if defined( __sun__ )
41 # include <sys/isa_defs.h>
42 #elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ )
43 # include <sys/endian.h>
44 #elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \
45  defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ )
46 # include <machine/endian.h>
47 #elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ )
48 # if !defined( __MINGW32__ )
49 # include <endian.h>
50 # if !defined( __BEOS__ )
51 # include <byteswap.h>
52 # endif
53 # endif
54 #endif
55 
56 /* Now attempt to set the define for platform byte order using any */
57 /* of the four forms SYMBOL, _SYMBOL, __SYMBOL & __SYMBOL__, which */
58 /* seem to encompass most endian symbol definitions */
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 defined( __BIG_ENDIAN__ ) && defined( __LITTLE_ENDIAN__ )
97 # if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __BIG_ENDIAN__
98 # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
99 # elif defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __LITTLE_ENDIAN__
100 # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
101 # endif
102 #elif defined( __BIG_ENDIAN__ )
103 # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
104 #elif defined( __LITTLE_ENDIAN__ )
105 # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
106 #endif
107 
108 /* if the platform byte order could not be determined, then try to */
109 /* set this define using common machine defines */
110 #if !defined(PLATFORM_BYTE_ORDER)
111 
112 #if defined( __alpha__ ) || defined( __alpha ) || defined( i386 ) || \
113  defined( __i386__ ) || defined( _M_I86 ) || defined( _M_IX86 ) || \
114  defined( __OS2__ ) || defined( sun386 ) || defined( __TURBOC__ ) || \
115  defined( vax ) || defined( vms ) || defined( VMS ) || \
116  defined( __VMS ) || defined( _M_X64 )
117 # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
118 
119 #elif defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \
120  defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \
121  defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \
122  defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \
123  defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \
124  defined( __VOS__ ) || defined( __TIGCC__ ) || defined( __TANDEM ) || \
125  defined( THINK_C ) || defined( __VMCMS__ )
126 # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
127 
128 #elif 0 /* **** EDIT HERE IF NECESSARY **** */
129 # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
130 #elif 0 /* **** EDIT HERE IF NECESSARY **** */
131 # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
132 #else
133 # error Please edit lines 126 or 128 in brg_endian.h to set the platform byte order
134 #endif
135 
136 #endif
137 
138 #endif