Date: Tue, 8 May 2001 10:20:30 +0300 (IDT) From: Eli Zaretskii X-Sender: eliz AT is To: Andris Pavenis cc: djgpp-workers AT delorie DOT com Subject: Re: libstdc++-v3: bug in handling text files for DJGPP In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 On Tue, 8 May 2001, Andris Pavenis wrote: > > DO I understand correctly that libstdc++ uses its own buffering (as > > opposed to the buffering code implemented in libc.a for stdio)? > > > > If so, it should use code similar to what the DJGPP library does for > > buffered I/O functions. > > Here is source of basic_filebuf::sync() > > virtual int > sync(void) > { > bool __testput = _M_out_cur && _M_out_beg < _M_out_end; > if (__testput) > { > // Make sure that libio resyncs its idea of the file position > // with the external file. > _M_file->sync(); > > // Need to restore current position. This interpreted as > // the position of the external byte sequence (_M_file) > // plus the offset in the current internal buffer > // (_M_out_beg - _M_out_cur) > streamoff __cur = _M_file->seekoff(0, ios_base::cur); > off_type __off = _M_out_cur - _M_out_beg; > _M_really_overflow(); > _M_file->seekpos(__cur + __off); > } > _M_last_overflowed = false; > return 0; > } > > _M_file->sync() is simply fflush(_M_file._M_cfile) Thanks. But the real problem seems to be inside seekoff, or maybe seekpos. In general, as we know from the libc experience, the way to solve these problems is to read the file in binary mode and remove the CR characters when delivering the data to applications. The buffered data should retain the CRs. Then seeking will DTRT, as it does on GNU/Linux.