Commit c8e63812 by Patrick Steinhardt

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.
parent e8f63411
......@@ -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, ": ");
}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment