diff options
| author | Calvin Buckley <calvin@cmpct.info> | 2021-07-17 16:21:05 -0300 |
|---|---|---|
| committer | Calvin Buckley <calvin@cmpct.info> | 2021-07-17 16:21:05 -0300 |
| commit | 950a7f76e2db0bd578717c96123e5e59770c242c (patch) | |
| tree | eca833cddfd20b07ce83931eb019a3d213e18571 /src | |
| parent | 6a7f04030e124855c3e617a21c814074a2585753 (diff) | |
| download | libgit2-950a7f76e2db0bd578717c96123e5e59770c242c.tar.gz | |
Variadic arguments aren't in C89
This refactors this to a wrapper function, as well as changing the
existing API have a va_list and ... version.
Diffstat (limited to 'src')
| -rw-r--r-- | src/trace.h | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/trace.h b/src/trace.h index e15118ef5..e93283788 100644 --- a/src/trace.h +++ b/src/trace.h @@ -21,31 +21,53 @@ struct git_trace_data { extern struct git_trace_data git_trace__data; -GIT_INLINE(void) git_trace__write_fmt( +GIT_INLINE(void) git_trace__vwrite_fmt( git_trace_level_t level, - const char *fmt, ...) + const char *fmt, va_list ap) { git_trace_cb callback = git_trace__data.callback; git_buf message = GIT_BUF_INIT; - va_list ap; - va_start(ap, fmt); git_buf_vprintf(&message, fmt, ap); - va_end(ap); callback(level, git_buf_cstr(&message)); git_buf_dispose(&message); } +GIT_INLINE(void) git_trace__write_fmt( + git_trace_level_t level, + const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + git_trace__vwrite_fmt(level, fmt, ap); + va_end(ap); +} + #define git_trace_level() (git_trace__data.level) +/* Varadic macros are a C99 feature */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define git_trace(l, ...) { \ if (git_trace__data.level >= l && \ git_trace__data.callback != NULL) { \ git_trace__write_fmt(l, __VA_ARGS__); \ } \ } +#else +GIT_INLINE(void) git_trace(git_trace_level_t level, const char *fmt, ...) +{ + if (git_trace__data.level >= level && + git_trace__data.callback != NULL) { + va_list ap; + va_start(ap, fmt); + git_trace__vwrite_fmt(level, fmt, ap); + va_end(ap); + } +} +#endif #else GIT_INLINE(void) git_trace__null( |
