Merge pull request #107 from p-l-/fix-hfmf
[legacy-proxmark3.git] / client / proxendian.h
blob866ea250714719da8485e34a95f9c50c2732a0d0
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 Hector Martin "marcan" <marcan@marcansoft.com>
3 //
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
6 // the license.
7 //-----------------------------------------------------------------------------
8 // Endianness convenience functions
9 //-----------------------------------------------------------------------------
11 #ifndef PROXENDIAN_H__
12 #define PROXENDIAN_H__
14 #include <stdint.h>
16 #ifdef _WIN32
17 # define HOST_LITTLE_ENDIAN
18 #else
19 # include <sys/types.h>
20 # ifndef BYTE_ORDER
21 # define BYTE_ORDER __BYTE_ORDER
22 # define LITTLE_ENDIAN __LITTLE_ENDIAN
23 # define BIG_ENDIAN __BIG_ENDIAN
24 # endif
25 # if !defined(BYTE_ORDER) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN)
26 # error Define BYTE_ORDER to be equal to either LITTLE_ENDIAN or BIG_ENDIAN
27 # endif
28 # if BYTE_ORDER == LITTLE_ENDIAN
29 # define HOST_LITTLE_ENDIAN
30 # endif
31 #endif
33 #ifdef HOST_LITTLE_ENDIAN
34 # define le16(x) (x)
35 # define le32(x) (x)
36 #else
38 static inline uint16_t le16(uint16_t v)
40 return (v>>8) | (v<<8);
43 static inline uint32_t le32(uint32_t v)
45 return (le16(v)<<16) | (le16(v>>16));
47 #endif // HOST_LITTLE_ENDIAN
49 #endif // PROXENDIAN_H__