summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/fvwrite.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1998-07-08 00:44:56 +0000
committerpeter <peter@FreeBSD.org>1998-07-08 00:44:56 +0000
commit22fd80b5ba14d8ddd9166a4d3bb4b21281197323 (patch)
treea91d76ac316b36b89aa7953b4b3aa9a1454caea8 /lib/libc/stdio/fvwrite.c
parent39ff18089a4cdb4c92375680b1f148ab86a589b7 (diff)
downloadFreeBSD-src-22fd80b5ba14d8ddd9166a4d3bb4b21281197323.zip
FreeBSD-src-22fd80b5ba14d8ddd9166a4d3bb4b21281197323.tar.gz
Replace my original asprintf() and vasprintf() hacks with something
more cleanly integrated with stdio. This should be faster and cleaner since it doesn't memcpy() the data into a seperate buffer. This lets stdio allocate and manage the buffer and then hand it over to the user. Obtained from: Todd Miller <Todd.Miller@courtesan.com> via OpenBSD
Diffstat (limited to 'lib/libc/stdio/fvwrite.c')
-rw-r--r--lib/libc/stdio/fvwrite.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/libc/stdio/fvwrite.c b/lib/libc/stdio/fvwrite.c
index 5061773..75dfca9 100644
--- a/lib/libc/stdio/fvwrite.c
+++ b/lib/libc/stdio/fvwrite.c
@@ -39,10 +39,11 @@
static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93";
#endif
static const char rcsid[] =
- "$Id: fvwrite.c,v 1.6 1997/12/24 13:17:13 ache Exp $";
+ "$Id: fvwrite.c,v 1.7 1997/12/24 23:23:18 ache Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "local.h"
#include "fvwrite.h"
@@ -111,6 +112,22 @@ __sfvwrite(fp, uio)
*/
do {
GETIOV(;);
+ if ((fp->_flags & (__SALC | __SSTR)) ==
+ (__SALC | __SSTR) && fp->_w < len) {
+ size_t blen = fp->_p - fp->_bf._base;
+
+ /*
+ * Alloc an extra 128 bytes (+ 1 for NULL)
+ * so we don't call realloc(3) so often.
+ */
+ fp->_w = len + 128;
+ fp->_bf._size = blen + len + 128;
+ fp->_bf._base =
+ realloc(fp->_bf._base, fp->_bf._size + 1);
+ if (fp->_bf._base == NULL)
+ goto err;
+ fp->_p = fp->_bf._base + blen;
+ }
w = fp->_w;
if (fp->_flags & __SSTR) {
if (len < w)
OpenPOWER on IntegriCloud