summaryrefslogtreecommitdiff
path: root/common/debug.c
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@redhat.com>2018-04-19 16:19:28 +0200
committerDaiki Ueno <ueno@gnu.org>2018-04-19 18:03:39 +0200
commit173ad93cc54057886b2055f3d73ea64a047127d1 (patch)
treede83c23e0bb349e9ab4d9b779738d514fbf35062 /common/debug.c
parenta95c7a3e936896349bf925ca7cd47f0a03166249 (diff)
build: Check strerror_l() and uselocale() seperately
NetBSD deliberately doesn't support per-thread locale and our thread-safe replacement of strerror() using strerror_l() cannot be used. Fallback to strerror_r() in that case.
Diffstat (limited to 'common/debug.c')
-rw-r--r--common/debug.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/common/debug.c b/common/debug.c
index 5f7546e..cfcd465 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];
-#ifdef HAVE_STRERROR_L
+#if defined(HAVE_STRERROR_L) && defined(HAVE_USELOCALE)
locale_t loc;
#endif
@@ -162,7 +162,12 @@ p11_debug_message_err (int flag,
va_end (args);
snprintf (strerr, sizeof (strerr), "Unknown error %d", errnum);
-#ifdef HAVE_STRERROR_L
+ /* 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)
loc = uselocale ((locale_t) 0);
if (loc != NULL)
strncpy (strerr, strerror_l (errnum, loc), sizeof (strerr));