diff options
author | Daiki Ueno <dueno@redhat.com> | 2018-04-27 09:51:59 +0200 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2018-05-01 13:30:43 +0200 |
commit | 6202903b261dfae740af3f8e985244bab48470ba (patch) | |
tree | 1a98dfeff05af569b7e1dd341da685dbf2e73a76 /common | |
parent | 173ad93cc54057886b2055f3d73ea64a047127d1 (diff) |
Revert "build: Check strerror_l() and uselocale() seperately"
This reverts commit 173ad93cc54057886b2055f3d73ea64a047127d1.
We should rather use newlocale() when per-thread locale is not set.
Otherwise uselocale() could return LC_GLOBAL_LOCALE on some
platforms (e.g. musl-libc) and calling strerror_l() with it leads to
an undefined behavior.
Diffstat (limited to 'common')
-rw-r--r-- | common/debug.c | 9 | ||||
-rw-r--r-- | common/message.c | 9 |
2 files changed, 4 insertions, 14 deletions
diff --git a/common/debug.c b/common/debug.c index cfcd465..5f7546e 100644 --- a/common/debug.c +++ b/common/debug.c @@ -151,7 +151,7 @@ p11_debug_message_err (int flag, { va_list args; char strerr[P11_DEBUG_MESSAGE_MAX]; -#if defined(HAVE_STRERROR_L) && defined(HAVE_USELOCALE) +#ifdef HAVE_STRERROR_L locale_t loc; #endif @@ -162,12 +162,7 @@ p11_debug_message_err (int flag, va_end (args); snprintf (strerr, sizeof (strerr), "Unknown error %d", errnum); - /* As strerror_r() is being deprecated in POSIX: - * http://austingroupbugs.net/view.php?id=655 - * we prefer to use strerror_l() with per-thread locale - * argument as a thread-safe variant of strerror(). - */ -#if defined(HAVE_STRERROR_L) && defined(HAVE_USELOCALE) +#ifdef HAVE_STRERROR_L loc = uselocale ((locale_t) 0); if (loc != NULL) strncpy (strerr, strerror_l (errnum, loc), sizeof (strerr)); diff --git a/common/message.c b/common/message.c index ca087ea..34e0d5b 100644 --- a/common/message.c +++ b/common/message.c @@ -104,7 +104,7 @@ p11_message_err (int errnum, char strerr[P11_MESSAGE_MAX]; va_list va; size_t length; -#if defined(HAVE_STRERROR_L) && defined(HAVE_USELOCALE) +#ifdef HAVE_STRERROR_L locale_t loc; #endif @@ -118,12 +118,7 @@ p11_message_err (int errnum, buffer[length] = 0; snprintf (strerr, sizeof (strerr), "Unknown error %d", errnum); - /* As strerror_r() is being deprecated in POSIX: - * http://austingroupbugs.net/view.php?id=655 - * we prefer to use strerror_l() with per-thread locale - * argument as a thread-safe variant of strerror(). - */ -#if defined(HAVE_STRERROR_L) && defined(HAVE_USELOCALE) +#ifdef HAVE_STRERROR_L loc = uselocale ((locale_t) 0); if (loc != NULL) strncpy (strerr, strerror_l (errnum, loc), sizeof (strerr)); |