Date: Thu, 01 Feb 2001 23:11:05 +0200 From: "Eli Zaretskii" Sender: halo1 AT zahav DOT net DOT il To: Martin Str|mberg Message-Id: <8011-Thu01Feb2001231104+0200-eliz@is.elta.co.il> X-Mailer: Emacs 20.6 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.6 CC: djgpp-workers AT delorie DOT com In-reply-to: <200101312110.WAA04560@father.ludd.luth.se> (message from Martin Str|mberg on Wed, 31 Jan 2001 22:10:34 +0100 (MET)) Subject: Re: Bug000323 References: <200101312110 DOT WAA04560 AT father DOT ludd DOT luth DOT se> Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > From: Martin Str|mberg > Date: Wed, 31 Jan 2001 22:10:34 +0100 (MET) > > According to Eli Zaretskii: > > > > On Wed, 31 Jan 2001, Martin Stromberg wrote: > > > > > > > Index: src/libc/ansi/stdio/doprnt.c > > > > > + > > > > > + if (fp->_flag & _IOAPPEND) > > > > > + { > > > > > + if ( llseek(fileno(fp), 0, SEEK_END) == -1 ) > > > > > + { > > > > > + return (EOF); > > > > > + } > > > > > + } > > > > > > > > This shouldn't be needed; the flsbuf() call should move to EOF. > > > > > > Well, I tried without it and it didn't work. > > > > Are you sure you tried this with a handle which had _IOAPPEND flag set, > > and with _flsbuf doing the Right Thing with _IOAPPEND? > > > > I don't see how could this not work, since _doprnt always calls putc to > > output the text, and putc always calls _flsbuf. > > Well, I'm having a troubles looking at what flags are set. But if you > try the test program in test/libc/ansi/stdio/append.c with and without > this part you'll see the difference. Ah, I see why. The test program prints a very short string and then closes the file. So the entire text is buffered inside the FILE object when fclose is called, and it is up to fclose to flush it. fclose calls fflush, but fflush doesn't go through _fslbuf, it calls _write directly. (I don't remember why, but it probably has a good reason.) Solution: add llseek to fflush, and you solved two problems: no need for llseek in _doprnt, and a bug with writing the last portion of the data from fflush is also squashed ;-)