3 Endianness stuff. exFAT uses little-endian byte order.
5 Copyright (C) 2009, 2010 Andrew Nayenko
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef BYTEORDER_H_INCLUDED
22 #define BYTEORDER_H_INCLUDED
27 #include <machine/endian.h>
28 #include <libkern/OSByteOrder.h>
29 #define bswap_16(x) OSSwapInt16(x)
30 #define bswap_32(x) OSSwapInt32(x)
31 #define bswap_64(x) OSSwapInt64(x)
32 /* GNU endian macros have "__" prefix, BSD ones don't */
33 #define __BYTE_ORDER BYTE_ORDER
34 #define __LITTLE_ENDIAN LITTLE_ENDIAN
35 #define __BIG_ENDIAN BIG_ENDIAN
41 typedef struct { uint16_t __u16; } le16_t;
42 typedef struct { uint32_t __u32; } le32_t;
43 typedef struct { uint64_t __u64; } le64_t;
45 #if __BYTE_ORDER == __LITTLE_ENDIAN
46 static inline uint16_t le16_to_cpu(le16_t v) { return v.__u16; }
47 static inline uint32_t le32_to_cpu(le32_t v) { return v.__u32; }
48 static inline uint64_t le64_to_cpu(le64_t v) { return v.__u64; }
50 static inline le16_t cpu_to_le16(uint16_t v) { le16_t t = {v}; return t; }
51 static inline le32_t cpu_to_le32(uint32_t v) { le32_t t = {v}; return t; }
52 static inline le64_t cpu_to_le64(uint64_t v) { le64_t t = {v}; return t; }
53 #elif __BYTE_ORDER == __BIG_ENDIAN
54 static inline uint16_t le16_to_cpu(le16_t v) { return bswap_16(v.__u16); }
55 static inline uint32_t le32_to_cpu(le32_t v) { return bswap_32(v.__u32); }
56 static inline uint64_t le64_to_cpu(le64_t v) { return bswap_64(v.__u64); }
58 static inline le16_t cpu_to_le16(uint16_t v)
59 { le16_t t = {bswap_16(v)}; return t; }
60 static inline le32_t cpu_to_le32(uint32_t v)
61 { le32_t t = {bswap_32(v)}; return t; }
62 static inline le64_t cpu_to_le64(uint64_t v)
63 { le64_t t = {bswap_64(v)}; return t; }
65 #error Wow! You have a PDP machine?!
68 #endif /* ifndef BYTEORDER_H_INCLUDED */