[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gcc 3.4.3, stdio_filebuf problem
From: |
Ralf Fassel |
Subject: |
gcc 3.4.3, stdio_filebuf problem |
Date: |
Wed, 09 Feb 2005 16:07:41 +0100 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Security Through Obscurity, linux) |
gcc 3.4.3, HP-UX 10.20
I got a weird problem with the following program on HP-10.20 w/ gcc
3.4.3 (but not with gcc 3.4.1):
#include <iostream>
#include <ext/stdio_filebuf.h>
typedef __gnu_cxx::stdio_filebuf<char> my_strbuf;
class mstream : public std::iostream
{
public:
mstream() : std::iostream(NULL) {
my_strbuf *strbuf = new my_strbuf(stdin, std::ios::in);
rdbuf(strbuf);
}
};
int
main(int argc, char *argv[]) {
size_t count = 2048, total = 0, blocks = 0;
if (argc > 1) count = atoi(argv[1]);
char buffer[count];
mstream inp;
while (!inp.eof()) {
inp.read(buffer, count);
total += inp.gcount();
blocks++;
if (count != inp.gcount()) {
std::cerr << "wanted " << count << ", got " << inp.gcount() <<
std::endl;
}
}
std::cerr << "total bytes read " << total << ", blocks " << blocks <<
std::endl;
}
The idea is to attach stdin (or any other FILE*) to the iostream via
the rdbuf() created from the FILE*.
Now this runs ok _except_ when I try to read buffers using an
`unusual' byte count in a pipe:
redirected from file, ok:
% ./t343 < big_file
./t343 < big_file
wanted 2048, got 1712
total bytes read 11601584, blocks 5665
redirected from file, byte count 2084, ok:
% ./t343 2084 < big_file
./t343 2084 < big_file
wanted 2084, got 2040
total bytes read 11601584, blocks 5567
in pipe, ok:
% cat big_file | ./t343
cat big_file | ./t343
wanted 2048, got 1712
total bytes read 11601584, blocks 5665
in pipe, byte count 2084, NOT OK:
% cat big_file | ./t343 2084
cat big_file | ./t343 2084
wanted 2084, got 1940
total bytes read 8192, blocks 4
Note the short read in the last case.
I had seen the same effect on Linux, but only once. When trying to
reproduce it, the error went away :-(. But on HP, it is definitely
reproducable. The same program compiled with gcc 3.4.1 runs ok on the
very same machine.
Any ideas?
R'
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gcc 3.4.3, stdio_filebuf problem,
Ralf Fassel <=