summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/compat.c16
-rw-r--r--common/compat.h8
-rw-r--r--common/message.c26
-rw-r--r--common/message.h4
-rw-r--r--common/path.c3
5 files changed, 55 insertions, 2 deletions
diff --git a/common/compat.c b/common/compat.c
index 3b1361c..e7bee3c 100644
--- a/common/compat.c
+++ b/common/compat.c
@@ -807,3 +807,19 @@ getauxval (unsigned long type)
}
#endif /* HAVE_GETAUXVAL */
+
+#ifndef HAVE_STRERROR_R
+
+int
+strerror_r (int errnum,
+ char *buf,
+ size_t buflen)
+{
+#ifdef OS_WIN32
+ return strerror_s (buf, buflen, errnum);
+#else
+ #error no strerror_r implementation
+#endif
+}
+
+#endif /* HAVE_STRERROR_R */
diff --git a/common/compat.h b/common/compat.h
index 1cedc35..5b76d00 100644
--- a/common/compat.h
+++ b/common/compat.h
@@ -310,4 +310,12 @@ unsigned long getauxval (unsigned long type);
#endif /* !HAVE_GETAUXVAL */
+#ifndef HAVE_STRERROR_R
+
+int strerror_r (int errnum,
+ char *buf,
+ size_t buflen);
+
+#endif /* HAVE_STRERROR_R */
+
#endif /* __COMPAT_H__ */
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,
...)
{
diff --git a/common/message.h b/common/message.h
index 60a7f81..3fe86df 100644
--- a/common/message.h
+++ b/common/message.h
@@ -48,6 +48,10 @@ extern char * (* p11_message_storage) (void);
void p11_message (const char* msg,
...) GNUC_PRINTF (1, 2);
+void p11_message_err (int errnum,
+ const char* msg,
+ ...) GNUC_PRINTF (2, 3);
+
void p11_message_store (const char* msg,
size_t length);
diff --git a/common/path.c b/common/path.c
index 2f976a8..f7bd2b9 100644
--- a/common/path.c
+++ b/common/path.c
@@ -137,8 +137,7 @@ expand_homedir (const char *remainder)
pwd = getpwuid (getuid ());
if (!pwd) {
error = errno;
- p11_message ("couldn't lookup home directory for user %d: %s",
- getuid (), strerror (errno));
+ p11_message_err (errno, "couldn't lookup home directory for user %d", getuid ());
errno = error;
return NULL;
}