Add byte-swapping macros to kernel.h
Unified · Split
| @@ -5,6 +5,8 @@ · 4 unmodified lines | ||
| 5 | 5 | #include <stddef.h> |
| 6 | 6 | #include <assert.h> |
| 7 | 7 | #include <linux/compiler.h> |
| 8 | +#include <endian.h> | |
| 9 | +#include <byteswap.h> | |
| 8 | 10 | |
| 9 | 11 | #ifndef UINT_MAX |
| 10 | 12 | #define UINT_MAX (~0U) |
| @@ -67,12 +69,33 @@ · 56 unmodified lines | ||
| 67 | 69 | #endif |
| 68 | 70 | #endif |
| 69 | 71 | |
| 70 | −/* | |
| 71 | − * Both need more care to handle endianness | |
| 72 | − * (Don't use bitmap_copy_le() for now) | |
| 73 | − */ | |
| 74 | −#define cpu_to_le64(x) (x) | |
| 75 | −#define cpu_to_le32(x) (x) | |
| 72 | +#if __BYTE_ORDER == __BIG_ENDIAN | |
| 73 | +#define cpu_to_le16 bswap_16 | |
| 74 | +#define cpu_to_le32 bswap_32 | |
| 75 | +#define cpu_to_le64 bswap_64 | |
| 76 | +#define le16_to_cpu bswap_16 | |
| 77 | +#define le32_to_cpu bswap_32 | |
| 78 | +#define le64_to_cpu bswap_64 | |
| 79 | +#define cpu_to_be16 | |
| 80 | +#define cpu_to_be32 | |
| 81 | +#define cpu_to_be64 | |
| 82 | +#define be16_to_cpu | |
| 83 | +#define be32_to_cpu | |
| 84 | +#define be64_to_cpu | |
| 85 | +#else | |
| 86 | +#define cpu_to_le16 | |
| 87 | +#define cpu_to_le32 | |
| 88 | +#define cpu_to_le64 | |
| 89 | +#define le16_to_cpu | |
| 90 | +#define le32_to_cpu | |
| 91 | +#define le64_to_cpu | |
| 92 | +#define cpu_to_be16 bswap_16 | |
| 93 | +#define cpu_to_be32 bswap_32 | |
| 94 | +#define cpu_to_be64 bswap_64 | |
| 95 | +#define be16_to_cpu bswap_16 | |
| 96 | +#define be32_to_cpu bswap_32 | |
| 97 | +#define be64_to_cpu bswap_64 | |
| 98 | +#endif | |
| 76 | 99 | |
| 77 | 100 | int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); |
| 78 | 101 | int scnprintf(char * buf, size_t size, const char * fmt, ...); |