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

[PATCH/RFC 02/11] strbuf: add non-variadic function strbuf_vaddf()

From
Erik Faye-Lund <kusmabite@googlemail.com>
Date
Nov 26, 2009, 00:39 UTC
Message-ID
<1259195958-2372-3-git-send-email-kusmabite@gmail.com>
In-Reply-To
<1259195958-2372-2-git-send-email-kusmabite@gmail.com>
From: Mike Pape <dotzenlabs@gmail.com>

This patch adds strbuf_vaddf, which takes a va_list as input instead of the variadic input that strbuf_addf takes. This is useful for fowarding varargs to strbuf_addf.

Signed-off-by: Mike Pape <dotzenlabs@gmail.com>
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
---
 strbuf.c |   15 +++++++++------
 strbuf.h |    1 +
 2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/strbuf.c b/strbuf.c
index a6153dc..e1833fb 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -190,23 +190,18 @@ void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len)
 	strbuf_setlen(sb, sb->len + len);
 }
 
-void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
+void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap)
 {
 	int len;
-	va_list ap;
 
 	if (!strbuf_avail(sb))
 		strbuf_grow(sb, 64);
-	va_start(ap, fmt);
 	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);
 		len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
-		va_end(ap);
 		if (len > strbuf_avail(sb)) {
 			die("this should not happen, your snprintf is broken");
 		}
@@ -214,6 +209,14 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
 	strbuf_setlen(sb, sb->len + len);
 }
 
+void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
+{
+	va_list va;
+	va_start(va, fmt);
+	strbuf_vaddf(sb, fmt, va);
+	va_end(va);
+}
+
 void strbuf_expand(struct strbuf *sb, const char *format, expand_fn_t fn,
 		   void *context)
 {
diff --git a/strbuf.h b/strbuf.h
index d05e056..8686bcb 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -119,6 +119,7 @@ extern size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder,
 
 __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 ap);
 
 extern size_t strbuf_fread(struct strbuf *, size_t, FILE *);
 /* XXX: if read fails, any partial read is undone */
-- 
1.6.5.rc2.7.g4f8d3
Previous: Erik Faye-LundNext: Erik Faye-Lund
Message 3 of 13 in “daemon-win32”
  1. 00/11 daemon-win32Erik Faye-Lund, Nov 26, 2009
  2. 01/11 mingw: add network-wrappers for daemonErik Faye-Lund, Nov 26, 2009
  3. 02/11 strbuf: add non-variadic function strbuf_vaddf()Erik Faye-Lund, Nov 26, 2009
  4. 03/11 mingw: implement syslogErik Faye-Lund, Nov 26, 2009
  5. 04/11 compat: add inet_pton and inet_ntop prototypesErik Faye-Lund, Nov 26, 2009
  6. 05/11 inet_ntop: fix a couple of old-style declsErik Faye-Lund, Nov 26, 2009
  7. 06/11 run-command: add kill_async() and is_async_alive()Erik Faye-Lund, Nov 26, 2009
  8. 07/11 run-command: support input-fdErik Faye-Lund, Nov 26, 2009
  9. 08/11 daemon: use explicit file descriptorErik Faye-Lund, Nov 26, 2009
  10. 09/11 daemon: use run-command api for async servingErik Faye-Lund, Nov 26, 2009
  11. 10/11 daemon: use full buffered mode for stderrErik Faye-Lund, Nov 26, 2009
  12. 11/11 mingw: compile git-daemonErik Faye-Lund, Nov 26, 2009
  13. Erik Faye-LundNov 26, 2009

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.