diff options
-rw-r--r-- | lib/libc/stdio/fvwrite.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/libc/stdio/fvwrite.c b/lib/libc/stdio/fvwrite.c index 07c4bc7a06d..ef854a3f9b0 100644 --- a/lib/libc/stdio/fvwrite.c +++ b/lib/libc/stdio/fvwrite.c @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: fvwrite.c,v 1.7 1998/08/14 21:39:40 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: fvwrite.c,v 1.8 1998/11/20 06:13:26 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> @@ -114,18 +114,20 @@ __sfvwrite(fp, uio) (__SALC | __SSTR) && fp->_w < len) { size_t blen = fp->_p - fp->_bf._base; unsigned char *_base; + int _size; - /* - * 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; - _base = realloc(fp->_bf._base, fp->_bf._size + 1); + /* Allocate space exponentially. */ + _size = fp->_bf._size; + do { + _size = (_size << 1) + 1; + } while (_size < blen + len); + _base = realloc(fp->_bf._base, _size + 1); if (_base == NULL) goto err; + fp->_w += _size - fp->_bf._size; fp->_bf._base = _base; - fp->_p = fp->_bf._base + blen; + fp->_bf._size = _size; + fp->_p = _base + blen; } w = fp->_w; if (fp->_flags & __SSTR) { |