From 46e99be201522502bc6397309cb01cf18058231e Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Tue, 19 Mar 2019 22:26:30 +0300 Subject: [PATCH] Supported XSI strerror_r() --- src/logging.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/logging.h b/src/logging.h index f432c5a..4134fe4 100644 --- a/src/logging.h +++ b/src/logging.h @@ -80,7 +80,7 @@ pthread_mutex_t log_mutex; #define LOG_PERROR(_msg, ...) { \ char _buf[1024] = ""; \ - char *_ptr = strerror_r(errno, _buf, 1024); \ + char *_ptr = errno_to_string(_buf, 1024); \ LOGGING_LOCK; \ printf("-- ERROR [%.03Lf tid=%d] -- " _msg ": %s\n", get_now_monotonic(), get_thread_id(), ##__VA_ARGS__, _ptr); \ fflush(stdout); \ @@ -120,3 +120,13 @@ pthread_mutex_t log_mutex; LOGGING_UNLOCK; \ } \ } + + +INLINE char *errno_to_string(char *buf, size_t size) { +#if defined(__GLIBC__) && defined(_GNU_SOURCE) + return strerror_r(errno, buf, size); +#else + strerror_r(errno, buf, size); + return buf; +#endif +}