This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [RFC] PR5820: two CTRL-D are not enough?!?
- From: Nathan Myers <ncm-nospam at cantrip dot org>
- To: libstdc++ at gcc dot gnu dot org
- Date: Tue, 2 Apr 2002 07:11:39 +0000
- Subject: Re: [RFC] PR5820: two CTRL-D are not enough?!?
- References: <3CA6FE7D.7000200@unitus.it>
On Sun, Mar 31, 2002 at 02:18:05PM +0200, Paolo Carlini wrote:
> this is one of weirdest PR I have seen in the last months and I have no
> idea if the current behaviour of v3 is conforming or not in this respect.
>
> Submitter maintains that usually two CTRL-D indicates end of output,
> whereas v3 needs /four/.
> This is the original testcase:
>
> #include <iostream>
>
> int main()
> {
> int i;
> char c;
>
> std::cout << "Enter an integer: ";
> std::cin >> i;
> if (!std::cin) {
> std::cerr << "Unexpected read problem\n";
> return 1;
> }
> std::cout << '\n' << "std::cin.eof()=" << std::cin.eof() << '\n';
> std::cout << "The number was: " << i << '\n';
> std::cin >> c;
> if (std::cin) {
> std::cerr << "Could read " << c << " after the number!\n";
> }
> }
>
> I have confirmed that this happens on linux and the following is an
> excerpt of a trace (after a "5" I had to press CTRL-D four times):
>
> ...
>
> SYS_197(0, 0xbffff610, 0, 0xbffff610, 0) = 0
> ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
> mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
> = 0x400c6000
> read(0, "5", 4096) = 1
> _llseek(0, -1, 0xbffff550, SEEK_CUR) = -1 ESPIPE (Illegal seek)
> _llseek(0, 0, 0xbffff550, SEEK_CUR) = -1 ESPIPE (Illegal seek)
> _llseek(0, 1, 0xbffff410, SEEK_CUR) = -1 ESPIPE (Illegal seek)
> _llseek(0, 0, 0xbffff410, SEEK_CUR) = -1 ESPIPE (Illegal seek)
> read(0, "", 4096) = 0
> _llseek(0, 1, 0xbffff420, SEEK_CUR) = -1 ESPIPE (Illegal seek)
> _llseek(0, 0, 0xbffff420, SEEK_CUR) = -1 ESPIPE (Illegal seek)
> read(0, "", 4096) = 0
> _llseek(0, 1, 0xbffff420, SEEK_CUR) = -1 ESPIPE (Illegal seek)
> _llseek(0, 0, 0xbffff420, SEEK_CUR) = -1 ESPIPE (Illegal seek)
> read(0, "", 4096) = 0
> write(1, "\n", 1) = 1
>
> ...
>
> In fact, the same testcase compiled by icc is not affected by the
> "problem"...
I agree this is a serious bug. A single ctrl-D should suffice,
but maybe the terminal mode is eating one of them. I don't see
a need for any calls to _llseek, never mind extra calls to read.
Nathan Myers
ncm at cantrip dot org