+/* See the file COPYING for licensing information. */
+
#include <stdio.h>
+#include <string.h>
#include <assert.h>
#include "libradsec.h"
#include "libradsec-impl.h"
"FreeRadius error" /* 6 RSE_FR */
"bad hostname or port" /* 7 RSE_BADADDR */
"no peer configured" /* 8 RSE_NOPEER */
- "ERR 9" /* RSE_ */
- "ERR 10" /* RSE_ */
+ "libevent error" /* 9 RSE_EVENT */
+ "connection error" /* 10 RSE_CONNERR */
"ERR 11" /* RSE_ */
"ERR 12" /* RSE_ */
"ERR 13" /* RSE_ */
"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)
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)