+#ifndef FIO_OS_HAS_CTIME_R
+#define os_ctime_r(x, y, z) (void) ctime_r((x), (y))
+#endif
+
+#ifdef FIO_USE_GENERIC_SWAP
+static inline uint16_t fio_swap16(uint16_t val)
+{
+ return (val << 8) | (val >> 8);
+}
+
+static inline uint32_t fio_swap32(uint32_t val)
+{
+ val = ((val & 0xff00ff00UL) >> 8) | ((val & 0x00ff00ffUL) << 8);
+
+ return (val >> 16) | (val << 16);
+}
+
+static inline uint64_t fio_swap64(uint64_t val)
+{
+ val = ((val & 0xff00ff00ff00ff00ULL) >> 8) |
+ ((val & 0x00ff00ff00ff00ffULL) << 8);
+ val = ((val & 0xffff0000ffff0000ULL) >> 16) |
+ ((val & 0x0000ffff0000ffffULL) << 16);
+
+ return (val >> 32) | (val << 32);
+}
+#endif
+
+#ifndef FIO_HAVE_BYTEORDER_FUNCS
+#ifdef CONFIG_LITTLE_ENDIAN
+#define __le16_to_cpu(x) (x)
+#define __le32_to_cpu(x) (x)
+#define __le64_to_cpu(x) (x)
+#define __cpu_to_le16(x) (x)
+#define __cpu_to_le32(x) (x)
+#define __cpu_to_le64(x) (x)
+#else
+#define __le16_to_cpu(x) fio_swap16(x)
+#define __le32_to_cpu(x) fio_swap32(x)
+#define __le64_to_cpu(x) fio_swap64(x)
+#define __cpu_to_le16(x) fio_swap16(x)
+#define __cpu_to_le32(x) fio_swap32(x)
+#define __cpu_to_le64(x) fio_swap64(x)
+#endif
+#endif /* FIO_HAVE_BYTEORDER_FUNCS */
+
+#ifdef FIO_INTERNAL
+#define le16_to_cpu(val) ({ \
+ typecheck(uint16_t, val); \
+ __le16_to_cpu(val); \
+})
+#define le32_to_cpu(val) ({ \
+ typecheck(uint32_t, val); \
+ __le32_to_cpu(val); \
+})
+#define le64_to_cpu(val) ({ \
+ typecheck(uint64_t, val); \
+ __le64_to_cpu(val); \
+})
+#endif
+
+#define cpu_to_le16(val) ({ \
+ typecheck(uint16_t, val); \
+ __cpu_to_le16(val); \
+})
+#define cpu_to_le32(val) ({ \
+ typecheck(uint32_t, val); \
+ __cpu_to_le32(val); \
+})
+#define cpu_to_le64(val) ({ \
+ typecheck(uint64_t, val); \
+ __cpu_to_le64(val); \
+})
+