--- a/src/error.c Sun Feb 22 07:21:28 2009 +0200
+++ b/src/error.c Sun Feb 22 07:53:34 2009 +0200
@@ -1,6 +1,12 @@
#include "error.h"
+#include <string.h>
+#include <stdio.h>
+
+#include <netdb.h>
+#include <gnutls/gnutls.h>
+
/*
* Helper macros
*/
@@ -26,3 +32,39 @@
}
}
+const char *error_msg (struct error_info *err)
+{
+ static char msg[ERROR_MSG_MAXLEN];
+
+ // intrepret .extra
+ switch (err->code & _ERR_EXTRA_MASK) {
+ case ERR_EXTRA_NONE:
+ // no additional info
+ snprintf(msg, ERROR_MSG_MAXLEN, "%s", error_name(err->code));
+ break;
+
+ case ERR_EXTRA_ERRNO:
+ // strerror
+ snprintf(msg, ERROR_MSG_MAXLEN, "%s: %s", error_name(err->code), strerror(err->extra));
+ break;
+
+ case ERR_EXTRA_GAI:
+ // gai_strerror
+ snprintf(msg, ERROR_MSG_MAXLEN, "%s: %s", error_name(err->code), gai_strerror(err->extra));
+ break;
+
+ case ERR_EXTRA_GNUTLS:
+ // gnutls_strerror
+ snprintf(msg, ERROR_MSG_MAXLEN, "%s: %s", error_name(err->code), gnutls_strerror(err->extra));
+ break;
+
+ default:
+ // ???
+ snprintf(msg, ERROR_MSG_MAXLEN, "%s(%#.8x): %#.8x", error_name(err->code), err->code, err->extra);
+ break;
+ }
+
+ // return static pointer
+ return msg;
+}
+