From: Florian Forster Date: Mon, 31 Mar 2008 13:51:13 +0000 (+0200) Subject: src/common.c: Make really sure BYTE_ORDER and BIG_ENDIAN are defined. X-Git-Tag: collectd-4.2.7~14 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c42a2315b0b8fa86264c8202f661bef8e683ed20;p=collectd.git src/common.c: Make really sure BYTE_ORDER and BIG_ENDIAN are defined. If both, BYTE_ORDER and BIG_ENDIAN, are undefined, the statement #if BYTE_ORDER == BIG_ENDIAN will be evaluated to `true', which may cause `ntohll' and `htonll' to behave weird. --- diff --git a/configure.in b/configure.in index 17462a12..e68d97e2 100644 --- a/configure.in +++ b/configure.in @@ -55,7 +55,7 @@ AC_HEADER_STDC AC_HEADER_SYS_WAIT AC_HEADER_DIRENT -AC_CHECK_HEADERS(stdint.h stdio.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h sys/ioctl.h) +AC_CHECK_HEADERS(stdint.h stdio.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h sys/ioctl.h endian.h) # For ping library AC_CHECK_HEADERS(netinet/in_systm.h, [], [], diff --git a/src/collectd.h b/src/collectd.h index 9951d8a9..59dc5d20 100644 --- a/src/collectd.h +++ b/src/collectd.h @@ -122,6 +122,24 @@ # endif /* !defined(isnan) */ #endif /* NAN_ZERO_ZERO */ +#if HAVE_ENDIAN_H +# include +#endif + +#ifndef BYTE_ORDER +# ifdef __BYTE_ORDER +# define BYTE_ORDER __BYTE_ORDER +# endif +#endif +#ifndef BIG_ENDIAN +# ifdef __BIG_ENDIAN +# define BIG_ENDIAN __BIG_ENDIAN +# endif +#endif +#if !defined(BYTE_ORDER) || !defined(BIG_ENDIAN) +# error "Cannot determine byte order" +#endif + #if HAVE_DIRENT_H # include # define NAMLEN(dirent) strlen((dirent)->d_name) diff --git a/src/common.c b/src/common.c index f93cf769..9314d814 100644 --- a/src/common.c +++ b/src/common.c @@ -24,6 +24,7 @@ # include "config.h" #endif +#include "collectd.h" #include "common.h" #include "plugin.h" @@ -554,7 +555,7 @@ long long get_kstat_value (kstat_t *ksp, char *name) unsigned long long ntohll (unsigned long long n) { -#if __BYTE_ORDER == __BIG_ENDIAN +#if BYTE_ORDER == BIG_ENDIAN return (n); #else return (((unsigned long long) ntohl (n)) << 32) + ntohl (n >> 32); @@ -563,7 +564,7 @@ unsigned long long ntohll (unsigned long long n) unsigned long long htonll (unsigned long long n) { -#if __BYTE_ORDER == __BIG_ENDIAN +#if BYTE_ORDER == BIG_ENDIAN return (n); #else return (((unsigned long long) htonl (n)) << 32) + htonl (n >> 32);