diff --git a/format.cc b/format.cc index 0c400aef..a4c9cee6 100644 --- a/format.cc +++ b/format.cc @@ -134,7 +134,13 @@ int safe_strerror( int error_code, char *&buffer, std::size_t buffer_size) FMT_NOEXCEPT(true) { assert(buffer != 0 && buffer_size != 0); int result = 0; -#ifdef _GNU_SOURCE +#if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE) || __ANDROID__ + // XSI-compliant version of strerror_r. + result = strerror_r(error_code, buffer, buffer_size); + if (result != 0) + result = errno; +#elif _GNU_SOURCE + // GNU-specific version of strerror_r. char *message = strerror_r(error_code, buffer, buffer_size); // If the buffer is full then the message is probably truncated. if (message == buffer && strlen(buffer) == buffer_size - 1)