Skip to content

Commit 1b18d0e

Browse files
committed
Add stdargs support to the error API.
1 parent aa1d2e8 commit 1b18d0e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/util/error.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,20 @@ int error_set(error *e, int code, const char *msg) {
2929
return code;
3030
}
3131

32-
int error_fmt(error *e, int code, const char *fmt, ...) {
33-
va_list ap;
34-
32+
int error_vfmt(error *e, int code, const char *fmt, va_list ap) {
3533
e->code = code;
36-
va_start(ap, fmt);
3734
vsnprintf(e->msg, ERROR_MSGBUF_LEN, fmt, ap);
38-
va_end(ap);
3935
#ifdef DEBUG
4036
fprintf(stderr, "ERROR %d: %s\n", e->code, e->msg);
4137
#endif
4238
return code;
4339
}
40+
41+
int error_fmt(error *e, int code, const char *fmt, ...) {
42+
int ret;
43+
va_list ap;
44+
va_start(ap, fmt);
45+
ret = error_vfmt(e, code, fmt, ap);
46+
va_end(ap);
47+
return ret;
48+
}

src/util/error.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ int error_alloc(error **e);
1818
void error_free(error *e);
1919
int error_set(error *e, int code, const char *msg);
2020
int error_fmt(error *e, int code, const char *fmt, ...);
21+
int error_vfmt(error *e, int code, const char *fmt, va_list ap);
2122

2223
extern error *global_err;
2324

0 commit comments

Comments
 (0)