Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add new pkg_vfprintf(3) function -- equivalent to vfprintf(3)
Matthew Seaman committed 12 years ago
commit 9f608b81335864b6ecb84216118415172bcb807f
parent 72e6e4c
3 files changed +39 -1
modified libpkg/pkg.h.in
@@ -1392,6 +1392,14 @@ int pkg_printf(const char * restrict fmt, ...);
int pkg_fprintf(FILE * restrict stream, const char * restrict fmt, ...);

/**
+
 * print to named stream from pkg as indicated by the format code fmt
+
 * @param ap varargs arglist
+
 * @param fmt String with embedded %-escapes indicating what to output
+
 * @return count of the number of characters printed
+
 */
+
int pkg_vfprintf(FILE * restrict stream, const char * restrict fmt, va_list ap);
+

+
/**
 * print to file descriptor d data from pkg as indicated by the format
 * code fmt
 * @param d Previously opened file descriptor to print to
modified libpkg/pkg_printf.3
@@ -46,6 +46,8 @@
.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"
+
.Ft int
.Fn pkg_dprintf "int fd" "const char * restrict format" ...
.Ft int
.Fn pkg_snprintf "char * restrict str" "size_t size" "const char * restrict format" ...
@@ -70,7 +72,9 @@ writes output to
.Dv stdout ,
the standard output stream;
.Fn pkg_fprintf
-
writes output to the given output
+
and
+
.Fn pkg_vfprintf
+
write output to the given output
.Fa stream ;
.Fn pkg_dprintf
writes output to the given file descriptor;
modified libpkg/pkg_printf.c
@@ -2698,6 +2698,32 @@ pkg_fprintf(FILE * restrict stream, const char * restrict format, ...)
}

/**
+
 * print to named stream 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 output
+
 * @return count of the number of characters printed
+
 */
+
int
+
pkg_vfprintf(FILE * restrict stream, 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 = fprintf(stream, "%s", sbuf_data(sbuf));
+
	} else
+
		count = -1;
+
	if (sbuf)
+
		sbuf_delete(sbuf);
+
	return (count);
+
}
+

+
/**
 * print to file descriptor d data from pkg as indicated by the format
 * code format
 * @param d Previously opened file descriptor to print to