summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-09-04 19:17:48 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-09-04 19:17:48 (GMT)
commit3d65cfcb6403d169b52045a9e5c242ad081539a7 (patch)
treecf46504a502636def4c4e7b83e2d0eb350a43938 /src/core
parent16c917248fd3de8ff4906bc0f4582a6d718fa88a (diff)
Chosen the right strerror_r() function depending on macros settings.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/logs.h27
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); \