git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCH 1/3] strbuf: Add strbuf_vaddf function

From
Julian Phillips <julian@quantumfyre.co.uk>
Date
Apr 11, 2010, 11:37 UTC
Message-ID
<20100411113733.80010.78232.julian@quantumfyre.co.uk>
In-Reply-To
<20100411112928.80010.1786.julian@quantumfyre.co.uk>
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);
 	len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
 	va_end(ap);
 	if (len < 0)
 		die("your vsnprintf is broken");
 	if (len > strbuf_avail(sb)) {
 		strbuf_grow(sb, len);
-		va_start(ap, fmt);
+		va_copy(ap, args);
 		len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
 		va_end(ap);
 		if (len > strbuf_avail(sb)) {
diff --git a/strbuf.h b/strbuf.h
index fac2dbc..ac52834 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -120,6 +120,7 @@ extern void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *
 
 __attribute__((format (printf,2,3)))
 extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
+extern void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list args);
 
 extern size_t strbuf_fread(struct strbuf *, size_t, FILE *);
 /* XXX: if read fails, any partial read is undone */
-- 
1.7.0.4
Previous: Julian PhillipsNext: Erik Faye-Lund
Message 2 of 24 in “JSON/XML output for scripting interface”
  1. 0/3 JSON/XML output for scripting interfaceJulian Phillips, Apr 11, 2010
  2. 1/3 strbuf: Add strbuf_vaddf functionJulian Phillips, Apr 11, 2010
  3. Erik Faye-LundApr 11, 2010
  4. Julian PhillipsApr 11, 2010
  5. 2/3 add a library of code for producing structured outputJulian Phillips, Apr 11, 2010
  6. Erik Faye-LundApr 11, 2010
  7. Julian PhillipsApr 11, 2010
  8. Jakub NarebskiApr 11, 2010
  9. Junio C HamanoApr 11, 2010
  10. Sverre RabbelierApr 11, 2010
  11. Julian PhillipsApr 11, 2010
  12. Jakub NarebskiApr 11, 2010
  13. Julian PhillipsApr 11, 2010
  14. Eric RaymondApr 11, 2010
  15. 3/3 status: add support for structured outputJulian Phillips, Apr 11, 2010
  16. Sverre RabbelierApr 11, 2010
  17. Julian PhillipsApr 11, 2010
  18. Sverre RabbelierApr 11, 2010
  19. Julian PhillipsApr 11, 2010
  20. Sverre RabbelierApr 11, 2010
  21. Jon SeymourApr 11, 2010
  22. Eric RaymondApr 11, 2010
  23. Jon SeymourApr 11, 2010
  24. Julian PhillipsApr 11, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.