From e6624fe5086dc3d86a3947e396ab7c52c0cdddb8 Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Fri, 12 Oct 2007 15:16:51 +0100 Subject: [PATCH] Add 16 bit endianness functions --- libfprint/fp_internal.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index 69af87d..23213b6 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -24,6 +24,16 @@ #include +#ifdef __DARWIN_NULL +/* Darwin does endianness slightly differently */ +#include +#define __BYTE_ORDER BYTE_ORDER +#define __LITTLE_ENDIAN LITTLE_ENDIAN +#define __BIG_ENDIAN BIG_ENDIAN +#else /* Linux */ +#include +#endif + #include #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a)) @@ -92,5 +102,20 @@ struct fp_print_data *fpi_print_data_new(struct fp_driver *drv, size_t length); unsigned char *fpi_print_data_get_buffer(struct fp_print_data *data); int fpi_print_data_compatible(struct fp_dev *dev, struct fp_print_data *data); +#define bswap16(x) (((x & 0xff) << 8) | (x >> 8)) +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define cpu_to_le16(x) (x) +#define le16_to_cpu(x) (x) +#define cpu_to_be16(x) bswap16(x) +#define be16_to_cpu(x) bswap16(x) +#elif __BYTE_ORDER == __BIG_ENDIAN +#define cpu_to_le16(x) bswap16(x) +#define le16_to_cpu(x) bswap16(x) +#define cpu_to_be16(x) (x) +#define be16_to_cpu(x) (x) +#else +#error "Unrecognized endianness" +#endif + #endif