This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
RE: [Patch] Fix libstdc++/9533
- From: Pétur Runólfsson <peturr02 at ru dot is>
- To: "Paolo Carlini" <pcarlini at unitus dot it>,<libstdc++ at gcc dot gnu dot org>
- Cc: "Benjamin Kosnik" <bkoz at redhat dot com>
- Date: Mon, 3 Mar 2003 18:43:51 -0000
- Subject: RE: [Patch] Fix libstdc++/9533
Hi
Here is a much better test case for 9533 that uses a fifo instead
of /dev/tty, so it can be run automatically.
Petur
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fstream>
#undef NDEBUG
#include <cassert>
int main()
{
using namespace std;
const int count = 10000;
signal(SIGPIPE, SIG_IGN);
unlink("xxx");
if (0 != mkfifo("xxx", S_IRWXU))
{
assert(false);
}
int fval = fork();
if (fval == -1)
{
unlink("xxx");
assert(false);
}
else if (fval == 0)
{
filebuf ofbuf;
ofbuf.open("xxx", ios_base::out);
assert(ofbuf.is_open());
sleep(1);
for (int i = 0; i < count; ++i)
ofbuf.sputc(i % 100);
ofbuf.pubsync();
sleep(1);
ofbuf.close();
exit(0);
}
filebuf ifbuf;
ifbuf.open("xxx", ios_base::in);
assert(ifbuf.is_open());
for (int j = 0; j < count; ++j)
{
int c1 = ifbuf.sbumpc();
printf("%d %d\n", j, c1);
assert(c1 == j % 100);
}
int c6 = ifbuf.sbumpc();
assert(c6 == filebuf::traits_type::eof());
sleep(2);
ifbuf.close();
unlink("xxx");
return 0;
}