Extract common OMFS code into a library
[omfsprogs.git] / libomfs / config.h
blob7de8516b754f49b0847f4f52bd92a1390147dde6
1 #ifndef _CONFIG_H
2 #define _CONFIG_H
4 #include <inttypes.h>
6 typedef unsigned char u8;
7 typedef uint16_t u16;
8 typedef uint32_t u32;
9 typedef uint64_t u64;
11 typedef char s8;
12 typedef int16_t s16;
13 typedef int32_t s32;
14 typedef int64_t s64;
16 typedef u64 __be64;
17 typedef u32 __be32;
18 typedef u16 __be16;
20 #if __BYTE_ORDER == __BIG_ENDIAN
21 #define swap_be64(a) (a)
22 #define swap_be32(a) (a)
23 #define swap_be16(a) (a)
24 #else
25 #define swap_be64(a) __swap64(a)
26 #define swap_be32(a) __swap32(a)
27 #define swap_be16(a) __swap16(a)
28 #endif
30 static inline u16 __swap16(u16 a)
32 return (((a & 0xff00) >> 8) |
33 ((a & 0x00ff) << 8));
36 static inline u32 __swap32(u32 a)
38 return (((a & 0xff000000U) >> 24) |
39 ((a & 0x00ff0000U) >> 8) |
40 ((a & 0x0000ff00U) << 8) |
41 ((a & 0x000000ffU) << 24));
44 static inline u64 __swap64(u64 a)
46 return (((a & 0xff00000000000000ULL) >> 56) |
47 ((a & 0x00ff000000000000ULL) >> 40) |
48 ((a & 0x0000ff0000000000ULL) >> 24) |
49 ((a & 0x000000ff00000000ULL) >> 8) |
50 ((a & 0x00000000ff000000ULL) << 8) |
51 ((a & 0x0000000000ff0000ULL) << 24) |
52 ((a & 0x000000000000ff00ULL) << 40) |
53 ((a & 0x00000000000000ffULL) << 56));
57 #endif /* _CONFIG_H */