From cbc6145977b90fe895d03ee5d86cdf9e100f2dfe Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Thu, 1 Apr 2021 10:21:12 +0300 Subject: [PATCH] using strerror_l() --- src/libs/tools.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/libs/tools.h b/src/libs/tools.h index 1ff84bc..fa0ac27 100644 --- a/src/libs/tools.h +++ b/src/libs/tools.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -146,10 +147,14 @@ INLINE int flock_timedwait_monotonic(int fd, long double timeout) { } INLINE char *errno_to_string(int error, char *buf, size_t size) { -# if defined(__GLIBC__) && defined(_GNU_SOURCE) - return strerror_r(error, buf, size); -# else - strerror_r(error, buf, size); + assert(buf); + assert(size > 0); + locale_t locale = newlocale(LC_MESSAGES_MASK, "C", NULL); + char *str = "!!! newlocale() error !!!"; + strncpy(buf, (locale ? strerror_l(error, locale) : str), size - 1); + buf[size - 1] = '\0'; + if (locale) { + freelocale(locale); + } return buf; -# endif }