Do an explicit test for XSI strerror_r
authorSara Golemon <sgolemon@fb.com>
Wed, 1 Jul 2015 21:56:12 +0000 (14:56 -0700)
committerSara Golemon <sgolemon@fb.com>
Wed, 1 Jul 2015 23:24:54 +0000 (16:24 -0700)
Summary: The current #if directive is a laundry list of
"strerror_r defaults to XSI style on these platforms",
and we keep missing some, so let's just do a proper test
and simplify the code directives.

Closes #232

Reviewed By: @paulbiss

Differential Revision: D2208843

folly/String.cpp
folly/configure.ac

index 66649caaaa5bdcb9f0b95de415bf4a59c81ff6d0..5ae7ee164c57e0b8dfc9650e69f7b4b70d3f2ea3 100644 (file)
@@ -342,9 +342,7 @@ fbstring errnoStr(int err) {
   } else {
     result.assign(buf);
   }
   } else {
     result.assign(buf);
   }
-#elif defined(__APPLE__) || defined(__FreeBSD__) ||\
-    defined(__CYGWIN__) || defined(__ANDROID__) ||\
-    ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE)
+#elif defined(HAVE_XSI_STRERROR_R)
   // Using XSI-compatible strerror_r
   int r = strerror_r(err, buf, sizeof(buf));
 
   // Using XSI-compatible strerror_r
   int r = strerror_r(err, buf, sizeof(buf));
 
index 8741396cfc4120d957628e09f69106aae1d63a05..b24e575f581a780c130d30a849ae70cf36b877af 100644 (file)
@@ -346,6 +346,28 @@ if test "$folly_cv_prog_cc_pthread_atfork" = "yes"; then
   AC_DEFINE([HAVE_PTHREAD_ATFORK], [1], [Define to 1 if the compiler supports pthread_atfork])
 fi
 
   AC_DEFINE([HAVE_PTHREAD_ATFORK], [1], [Define to 1 if the compiler supports pthread_atfork])
 fi
 
+# Check for XSI-compatible strerror_r as default implementation
+AC_CACHE_CHECK(
+  [for XSI style strerror_r support],
+  [folly_cv_prog_cc_xsi_strerror_r],
+  [AC_RUN_IFELSE(
+    [AC_LANG_SOURCE[
+      #include <string.h>
+      #include <errno.h>
+      int main(int argc, char** argv) {
+        char buf[1024];
+        buf[0] = 0;
+        int ret = strerror_r(ENOMEM, buf, sizeof(buf));
+        return ret;
+      }
+    ]],
+    [folly_cv_prog_cc_xsi_strerror_r=yes],
+    [folly_cv_prog_cc_xsi_strerror_r=no])])
+
+if test "$folly_cv_prog_cc_xsi_strerror_r" = "yes"; then
+  AC_DEFINE([HAVE_XSI_STRERROR_R], [1], [Define to 1 if the runtime supports XSI-style strerror_r])
+fi
+
 # Checks for library functions.
 AC_CHECK_FUNCS([getdelim \
                 gettimeofday \
 # Checks for library functions.
 AC_CHECK_FUNCS([getdelim \
                 gettimeofday \