Fix error checking for strerror_r implementations that return the error code.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@272640 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2016-06-14 06:03:20 +00:00
parent e443672b05
commit 17402e36fa

View File

@@ -70,8 +70,10 @@ string do_strerror_r(int ev) {
string do_strerror_r(int ev) {
char buffer[strerror_buff_size];
const int old_errno = errno;
if (::strerror_r(ev, buffer, strerror_buff_size) == -1) {
const int new_errno = errno;
if ((int ret = ::strerror_r(ev, buffer, strerror_buff_size)) != 0) {
// If `ret == -1` then the error is specified using `errno`, otherwise
// `ret` represents the error.
const int new_errno = ret == -1 ? errno : ret;
errno = old_errno;
if (new_errno == EINVAL) {
std::snprintf(buffer, strerror_buff_size, "Unknown error %d", ev);