From 2f0ef33f9d9cc0206e1063c42a64d614de9b1fea Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Fri, 26 Apr 2024 16:29:59 +0200 Subject: [PATCH] fix(linux): fixed build errors on MacOS --- .../esp_hw_support/port/linux/esp_random.c | 6 ++++++ .../linux/{linux_include => include}/sys/cdefs.h | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) rename components/linux/{linux_include => include}/sys/cdefs.h (59%) diff --git a/components/esp_hw_support/port/linux/esp_random.c b/components/esp_hw_support/port/linux/esp_random.c index 19bed4dc65..9cd06df1d5 100644 --- a/components/esp_hw_support/port/linux/esp_random.c +++ b/components/esp_hw_support/port/linux/esp_random.c @@ -6,7 +6,13 @@ #include #include #include + +// getentropy live in different header files on Mac and Linux +#if (defined(__APPLE__) && defined(__MACH__)) +#include +#else #include +#endif #include "esp_log.h" diff --git a/components/linux/linux_include/sys/cdefs.h b/components/linux/include/sys/cdefs.h similarity index 59% rename from components/linux/linux_include/sys/cdefs.h rename to components/linux/include/sys/cdefs.h index 2b34193912..1e10b63a1f 100644 --- a/components/linux/linux_include/sys/cdefs.h +++ b/components/linux/include/sys/cdefs.h @@ -12,6 +12,20 @@ #pragma once +#if (defined(__APPLE__) && defined(__MACH__)) +// MacOS + +#if !defined(__containerof) +#define __containerof(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) +#endif + +#include_next // include the actual cdefs.h (which does not contain containerof) + +#else +// Linux + #include // We need a define. We can't typedef here since, depending on the include order, @@ -20,3 +34,5 @@ #include_next #include + +#endif