diff options
author | ache <ache@FreeBSD.org> | 1997-12-24 23:23:18 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 1997-12-24 23:23:18 +0000 |
commit | 33cd251a1b5fd365424f8c5044b05822a430c102 (patch) | |
tree | 1b4868f15792a5fe101e4930c08a93586ab6ccfb /lib/libc/stdio | |
parent | d6bcc605a0dda1fae5485a69235f91b7eaa17666 (diff) | |
download | FreeBSD-src-33cd251a1b5fd365424f8c5044b05822a430c102.zip FreeBSD-src-33cd251a1b5fd365424f8c5044b05822a430c102.tar.gz |
1) Restore back comment about snprintf()
2) Optimize string buffer copy to call memcpy() and update pointers
only for count > 0, it makes snprintf(NULL, 0, ...) more efficient
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r-- | lib/libc/stdio/fvwrite.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/libc/stdio/fvwrite.c b/lib/libc/stdio/fvwrite.c index 8ff7446..5061773 100644 --- a/lib/libc/stdio/fvwrite.c +++ b/lib/libc/stdio/fvwrite.c @@ -39,7 +39,7 @@ static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93"; #endif static const char rcsid[] = - "$Id: fvwrite.c,v 1.5 1997/02/22 15:02:08 peter Exp $"; + "$Id: fvwrite.c,v 1.6 1997/12/24 13:17:13 ache Exp $"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> @@ -104,9 +104,10 @@ __sfvwrite(fp, uio) * one _bf._size byte chunk directly (without copying). * * String output is a special case: write as many bytes - * as fit, but pretend we wrote everything. This avoids - * snprintf() write function (so that the write function - * can be invalid). + * as fit, but pretend we wrote everything. This makes + * snprintf() return the number of bytes needed, rather + * than the number used, and avoids its write function + * (so that the write function can be invalid). */ do { GETIOV(;); @@ -114,9 +115,11 @@ __sfvwrite(fp, uio) if (fp->_flags & __SSTR) { if (len < w) w = len; - COPY(w); /* copy MIN(fp->_w,len), */ - fp->_w -= w; - fp->_p += w; + if (w > 0) { + COPY(w); /* copy MIN(fp->_w,len), */ + fp->_w -= w; + fp->_p += w; + } w = len; /* but pretend copied all */ } else if (fp->_p > fp->_bf._base && len > w) { /* fill and flush */ |