Re: [RFC/PATCH 1/3] strbuf: Add strbuf_vaddf function
- From
Erik Faye-Lund <kusmabite@googlemail.com>
- Date
- Apr 11, 2010, 12:42 UTC
- Message-ID
- <n2i40aa078e1004110542kcfba8b6dw8848cd8f5647fda7@mail.gmail.com>
- In-Reply-To
- <20100411113733.80010.78232.julian@quantumfyre.co.uk>
On Sun, Apr 11, 2010 at 1:37 PM, Julian Phillips <julian@quantumfyre.co.uk> wrote:
Show 32 quoted lines
> Add strbuf_vaddf which is to strbuf_addf as vprintf is to printf.
>
> Signed-off-by: Julian Phillips <julian@quantumfyre.co.uk>
> ---
> strbuf.c | 13 +++++++++++--
> strbuf.h | 1 +
> 2 files changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/strbuf.c b/strbuf.c
> index bc3a080..8f312f8 100644
> --- a/strbuf.c
> +++ b/strbuf.c
> @@ -194,19 +194,28 @@ void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len)
>
> void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
> {
> + va_list ap;
> +
> + va_start(ap, fmt);
> + strbuf_vaddf(sb, fmt, ap);
> + va_end(ap);
> +}
> +
> +void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list args)
> +{
> int len;
> va_list ap;
>
> if (!strbuf_avail(sb))
> strbuf_grow(sb, 64);
> - va_start(ap, fmt);
> + va_copy(ap, args);Isn't va_copy C99? The only other place we use this is in compat/winansi.c, but that file is only compiled on Windows. Both compilers we support on Windows supports va_copy (or some way of emulating it).
IIRC, strbuf_vaddf() has been attempted added multiple times before (by me, for one), and the efforts have always ended up being scrapped due to the lack of a portable va_copy.
-- Erik "kusma" Faye-Lund