errors: introduce `git_error_vset` function Right now, we only provide a `git_error_set` that has a variadic function signature. It's impossible to drive this function in a C89-compliant way from other functions that have a variadic signature, though, like for example `git_parse_error`. Implement a new `git_error_vset` function that gets a `va_list` as parameter, fixing the above problem.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
diff --git a/src/errors.c b/src/errors.c
index 8ef4919..18d6c2d 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -49,9 +49,17 @@ void git_error_set_oom(void)
GIT_GLOBAL->last_error = &g_git_oom_error;
}
-void git_error_set(int error_class, const char *string, ...)
+void git_error_set(int error_class, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ git_error_vset(error_class, fmt, ap);
+ va_end(ap);
+}
+
+void git_error_vset(int error_class, const char *fmt, va_list ap)
{
- va_list arglist;
#ifdef GIT_WIN32
DWORD win32_error_code = (error_class == GIT_ERROR_OS) ? GetLastError() : 0;
#endif
@@ -59,11 +67,8 @@ void git_error_set(int error_class, const char *string, ...)
git_buf *buf = &GIT_GLOBAL->error_buf;
git_buf_clear(buf);
- if (string) {
- va_start(arglist, string);
- git_buf_vprintf(buf, string, arglist);
- va_end(arglist);
-
+ if (fmt) {
+ git_buf_vprintf(buf, fmt, ap);
if (error_class == GIT_ERROR_OS)
git_buf_PUTS(buf, ": ");
}
diff --git a/src/errors.h b/src/errors.h
index f2af1e3..86f06f9 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -14,8 +14,8 @@
/*
* Set the error message for this thread, formatting as needed.
*/
-
-void git_error_set(int error_class, const char *string, ...) GIT_FORMAT_PRINTF(2, 3);
+void git_error_set(int error_class, const char *fmt, ...) GIT_FORMAT_PRINTF(2, 3);
+void git_error_vset(int error_class, const char *fmt, va_list ap);
/**
* Set the error message for a regex failure, using the internal regex