Skip to content

Commit

Permalink
unix: don't use setlocale()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bnoordhuis committed May 3, 2012
1 parent 5d19aa8 commit 395e256
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/unix/dl.c
Expand Up @@ -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;
}
}

0 comments on commit 395e256

Please sign in to comment.