summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvkalintiris <vasilis@netdata.cloud>2023-11-29 11:05:41 +0200
committerGitHub <noreply@github.com>2023-11-29 11:05:41 +0200
commit4f6fe91a6d3265fecae01c9d3ee136d2d48208db (patch)
tree61d651bbeeae2f5afd088fc294d700683fae28f9
parentf68b01fd0ab2997c6d464010197b7dd66561d2d5 (diff)
Fix builds on macOS due to missing endianness functions (#16489)
-rw-r--r--CMakeLists.txt1
-rw-r--r--Makefile.am1
-rw-r--r--libnetdata/endian.h32
-rw-r--r--libnetdata/os.h1
4 files changed, 35 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6d6752ea7c..5d70d470bd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -465,6 +465,7 @@ set(LIBNETDATA_FILES
libnetdata/log/log.h
libnetdata/os.c
libnetdata/os.h
+ libnetdata/endian.h
libnetdata/onewayalloc/onewayalloc.c
libnetdata/onewayalloc/onewayalloc.h
libnetdata/popen/popen.c
diff --git a/Makefile.am b/Makefile.am
index eb9c8ff7d3..addb9c9f3e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -193,6 +193,7 @@ LIBNETDATA_FILES = \
libnetdata/procfile/procfile.h \
libnetdata/os.c \
libnetdata/os.h \
+ libnetdata/endian.h \
libnetdata/simple_pattern/simple_pattern.c \
libnetdata/simple_pattern/simple_pattern.h \
libnetdata/socket/socket.c \
diff --git a/libnetdata/endian.h b/libnetdata/endian.h
new file mode 100644
index 0000000000..66f75cb1ad
--- /dev/null
+++ b/libnetdata/endian.h
@@ -0,0 +1,32 @@
+#ifndef LIBNETDATA_ENDIAN_H
+#define LIBNETDATA_ENDIAN_H
+
+/** compatibility header for endian.h
+ * This is a simple compatibility shim to convert
+ * BSD/Linux endian macros to the Mac OS X equivalents.
+ * It is public domain.
+ * */
+
+#ifndef __APPLE__
+#error "This header file (endian.h) is MacOS X specific.\n"
+#endif /* __APPLE__ */
+
+
+#include <libkern/OSByteOrder.h>
+
+#define htobe16(x) OSSwapHostToBigInt16(x)
+#define htole16(x) OSSwapHostToLittleInt16(x)
+#define be16toh(x) OSSwapBigToHostInt16(x)
+#define le16toh(x) OSSwapLittleToHostInt16(x)
+
+#define htobe32(x) OSSwapHostToBigInt32(x)
+#define htole32(x) OSSwapHostToLittleInt32(x)
+#define be32toh(x) OSSwapBigToHostInt32(x)
+#define le32toh(x) OSSwapLittleToHostInt32(x)
+
+#define htobe64(x) OSSwapHostToBigInt64(x)
+#define htole64(x) OSSwapHostToLittleInt64(x)
+#define be64toh(x) OSSwapBigToHostInt64(x)
+#define le64toh(x) OSSwapLittleToHostInt64(x)
+
+#endif /* LIBNETDATA_ENDIAN_H */
diff --git a/libnetdata/os.h b/libnetdata/os.h
index 3cda79ed7b..197548b0da 100644
--- a/libnetdata/os.h
+++ b/libnetdata/os.h
@@ -37,6 +37,7 @@ int getsysctl(const char *name, int *mib, size_t miblen, void *ptr, size_t *len)
#if __APPLE__
#include <sys/sysctl.h>
+#include "endian.h"
#define GETSYSCTL_BY_NAME(name, var) getsysctl_by_name(name, &(var), sizeof(var))
int getsysctl_by_name(const char *name, void *ptr, size_t len);