src/common.c: Make really sure BYTE_ORDER and BIG_ENDIAN are defined.
authorFlorian Forster <octo@huhu.verplant.org>
Mon, 31 Mar 2008 13:51:13 +0000 (15:51 +0200)
committerFlorian Forster <octo@huhu.verplant.org>
Mon, 31 Mar 2008 13:51:13 +0000 (15:51 +0200)
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.

configure.in
src/collectd.h
src/common.c

index 17462a1..e68d97e 100644 (file)
@@ -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, [], [],
index 9951d8a..59dc5d2 100644 (file)
 # endif /* !defined(isnan) */
 #endif /* NAN_ZERO_ZERO */
 
+#if HAVE_ENDIAN_H
+# include <endian.h>
+#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 <dirent.h>
 # define NAMLEN(dirent) strlen((dirent)->d_name)
index f93cf76..9314d81 100644 (file)
@@ -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);