No Description

brg_endian.h 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. ---------------------------------------------------------------------------
  3. Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved.
  4. The redistribution and use of this software (with or without changes)
  5. is allowed without the payment of fees or royalties provided that:
  6. source code distributions include the above copyright notice, this
  7. list of conditions and the following disclaimer;
  8. binary distributions include the above copyright notice, this list
  9. of conditions and the following disclaimer in their documentation.
  10. This software is provided 'as is' with no explicit or implied warranties
  11. in respect of its operation, including, but not limited to, correctness
  12. and fitness for purpose.
  13. ---------------------------------------------------------------------------
  14. Issue Date: 20/12/2007
  15. */
  16. #ifndef _BRG_ENDIAN_H
  17. #define _BRG_ENDIAN_H
  18. #define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */
  19. #define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */
  20. /* Include files where endian defines and byteswap functions may reside */
  21. #if defined( __sun )
  22. # include <sys/isa_defs.h>
  23. #elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ )
  24. # include <sys/endian.h>
  25. #elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \
  26. defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ )
  27. # include <machine/endian.h>
  28. #elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ )
  29. # if !defined( __MINGW32__ ) && !defined( _AIX )
  30. # include <endian.h>
  31. # if !defined( __BEOS__ )
  32. # include <byteswap.h>
  33. # endif
  34. # endif
  35. #endif
  36. /* Now attempt to set the define for platform byte order using any */
  37. /* of the four forms SYMBOL, _SYMBOL, __SYMBOL & __SYMBOL__, which */
  38. /* seem to encompass most endian symbol definitions */
  39. #if defined( BIG_ENDIAN ) && defined( LITTLE_ENDIAN )
  40. # if defined( BYTE_ORDER ) && BYTE_ORDER == BIG_ENDIAN
  41. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  42. # elif defined( BYTE_ORDER ) && BYTE_ORDER == LITTLE_ENDIAN
  43. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  44. # endif
  45. #elif defined( BIG_ENDIAN )
  46. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  47. #elif defined( LITTLE_ENDIAN )
  48. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  49. #endif
  50. #if defined( _BIG_ENDIAN ) && defined( _LITTLE_ENDIAN )
  51. # if defined( _BYTE_ORDER ) && _BYTE_ORDER == _BIG_ENDIAN
  52. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  53. # elif defined( _BYTE_ORDER ) && _BYTE_ORDER == _LITTLE_ENDIAN
  54. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  55. # endif
  56. #elif defined( _BIG_ENDIAN )
  57. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  58. #elif defined( _LITTLE_ENDIAN )
  59. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  60. #endif
  61. #if defined( __BIG_ENDIAN ) && defined( __LITTLE_ENDIAN )
  62. # if defined( __BYTE_ORDER ) && __BYTE_ORDER == __BIG_ENDIAN
  63. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  64. # elif defined( __BYTE_ORDER ) && __BYTE_ORDER == __LITTLE_ENDIAN
  65. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  66. # endif
  67. #elif defined( __BIG_ENDIAN )
  68. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  69. #elif defined( __LITTLE_ENDIAN )
  70. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  71. #endif
  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. /* if the platform byte order could not be determined, then try to */
  84. /* set this define using common machine defines */
  85. #if !defined(PLATFORM_BYTE_ORDER)
  86. #if defined( __alpha__ ) || defined( __alpha ) || defined( i386 ) || \
  87. defined( __i386__ ) || defined( _M_I86 ) || defined( _M_IX86 ) || \
  88. defined( __OS2__ ) || defined( sun386 ) || defined( __TURBOC__ ) || \
  89. defined( vax ) || defined( vms ) || defined( VMS ) || \
  90. defined( __VMS ) || defined( _M_X64 )
  91. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  92. #elif defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \
  93. defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \
  94. defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \
  95. defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \
  96. defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \
  97. defined( __VOS__ ) || defined( __TIGCC__ ) || defined( __TANDEM ) || \
  98. defined( THINK_C ) || defined( __VMCMS__ ) || defined( _AIX )
  99. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  100. #elif 0 /* **** EDIT HERE IF NECESSARY **** */
  101. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  102. #elif 0 /* **** EDIT HERE IF NECESSARY **** */
  103. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  104. #else
  105. # error Please edit lines 126 or 128 in brg_endian.h to set the platform byte order
  106. #endif
  107. #endif
  108. #endif