diff options
author | 1997-11-29 19:54:47 +0000 | |
---|---|---|
committer | 1997-11-29 19:54:47 +0000 | |
commit | 78f54e551ce4905b49ea2f783dbde347cc5391ba (patch) | |
tree | dc40c4d8751e4cbc182dd5c8bae3cb9aa02f24f1 /lib/libc/stdio/fvwrite.c | |
parent | Return -1, not EOF for size < 1. XPG4.2 specifies the return value (diff) | |
download | wireguard-openbsd-78f54e551ce4905b49ea2f783dbde347cc5391ba.tar.xz wireguard-openbsd-78f54e551ce4905b49ea2f783dbde347cc5391ba.zip |
Implement asprintf(3) and vasprintf(3) functions similar to the
ones in the glibc. Some man pages changes from FreeBSD
(asprintf.c/vasprintf.c are not based on GNU or FreeBSD code).
Diffstat (limited to 'lib/libc/stdio/fvwrite.c')
-rw-r--r-- | lib/libc/stdio/fvwrite.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/libc/stdio/fvwrite.c b/lib/libc/stdio/fvwrite.c index 259152be86f..c01968b72f8 100644 --- a/lib/libc/stdio/fvwrite.c +++ b/lib/libc/stdio/fvwrite.c @@ -35,10 +35,11 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: fvwrite.c,v 1.4 1996/10/26 08:16:07 tholo Exp $"; +static char rcsid[] = "$OpenBSD: fvwrite.c,v 1.5 1997/11/29 19:54:48 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <errno.h> #include "local.h" @@ -109,6 +110,21 @@ __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; + /* XXX - check return val */ + fp->_bf._base = + realloc(fp->_bf._base, fp->_bf._size + 1); + fp->_p = fp->_bf._base + blen; + } w = fp->_w; if (fp->_flags & __SSTR) { if (len < w) |