[Patch] Fix libstdc++/11378 (3rd take)

Nathan Myers ncm-nospam@cantrip.org
Sat Jul 12 16:45:00 GMT 2003

On Sat, Jul 12, 2003 at 01:52:06PM +0200, Paolo Carlini wrote:
> Hi,
> this is the 3rd try: in this case I have added an autoconf
> test for writev, which is then used when available, as per
> Nathan's indication.
> I would really like to have this in and close 11378 once
> and for all.

Wow, that's fast work!  Looks clean too.

There is one thing left, though.  writev() (like write()) is allowed
to return a "short write", writing less than was asked, and we're
supposed to call it again until it either finishes or fails to make
progress.  That means a loop in, or around the call to, xsputn_2.  
If it writes only part of the internal buffer before failing, we 
probably should memmove() the rest of the internal buffer back to 
the beginning and update pptr() accordingly.  Finally, overflow()
should behave similarly, which also means __basic_file<>::xsputn()
needs a loop too.

I'm sorry that this is seeming to blow up in your face.  I only
just noticed the underlying correctness problem.  It has to work
right (i.e. not corrupt the streambuf) if write() only ever returns 
1 or -1, and if it returns 1 and then -1.  That makes the code 
uglier, unfortunately.  

Getting that right with multibyte character encodings will be a
separate exercise, using some of the same algorithms involved in
seeking.  First let's get the noconv case right.

Nathan Myers

More information about the Libstdc++ mailing list