diff --git a/CHANGES b/CHANGES
index 45ed3ce1f..3026eb543 100644
--- CHANGES
+++ CHANGES
@@ -3,6 +3,7 @@ RRDtool - master ...
 ====================
 Bugfixes
 --------
+* Fix MacOS Build error (no SOCK_CLOEXEC on mac) @ensc fixes oetiker#1261
 
 Features
 --------
diff --git a/src/compat-cloexec.c b/src/compat-cloexec.c
index 6931fa7ed..cd6c9d055 100644
--- src/compat-cloexec.c
+++ src/compat-cloexec.c
@@ -17,7 +17,7 @@
 
 inline static bool have_decl_o_cloexec(void)
 {
-#ifdef HAVE_DECL_O_CLOEXEC
+#if defined(HAVE_DECL_O_CLOEXEC) && HAVE_DECL_O_CLOEXEC
 	return true;
 #else
 	return false;
diff --git a/src/compat-cloexec.h b/src/compat-cloexec.h
index 0d4d2b6ee..13bfffc06 100644
--- src/compat-cloexec.h
+++ src/compat-cloexec.h
@@ -3,11 +3,11 @@
 
 #include <rrd_config.h>
 
-#ifndef HAVE_DECL_O_CLOEXEC
+#if !defined(HAVE_DECL_O_CLOEXEC) || !HAVE_DECL_O_CLOEXEC
 #  define O_CLOEXEC 0
 #endif
 
-#ifndef HAVE_DECL_SOCK_CLOEXEC
+#if !defined(HAVE_DECL_SOCK_CLOEXEC) || !HAVE_DECL_SOCK_CLOEXEC
 #  define SOCK_CLOEXEC 0
 #endif
 
