From 1b18d0e88ebbc05d36a327a32a6770f79ce5b511 Mon Sep 17 00:00:00 2001 From: Olexa Bilaniuk Date: Fri, 4 Aug 2017 14:40:57 -0400 Subject: [PATCH] Add stdargs support to the error API. --- src/util/error.c | 15 ++++++++++----- src/util/error.h | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/util/error.c b/src/util/error.c index 19ce184363..2f570144e8 100644 --- a/src/util/error.c +++ b/src/util/error.c @@ -29,15 +29,20 @@ int error_set(error *e, int code, const char *msg) { return code; } -int error_fmt(error *e, int code, const char *fmt, ...) { - va_list ap; - +int error_vfmt(error *e, int code, const char *fmt, va_list ap) { e->code = code; - va_start(ap, fmt); vsnprintf(e->msg, ERROR_MSGBUF_LEN, fmt, ap); - va_end(ap); #ifdef DEBUG fprintf(stderr, "ERROR %d: %s\n", e->code, e->msg); #endif return code; } + +int error_fmt(error *e, int code, const char *fmt, ...) { + int ret; + va_list ap; + va_start(ap, fmt); + ret = error_vfmt(e, code, fmt, ap); + va_end(ap); + return ret; +} diff --git a/src/util/error.h b/src/util/error.h index fc1ecb1663..0f7651fec0 100644 --- a/src/util/error.h +++ b/src/util/error.h @@ -18,6 +18,7 @@ int error_alloc(error **e); void error_free(error *e); int error_set(error *e, int code, const char *msg); int error_fmt(error *e, int code, const char *fmt, ...); +int error_vfmt(error *e, int code, const char *fmt, va_list ap); extern error *global_err;