Bionic use of strerror_r (#742)
Since API 23 Android Bionic uses the GNU convention for strerror_r. Following bionic/libc line 96, https://android.googlesource.com/platform/bionic.git/+/refs/heads/master/libc/include/string.h Signed-off-by: roderick-koehle <50633232+roderick-koehle@users.noreply.github.com>
This commit is contained in:
parent
ca01555936
commit
d2b2f9124e
1 changed files with 3 additions and 1 deletions
|
@ -165,13 +165,15 @@ __safe_strerror(int errnum, char * buffer, size_t buffer_length)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
strerror_s(buffer, buffer_length, errnum);
|
strerror_s(buffer, buffer_length, errnum);
|
||||||
#elif (defined(_GNU_SOURCE) && !defined(ANDROID))
|
#elif defined(_GNU_SOURCE) && (!defined(ANDROID) || __ANDROID_API__ >= 23)
|
||||||
|
/* GNU-specific */
|
||||||
char * msg = strerror_r(errnum, buffer, buffer_length);
|
char * msg = strerror_r(errnum, buffer, buffer_length);
|
||||||
if (msg != buffer) {
|
if (msg != buffer) {
|
||||||
strncpy(buffer, msg, buffer_length);
|
strncpy(buffer, msg, buffer_length);
|
||||||
buffer[buffer_length - 1] = '\0';
|
buffer[buffer_length - 1] = '\0';
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
/* XSI-compliant */
|
||||||
int error_status = strerror_r(errnum, buffer, buffer_length);
|
int error_status = strerror_r(errnum, buffer, buffer_length);
|
||||||
if (error_status != 0) {
|
if (error_status != 0) {
|
||||||
throw std::runtime_error("Failed to get error string for errno: " + std::to_string(errnum));
|
throw std::runtime_error("Failed to get error string for errno: " + std::to_string(errnum));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue