From bd4c2f962df01e622828496b0b68b60cc8ab0783 Mon Sep 17 00:00:00 2001 From: Sean Cannella Date: Mon, 1 Jul 2013 08:06:12 -0700 Subject: [PATCH] strerror_r is XSI compliant on Apple/FreeBSD Summary: - Noticed this due to an -fpermissive compiler warning while compiling HHVM for OSX (complaint of trying to cast int to char*) Test Plan: - Compiled - Confirmed the build warning is fixed by this on the Mac OS X build Reviewed By: tudorb@fb.com FB internal diff: D865169 --- folly/String.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/folly/String.cpp b/folly/String.cpp index 4f1303ee..aae439fc 100644 --- a/folly/String.cpp +++ b/folly/String.cpp @@ -241,12 +241,15 @@ fbstring errnoStr(int err) { fbstring result; + // https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/strerror_r.3.html // http://www.kernel.org/doc/man-pages/online/pages/man3/strerror.3.html -#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE +#if defined(__APPLE__) || defined(__FreeBSD__) || \ + ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE) // Using XSI-compatible strerror_r int r = strerror_r(err, buf, sizeof(buf)); - if (r == -1) { + // OSX/FreeBSD use EINVAL and Linux uses -1 so just check for non-zero + if (r != 0) { result = to( "Unknown error ", err, " (strerror_r failed with error ", errno, ")"); -- 2.34.1