summaryrefslogtreecommitdiff
path: root/common/message.c
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2013-07-17 18:08:11 +0200
committerStef Walter <stef@thewalter.net>2013-07-18 13:04:37 +0200
commit9a1fe66f08149596567fedb4e2338ae786a19ab9 (patch)
tree562ee2eedc17f0dd83f62890d3b4d12f02ee5a72 /common/message.c
parente403f7b33ac35e961c72ed1b6335bbe3084e4642 (diff)
downloadp11-kit-9a1fe66f08149596567fedb4e2338ae786a19ab9.tar.gz
Avoid using the non-thread-safe strerror() function
https://bugzilla.redhat.com/show_bug.cgi?id=985481
Diffstat (limited to 'common/message.c')
-rw-r--r--common/message.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/common/message.c b/common/message.c
index 8b54ad1..e68dfac 100644
--- a/common/message.c
+++ b/common/message.c
@@ -86,6 +86,32 @@ p11_message_store (const char* msg,
}
void
+p11_message_err (int errnum,
+ const char* msg,
+ ...)
+{
+ char buffer[P11_MESSAGE_MAX];
+ char strerr[P11_MESSAGE_MAX];
+ va_list va;
+ size_t length;
+
+ va_start (va, msg);
+ length = vsnprintf (buffer, P11_MESSAGE_MAX - 1, msg, va);
+ va_end (va);
+
+ /* Was it truncated? */
+ if (length > P11_MESSAGE_MAX - 1)
+ length = P11_MESSAGE_MAX - 1;
+ buffer[length] = 0;
+
+ strncpy (strerr, "Unknown error", sizeof (strerr));
+ strerror_r (errnum, strerr, sizeof (strerr));
+ strerr[P11_MESSAGE_MAX - 1] = 0;
+
+ p11_message ("%s: %s", buffer, strerr);
+}
+
+void
p11_message (const char* msg,
...)
{