/* global variable exported in debug.h */
int p11_debug_current_flags = ~0;
+#ifdef HAVE_LOCALE_H
+extern locale_t p11_message_locale;
+#endif
+
static int
parse_environ_flags (void)
{
{
va_list args;
char strerr[P11_DEBUG_MESSAGE_MAX];
-#ifdef HAVE_STRERROR_L
- locale_t loc;
-#endif
if (flag & p11_debug_current_flags) {
fprintf (stderr, "(p11-kit:%d) ", getpid());
va_end (args);
snprintf (strerr, sizeof (strerr), "Unknown error %d", errnum);
-#ifdef HAVE_STRERROR_L
- loc = uselocale ((locale_t) 0);
- if (loc != NULL)
- strncpy (strerr, strerror_l (errnum, loc), sizeof (strerr));
+#if defined(HAVE_STRERROR_L) && defined(HAVE_NEWLOCALE)
+ if (p11_message_locale != (locale_t) 0)
+ strncpy (strerr, strerror_l (errnum, p11_message_locale), sizeof (strerr));
#else
strerror_r (errnum, strerr, sizeof (strerr));
#endif
#include "message.h"
#include <assert.h>
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
unsigned int p11_forkid = 1;
+#ifdef HAVE_LOCALE_H
+extern locale_t p11_message_locale;
+#endif
+
static char *
thread_local_message (void)
{
p11_mutex_init (&p11_virtual_mutex);
pthread_key_create (&thread_local, free);
p11_message_storage = thread_local_message;
+#ifdef HAVE_NEWLOCALE
+ p11_message_locale = newlocale (LC_ALL_MASK, "POSIX", (locale_t) 0);
+#endif
pthread_atfork (NULL, NULL, count_forks);
}
free (pthread_getspecific (thread_local));
pthread_setspecific (thread_local, NULL);
+#ifdef HAVE_NEWLOCALE
+ freelocale (p11_message_locale);
+#endif
p11_message_storage = dont_store_message;
pthread_key_delete (thread_local);
p11_mutex_uninit (&p11_virtual_mutex);
static bool print_messages = false;
+#ifdef HAVE_LOCALE_H
+locale_t p11_message_locale = (locale_t) 0;
+#endif
+
static char *
default_message_storage (void)
{
char strerr[P11_MESSAGE_MAX];
va_list va;
size_t length;
-#ifdef HAVE_STRERROR_L
- locale_t loc;
-#endif
va_start (va, msg);
length = vsnprintf (buffer, P11_MESSAGE_MAX - 1, msg, va);
buffer[length] = 0;
snprintf (strerr, sizeof (strerr), "Unknown error %d", errnum);
-#ifdef HAVE_STRERROR_L
- loc = uselocale ((locale_t) 0);
- if (loc != NULL)
- strncpy (strerr, strerror_l (errnum, loc), sizeof (strerr));
+#if defined(HAVE_STRERROR_L) && defined(HAVE_NEWLOCALE)
+ if (p11_message_locale != (locale_t) 0)
+ strncpy (strerr, strerror_l (errnum, p11_message_locale), sizeof (strerr));
#else
strerror_r (errnum, strerr, sizeof (strerr));
#endif
#include "message.h"
#include <errno.h>
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
#include <stdlib.h>
#include <stdio.h>
+#ifdef HAVE_LOCALE_H
+extern locale_t p11_message_locale;
+#endif
+
static void
test_with_err (void)
{
const char *last;
char *expected;
+#ifdef HAVE_NEWLOCALE
+ p11_message_locale = newlocale (LC_ALL_MASK, "POSIX", (locale_t) 0);
+#endif
+
errno = E2BIG;
p11_message_err (ENOENT, "Details: %s", "value");
last = p11_message_last ();
assert_not_reached ();
assert_str_eq (expected, last);
free (expected);
+
+#ifdef HAVE_NEWLOCALE
+ freelocale (p11_message_locale);
+#endif
}
int
AC_CHECK_MEMBERS([struct dirent.d_type],,,[#include <dirent.h>])
AC_CHECK_FUNCS([getprogname getexecname basename mkstemp mkdtemp])
AC_CHECK_FUNCS([getauxval issetugid getresuid secure_getenv])
- AC_CHECK_FUNCS([strnstr memdup strndup strerror_l strerror_r])
+ AC_CHECK_FUNCS([strnstr memdup newlocale strndup strerror_l strerror_r])
AC_CHECK_FUNCS([reallocarray])
AC_CHECK_FUNCS([fdwalk])
AC_CHECK_FUNCS([setenv])