+2003-03-17 Paolo Carlini <pcarlini@unitus.it>
+ Petur Runolfsson <peturr02@ru.is>
+
+ PR libstdc++/10097
+ * src/fstream.cc (basic_filebuf<char>::_M_underflow_common,
+ basic_filebuf<wchar_t>::_M_underflow_common):
+ if (gptr() < egptr()) return *gptr().
+ * testsuite/27_io/filebuf_virtuals.cc (test16): Add.
+
+ * testsuite/27_io/filebuf_members.cc (test_04): Minor
+ changes: unlink fifo before making it, fix spelling error.
+
2003-03-17 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/Makefile.am (CLEANFILES): Add tmp*.
// File based streams -*- C++ -*-
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// normal buffers and jet outta here before expensive
// fileops happen...
if (_M_pback_init)
+ _M_pback_destroy();
+
+ if (_M_in_cur && _M_in_cur < _M_in_end)
{
- _M_pback_destroy();
- if (_M_in_cur < _M_in_end)
- {
- __ret = traits_type::to_int_type(*_M_in_cur);
- if (__bump)
- _M_in_cur_move(1);
- return __ret;
- }
+ __ret = traits_type::to_int_type(*_M_in_cur);
+ if (__bump)
+ _M_in_cur_move(1);
+ return __ret;
}
// Sync internal and external buffers.
// normal buffers and jet outta here before expensive
// fileops happen...
if (_M_pback_init)
+ _M_pback_destroy();
+
+ if (_M_in_cur && _M_in_cur < _M_in_end)
{
- _M_pback_destroy();
- if (_M_in_cur < _M_in_end)
- {
- __ret = traits_type::to_int_type(*_M_in_cur);
- if (__bump)
- _M_in_cur_move(1);
- return __ret;
- }
+ __ret = traits_type::to_int_type(*_M_in_cur);
+ if (__bump)
+ _M_in_cur_move(1);
+ return __ret;
}
// Sync internal and external buffers.
const char* name = "tmp_fifo1";
signal(SIGPIPE, SIG_IGN);
+ unlink(name);
if (0 != mkfifo(name, S_IRWXU))
{
- std::cerr << "failed to creat fifo" << std::endl;
+ std::cerr << "failed to create fifo" << std::endl;
exit(-1);
}
// 27.8.1.4 Overridden virtual functions
#include <fstream>
+#include <unistd.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <locale>
#include <testsuite_hooks.h>
fbin.close();
}
+class UnderBuf : public std::filebuf
+{
+public:
+ int_type
+ pub_underflow()
+ { return underflow(); }
+
+ std::streamsize
+ pub_showmanyc()
+ { return showmanyc(); }
+};
+
+// libstdc++/10097
+void test16()
+{
+ using namespace std;
+ bool test = true;
+
+ const char* name = "tmp_fifo1";
+
+ signal(SIGPIPE, SIG_IGN);
+ unlink(name);
+
+ if (0 != mkfifo(name, S_IRWXU))
+ {
+ VERIFY( false );
+ }
+
+ int fval = fork();
+ if (fval == -1)
+ {
+ unlink(name);
+ VERIFY( false );
+ }
+ else if (fval == 0)
+ {
+ filebuf fbout;
+ fbout.open(name, ios_base::out);
+ fbout.sputn("0123456789", 10);
+ fbout.pubsync();
+ sleep(2);
+ fbout.close();
+ exit(0);
+ }
+
+ UnderBuf fb;
+ fb.open(name, ios_base::in);
+ sleep(1);
+
+ fb.sgetc();
+ streamsize n = fb.pub_showmanyc();
+
+ while (n > 0)
+ {
+ --n;
+
+ UnderBuf::int_type c = fb.pub_underflow();
+ VERIFY( c != UnderBuf::traits_type::eof() );
+
+ fb.sbumpc();
+ }
+
+ fb.close();
+}
+
main()
{
test01();
test13();
test14();
test15();
+ test16();
return 0;
}