This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Analysis of libstdc++/2071 test case
- To: rittle at rsch dot comm dot mot dot com
- Subject: Re: Analysis of libstdc++/2071 test case
- From: Peter Schmid <schmid at snake dot iap dot physik dot tu-darmstadt dot de>
- Date: Wed, 9 May 2001 18:31:20 +0200 (CEST)
- cc: libstdc++ at gcc dot gnu dot org
First of all, I like to thank you for your excellent analysis of the
problem. I can confirm that reading from cin produces illegal seeks.
The program,
#include <iostream>
using namespace std;
int main()
{
int i;
cin >> i;
cout << "i == " << i << endl;
}
included in your email, generates 18 illegal seeks, like:
_llseek(0, -5, 0xbffff62c, SEEK_CUR) = -1 ESPIPE (Illegal seek).
If I add some error checking to your second code, check the value of
errno, and run the resulting program compiled by gcc version 3.1
20010508 (experimental) on i686-pc-linux-gnu (glibc 2.2).
#include <errno.h>
#include <stdio.h>
int main ()
{
char buf;
char buf2;
if (fread (&buf, 1, 1, stdin) != 1)
perror(NULL);
if (fseek (stdin, 0, SEEK_CUR) == -1)
perror(NULL);
if (fread (&buf2, 1, 1, stdin) != 1)
perror(NULL);;
printf ("%c %c %d\n", buf, buf2, errno);
return 0;
}
The output is as follows:
./a.out
1234
Illegal seek
1 2 29
If I replace the fseek with an lseek on STDIN_FILENO, the same error
message occurs.
I believe that seeking on the stdin file descriptor is not
allowed. Therefore, the result of a program run of the above program is
not well defined.
I see no reason why the call to fseek is not dropped when reading from
stdin.
Hope this helps,
Peter Schmid