[PATCH] Do not break buffers in fvwrite for unbuffered files
Corinna Vinschen
vinschen@redhat.com
Mon Nov 4 14:19:00 GMT 2013
Hi Federico,
On Nov 1 10:39, Federico Terraneo wrote:
> On 10/31/2013 03:41 PM, Corinna Vinschen wrote:
> > On Oct 31 12:55, Federico Terraneo wrote:
> >>
> >> This can't happen, since there's an
> >>
> >> else if (fp->_p > fp->_bf._base || len < fp->_bf._size)
> >>
> >> that catches this case and fills the file buffer instead.
> >
> > Oh, hmm. I didn't notice the || in the if clause. Doesn't that
> > mean that the last else branch is never used since there's always a
> > buffer at _bf._base? The fact that we use a FILE buffer is now
> > sufficient to use it and never to write directly, AFAICS.
> >
>
> Not exactly. The
>
> if (fp->_p > fp->_bf._base
>
> isn't true if there's a buffer. It's true if there is at least a
> character in the buffer, fp->_p is the 'put pointer'.
> [...]
Apparently I didn't wear my glasses because I misread the if clause.
Somehow I managed to read that as
if (fp->_bf._base || len < fp->_bf._size)
entirely dropping the "fp->_p > ". Sorry about that.
I checked the patch in with a minor change:
> - w = fp->_write (ptr, fp->_cookie, p, MIN (len, BUFSIZ));
> + w = fp->_write (ptr, fp->_cookie, p, MIN (len, INT_MAX));
I made that
w = fp->_write (ptr, fp->_cookie, p,
MIN (len, INT_MAX - INT_MAX % BUFSIZ));
so the chunk is a multiple of BUFSIZ.
Thanks a lot,
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20131104/87b3b081/attachment.sig>
More information about the Newlib
mailing list