libstdc++/9024: Input fails after call to basic_filebuf<>::pubsetbuf(0, 0)
peturr02@ru.is
peturr02@ru.is
Fri Dec 20 06:46:00 GMT 2002
>Number: 9024
>Category: libstdc++
>Synopsis: Input fails after call to basic_filebuf<>::pubsetbuf(0, 0)
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Dec 20 06:46:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: peturr02@ru.is
>Release: gcc-3.2.1
>Organization:
>Environment:
Redhat Linux 8.0 on i686; glibc-2.2.93
>Description:
It is not possible to use a basic_ifstream s for input if s.rdbuf()->pubsetbuf(0, 0) has been called.
The call pubsetbuf(0, 0) is described in:
Bjarne Stroustrup, The C++ Programing Language, 3rd edition,
Section 21.6.4, page 647:
"By default, setbuf(0, 0) means "unbuffered""
Nicolai M. Josuttis, The C++ Standard Library, page 664:
"...the use of [pubsetbuf] is only portable if it is called
before the first I/O operation is performed and it is called as pubsetbuf(0, 0)..."
>How-To-Repeat:
See attachment.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="setbuf.cc"
Content-Disposition: inline; filename="setbuf.cc"
//////////////////////////////////////////////////////////////////////
// setbuf.cc
//
// Test program for basic_filebuf<>::pubsetbuf
//
// Bjarne Stroustrup, The C++ Programing Language, 3rd edition,
// Section 21.6.4, page 647:
// "By default, setbuf(0, 0) means "unbuffered""
//
// Nicolai M. Josuttis, The C++ Standard Library, page 664:
// "...the use of [pubsetbuf] is only portable if it is called
// before the first I/O operation is performed and it is called as
// pubsetbuf(0, 0)..."
//////////////////////////////////////////////////////////////////////
#include <fstream>
#include <string>
#include <iterator>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;
int main()
{
string const str1 = "abcdefghijklmnopqrstuvwxyz";
string str2;
string str3;
char name[] = "pubsetbuftestXXXXXX";
mktemp(name);
{
ofstream stream1;
if (!stream1.rdbuf()->pubsetbuf(0, 0))
assert(false);
stream1.open(name);
copy(str1.begin(), str1.end(), ostreambuf_iterator<char>(stream1));
}
{
ifstream stream2;
stream2.open(name);
copy(istreambuf_iterator<char>(stream2), istreambuf_iterator<char>(),
back_inserter(str2));
}
{
ifstream stream3;
if (!stream3.rdbuf()->pubsetbuf(0, 0))
assert(false);
stream3.open(name);
copy(istreambuf_iterator<char>(stream3),
istreambuf_iterator<char>(),
back_inserter(str3));
}
remove(name);
cout << "str1 = " << str1 << endl;
cout << "str2 = " << str2 << endl;
cout << "str3 = " << str3 << endl;
assert(str1 == str2);
assert(str1 == str3);
return 0;
}
More information about the Gcc-bugs
mailing list