This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

More on libstdc++/6746


Hi,

Apologies if someone recieves this twice, it seems the mailing
list software thought it was spam.

> III- Create a new, sort-of-underflow, funtion to be called _only_ upon 
> file opening, which basically fills the buffer by way of a O_NOBLOCK 
> read system call 

This should be called from filebuf::showmanyc, not from filebuf::open
so that ifstream::readsome doesn't stop after BUFSIZ characters,
and can be used for fifos and ttys.

Here's a test case (this stops after reading 0 characters with 3.2.1,
after reading 8192 (BUFSIZ) characters with current mainline, but
should read 81920 characters):

#include <fstream>
#include <cstdio>

#undef NDEBUG
#include <cassert>

int main()
{
	using namespace std;

	const char* strlit = "0123456789";

	filebuf fbout;
	fbout.open("tmp", ios_base::out | ios_base::trunc);
	
	int written = 0;
	for (int i = 0; i < BUFSIZ; ++i)
		written += fbout.sputn(strlit, 10);

	fbout.close();

	ifstream in("tmp");
	
	int sum = 0;
	bool gotsome;

	do
	{
		char buf[100];
		int n = in.readsome(buf, sizeof(buf));
		gotsome = (n > 0);
		sum += n;
	}
	while (gotsome);
	printf("got %d, expected %d, BUFSIZ = %d\n", sum, written, BUFSIZ);
	assert(sum == written);
	return 0;
}

Petur


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]