This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/9339: filebuf::pubsetbuf(0, 0) doesn't turn off buffering
- From: peturr02 at ru dot is
- To: gcc-gnats at gcc dot gnu dot org
- Date: 16 Jan 2003 10:35:51 -0000
- Subject: libstdc++/9339: filebuf::pubsetbuf(0, 0) doesn't turn off buffering
- Reply-to: peturr02 at ru dot is
>Number: 9339
>Category: libstdc++
>Synopsis: filebuf::pubsetbuf(0, 0) doesn't turn off buffering
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Jan 16 02:36:01 PST 2003
>Closed-Date:
>Last-Modified:
>Originator: peturr02@ru.is
>Release: gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
Calling fb.pubsetbuf(0, 0) on a basic_filebuf<> fb only turns off the filebuf's own buffers, not the buffers in the underlying FILE*, so fb remains buffered in effect.
>How-To-Repeat:
See attachment.
>Fix:
Call setbuf(f, 0) after f = fopen() if unbuffered I/O has been requested.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="filesetbufbug.cc"
Content-Disposition: inline; filename="filesetbufbug.cc"
#include <fstream>
#include <cstdio>
using namespace std;
int main()
{
filebuf fbuf01;
fbuf01.pubsetbuf(0, 0);
fbuf01.open("tmp", ios_base::out | ios_base::trunc);
fbuf01.pubsetbuf(0, 0);
fbuf01.sputn("g++", 3);
filebuf fbuf02;
fbuf02.open("tmp", ios_base::in);
char buf[256];
int n = fbuf02.sgetn(buf, 256);
assert(n > 0);
return 0;
}