diff options
Diffstat (limited to 'src/bytorder.h')
| -rw-r--r-- | src/bytorder.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/bytorder.h b/src/bytorder.h new file mode 100644 index 0000000..cb8231e --- /dev/null +++ b/src/bytorder.h @@ -0,0 +1,52 @@ +#if defined(ALF_LSB_FIRST) && defined(ALF_MSB_FIRST) +# error Cannot define both ALF_LSB_FIRST and ALF_MSB_FIRST +#endif + +#if defined(ALF_LSB_FIRST) || defined(ALF_MSB_FIRST) +# define ALF_ENDIAN_OK +#endif + +/* try to get the byte order on this platform. + if we succeed, either ALF_LSB_FIRST or ALF_MSB_FIRST will + defined, and so will ALF_ENDIAN_OK. */ + +#ifndef ALF_ENDIAN_OK +# if defined(__BYTE_ORDER__) +# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# define ALF_LSB_FIRST +# define ALF_ENDIAN_OK +# else +# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define ALF_MSB_FIRST +# define ALF_ENDIAN_OK +# endif +# endif +# endif +#endif + +#ifndef ALF_ENDIAN_OK +# if defined(__LITTLE_ENDIAN__) +# define ALF_LSB_FIRST +# define ALF_ENDIAN_OK +# else +# if defined(__BIG_ENDIAN__) +# define ALF_MSB_FIRST +# define ALF_ENDIAN_OK +# endif +# endif +#endif + +#ifdef ALF_ENDIAN_OK +# ifdef ALF_LSB_FIRST +# define HIBYTE 2 +# define MIDBYTE 1 +# define LOBYTE 0 +# else +# define HIBYTE 1 +# define MIDBYTE 2 +# define LOBYTE 3 +# endif +#else +# warning Cannot determine endianness, falling back to safe but slow append_bit(). +# warning Recompile with -DALF_LSB_FIRST or -DALF_MSB_FIRST. +#endif |
