public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: peturr02@ru.is To: gcc-gnats@gcc.gnu.org Subject: libstdc++/9024: Input fails after call to basic_filebuf<>::pubsetbuf(0, 0) Date: Fri, 20 Dec 2002 06:46:00 -0000 [thread overview] Message-ID: <20021220143759.7319.qmail@sources.redhat.com> (raw) >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; }
next reply other threads:[~2002-12-20 14:46 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-12-20 6:46 peturr02 [this message] 2002-12-20 11:07 paolo 2002-12-20 11:16 paolo 2002-12-20 11:26 Paolo Carlini 2002-12-20 14:34 paolo 2003-03-02 21:26 Paolo Carlini 2003-03-03 10:46 Pétur Runólfsson 2003-03-03 10:56 Paolo Carlini
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20021220143759.7319.qmail@sources.redhat.com \ --to=peturr02@ru.is \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).