unix: don't use setlocale()

setlocale() is not inherently thread-safe. We'll have to live with the fact
that test/test-dlerror.c fails on systems with localized error messages.
This commit is contained in:
Ben Noordhuis 2012-05-03 19:39:37 +02:00
parent 5d19aa84f0
commit 395e256889

View File

@ -65,23 +65,18 @@ const char* uv_dlerror(uv_lib_t* lib) {
static int uv__dlerror(uv_lib_t* lib) {
char* errmsg;
char* locale;
/* Make error message independent of locale. */
locale = setlocale(LC_MESSAGES, NULL);
if (strcmp(locale, "C") == 0) {
errmsg = dlerror();
} else {
setlocale(LC_MESSAGES, "C");
errmsg = dlerror();
setlocale(LC_MESSAGES, locale);
}
if (lib->errmsg)
free(lib->errmsg);
if (errmsg)
return lib->errmsg = strdup(errmsg), -1;
else
return lib->errmsg = NULL, 0;
errmsg = dlerror();
if (errmsg) {
lib->errmsg = strdup(errmsg);
return -1;
}
else {
lib->errmsg = NULL;
return 0;
}
}