Skip to content

Commit

Permalink
Add stdargs support to the error API.
Browse files Browse the repository at this point in the history
  • Loading branch information
obilaniu committed Aug 4, 2017
1 parent aa1d2e8 commit 1b18d0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/util/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/util/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 1b18d0e

Please sign in to comment.