mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-03-15 20:13:42 +00:00
Using strerror_r() instead of strerror_l() for better compatibility
This commit is contained in:
@@ -29,7 +29,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <locale.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@@ -177,15 +176,16 @@ INLINE int us_flock_timedwait_monotonic(int fd, long double timeout) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
INLINE char *us_errno_to_string(int error) {
|
INLINE char *us_errno_to_string(int error) {
|
||||||
locale_t locale = newlocale(LC_MESSAGES_MASK, "C", NULL);
|
char buf[2048];
|
||||||
char *buf;
|
const size_t max_len = sizeof(buf) - 1;
|
||||||
if (locale) {
|
# if (_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE
|
||||||
buf = us_strdup(strerror_l(error, locale));
|
if (strerror_r(error, buf, max_len) != 0) {
|
||||||
freelocale(locale);
|
assert(snprintf(buf, max_len, "Errno = %d", error) > 0);
|
||||||
} else {
|
|
||||||
buf = us_strdup("!!! newlocale() error !!!");
|
|
||||||
}
|
}
|
||||||
return buf;
|
return us_strdup(buf);
|
||||||
|
# else
|
||||||
|
return us_strdup(strerror_r(error, buf, max_len));
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE char *us_signum_to_string(int signum) {
|
INLINE char *us_signum_to_string(int signum) {
|
||||||
|
|||||||
Reference in New Issue
Block a user