style
[RRG-proxmark3.git] / client / src / proxendian.h
blobd258d2ce880fde7f11bc0b96fc46bf75d649eabe
1 //-----------------------------------------------------------------------------
2 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
3 //
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.
8 //
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__
22 #include "common.h"
24 #ifdef _WIN32
25 # define HOST_LITTLE_ENDIAN
26 #else
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>
30 # else
31 # include <endian.h>
32 # endif
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
36 # endif
37 # if __BYTE_ORDER == __LITTLE_ENDIAN
38 # define HOST_LITTLE_ENDIAN
39 # endif
40 # else
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
43 # endif
44 # if BYTE_ORDER == LITTLE_ENDIAN
45 # define HOST_LITTLE_ENDIAN
46 # endif
47 # endif
48 #endif
50 #ifdef HOST_LITTLE_ENDIAN
51 # define le16(x) (x)
52 # define le32(x) (x)
53 #else
55 static inline uint16_t le16(uint16_t v) {
56 return (uint16_t)(
57 (v >> 8) | (v << 8)
61 static inline uint32_t le32(uint32_t v) {
62 return (uint32_t)(
63 (le16(v) << 16) | (le16(v >> 16))
66 #endif // HOST_LITTLE_ENDIAN
68 #endif // PROXENDIAN_H__