Mail Archives: djgpp-workers/2001/05/08/04:36:40
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.
- Raw text -