Fix folly compilation on MacOSX
authorSara Golemon <sgolemon@fb.com>
Wed, 10 Sep 2014 18:35:44 +0000 (11:35 -0700)
committerSara Golemon <sgolemon@fb.com>
Wed, 10 Sep 2014 23:59:55 +0000 (16:59 -0700)
Summary:
We don't always have features.h
and our glibc doesn't have __GLIBC_PREREQ()

@override-unit-failures

Test Plan: Builds on MacOSX

Reviewed By: pt@fb.com

Subscribers: njormrod

FB internal diff: D1546679

folly/ThreadName.h
folly/io/async/EventFDWrapper.h

index dbcdc84ed2ed55f8b67677f957e46d3d21b9d426..f2b7d063cc2930bf8978d7727b4a45f245446c23 100644 (file)
 
 namespace folly {
 
+// This looks a bit weird, but it's necessary to avoid
+// having an undefined compiler function called.
+#if defined(__GLIBC__) && !defined(__APPLE__)
+#if __GLIBC_PREREQ(2, 12)
+# define FOLLY_GLIBC_2_12
+#endif
+#endif
+
 inline bool setThreadName(pthread_t id, StringPiece name) {
-#if (defined(__GLIBC__) && __GLIBC_PREREQ(2, 12))
+#ifdef FOLLY_GLIBC_2_12
   return 0 == pthread_setname_np(id, name.fbstr().substr(0, 15).c_str());
 #else
   return false;
index 294d9d37b881a54660d4c2f51442ab6a941e0160..80a81735e9bea4048cdc2116aaa7799a87d52d15 100644 (file)
 
 #pragma once
 
-#include <features.h>
+#ifndef FOLLY_NO_CONFIG
+#include <folly/folly-config.h>
+#endif
+
+#ifdef FOLLY_HAVE_FEATURES_H
+# include <features.h>
+#endif
+
+#if defined(__GLIBC__) && !defined(__APPLE__)
+#if __GLIBC_PREREQ(2, 9)
+# define FOLLY_GLIBC_2_9
+#endif
+#endif
 
 // <sys/eventfd.h> doesn't exist on older glibc versions
-#if (defined(__GLIBC__) && __GLIBC_PREREQ(2, 9))
+#ifdef FOLLY_GLIBC_2_9
 #include <sys/eventfd.h>
-#else /* !(defined(__GLIBC__) && __GLIBC_PREREQ(2, 9)) */
+#else /* !def FOLLY_GLIBC_2_9 */
 
 #include <sys/syscall.h>
 #include <unistd.h>