From d2b2f9124ece53dbab255f5889b42ff498035775 Mon Sep 17 00:00:00 2001 From: roderick-koehle <50633232+roderick-koehle@users.noreply.github.com> Date: Wed, 29 May 2019 20:15:50 +0200 Subject: [PATCH] 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> --- rclcpp/src/rclcpp/signal_handler.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rclcpp/src/rclcpp/signal_handler.cpp b/rclcpp/src/rclcpp/signal_handler.cpp index ab981be..dbdc1ae 100644 --- a/rclcpp/src/rclcpp/signal_handler.cpp +++ b/rclcpp/src/rclcpp/signal_handler.cpp @@ -165,13 +165,15 @@ __safe_strerror(int errnum, char * buffer, size_t buffer_length) { #if defined(_WIN32) 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); if (msg != buffer) { strncpy(buffer, msg, buffer_length); buffer[buffer_length - 1] = '\0'; } #else + /* XSI-compliant */ int error_status = strerror_r(errnum, buffer, buffer_length); if (error_status != 0) { throw std::runtime_error("Failed to get error string for errno: " + std::to_string(errnum));