diff options
-rw-r--r-- | src/core/logs.h | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/core/logs.h b/src/core/logs.h index fd6e777..8019382 100644 --- a/src/core/logs.h +++ b/src/core/logs.h @@ -78,12 +78,30 @@ void log_variadic_message(LogMessageType, const char *, ...); #define LOG_ERROR(tp, msg) \ log_variadic_message(tp, "[%s:%u] %s", __FUNCTION__, __LINE__, msg) +#if (_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE + +# define STRERROR_SAFE(buf, ptr) \ + do \ + { \ + strerror_r(errno, buf, sizeof(buf)); \ + ptr = buf; \ + } \ + while (0) + +#else + +# define STRERROR_SAFE(buf, ptr) \ + ptr = strerror_r(errno, buf, sizeof(buf)) \ + +#endif + #define LOG_ERROR_N(func) \ do \ { \ char __msg[1024]; \ - strerror_r(errno, __msg, sizeof(__msg)); \ - log_variadic_message(LMT_EXT_ERROR, "[%s:%u] %s: %s", __FUNCTION__, __LINE__, func, __msg); \ + const char *__msg_ptr; \ + STRERROR_SAFE(__msg, __msg_ptr); \ + log_variadic_message(LMT_EXT_ERROR, "[%s:%u] %s: %s", __FUNCTION__, __LINE__, func, __msg_ptr); \ } \ while (0) @@ -93,10 +111,7 @@ void log_variadic_message(LogMessageType, const char *, ...); char __msg[1024]; \ const char *__msg_ptr; \ if (errcode == EAI_SYSTEM) \ - { \ - strerror_r(errno, __msg, sizeof(__msg)); \ - __msg_ptr = __msg; \ - } \ + STRERROR_SAFE(__msg, __msg_ptr); \ else \ __msg_ptr = gai_strerror(errcode); \ log_variadic_message(LMT_EXT_ERROR, "[%s:%u] %s: %s", __FUNCTION__, __LINE__, func, __msg_ptr); \ |