From: Olga Telezhnaya Date: Wed, 21 Mar 2018 18:28:49 GMT Subject: [PATCH v5 1/6] strbuf: add shortcut to work with error messages Message-ID: <0102016249d21c40-0edf6647-4d26-46fc-8cfd-5a446b93a5e2-000000@eu-west-1.amazonses.com> In-Reply-To: <01020162442818b4-c153f9ce-3813-41a6-aebd-f5cb2b98b1fa-000000@eu-west-1.amazonses.com> Add function strbuf_error() that helps to save few lines of code. Function expands fmt with placeholders, append resulting error message to strbuf *err, and return error code ret. Signed-off-by: Olga Telezhnaia --- strbuf.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/strbuf.h b/strbuf.h index e6cae5f4398c8..fa66d4835f1a7 100644 --- a/strbuf.h +++ b/strbuf.h @@ -620,4 +620,17 @@ char *xstrvfmt(const char *fmt, va_list ap); __attribute__((format (printf, 1, 2))) char *xstrfmt(const char *fmt, ...); +/* + * Expand error message, append it to strbuf *err, then return error code ret. + * Allow to save few lines of code. + */ +static inline int strbuf_error(struct strbuf *err, int ret, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + strbuf_vaddf(err, fmt, ap); + va_end(ap); + return ret; +} + #endif /* STRBUF_H */ -- https://github.com/git/git/pull/466