summaryrefslogtreecommitdiff
path: root/lib/err.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2010-09-29 21:53:43 +0200
committerLinus Nordberg <linus@nordu.net>2010-09-29 21:53:43 +0200
commit727af5678906c03eedff8d8262d39fad788973a6 (patch)
treef9192ecc6b6590d79c356106004f14f2f46b7c2d /lib/err.c
parentde906e3721e19d9d8b2c61f834d8057bcce47af1 (diff)
Refactoring in preparation for handling more cases than client sending one packet.
Diffstat (limited to 'lib/err.c')
-rw-r--r--lib/err.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/err.c b/lib/err.c
index 74edeb0..4c88ce1 100644
--- a/lib/err.c
+++ b/lib/err.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <string.h>
#include <assert.h>
#include "libradsec.h"
#include "libradsec-impl.h"
@@ -27,6 +28,7 @@ const char *_errtxt[] = {
"ERR " /* RSE_ */
"some error" /* 21 RSE_SOME_ERROR */
};
+#define ERRTXT_SIZE (sizeof(_errtxt) / sizeof(*_errtxt))
static struct rs_error *
_err_new (unsigned int code, const char *file, int line, const char *fmt, va_list args)
@@ -39,8 +41,16 @@ _err_new (unsigned int code, const char *file, int line, const char *fmt, va_lis
int n;
memset (err, 0, sizeof(struct rs_error));
err->code = code;
- n = vsnprintf (err->buf, sizeof(err->buf), fmt, args);
- if (n > 0)
+ if (fmt)
+ n = vsnprintf (err->buf, sizeof(err->buf), fmt, args);
+ else
+ {
+ strncpy (err->buf,
+ err->code < ERRTXT_SIZE ? _errtxt[err->code] : "",
+ sizeof(err->buf));
+ n = strlen (err->buf);
+ }
+ if (n >= 0)
{
char *sep = strrchr (file, '/');
if (sep)