diff options
Diffstat (limited to 'libcxx/src/system_error.cpp')
-rw-r--r-- | libcxx/src/system_error.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/libcxx/src/system_error.cpp b/libcxx/src/system_error.cpp index 748b5f7..d7115fc 100644 --- a/libcxx/src/system_error.cpp +++ b/libcxx/src/system_error.cpp @@ -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); |