[master] 6729ae2b7 vte: Add a VTE_Printf() convenience

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Aug 21 20:52:06 UTC 2023


commit 6729ae2b7641dca1ac9b958ee0c194000779457b
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Thu Aug 17 12:03:13 2023 +0200

    vte: Add a VTE_Printf() convenience

diff --git a/include/vte.h b/include/vte.h
index b570a5c84..438321611 100644
--- a/include/vte.h
+++ b/include/vte.h
@@ -31,4 +31,5 @@ struct vte;
 
 struct vte *VTE_new(int maxfields, int width);
 int VTE_cat(struct vte *, const char *);
+int VTE_printf(struct vte *, const char *, ...) v_printflike_(2, 3);
 void VTE_destroy(struct vte **);
diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c
index 554bb92c1..8529c05fe 100644
--- a/lib/libvarnish/vte.c
+++ b/lib/libvarnish/vte.c
@@ -32,6 +32,7 @@
 #include "config.h"
 
 #include <errno.h>
+#include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h> /* for MUSL (ssize_t) */
@@ -162,6 +163,30 @@ VTE_cat(struct vte *vte, const char *s)
 	return (vte_update(vte));
 }
 
+int
+VTE_printf(struct vte *vte, const char *fmt, ...)
+{
+	va_list ap;
+	int res;
+
+	CHECK_OBJ_NOTNULL(vte, VTE_MAGIC);
+	AN(fmt);
+
+	if (vte->o_sep != 0)
+		return (-1);
+
+	va_start(ap, fmt);
+	res = VSB_vprintf(vte->vsb, fmt, ap);
+	va_end(ap);
+
+	if (res < 0) {
+		vte->o_sep = -1;
+		return (-1);
+	}
+
+	return (vte_update(vte));
+}
+
 void
 VCLI_VTE(struct cli *cli, struct vsb **src, int width)
 {


More information about the varnish-commit mailing list