1 //-----------------------------------------------------------------------------
2 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // See LICENSE.txt for the text of the license.
15 //-----------------------------------------------------------------------------
16 // Endianness convenience functions
17 //-----------------------------------------------------------------------------
19 #ifndef PROXENDIAN_H__
20 #define PROXENDIAN_H__
25 # define HOST_LITTLE_ENDIAN
27 // Only some OSes include endian.h from sys/types.h, not Termux, so let's include endian.h directly
28 # if defined(__APPLE__)
29 # include <machine/endian.h>
33 # if !defined(BYTE_ORDER)
34 # if !defined(__BYTE_ORDER) || (__BYTE_ORDER != __LITTLE_ENDIAN && __BYTE_ORDER != __BIG_ENDIAN)
35 # error Define BYTE_ORDER to be equal to either LITTLE_ENDIAN or BIG_ENDIAN
37 # if __BYTE_ORDER == __LITTLE_ENDIAN
38 # define HOST_LITTLE_ENDIAN
41 # if BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN
42 # error Define BYTE_ORDER to be equal to either LITTLE_ENDIAN or BIG_ENDIAN
44 # if BYTE_ORDER == LITTLE_ENDIAN
45 # define HOST_LITTLE_ENDIAN
50 #ifdef HOST_LITTLE_ENDIAN
55 static inline uint16_t le16(uint16_t v
) {
61 static inline uint32_t le32(uint32_t v
) {
63 (le16(v
) << 16) | (le16(v
>> 16))
66 #endif // HOST_LITTLE_ENDIAN
68 #endif // PROXENDIAN_H__