IBR-DTNSuite  0.8
ibrcommon/ibrcommon/ssl/gcm/brg_endian.h
Go to the documentation of this file.
00001 /*
00002  ---------------------------------------------------------------------------
00003  Copyright (c) 1998-2006, Brian Gladman, Worcester, UK. All rights reserved.
00004 
00005  LICENSE TERMS
00006 
00007  The free distribution and use of this software in both source and binary
00008  form is allowed (with or without changes) provided that:
00009 
00010    1. distributions of this source code include the above copyright
00011       notice, this list of conditions and the following disclaimer;
00012 
00013    2. distributions in binary form include the above copyright
00014       notice, this list of conditions and the following disclaimer
00015       in the documentation and/or other associated materials;
00016 
00017    3. the copyright holder's name is not used to endorse products
00018       built using this software without specific written permission.
00019 
00020  ALTERNATIVELY, provided that this notice is retained in full, this product
00021  may be distributed under the terms of the GNU General Public License (GPL),
00022  in which case the provisions of the GPL apply INSTEAD OF those given above.
00023 
00024  DISCLAIMER
00025 
00026  This software is provided 'as is' with no explicit or implied warranties
00027  in respect of its properties, including, but not limited to, correctness
00028  and/or fitness for purpose.
00029  ---------------------------------------------------------------------------
00030  Issue 20/10/2006
00031 */
00032 
00033 #ifndef BRG_ENDIAN_H
00034 #define BRG_ENDIAN_H
00035 
00036 #define IS_BIG_ENDIAN      4321 /* byte 0 is most significant (mc68k) */
00037 #define IS_LITTLE_ENDIAN   1234 /* byte 0 is least significant (i386) */
00038 
00039 /* Include files where endian defines and byteswap functions may reside */
00040 #if defined( __sun__ )
00041 #  include <sys/isa_defs.h>
00042 #elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ )
00043 #  include <sys/endian.h>
00044 #elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \
00045       defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ )
00046 #  include <machine/endian.h>
00047 #elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ )
00048 #  if !defined( __MINGW32__ )
00049 #    include <endian.h>
00050 #    if !defined( __BEOS__ )
00051 #      include <byteswap.h>
00052 #    endif
00053 #  endif
00054 #endif
00055 
00056 /* Now attempt to set the define for platform byte order using any  */
00057 /* of the four forms SYMBOL, _SYMBOL, __SYMBOL & __SYMBOL__, which  */
00058 /* seem to encompass most endian symbol definitions                 */
00059 
00060 #if defined( BIG_ENDIAN ) && defined( LITTLE_ENDIAN )
00061 #  if defined( BYTE_ORDER ) && BYTE_ORDER == BIG_ENDIAN
00062 #    define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
00063 #  elif defined( BYTE_ORDER ) && BYTE_ORDER == LITTLE_ENDIAN
00064 #    define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
00065 #  endif
00066 #elif defined( BIG_ENDIAN )
00067 #  define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
00068 #elif defined( LITTLE_ENDIAN )
00069 #  define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
00070 #endif
00071 
00072 #if defined( _BIG_ENDIAN ) && defined( _LITTLE_ENDIAN )
00073 #  if defined( _BYTE_ORDER ) && _BYTE_ORDER == _BIG_ENDIAN
00074 #    define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
00075 #  elif defined( _BYTE_ORDER ) && _BYTE_ORDER == _LITTLE_ENDIAN
00076 #    define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
00077 #  endif
00078 #elif defined( _BIG_ENDIAN )
00079 #  define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
00080 #elif defined( _LITTLE_ENDIAN )
00081 #  define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
00082 #endif
00083 
00084 #if defined( __BIG_ENDIAN ) && defined( __LITTLE_ENDIAN )
00085 #  if defined( __BYTE_ORDER ) && __BYTE_ORDER == __BIG_ENDIAN
00086 #    define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
00087 #  elif defined( __BYTE_ORDER ) && __BYTE_ORDER == __LITTLE_ENDIAN
00088 #    define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
00089 #  endif
00090 #elif defined( __BIG_ENDIAN )
00091 #  define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
00092 #elif defined( __LITTLE_ENDIAN )
00093 #  define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
00094 #endif
00095 
00096 #if defined( __BIG_ENDIAN__ ) && defined( __LITTLE_ENDIAN__ )
00097 #  if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __BIG_ENDIAN__
00098 #    define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
00099 #  elif defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __LITTLE_ENDIAN__
00100 #    define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
00101 #  endif
00102 #elif defined( __BIG_ENDIAN__ )
00103 #  define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
00104 #elif defined( __LITTLE_ENDIAN__ )
00105 #  define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
00106 #endif
00107 
00108 /*  if the platform byte order could not be determined, then try to */
00109 /*  set this define using common machine defines                    */
00110 #if !defined(PLATFORM_BYTE_ORDER)
00111 
00112 #if   defined( __alpha__ ) || defined( __alpha ) || defined( i386 )       || \
00113       defined( __i386__ )  || defined( _M_I86 )  || defined( _M_IX86 )    || \
00114       defined( __OS2__ )   || defined( sun386 )  || defined( __TURBOC__ ) || \
00115       defined( vax )       || defined( vms )     || defined( VMS )        || \
00116       defined( __VMS )     || defined( _M_X64 )
00117 #  define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
00118 
00119 #elif defined( AMIGA )   || defined( applec )    || defined( __AS400__ )  || \
00120       defined( _CRAY )   || defined( __hppa )    || defined( __hp9000 )   || \
00121       defined( ibm370 )  || defined( mc68000 )   || defined( m68k )       || \
00122       defined( __MRC__ ) || defined( __MVS__ )   || defined( __MWERKS__ ) || \
00123       defined( sparc )   || defined( __sparc)    || defined( SYMANTEC_C ) || \
00124       defined( __VOS__ ) || defined( __TIGCC__ ) || defined( __TANDEM )   || \
00125       defined( THINK_C ) || defined( __VMCMS__ )
00126 #  define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
00127 
00128 #elif 0     /* **** EDIT HERE IF NECESSARY **** */
00129 #  define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
00130 #elif 0     /* **** EDIT HERE IF NECESSARY **** */
00131 #  define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
00132 #else
00133 #  error Please edit lines 126 or 128 in brg_endian.h to set the platform byte order
00134 #endif
00135 
00136 #endif
00137 
00138 #endif