diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2019-05-08 14:08:02 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2019-05-08 14:08:02 +0200 |
commit | 2c20fae8a1fd28854aeeee8e070f70f763bad848 (patch) | |
tree | 3d9ebfc2d3fc860e4dd3d56baa5911ebea7ae8f0 | |
parent | 8fc776833f83c417d57c43f41479bc034c3863c6 (diff) | |
download | fbida-2c20fae8a1fd28854aeeee8e070f70f763bad848.tar.gz |
add byteorder.h
-rw-r--r-- | byteorder.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/byteorder.h b/byteorder.h new file mode 100644 index 0000000..7b2f099 --- /dev/null +++ b/byteorder.h @@ -0,0 +1,22 @@ +#include <sys/types.h> + +#ifndef __BYTE_ORDER +# ifndef BYTE_ORDER +# error unknown byteorder +# endif +# define __BYTE_ORDER BYTE_ORDER +# define __LITTLE_ENDIAN LITTLE_ENDIAN +# define __BIG_ENDIAN BIG_ENDIAN +#endif + +#if BYTE_ORDER == LITTLE_ENDIAN +# define le16_to_cpu(x) (x) +# define le32_to_cpu(x) (x) +#elif BYTE_ORDER == BIG_ENDIAN +# define le16_to_cpu(x) (((x>>8) & 0x00ff) |\ + ((x<<8) & 0xff00)) +# define le32_to_cpu(x) (((x>>24) & 0x000000ff) |\ + ((x>>8) & 0x0000ff00) |\ + ((x<<8) & 0x00ff0000) |\ + ((x<<24) & 0xff000000)) +#endif |