summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@redhat.com>2017-06-09 14:41:13 +0200
committerDaiki Ueno <ueno@gnu.org>2017-06-12 11:30:42 +0200
commitbf3c1a9d8e4ace4c3a92b4af56e4b62657907522 (patch)
tree9faf2a8ca30854662c81fbc69a506f456d4c3fae
parentbf168f00e64a0291f5a718eb451915768659c160 (diff)
compat: Prefer strerror_l to strerror_r
strerror_r is being obsolete in the next POSIX specification: http://austingroupbugs.net/view.php?id=655
-rw-r--r--common/message.c15
-rw-r--r--configure.ac4
2 files changed, 16 insertions, 3 deletions
diff --git a/common/message.c b/common/message.c
index 35f2764..ccc310e 100644
--- a/common/message.c
+++ b/common/message.c
@@ -49,6 +49,10 @@
#include "message.h"
#include <assert.h>
+#include <errno.h>
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
@@ -100,6 +104,9 @@ p11_message_err (int errnum,
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);
@@ -110,8 +117,14 @@ p11_message_err (int errnum,
length = P11_MESSAGE_MAX - 1;
buffer[length] = 0;
- strncpy (strerr, "Unknown error", sizeof (strerr));
+ 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));
+#else
strerror_r (errnum, strerr, sizeof (strerr));
+#endif
strerr[P11_MESSAGE_MAX - 1] = 0;
p11_message ("%s: %s", buffer, strerr);
diff --git a/configure.ac b/configure.ac
index e978201..2fab9e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -86,11 +86,11 @@ if test "$os_unix" = "yes"; then
])
# These are thngs we can work around
- AC_CHECK_HEADERS([sys/resource.h])
+ AC_CHECK_HEADERS([locale.h sys/resource.h])
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_r])
+ AC_CHECK_FUNCS([strnstr memdup strndup strerror_l strerror_r])
AC_CHECK_FUNCS([fdwalk])
AC_CHECK_FUNCS([setenv])
AC_CHECK_FUNCS([getpeereid])