diff options
author | Linus Nordberg <linus@nordu.net> | 2010-09-29 21:53:43 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2010-09-29 21:53:43 +0200 |
commit | 727af5678906c03eedff8d8262d39fad788973a6 (patch) | |
tree | f9192ecc6b6590d79c356106004f14f2f46b7c2d /lib/err.c | |
parent | de906e3721e19d9d8b2c61f834d8057bcce47af1 (diff) |
Refactoring in preparation for handling more cases than client sending one packet.
Diffstat (limited to 'lib/err.c')
-rw-r--r-- | lib/err.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -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) |