From 306e855ad169f8a9acf32f7e08ae4bac6d131c67 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Fri, 24 Jun 2011 16:53:46 +0200 Subject: [PATCH] [Listener] Test the platform for endian.h The header is Glibc-specific. On BSD platforms, one have to use . (This was the occasion to improve the preprocessor code here.) --- owlps-listener/owlps-listener.h | 34 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/owlps-listener/owlps-listener.h b/owlps-listener/owlps-listener.h index 38e67a9..bb0f033 100644 --- a/owlps-listener/owlps-listener.h +++ b/owlps-listener/owlps-listener.h @@ -19,20 +19,22 @@ #include -#include +#include + +#ifdef __GLIBC__ +# include /* defines le*toh only in glibc >= 2.9. If we use an older - * version of glibc, or another libc (e.g. uClibc), we must define them - * manually. + * version of glibc, or another glibc-friendly libc (e.g. uClibc), we + * must define them manually. */ -#if __BYTE_ORDER == __LITTLE_ENDIAN -# ifndef le32toh -# define le32toh(x) (x) -# endif // le32toh -# ifndef le16toh -# define le16toh(x) (x) -# endif // le16toh -#else // __BYTE_ORDER == __LITTLE_ENDIAN -# if __BYTE_ORDER == __BIG_ENDIAN +# if __BYTE_ORDER == __LITTLE_ENDIAN +# ifndef le32toh +# define le32toh(x) (x) +# endif // le32toh +# ifndef le16toh +# define le16toh(x) (x) +# endif // le16toh +# elif __BYTE_ORDER == __BIG_ENDIAN # ifndef le32toh # include # define le32toh(x) bswap_32(x) @@ -41,8 +43,12 @@ # include # define le16toh(x) bswap_16(x) # endif // le16toh -# endif // __BYTE_ORDER == __BIG_ENDIAN -#endif // __BYTE_ORDER == __LITTLE_ENDIAN +# else // __BYTE_ORDER +# error "This program does not handle strange architectures." +# endif // __BYTE_ORDER +#else // __GLIBC__ +# include +#endif // __GLIBC__ /* Arguments & program configuration */