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 }