OSDN Git Service

Use safer names for byteorder stuff.
[android-x86/external-exfat.git] / libexfat / byteorder.h
1 /*
2         byteorder.h (12.01.10)
3         Endianness stuff. exFAT uses little-endian byte order.
4
5         Copyright (C) 2010-2013  Andrew Nayenko
6
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.
11
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.
16
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/>.
19 */
20
21 #ifndef BYTEORDER_H_INCLUDED
22 #define BYTEORDER_H_INCLUDED
23
24 #include <stdint.h>
25 #include "platform.h"
26
27 typedef struct { uint16_t __u16; } le16_t;
28 typedef struct { uint32_t __u32; } le32_t;
29 typedef struct { uint64_t __u64; } le64_t;
30
31 #if EXFAT_BYTE_ORDER == EXFAT_LITTLE_ENDIAN
32 static inline uint16_t le16_to_cpu(le16_t v) { return v.__u16; }
33 static inline uint32_t le32_to_cpu(le32_t v) { return v.__u32; }
34 static inline uint64_t le64_to_cpu(le64_t v) { return v.__u64; }
35
36 static inline le16_t cpu_to_le16(uint16_t v) { le16_t t = {v}; return t; }
37 static inline le32_t cpu_to_le32(uint32_t v) { le32_t t = {v}; return t; }
38 static inline le64_t cpu_to_le64(uint64_t v) { le64_t t = {v}; return t; }
39 #elif EXFAT_BYTE_ORDER == EXFAT_BIG_ENDIAN
40 static inline uint16_t le16_to_cpu(le16_t v)
41         { return exfat_bswap16(v.__u16); }
42 static inline uint32_t le32_to_cpu(le32_t v)
43         { return exfat_bswap32(v.__u32); }
44 static inline uint64_t le64_to_cpu(le64_t v)
45         { return exfat_bswap64(v.__u64); }
46
47 static inline le16_t cpu_to_le16(uint16_t v)
48         { le16_t t = {exfat_bswap16(v)}; return t; }
49 static inline le32_t cpu_to_le32(uint32_t v)
50         { le32_t t = {exfat_bswap32(v)}; return t; }
51 static inline le64_t cpu_to_le64(uint64_t v)
52         { le64_t t = {exfat_bswap64(v)}; return t; }
53 #else
54 #error Wow! You have a PDP machine?!
55 #endif
56
57 #endif /* ifndef BYTEORDER_H_INCLUDED */