Module Name:    src
Committed By:   christos
Date:           Mon May 20 20:35:45 UTC 2019

Modified Files:
        src/sys/kern: subr_prf.c
        src/sys/sys: systm.h

Log Message:
Add a simple vasprintf() implementation that uses 2 passes, one to compute
the length and a second to place the data. Requested by rmind@


To generate a diff of this commit:
cvs rdiff -u -r1.176 -r1.177 src/sys/kern/subr_prf.c
cvs rdiff -u -r1.284 -r1.285 src/sys/sys/systm.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/subr_prf.c
diff -u src/sys/kern/subr_prf.c:1.176 src/sys/kern/subr_prf.c:1.177
--- src/sys/kern/subr_prf.c:1.176	Mon Jan 14 14:21:54 2019
+++ src/sys/kern/subr_prf.c	Mon May 20 16:35:45 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_prf.c,v 1.176 2019/01/14 19:21:54 jdolecek Exp $	*/
+/*	$NetBSD: subr_prf.c,v 1.177 2019/05/20 20:35:45 christos Exp $	*/
 
 /*-
  * Copyright (c) 1986, 1988, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.176 2019/01/14 19:21:54 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.177 2019/05/20 20:35:45 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1181,6 +1181,18 @@ vsnprintf(char *bf, size_t size, const c
 	return retval;
 }
 
+int
+vasprintf(char **bf, const char *fmt, va_list ap)
+{
+	int retval;
+	va_list cap;
+
+	va_copy(cap, ap);
+	retval = kprintf(fmt, TOBUFONLY, NULL, NULL, ap) + 1;
+	*bf = kmem_alloc(retval, KM_SLEEP);
+	return vsnprintf(*bf, retval, fmt, cap);
+}
+
 /*
  * kprintf: scaled down version of printf(3).
  *

Index: src/sys/sys/systm.h
diff -u src/sys/sys/systm.h:1.284 src/sys/sys/systm.h:1.285
--- src/sys/sys/systm.h:1.284	Sat May  4 06:07:11 2019
+++ src/sys/sys/systm.h	Mon May 20 16:35:45 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: systm.h,v 1.284 2019/05/04 10:07:11 maxv Exp $	*/
+/*	$NetBSD: systm.h,v 1.285 2019/05/20 20:35:45 christos Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1988, 1991, 1993
@@ -236,6 +236,8 @@ void	printf(const char *, ...) __printfl
 
 int	snprintf(char *, size_t, const char *, ...) __printflike(3, 4);
 
+int	vasprintf(char **, const char *, va_list) __printflike(2, 0);
+
 void	vprintf(const char *, va_list) __printflike(1, 0);
 
 int	vsnprintf(char *, size_t, const char *, va_list) __printflike(3, 0);

Reply via email to