Fix builds on macOS due to missing endianness functions (#16489)
vkalintiris committed
Nov 29, 2023 at 11:05 UTC
4f6fe91a6d3265fecae01c9d3ee136d2d48208db
4 files changed
+35
CMakeLists.txt
+1
@@ -465,6 +465,7 @@ set(LIBNETDATA_FILES
465
libnetdata/log/log.h
466
libnetdata/os.c
467
libnetdata/os.h
468
+ libnetdata/endian.h
469
libnetdata/onewayalloc/onewayalloc.c
470
libnetdata/onewayalloc/onewayalloc.h
471
libnetdata/popen/popen.c
Makefile.am
+1
@@ -193,6 +193,7 @@ LIBNETDATA_FILES = \
193
libnetdata/procfile/procfile.h \
194
libnetdata/os.c \
195
libnetdata/os.h \
196
+ libnetdata/endian.h \
197
libnetdata/simple_pattern/simple_pattern.c \
198
libnetdata/simple_pattern/simple_pattern.h \
199
libnetdata/socket/socket.c \
libnetdata/endian.h
new
+32
@@ -0,0 +1,32 @@
1
+#ifndef LIBNETDATA_ENDIAN_H
2
+#define LIBNETDATA_ENDIAN_H
3
+
4
+/** compatibility header for endian.h
5
+ * This is a simple compatibility shim to convert
6
+ * BSD/Linux endian macros to the Mac OS X equivalents.
7
+ * It is public domain.
8
+ * */
9
+
10
+#ifndef __APPLE__
11
+#error "This header file (endian.h) is MacOS X specific.\n"
12
+#endif /* __APPLE__ */
13
+
14
+
15
+#include <libkern/OSByteOrder.h>
16
+
17
+#define htobe16(x) OSSwapHostToBigInt16(x)
18
+#define htole16(x) OSSwapHostToLittleInt16(x)
19
+#define be16toh(x) OSSwapBigToHostInt16(x)
20
+#define le16toh(x) OSSwapLittleToHostInt16(x)
21
+
22
+#define htobe32(x) OSSwapHostToBigInt32(x)
23
+#define htole32(x) OSSwapHostToLittleInt32(x)
24
+#define be32toh(x) OSSwapBigToHostInt32(x)
25
+#define le32toh(x) OSSwapLittleToHostInt32(x)
26
+
27
+#define htobe64(x) OSSwapHostToBigInt64(x)
28
+#define htole64(x) OSSwapHostToLittleInt64(x)
29
+#define be64toh(x) OSSwapBigToHostInt64(x)
30
+#define le64toh(x) OSSwapLittleToHostInt64(x)
31
+
32
+#endif /* LIBNETDATA_ENDIAN_H */
libnetdata/os.h
+1
@@ -37,6 +37,7 @@ int getsysctl(const char *name, int *mib, size_t miblen, void *ptr, size_t *len)
37
#if __APPLE__
38
39
#include <sys/sysctl.h>
40
+#include "endian.h"
41
42
#define GETSYSCTL_BY_NAME(name, var) getsysctl_by_name(name, &(var), sizeof(var))
43
int getsysctl_by_name(const char *name, void *ptr, size_t len);