From: Sean Cannella Date: Mon, 1 Jul 2013 15:06:12 +0000 (-0700) Subject: strerror_r is XSI compliant on Apple/FreeBSD X-Git-Tag: v0.22.0~936 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=bd4c2f962df01e622828496b0b68b60cc8ab0783;p=folly.git 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 --- 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, ")");