Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add pkg_vprintf(3)
Matthew Seaman committed 12 years ago
commit 7f803201142858070a42b5c647564849a5fb2d2f
parent 9f608b8
3 files changed +40 -2
modified libpkg/pkg.h.in
@@ -1384,6 +1384,14 @@ struct pkg_repo *pkg_repo_find_name(const char *name);
int pkg_printf(const char * restrict fmt, ...);

/**
+
 * print to stdout data from pkg as indicated by the format code fmt
+
 * @param ap Varargs list of struct pkg etc. supplying the data
+
 * @param fmt String with embedded %-escapes indicating what to print
+
 * @return count of the number of characters printed
+
 */
+
int pkg_vprintf(const char * restrict fmt, va_list ap);
+

+
/**
 * print to named stream from pkg as indicated by the format code fmt
 * @param ... Varargs list of struct pkg etc. supplying the data
 * @param fmt String with embedded %-escapes indicating what to output
modified libpkg/pkg_printf.3
@@ -44,6 +44,8 @@
.Ft int
.Fn pkg_printf "const char * restrict format" ...
.Ft int
+
.Fn pkg_vprintf "const char * restrict format" "va_list ap"
+
.Ft int
.Fn pkg_fprintf "FILE * restrict stream" "const char * restrict format" ...
.Ft int
.Fn pkg_vfprintf "FILE * restrict stream" "const char * restrict format" "va_list ap"
@@ -67,8 +69,10 @@ as described below, analogously to the similarly named
family of functions.
The
.Fn pkg_printf
-
function
-
writes output to
+
and
+
.Fn pkg_vprintf
+
functions
+
write output to
.Dv stdout ,
the standard output stream;
.Fn pkg_fprintf
modified libpkg/pkg_printf.c
@@ -2669,6 +2669,32 @@ pkg_printf(const char * restrict format, ...)
}

/**
+
 * print to stdout data from pkg as indicated by the format code format
+
 * @param ap Varargs list of struct pkg etc. supplying the data
+
 * @param format String with embedded %-escapes indicating what to print
+
 * @return count of the number of characters printed
+
 */
+
int
+
pkg_vprintf(const char * restrict format, va_list ap)
+
{
+
	struct sbuf	*sbuf;
+
	int		 count;
+

+
	sbuf  = sbuf_new_auto();
+

+
	if (sbuf)
+
		sbuf = pkg_sbuf_vprintf(sbuf, format, ap);
+
	if (sbuf && sbuf_len(sbuf) >= 0) {
+
		sbuf_finish(sbuf);
+
		count = printf("%s", sbuf_data(sbuf));
+
	} else
+
		count = -1;
+
	if (sbuf)
+
		sbuf_delete(sbuf);
+
	return (count);
+
}
+

+
/**
 * print to named stream from pkg as indicated by the format code format
 * @param ... Varargs list of struct pkg etc. supplying the data
 * @param format String with embedded %-escapes indicating what to output