summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff')
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/10132-2.cc54
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-1.cc83
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-2.cc86
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-3.cc81
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-4.cc72
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/45628-2.cc103
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-in.cc124
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc124
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-out.cc124
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/11543.cc153
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12232.cc71
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-1.cc80
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-2.cc81
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-3.cc80
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-4.cc81
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-in.cc125
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc123
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-out.cc123
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/26777.cc90
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc63
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc66
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-out.cc63
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/4.cc93
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/45628-1.cc79
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/1.cc137
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/11543.cc141
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-1.cc78
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-2.cc79
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-3.cc78
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-4.cc79
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/2.cc90
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/3.cc51
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/4.cc94
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/9875_seekoff.cc99
34 files changed, 3148 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/10132-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/10132-2.cc
new file mode 100644
index 000000000..008b56d21
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/10132-2.cc
@@ -0,0 +1,54 @@
+// 2003-04-24 bkoz
+
+// Copyright (C) 2003, 2004, 2005, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.1 - Template class basic_filebuf
+// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES.
+
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_character.h>
+
+// libstdc++/10132, add on
+void test07()
+{
+ bool test __attribute__((unused)) = true;
+ typedef std::basic_filebuf<__gnu_test::pod_ushort> gnu_filebuf;
+
+ try
+ {
+ // Need codecvt facet for width argument in seekoff.
+ gnu_filebuf obj;
+ obj.pubseekoff(2, std::ios_base::beg);
+ }
+ catch(std::exception& obj)
+ {
+ test = false;
+ VERIFY( test );
+ }
+}
+
+int main()
+{
+ test07();
+ return 0;
+}
+
+
+
+// more surf!!!
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-1.cc
new file mode 100644
index 000000000..14e0b0a3a
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-1.cc
@@ -0,0 +1,83 @@
+// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <locale>
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_character.h>
+
+// libstdc++/12790
+void test01()
+{
+ using namespace std;
+ using __gnu_test::pod_uchar;
+ typedef basic_filebuf<pod_uchar>::traits_type traits_type;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_seekoff_12790";
+
+ locale loc(locale::classic(),
+ new codecvt<traits_type::char_type, char,
+ traits_type::state_type>);
+
+ basic_filebuf<pod_uchar> fb;
+ fb.pubimbue(loc);
+
+ fb.open(name, ios_base::out);
+ fb.sputc(pod_uchar::from<char>(0xff));
+ fb.sputc(pod_uchar::from<char>(0));
+ fb.sputc(pod_uchar::from<char>(0));
+ fb.sputc(pod_uchar::from<char>('a'));
+ fb.sputc(pod_uchar::from<char>('a'));
+ fb.sputc(pod_uchar::from<char>('a'));
+ fb.sputc(pod_uchar::from<char>('a'));
+ fb.close();
+
+ fb.open(name, ios_base::in);
+ fb.sbumpc();
+ fb.sbumpc();
+ fb.sbumpc();
+
+ // Check that seekoff calls codecvt::length with the correct state.
+ traits_type::pos_type pos = fb.pubseekoff(0, ios_base::cur);
+ VERIFY( pos != traits_type::pos_type(traits_type::off_type(-1)) );
+
+ traits_type::int_type c = fb.sbumpc();
+ VERIFY( c != traits_type::eof() );
+ VERIFY( traits_type::eq(traits_type::to_char_type(c),
+ pod_uchar::from<char>('a')) );
+ fb.sbumpc();
+ fb.sbumpc();
+ c = fb.sbumpc();
+ VERIFY( c != traits_type::eof() );
+ VERIFY( traits_type::eq(traits_type::to_char_type(c),
+ pod_uchar::from<char>('a')) );
+ c = fb.sbumpc();
+ VERIFY( c == traits_type::eof() );
+
+ fb.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-2.cc
new file mode 100644
index 000000000..64ada570c
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-2.cc
@@ -0,0 +1,86 @@
+// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <locale>
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_character.h>
+
+// libstdc++/12790
+void test01()
+{
+ using namespace std;
+ using __gnu_test::pod_uchar;
+ typedef basic_filebuf<pod_uchar>::traits_type traits_type;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_seekoff_12790";
+
+ locale loc(locale::classic(),
+ new codecvt<traits_type::char_type, char,
+ traits_type::state_type>);
+
+ basic_filebuf<pod_uchar> fb;
+ fb.pubimbue(loc);
+
+ fb.open(name, ios_base::out);
+ fb.sputc(pod_uchar::from<char>(0xff));
+ fb.sputc(pod_uchar::from<char>(0));
+ fb.sputc(pod_uchar::from<char>(0));
+ fb.sputc(pod_uchar::from<char>('a'));
+ fb.sputc(pod_uchar::from<char>('a'));
+ fb.sputc(pod_uchar::from<char>('a'));
+ fb.sputc(pod_uchar::from<char>('a'));
+ fb.close();
+
+ fb.open(name, ios_base::in);
+ fb.sbumpc();
+ fb.sbumpc();
+ fb.sbumpc();
+
+ // Check that seekoff resets the state when seeking to beginning.
+ traits_type::pos_type pos = fb.pubseekoff(0, ios_base::beg);
+ VERIFY( pos != traits_type::pos_type(traits_type::off_type(-1)) );
+
+ traits_type::int_type c = fb.sbumpc();
+ VERIFY( c != traits_type::eof() );
+ VERIFY( traits_type::eq(traits_type::to_char_type(c),
+ pod_uchar::from<char>(0xff)) );
+ fb.sbumpc();
+ fb.sbumpc();
+ fb.sbumpc();
+ fb.sbumpc();
+ fb.sbumpc();
+ c = fb.sbumpc();
+ VERIFY( c != traits_type::eof() );
+ VERIFY( traits_type::eq(traits_type::to_char_type(c),
+ pod_uchar::from<char>('a')) );
+ c = fb.sbumpc();
+ VERIFY( c == traits_type::eof() );
+
+ fb.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-3.cc
new file mode 100644
index 000000000..79cda63fe
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-3.cc
@@ -0,0 +1,81 @@
+// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <locale>
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_character.h>
+
+// libstdc++/12790
+void test01()
+{
+ using namespace std;
+ using __gnu_test::pod_uchar;
+ typedef basic_filebuf<pod_uchar>::traits_type traits_type;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_seekoff_12790";
+
+ locale loc(locale::classic(),
+ new codecvt<traits_type::char_type, char,
+ traits_type::state_type>);
+
+ basic_filebuf<pod_uchar> fb;
+ fb.pubimbue(loc);
+
+ fb.open(name, ios_base::out | ios_base::trunc);
+ fb.sputc(pod_uchar::from<char>('b'));
+ fb.sputc(pod_uchar::from<char>(0xff));
+ fb.sputc(pod_uchar::from<char>('a'));
+ fb.sputc(pod_uchar::from<char>(0xfc));
+ fb.sputc(pod_uchar::from<char>(0));
+ fb.sputc(pod_uchar::from<char>(0));
+
+ fb.close();
+ fb.open(name, ios_base::in);
+
+ fb.sbumpc();
+ fb.sbumpc();
+
+ // Check that seekoff returns the correct state
+ traits_type::pos_type pos = fb.pubseekoff(0, ios_base::cur);
+
+ traits_type::int_type c = fb.sbumpc();
+ VERIFY( c != traits_type::eof() );
+ VERIFY( traits_type::eq(traits_type::to_char_type(c),
+ pod_uchar::from<char>('a')) );
+ fb.sbumpc();
+
+ fb.pubseekpos(pos);
+
+ c = fb.sbumpc();
+ VERIFY( c != traits_type::eof() );
+ VERIFY( traits_type::eq(traits_type::to_char_type(c),
+ pod_uchar::from<char>('a')) );
+
+ fb.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-4.cc
new file mode 100644
index 000000000..3bf4353d7
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-4.cc
@@ -0,0 +1,72 @@
+// Copyright (C) 2003, 2005, 2009, 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <locale>
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_character.h>
+
+// libstdc++/12790
+void test01()
+{
+ using namespace std;
+ using __gnu_test::pod_uchar;
+ typedef basic_filebuf<pod_uchar>::traits_type traits_type;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_seekoff_12790";
+
+ locale loc(locale::classic(),
+ new codecvt<traits_type::char_type, char,
+ traits_type::state_type>);
+
+ basic_filebuf<pod_uchar> fb;
+ fb.pubsetbuf(0, 0);
+ fb.pubimbue(loc);
+
+ fb.open(name, ios_base::in | ios_base::out | ios_base::trunc);
+ fb.sputc(pod_uchar::from<char>('b'));
+ fb.sputc(pod_uchar::from<char>(0xff));
+
+ // Check that seekoff sets the current state during output
+ fb.pubseekoff(0, ios_base::cur);
+ fb.sputc(pod_uchar::from<char>('a'));
+ fb.sputc(pod_uchar::from<char>(0xff));
+ fb.sputc(pod_uchar::from<char>(0));
+ fb.sputc(pod_uchar::from<char>(0));
+
+ fb.pubseekoff(0, ios_base::beg);
+ fb.sbumpc();
+ fb.sbumpc();
+
+ traits_type::int_type c = fb.sbumpc();
+ VERIFY( c != traits_type::eof() );
+ VERIFY( traits_type::eq(traits_type::to_char_type(c),
+ pod_uchar::from<char>('a')) );
+
+ fb.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/45628-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/45628-2.cc
new file mode 100644
index 000000000..6e40a89aa
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/45628-2.cc
@@ -0,0 +1,103 @@
+// Copyright (C) 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_character.h>
+
+const char name_01[] = "tmp_seekoff_45628.tst";
+
+unsigned underflows, overflows;
+
+class my_filebuf
+: public std::basic_filebuf<__gnu_test::pod_uchar>
+{
+ virtual int_type
+ underflow()
+ {
+ ++underflows;
+ return std::basic_filebuf<__gnu_test::pod_uchar>::underflow();
+ }
+ virtual int_type
+ overflow(int_type c)
+ {
+ ++overflows;
+ return std::basic_filebuf<__gnu_test::pod_uchar>::overflow(c);
+ }
+};
+
+// libstdc++/45628
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ using __gnu_test::pod_uchar;
+ std::locale loc(std::locale::classic(),
+ new std::codecvt<my_filebuf::traits_type::char_type, char,
+ my_filebuf::traits_type::state_type>);
+
+ my_filebuf::pos_type opos[3], ipos[3];
+ my_filebuf q;
+ q.pubimbue(loc);
+
+ q.open(name_01, std::ios_base::in | std::ios_base::out
+ | std::ios_base::trunc);
+
+ q.sputc(pod_uchar::from<char>('a'));
+ opos[0] = q.pubseekoff(0, std::ios_base::cur);
+ q.sputc(pod_uchar::from<char>('b'));
+ opos[1] = q.pubseekoff(0, std::ios_base::cur);
+ q.sputc(pod_uchar::from<char>('c'));
+ opos[2] = q.pubseekoff(0, std::ios_base::cur);
+
+ VERIFY( overflows <= 9 ); // pubseekoff calls overflow twice if converting.
+ // NB: checking opos==ipos is not very rigorous as long as it flushes, since
+ // all positions will be at initial state.
+ q.pubseekoff(0, std::ios_base::beg);
+
+ q.sbumpc();
+ VERIFY( underflows == 1 );
+
+ ipos[0] = q.pubseekoff(0, std::ios_base::cur);
+ VERIFY( ipos[0] == opos[0] );
+ q.sbumpc();
+ ipos[1] = q.pubseekoff(0, std::ios_base::cur);
+ VERIFY( ipos[1] == opos[1] );
+ q.sbumpc();
+ ipos[2] = q.pubseekoff(0, std::ios_base::cur);
+ VERIFY( ipos[2] == opos[2] );
+
+ VERIFY( underflows == 1 ); // pubseekoff never flushes get area
+
+ // Bonus test: check automatic mode switches.
+ q.sputc(pod_uchar::from<char>('d'));
+
+ q.pubseekpos( ipos[1] );
+ q.sputc(pod_uchar::from<char>('e'));
+
+ VERIFY( my_filebuf::traits_type::eq(
+ my_filebuf::traits_type::to_char_type(q.sgetc()),
+ pod_uchar::from<char>('d')) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-in.cc
new file mode 100644
index 000000000..248874617
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-in.cc
@@ -0,0 +1,124 @@
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %*.txt
+
+const char name_01[] = "seekoff.txt";
+
+void test05()
+{
+ using namespace std;
+ using namespace __gnu_test;
+
+ typedef filebuf::int_type int_type;
+ typedef filebuf::pos_type pos_type;
+ typedef filebuf::off_type off_type;
+ typedef filebuf::traits_type traits_type;
+
+ bool test __attribute__((unused)) = true;
+ streamsize strmsz_1;
+
+ int_type c1;
+ int_type c2;
+ int_type c3;
+
+ pos_type pt_1(off_type(-1));
+ pos_type pt_2(off_type(0));
+ off_type off_1 = 0;
+ off_type off_2 = 0;
+
+ // seekoff
+ // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
+ // alters the stream position to off
+
+ // in
+ {
+ constraint_filebuf fb;
+ fb.open(name_01, ios_base::in);
+ VERIFY( !fb.write_position() );
+
+ //beg
+ strmsz_1 = fb.in_avail();
+ pt_1 = fb.pubseekoff(2, ios_base::beg);
+ fb.in_avail();
+ off_1 = off_type(pt_1);
+ VERIFY( off_1 > 0 );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == '9' );
+ fb.pubseekoff(3, ios_base::beg);
+ c2 = fb.sputc('\n'); //current in pointer +1
+ fb.pubseekoff(4, ios_base::beg);
+ c3 = fb.sgetc();
+ VERIFY( c2 == traits_type::eof() );
+ VERIFY( c3 == '9' );
+ fb.pubsync();
+ c1 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //cur
+ pt_2 = fb.pubseekoff(2, ios_base::cur);
+ off_2 = off_type(pt_2);
+ VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == '1' );
+ fb.pubseekoff(0, ios_base::cur);
+ c2 = fb.sputc('x'); //test current out pointer
+ c3 = fb.sputc('\n');
+ VERIFY( c2 == traits_type::eof() );
+ VERIFY( c3 == traits_type::eof() );
+ fb.pubseekoff(0, ios_base::cur);
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //end
+ pt_2 = fb.pubseekoff(0, ios_base::end);
+ off_1 = off_type(pt_2);
+ VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends
+ c3 = fb.sputc('\n');
+ strmsz_1 = fb.sputn("because because because. . .", 28);
+ VERIFY( strmsz_1 == 0 );
+ fb.pubseekoff(-1, ios_base::end);
+ fb.sgetc();
+ c1 = fb.sungetc();
+ // Defect? retval of sungetc is not necessarily the character ungotten.
+ // So re-get it.
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+ VERIFY( !fb.write_position() );
+ }
+}
+
+int main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc
new file mode 100644
index 000000000..4dc6d8648
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc
@@ -0,0 +1,124 @@
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+// { dg-require-binary-io "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %*.txt
+
+const char name_01[] = "seekoff-1io.tst";
+
+void test05()
+{
+ using namespace std;
+ using namespace __gnu_test;
+
+ typedef filebuf::int_type int_type;
+ typedef filebuf::pos_type pos_type;
+ typedef filebuf::off_type off_type;
+
+ bool test __attribute__((unused)) = true;
+ streamsize strmsz_1;
+
+ int_type c1;
+ int_type c2;
+ int_type c3;
+
+ pos_type pt_1(off_type(-1));
+ pos_type pt_2(off_type(0));
+ off_type off_1 = 0;
+ off_type off_2 = 0;
+
+ // seekoff
+ // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
+ // alters the stream position to off
+
+ // in | out
+ {
+ constraint_filebuf fb;
+ fb.open(name_01, ios_base::out | ios_base::in);
+ VERIFY( !fb.write_position() );
+ VERIFY( !fb.read_position() );
+
+ //beg
+ strmsz_1 = fb.in_avail();
+ pt_1 = fb.pubseekoff(2, ios_base::beg);
+ fb.in_avail();
+ off_1 = off_type(pt_1);
+ VERIFY( off_1 > 0 );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == '9' );
+ fb.pubseekoff(3, ios_base::beg);
+ c2 = fb.sputc('\n'); //current in pointer +1
+ fb.pubseekoff(4, ios_base::beg);
+ c3 = fb.sgetc();
+ VERIFY( c2 != c3 );
+ VERIFY( c3 == '9' );
+ fb.pubsync();
+ c1 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //cur
+ pt_2 = fb.pubseekoff(2, ios_base::cur);
+ off_2 = off_type(pt_2);
+ VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == '1' );
+ fb.pubseekoff(0, ios_base::cur);
+ c2 = fb.sputc('x'); //test current out pointer
+ c3 = fb.sputc('\n');
+ fb.pubseekoff(0, ios_base::cur);
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //end
+ pt_2 = fb.pubseekoff(0, ios_base::end);
+ off_1 = off_type(pt_2);
+ VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends
+ c3 = fb.sputc('\n');
+ strmsz_1 = fb.sputn("because because because. . .", 28);
+ VERIFY( strmsz_1 == 28 );
+ fb.pubseekoff(-1, ios_base::end);
+ fb.sgetc();
+ c1 = fb.sungetc();
+ // Defect? retval of sungetc is not necessarily the character ungotten.
+ // So re-get it.
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+ VERIFY( !fb.write_position() );
+ VERIFY( fb.read_position() );
+ }
+}
+
+int main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-out.cc
new file mode 100644
index 000000000..8d7ab1dfc
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-out.cc
@@ -0,0 +1,124 @@
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %*.txt
+
+const char name_01[] = "seekoff-1out.tst";
+
+void test05()
+{
+ using namespace std;
+ using namespace __gnu_test;
+
+ typedef filebuf::int_type int_type;
+ typedef filebuf::pos_type pos_type;
+ typedef filebuf::off_type off_type;
+ typedef filebuf::traits_type traits_type;
+
+ bool test __attribute__((unused)) = true;
+ streamsize strmsz_1;
+
+ int_type c1;
+ int_type c2;
+ int_type c3;
+
+ pos_type pt_1(off_type(-1));
+ pos_type pt_2(off_type(0));
+ off_type off_1 = 0;
+ off_type off_2 = 0;
+
+ // seekoff
+ // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
+ // alters the stream position to off
+
+ // out
+ {
+ constraint_filebuf fb;
+ fb.open(name_01, ios_base::out);
+ VERIFY( !fb.write_position() );
+ VERIFY( !fb.read_position() );
+
+ //beg
+ strmsz_1 = fb.in_avail();
+ pt_1 = fb.pubseekoff(2, ios_base::beg);
+ fb.in_avail();
+ off_1 = off_type(pt_1);
+ VERIFY( off_1 > 0 );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == traits_type::eof() );
+ fb.pubseekoff(3, ios_base::beg);
+ c2 = fb.sputc('\n'); //current in pointer +1
+ fb.pubseekoff(4, ios_base::beg);
+ c3 = fb.sgetc();
+ VERIFY( c2 != c3 );
+ VERIFY( c3 == traits_type::eof() );
+ fb.pubsync();
+ c1 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //cur
+ pt_2 = fb.pubseekoff(2, ios_base::cur);
+ off_2 = off_type(pt_2);
+ VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == traits_type::eof() );
+ fb.pubseekoff(0, ios_base::cur);
+ c2 = fb.sputc('x'); //test current out pointer
+ c3 = fb.sputc('\n');
+ fb.pubseekoff(0, ios_base::cur);
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //end
+ pt_2 = fb.pubseekoff(0, ios_base::end);
+ off_1 = off_type(pt_2);
+ VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends
+ c3 = fb.sputc('\n');
+ strmsz_1 = fb.sputn("because because because. . .", 28);
+ VERIFY( strmsz_1 == 28 );
+ fb.pubseekoff(-1, ios_base::end);
+ fb.sgetc();
+ c1 = fb.sungetc();
+ // Defect? retval of sungetc is not necessarily the character ungotten.
+ // So re-get it.
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+ VERIFY( !fb.write_position() );
+ VERIFY( !fb.read_position() );
+ }
+}
+
+int main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/11543.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/11543.cc
new file mode 100644
index 000000000..2f6cf2988
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/11543.cc
@@ -0,0 +1,153 @@
+// Copyright (C) 2003, 2009
+// Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+struct MyState
+{
+};
+
+struct MyCharTraits : std::char_traits<char>
+{
+ typedef std::fpos<MyState> pos_type;
+ typedef MyState state_type;
+};
+
+namespace std
+{
+ template <>
+ class codecvt<char, char, MyState> :
+ public locale::facet, public codecvt_base
+ {
+ public:
+ typedef char intern_type;
+ typedef char extern_type;
+ typedef MyState state_type;
+
+ explicit codecvt(size_t refs = 0)
+ : locale::facet(refs) { }
+
+ result out(state_type& state, const intern_type* from,
+ const intern_type* from_end, const intern_type*& from_next,
+ extern_type* to, extern_type* to_limit,
+ extern_type*& to_next) const
+ { return do_out(state, from, from_end, from_next,
+ to, to_limit, to_next); }
+
+ result unshift(state_type& state, extern_type* to, extern_type* to_limit,
+ extern_type*& to_next) const
+ { return do_unshift(state, to, to_limit, to_next); }
+
+ result in(state_type& state, const extern_type* from,
+ const extern_type* from_end, const extern_type*& from_next,
+ intern_type* to, intern_type* to_limit,
+ intern_type*& to_next) const
+ { return do_in(state, from, from_end, from_next,
+ to, to_limit, to_next); }
+
+ int encoding() const throw()
+ { return do_encoding(); }
+
+ bool always_noconv() const throw()
+ { return do_always_noconv(); }
+
+ int length(state_type& state, const extern_type* from,
+ const extern_type* end, size_t max) const
+ { return do_length(state, from, end, max); }
+
+ int max_length() const throw()
+ { return do_max_length(); }
+
+ static locale::id id;
+
+ protected:
+ virtual ~codecvt();
+
+ virtual result do_out(state_type&, const intern_type* from,
+ const intern_type*, const intern_type*& from_next,
+ extern_type* to, extern_type*,
+ extern_type*& to_next) const
+ {
+ from_next = from;
+ to_next = to;
+ return noconv;
+ }
+
+ virtual result do_in(state_type&, const extern_type* from,
+ const extern_type*, const extern_type*& from_next,
+ intern_type* to, intern_type*,
+ intern_type*& to_next) const
+ {
+ from_next = from;
+ to_next = to;
+ return noconv;
+ }
+
+ virtual result do_unshift(state_type&, extern_type*, extern_type*,
+ extern_type*&) const
+ { return noconv; }
+
+ virtual int do_encoding() const throw()
+ { return 1; }
+
+ virtual bool do_always_noconv() const throw()
+ { return true; }
+
+ virtual int do_length(state_type&, const extern_type* from,
+ const extern_type* end, size_t max) const
+ {
+ size_t len = end - from;
+ return std::min(max, len);
+ }
+
+ virtual int do_max_length() const throw()
+ { return 1; }
+ };
+
+ locale::id codecvt<char, char, MyState>::id;
+
+ codecvt<char, char, MyState>::~codecvt()
+ { }
+}
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::locale loc(std::locale::classic(),
+ new std::codecvt<char, char, MyState>);
+ std::basic_filebuf<char, MyCharTraits> fb;
+ fb.pubimbue(loc);
+ fb.open("tmp_11543", std::ios_base::out);
+ VERIFY( fb.is_open() );
+ MyCharTraits::pos_type pos = fb.pubseekoff(0, std::ios_base::beg);
+ VERIFY( pos != MyCharTraits::pos_type(MyCharTraits::off_type(-1)) );
+ fb.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12232.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12232.cc
new file mode 100644
index 000000000..a60293274
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12232.cc
@@ -0,0 +1,71 @@
+// Copyright (C) 2003, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const char name[] = "tmp_12232";
+
+// libstdc++/12232
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ filebuf fbout;
+ fbout.open(name, ios_base::out);
+ fbout.sputn("abc", 3);
+
+ streampos p1 = fbout.pubseekoff(0, ios_base::cur, ios_base::in);
+ VERIFY( p1 != streampos(-1) );
+ fbout.sputn("de", 2);
+
+ streampos p2 = fbout.pubseekpos(p1, ios_base::openmode());
+ VERIFY( p2 != streampos(-1) );
+ fbout.sputn("34", 2);
+
+ streampos p3 = fbout.pubseekoff(0, ios_base::beg, ios_base::ate);
+ VERIFY( p3 != streampos(-1) );
+ fbout.sputn("012", 3);
+
+ fbout.close();
+
+ filebuf fbin;
+ fbin.open(name, ios_base::in);
+
+ streampos p4 = fbin.pubseekoff(0, ios_base::beg, ios_base::ate);
+ VERIFY( p4 != streampos(-1) );
+ VERIFY( fbin.sgetc() == '0' );
+
+ streampos p5 = fbin.pubseekoff(-1, ios_base::end, ios_base::out);
+ VERIFY( p5 != streampos(-1) );
+ VERIFY( fbin.sbumpc() == '4' );
+
+ streampos p6 = fbin.pubseekpos(p4, ios_base::binary);
+ VERIFY( p6 != streampos(-1) );
+ VERIFY( fbin.sbumpc() == '0' );
+
+ fbin.close();
+}
+
+int main()
+{
+ void test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-1.cc
new file mode 100644
index 000000000..d2860cbf5
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-1.cc
@@ -0,0 +1,80 @@
+// Copyright (C) 2003, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <locale>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+class Cvt : public std::codecvt<char, char, std::mbstate_t>
+{
+public:
+ mutable bool unshift_called;
+
+ Cvt()
+ : unshift_called(false)
+ { }
+
+protected:
+ bool
+ do_always_noconv() const throw()
+ { return false; }
+
+ int
+ do_encoding() const throw()
+ { return -1; }
+
+ std::codecvt_base::result
+ do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const
+ {
+ unshift_called = true;
+ to_next = to;
+ return std::codecvt_base::ok;
+ }
+};
+
+// libstdc++/12790
+// basic_filebuf::seekoff() should call codecvt::unshift()
+void test01()
+{
+ using namespace std;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_seekoff_12790";
+
+ Cvt* cvt = new Cvt;
+ locale loc(locale::classic(), cvt);
+
+ filebuf fb;
+ fb.pubimbue(loc);
+
+ fb.open(name, ios_base::out);
+ fb.sputc('a');
+
+ VERIFY( !cvt->unshift_called );
+ fb.pubseekoff(0, ios_base::cur);
+ VERIFY( cvt->unshift_called );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-2.cc
new file mode 100644
index 000000000..f0f1b9938
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-2.cc
@@ -0,0 +1,81 @@
+// Copyright (C) 2003, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <locale>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+class Cvt : public std::codecvt<char, char, std::mbstate_t>
+{
+public:
+ mutable bool unshift_called;
+
+ Cvt()
+ : unshift_called(false)
+ { }
+
+protected:
+ bool
+ do_always_noconv() const throw()
+ { return false; }
+
+ int
+ do_encoding() const throw()
+ { return -1; }
+
+ std::codecvt_base::result
+ do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const
+ {
+ unshift_called = true;
+ to_next = to;
+ return std::codecvt_base::ok;
+ }
+};
+
+// libstdc++/12790
+// basic_filebuf::seekoff() should call codecvt::unshift()
+void test01()
+{
+ using namespace std;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_seekoff_12790";
+
+ Cvt* cvt = new Cvt;
+ locale loc(locale::classic(), cvt);
+
+ filebuf fb;
+ fb.pubsetbuf(0, 0);
+ fb.pubimbue(loc);
+
+ fb.open(name, ios_base::out);
+ fb.sputc('a');
+
+ VERIFY( !cvt->unshift_called );
+ fb.pubseekoff(0, ios_base::cur);
+ VERIFY( cvt->unshift_called );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-3.cc
new file mode 100644
index 000000000..026d75029
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-3.cc
@@ -0,0 +1,80 @@
+// Copyright (C) 2003, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <locale>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+class Cvt : public std::codecvt<char, char, std::mbstate_t>
+{
+public:
+ mutable bool unshift_called;
+
+ Cvt()
+ : unshift_called(false)
+ { }
+
+protected:
+ bool
+ do_always_noconv() const throw()
+ { return false; }
+
+ int
+ do_encoding() const throw()
+ { return -1; }
+
+ std::codecvt_base::result
+ do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const
+ {
+ unshift_called = true;
+ to_next = to;
+ return std::codecvt_base::ok;
+ }
+};
+
+// libstdc++/12790
+// basic_filebuf::seekoff() should call codecvt::unshift(),
+// but only if writing
+void test01()
+{
+ using namespace std;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_seekoff_12790";
+
+ Cvt* cvt = new Cvt;
+ locale loc(locale::classic(), cvt);
+
+ filebuf fb;
+ fb.pubimbue(loc);
+
+ fb.open(name, ios_base::out);
+
+ VERIFY( !cvt->unshift_called );
+ fb.pubseekoff(0, ios_base::cur);
+ VERIFY( !cvt->unshift_called );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-4.cc
new file mode 100644
index 000000000..60813c899
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-4.cc
@@ -0,0 +1,81 @@
+// Copyright (C) 2003, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <locale>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+class Cvt : public std::codecvt<char, char, std::mbstate_t>
+{
+public:
+ mutable bool unshift_called;
+
+ Cvt()
+ : unshift_called(false)
+ { }
+
+protected:
+ bool
+ do_always_noconv() const throw()
+ { return false; }
+
+ int
+ do_encoding() const throw()
+ { return -1; }
+
+ std::codecvt_base::result
+ do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const
+ {
+ unshift_called = true;
+ to_next = to;
+ return std::codecvt_base::ok;
+ }
+};
+
+// libstdc++/12790
+// basic_filebuf::seekoff() should call codecvt::unshift()
+void test01()
+{
+ using namespace std;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_seekoff_12790";
+
+ Cvt* cvt = new Cvt;
+ locale loc(locale::classic(), cvt);
+
+ filebuf fb;
+ fb.pubimbue(loc);
+
+ fb.open(name, ios_base::out);
+ fb.sputc('a');
+ fb.pubsync(); // Does not call unshift()
+
+ VERIFY( !cvt->unshift_called );
+ fb.pubseekoff(0, ios_base::cur);
+ VERIFY( cvt->unshift_called );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-in.cc
new file mode 100644
index 000000000..3a8809da2
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-in.cc
@@ -0,0 +1,125 @@
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %*.txt
+
+const char name_01[] = "seekoff.txt";
+
+void test05()
+{
+ using namespace std;
+ using namespace __gnu_test;
+
+ typedef filebuf::int_type int_type;
+ typedef filebuf::pos_type pos_type;
+ typedef filebuf::off_type off_type;
+ typedef filebuf::traits_type traits_type;
+
+ bool test __attribute__((unused)) = true;
+ streamsize strmsz_1;
+
+ int_type c1;
+ int_type c2;
+ int_type c3;
+
+ pos_type pt_1(off_type(-1));
+ pos_type pt_2(off_type(0));
+ off_type off_1 = 0;
+ off_type off_2 = 0;
+
+ // seekoff
+ // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
+ // alters the stream position to off
+
+ // in
+ {
+ constraint_filebuf fb;
+ fb.pubsetbuf(0, 0);
+ fb.open(name_01, ios_base::in);
+ VERIFY( fb.unbuffered() );
+
+ //beg
+ strmsz_1 = fb.in_avail();
+ pt_1 = fb.pubseekoff(2, ios_base::beg);
+ fb.in_avail();
+ off_1 = off_type(pt_1);
+ VERIFY( off_1 > 0 );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == '9' );
+ fb.pubseekoff(3, ios_base::beg);
+ c2 = fb.sputc('\n'); //current in pointer +1
+ fb.pubseekoff(4, ios_base::beg);
+ c3 = fb.sgetc();
+ VERIFY( c2 == traits_type::eof() );
+ VERIFY( c3 == '9' );
+ fb.pubsync();
+ c1 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //cur
+ pt_2 = fb.pubseekoff(2, ios_base::cur);
+ off_2 = off_type(pt_2);
+ VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == '1' );
+ fb.pubseekoff(0, ios_base::cur);
+ c2 = fb.sputc('x'); //test current out pointer
+ c3 = fb.sputc('\n');
+ VERIFY( c2 == traits_type::eof() );
+ VERIFY( c3 == traits_type::eof() );
+ fb.pubseekoff(0, ios_base::cur);
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //end
+ pt_2 = fb.pubseekoff(0, ios_base::end);
+ off_1 = off_type(pt_2);
+ VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends
+ c3 = fb.sputc('\n');
+ strmsz_1 = fb.sputn("because because because. . .", 28);
+ VERIFY( strmsz_1 == 0 );
+ fb.pubseekoff(-1, ios_base::end);
+ fb.sgetc();
+ c1 = fb.sungetc();
+ // Defect? retval of sungetc is not necessarily the character ungotten.
+ // So re-get it.
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+ VERIFY( fb.unbuffered() );
+ }
+}
+
+int main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc
new file mode 100644
index 000000000..89fab2aed
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc
@@ -0,0 +1,123 @@
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+// { dg-require-binary-io "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %*.txt
+
+const char name_01[] = "seekoff-2io.tst";
+
+void test05()
+{
+ using namespace std;
+ using namespace __gnu_test;
+
+ typedef filebuf::int_type int_type;
+ typedef filebuf::pos_type pos_type;
+ typedef filebuf::off_type off_type;
+
+ bool test __attribute__((unused)) = true;
+ streamsize strmsz_1;
+
+ int_type c1;
+ int_type c2;
+ int_type c3;
+
+ pos_type pt_1(off_type(-1));
+ pos_type pt_2(off_type(0));
+ off_type off_1 = 0;
+ off_type off_2 = 0;
+
+ // seekoff
+ // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
+ // alters the stream position to off
+
+ // in | out
+ {
+ constraint_filebuf fb;
+ fb.pubsetbuf(0, 0);
+ fb.open(name_01, ios_base::out | ios_base::in);
+ VERIFY( fb.unbuffered() );
+
+ //beg
+ strmsz_1 = fb.in_avail();
+ pt_1 = fb.pubseekoff(2, ios_base::beg);
+ fb.in_avail();
+ off_1 = off_type(pt_1);
+ VERIFY( off_1 > 0 );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == '9' );
+ fb.pubseekoff(3, ios_base::beg);
+ c2 = fb.sputc('\n'); //current in pointer +1
+ fb.pubseekoff(4, ios_base::beg);
+ c3 = fb.sgetc();
+ VERIFY( c2 != c3 );
+ VERIFY( c3 == '9' );
+ fb.pubsync();
+ c1 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //cur
+ pt_2 = fb.pubseekoff(2, ios_base::cur);
+ off_2 = off_type(pt_2);
+ VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == '1' );
+ fb.pubseekoff(0, ios_base::cur);
+ c2 = fb.sputc('x'); //test current out pointer
+ c3 = fb.sputc('\n');
+ fb.pubseekoff(0, ios_base::cur);
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //end
+ pt_2 = fb.pubseekoff(0, ios_base::end);
+ off_1 = off_type(pt_2);
+ VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends
+ c3 = fb.sputc('\n');
+ strmsz_1 = fb.sputn("because because because. . .", 28);
+ VERIFY( strmsz_1 == 28 );
+ fb.pubseekoff(-1, ios_base::end);
+ fb.sgetc();
+ c1 = fb.sungetc();
+ // Defect? retval of sungetc is not necessarily the character ungotten.
+ // So re-get it.
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+ VERIFY( fb.unbuffered() );
+ }
+}
+
+int main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-out.cc
new file mode 100644
index 000000000..b1ad66e89
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-out.cc
@@ -0,0 +1,123 @@
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %*.txt
+
+const char name_01[] = "seekoff-2out.tst";
+
+void test05()
+{
+ using namespace std;
+ using namespace __gnu_test;
+
+ typedef filebuf::int_type int_type;
+ typedef filebuf::pos_type pos_type;
+ typedef filebuf::off_type off_type;
+ typedef filebuf::traits_type traits_type;
+
+ bool test __attribute__((unused)) = true;
+ streamsize strmsz_1;
+
+ int_type c1;
+ int_type c2;
+ int_type c3;
+
+ pos_type pt_1(off_type(-1));
+ pos_type pt_2(off_type(0));
+ off_type off_1 = 0;
+ off_type off_2 = 0;
+
+ // seekoff
+ // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
+ // alters the stream position to off
+
+ // out
+ {
+ constraint_filebuf fb;
+ fb.pubsetbuf(0, 0);
+ fb.open(name_01, ios_base::out);
+ VERIFY( fb.unbuffered() );
+
+ //beg
+ strmsz_1 = fb.in_avail();
+ pt_1 = fb.pubseekoff(2, ios_base::beg);
+ fb.in_avail();
+ off_1 = off_type(pt_1);
+ VERIFY( off_1 > 0 );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == traits_type::eof() );
+ fb.pubseekoff(3, ios_base::beg);
+ c2 = fb.sputc('\n'); //current in pointer +1
+ fb.pubseekoff(4, ios_base::beg);
+ c3 = fb.sgetc();
+ VERIFY( c2 != c3 );
+ VERIFY( c3 == traits_type::eof() );
+ fb.pubsync();
+ c1 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //cur
+ pt_2 = fb.pubseekoff(2, ios_base::cur);
+ off_2 = off_type(pt_2);
+ VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == traits_type::eof() );
+ fb.pubseekoff(0, ios_base::cur);
+ c2 = fb.sputc('x'); //test current out pointer
+ c3 = fb.sputc('\n');
+ fb.pubseekoff(0, ios_base::cur);
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //end
+ pt_2 = fb.pubseekoff(0, ios_base::end);
+ off_1 = off_type(pt_2);
+ VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends
+ c3 = fb.sputc('\n');
+ strmsz_1 = fb.sputn("because because because. . .", 28);
+ VERIFY( strmsz_1 == 28 );
+ fb.pubseekoff(-1, ios_base::end);
+ fb.sgetc();
+ c1 = fb.sungetc();
+ // Defect? retval of sungetc is not necessarily the character ungotten.
+ // So re-get it.
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+ VERIFY( fb.unbuffered() );
+ }
+}
+
+int main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/26777.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/26777.cc
new file mode 100644
index 000000000..d98234bab
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/26777.cc
@@ -0,0 +1,90 @@
+// { dg-require-fork "" }
+// { dg-require-mkfifo "" }
+
+// 2006-03-22 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2006, 2007, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// No asserts, avoid leaking the semaphores if a VERIFY fails.
+#undef _GLIBCXX_ASSERT
+
+#include <testsuite_hooks.h>
+#include <fstream>
+#include <sstream>
+#include <cstdlib>
+#include <unistd.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+// libstdc++/26777
+bool test01()
+{
+ using namespace std;
+ using namespace __gnu_test;
+
+ bool test __attribute__((unused)) = true;
+
+ const char* name = "tmp_fifo6";
+
+ signal(SIGPIPE, SIG_IGN);
+
+ unlink(name);
+ mkfifo(name, S_IRWXU);
+ semaphore s1, s2;
+
+ int child = fork();
+ VERIFY( child != -1 );
+
+ if (child == 0)
+ {
+ filebuf fbout;
+ fbout.open(name, ios_base::in | ios_base::out);
+ VERIFY( fbout.is_open() );
+ fbout.sputn("Whatever", 8);
+ fbout.pubsync();
+ s1.signal();
+ s2.wait();
+ fbout.close();
+ s1.signal();
+ exit(0);
+ }
+
+ filebuf fbin;
+ fbin.open(name, ios::in);
+ s1.wait();
+
+ fbin.sgetc();
+ fbin.pubseekoff(0, ios::cur, ios::in);
+ s2.signal();
+ s1.wait();
+
+ ostringstream oss;
+ oss << &fbin;
+ fbin.close();
+
+ VERIFY( oss.str() == "Whatever" );
+
+ return test;
+}
+
+int main()
+{
+ return !test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc
new file mode 100644
index 000000000..a0c4d5a86
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc
@@ -0,0 +1,63 @@
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.3 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void test02(std::filebuf& in, bool pass)
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+ typedef streambuf::pos_type pos_type;
+ typedef streambuf::off_type off_type;
+ pos_type bad = pos_type(off_type(-1));
+ pos_type p = 0;
+
+ // seekoff
+ p = in.pubseekoff(0, ios_base::beg, ios_base::in);
+ VERIFY( pass == (p != bad) );
+
+ p = in.pubseekoff(0, ios_base::beg, ios_base::out);
+ VERIFY( pass == (p != bad) ); // See libstdc++/12232
+
+ p = in.pubseekoff(0, ios_base::beg);
+ VERIFY( pass == (p != bad) );
+}
+
+const char name_01[] = "filebuf_virtuals-1.tst"; // file with data in it
+const char name_03[] = "filebuf_members-1.tst"; // empty file
+
+int main()
+{
+ using namespace std;
+
+ filebuf in1;
+ in1.open(name_01, ios_base::in);
+ filebuf in2;
+ filebuf in3;
+ in3.open(name_03, ios_base::in);
+ test02(in1, true);
+ test02(in2, false);
+ test02(in3, true);
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc
new file mode 100644
index 000000000..803a81f27
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc
@@ -0,0 +1,66 @@
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.3 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void test02(std::filebuf& in, bool pass)
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+ typedef streambuf::pos_type pos_type;
+ typedef streambuf::off_type off_type;
+ pos_type bad = pos_type(off_type(-1));
+ pos_type p = 0;
+
+ // seekoff
+ p = in.pubseekoff(0, ios_base::beg, ios_base::in);
+ if (pass)
+ VERIFY( p != bad );
+
+ p = in.pubseekoff(0, ios_base::beg, ios_base::out);
+ if (pass)
+ VERIFY( p != bad );
+
+ p = in.pubseekoff(0, ios_base::beg);
+ if (pass)
+ VERIFY( p != bad );
+}
+
+const char name_01[] = "filebuf_virtuals-1.tst"; // file with data in it
+const char name_03[] = "filebuf_members-1.tst"; // empty file
+
+int main()
+{
+ using namespace std;
+
+ filebuf in1;
+ in1.open(name_01, ios_base::in | ios_base::out);
+ filebuf in2;
+ filebuf in3;
+ in3.open(name_03, ios_base::in | ios_base::out);
+ test02(in1, true);
+ test02(in2, false);
+ test02(in3, true);
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-out.cc
new file mode 100644
index 000000000..08eac2933
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-out.cc
@@ -0,0 +1,63 @@
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.3 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void test02(std::filebuf& in, bool pass)
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+ typedef streambuf::pos_type pos_type;
+ typedef streambuf::off_type off_type;
+ pos_type bad = pos_type(off_type(-1));
+ pos_type p = 0;
+
+ // seekoff
+ p = in.pubseekoff(0, ios_base::beg, ios_base::in);
+ VERIFY( pass == (p != bad) ); // See libstdc++/12232
+
+ p = in.pubseekoff(0, ios_base::beg, ios_base::out);
+ VERIFY( pass == (p != bad) );
+
+ p = in.pubseekoff(0, ios_base::beg);
+ VERIFY( pass == (p != bad) );
+}
+
+const char name_01[] = "filebuf_virtuals-1.tst"; // file with data in it
+const char name_03[] = "filebuf_members-1.tst"; // empty file
+
+int main()
+{
+ using namespace std;
+
+ filebuf out1;
+ out1.open(name_01, ios_base::out);
+ filebuf out2;
+ filebuf out3;
+ out3.open(name_03, ios_base::out);
+ test02(out1, true);
+ test02(out2, false);
+ test02(out3, true);
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/4.cc
new file mode 100644
index 000000000..fe21b3a88
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/4.cc
@@ -0,0 +1,93 @@
+// { dg-require-fileio "" }
+
+// Copyright (C) 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <cstring>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ typedef filebuf::pos_type pos_type;
+ const char name[] = "tmp_seekoff-4.tst";
+
+ const size_t size = 12;
+ char buf[size];
+ streamsize n;
+
+ filebuf fb;
+ fb.open(name, ios_base::in | ios_base::out | ios_base::trunc);
+
+ n = fb.sputn("abcd", 4);
+ VERIFY( n == 4 );
+
+ fb.pubseekoff(0, ios_base::beg);
+ n = fb.sgetn(buf, 3);
+ VERIFY( n == 3 );
+ VERIFY( !memcmp(buf, "abc", 3) );
+
+ // Check read => write without pubseekoff(0, ios_base::cur)
+
+ n = fb.sputn("ef", 2);
+ VERIFY( n == 2 );
+
+ fb.pubseekoff(0, ios_base::beg);
+
+ n = fb.sgetn(buf, size);
+ VERIFY( n == 5 );
+ VERIFY( !memcmp(buf, "abcef", 5) );
+
+ fb.pubseekoff(0, ios_base::beg);
+ n = fb.sputn("gh", 2);
+ VERIFY( n == 2 );
+
+ // Check write => read without pubseekoff(0, ios_base::cur)
+
+ n = fb.sgetn( buf, 3 );
+ VERIFY( !memcmp(buf, "cef", 3) );
+
+ n = fb.sputn("ijkl", 4);
+ VERIFY( n == 4 );
+
+ fb.pubseekoff(0, ios_base::beg);
+ n = fb.sgetn(buf, 2);
+ VERIFY( n == 2 );
+ VERIFY( !memcmp(buf, "gh", 2) );
+
+ fb.pubseekoff(0, ios_base::end);
+ n = fb.sputn("mno", 3);
+ VERIFY( n == 3 );
+
+ fb.pubseekoff(0, ios_base::beg);
+ n = fb.sgetn(buf, size);
+ VERIFY( n == 12 );
+ VERIFY( !memcmp(buf, "ghcefijklmno", 12) );
+
+ fb.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/45628-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/45628-1.cc
new file mode 100644
index 000000000..a80a33876
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/45628-1.cc
@@ -0,0 +1,79 @@
+// Copyright (C) 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const char name_01[] = "tmp_seekoff_45628.tst";
+
+unsigned underflows, overflows;
+
+class my_filebuf
+: public std::filebuf
+{
+ virtual int_type
+ underflow()
+ {
+ ++underflows;
+ return std::filebuf::underflow();
+ }
+ virtual int_type
+ overflow(int_type c)
+ {
+ ++overflows;
+ return std::filebuf::overflow(c);
+ }
+};
+
+// libstdc++/45628
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ my_filebuf q;
+ q.open(name_01, std::ios_base::in | std::ios_base::out
+ | std::ios_base::trunc);
+
+ q.sputc('a');
+ q.pubseekoff(0, std::ios_base::cur);
+ q.sputc('b');
+ q.pubseekoff(0, std::ios_base::cur);
+ q.sputc('c');
+ q.pubseekoff(0, std::ios_base::cur);
+
+ VERIFY( overflows <= 1 ); // only initial sputc allowed to overflow
+ q.pubseekoff(0, std::ios_base::beg);
+
+ q.sbumpc();
+ VERIFY( underflows == 1 );
+
+ q.pubseekoff(0, std::ios_base::cur);
+ q.sbumpc();
+ q.pubseekoff(0, std::ios_base::cur);
+ q.sbumpc();
+ q.pubseekoff(0, std::ios_base::cur);
+
+ VERIFY( underflows == 1 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/1.cc
new file mode 100644
index 000000000..c6f13dcd0
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/1.cc
@@ -0,0 +1,137 @@
+// { dg-require-namedlocale "se_NO.UTF-8" }
+
+// 2003-09-08 Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <cstdio>
+#include <testsuite_hooks.h>
+
+// Check that basic_filebuf::seekoff handles UTF-8 when open for input.
+void test01()
+{
+ using namespace std;
+ typedef wfilebuf::pos_type pos_type;
+ typedef wfilebuf::int_type int_type;
+
+ bool test __attribute__((unused)) = true;
+ const char name[] = "tmp_seekoff-1.tst";
+ const int_type eof = wfilebuf::traits_type::eof();
+
+ const char cstr[] =
+ "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13"
+ "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&"
+ "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2"
+ "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a"
+ "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2"
+ "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99"
+ "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3"
+ "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85"
+ "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4"
+ "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94"
+ "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf"
+ "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0"
+ "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0"
+ "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0"
+ "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0"
+ "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0"
+ "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80"
+ "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80"
+ "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1"
+ "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80"
+ "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80"
+ "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80"
+ "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80"
+ "\xfd\x80\x80\x80\x80\x80";
+
+ const wchar_t wstr[] = {
+ 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc,
+ 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!',
+ L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+',
+ L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5',
+ L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?',
+ L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85,
+ 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
+ 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100,
+ 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109,
+ 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112,
+ 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9,
+ 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802,
+ 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b,
+ 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814,
+ 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@',
+ 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000,
+ 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000,
+ 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000,
+ 0x20000000, 0x40000000, 0x0
+ };
+
+ const size_t clen = sizeof(cstr) / sizeof(cstr[0]);
+ const size_t wlen = sizeof(wstr) / sizeof(wstr[0]);
+
+ const int loops = 2 * BUFSIZ / wlen;
+ locale loc = locale("se_NO.UTF-8");
+
+ FILE* file = fopen(name, "w");
+ for (int i = 0; i < loops; ++i)
+ fwrite(cstr, 1, clen, file);
+ fclose(file);
+
+ wfilebuf fb;
+ fb.pubimbue(loc);
+ fb.open(name, ios_base::in);
+
+ pos_type p1 = fb.pubseekoff(0, ios_base::cur);
+ pos_type end = fb.pubseekoff(0, ios_base::end);
+ pos_type beg = fb.pubseekoff(0, ios_base::beg);
+ VERIFY( p1 == beg );
+
+ const size_t limit = wlen * loops;
+ for (size_t index = 0; index < limit; ++index)
+ {
+ // Call seekoff at pseudo-random intervals.
+ if (index % 5 == 0 || index % 7 == 0)
+ {
+ pos_type p2 = fb.pubseekoff(0, ios_base::cur);
+ VERIFY( p2 != pos_type(-1) );
+ }
+ int_type c1 = fb.sbumpc();
+ VERIFY( c1 != eof );
+ VERIFY( static_cast<wchar_t>(c1) == wstr[index % wlen] );
+ }
+
+ pos_type p3 = fb.pubseekoff(0, ios_base::cur);
+ VERIFY( p3 == end );
+
+ int_type c2 = fb.sbumpc();
+ VERIFY( c2 == eof );
+
+ fb.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/11543.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/11543.cc
new file mode 100644
index 000000000..fd0c19ea3
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/11543.cc
@@ -0,0 +1,141 @@
+// Copyright (C) 2003, 2009
+// Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+struct MyState
+{
+};
+
+struct MyCharTraits : std::char_traits<wchar_t>
+{
+ typedef std::fpos<MyState> pos_type;
+ typedef MyState state_type;
+};
+
+namespace std
+{
+ template <>
+ class codecvt<wchar_t, char, MyState> :
+ public locale::facet, public codecvt_base
+ {
+ public:
+ typedef wchar_t intern_type;
+ typedef char extern_type;
+ typedef MyState state_type;
+
+ explicit codecvt(size_t refs = 0)
+ : locale::facet(refs) { }
+
+ result out(state_type& state, const intern_type* from,
+ const intern_type* from_end, const intern_type*& from_next,
+ extern_type* to, extern_type* to_limit,
+ extern_type*& to_next) const
+ { return do_out(state, from, from_end, from_next,
+ to, to_limit, to_next); }
+
+ result unshift(state_type& state, extern_type* to, extern_type* to_limit,
+ extern_type*& to_next) const
+ { return do_unshift(state, to, to_limit, to_next); }
+
+ result in(state_type& state, const extern_type* from,
+ const extern_type* from_end, const extern_type*& from_next,
+ intern_type* to, intern_type* to_limit,
+ intern_type*& to_next) const
+ { return do_in(state, from, from_end, from_next,
+ to, to_limit, to_next); }
+
+ int encoding() const throw()
+ { return do_encoding(); }
+
+ bool always_noconv() const throw()
+ { return do_always_noconv(); }
+
+ int length(state_type& state, const extern_type* from,
+ const extern_type* end, size_t max) const
+ { return do_length(state, from, end, max); }
+
+ int max_length() const throw()
+ { return do_max_length(); }
+
+ static locale::id id;
+
+ protected:
+ virtual ~codecvt();
+
+ virtual result do_out(state_type&, const intern_type*,
+ const intern_type*, const intern_type*&,
+ extern_type*, extern_type*, extern_type*&) const
+ { return error; }
+
+ virtual result do_in(state_type&, const extern_type*, const extern_type*,
+ const extern_type*&, intern_type*, intern_type*,
+ intern_type*&) const
+ { return error; }
+
+ virtual result do_unshift(state_type&, extern_type*, extern_type*,
+ extern_type*&) const
+ { return noconv; }
+
+ virtual int do_encoding() const throw()
+ { return 1; }
+
+ virtual bool do_always_noconv() const throw()
+ { return false; }
+
+ virtual int do_length(state_type&, const extern_type* from,
+ const extern_type* end, size_t max) const
+ {
+ size_t len = end - from;
+ return std::min(max, len);
+ }
+
+ virtual int do_max_length() const throw()
+ { return 1; }
+ };
+
+ locale::id codecvt<wchar_t, char, MyState>::id;
+
+ codecvt<wchar_t, char, MyState>::~codecvt()
+ { }
+}
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::locale loc(std::locale::classic(),
+ new std::codecvt<wchar_t, char, MyState>);
+ std::basic_filebuf<wchar_t, MyCharTraits> fb;
+ fb.pubimbue(loc);
+ fb.open("tmp_11543", std::ios_base::out);
+ VERIFY( fb.is_open() );
+ MyCharTraits::pos_type pos = fb.pubseekoff(0, std::ios_base::beg);
+ VERIFY( pos != MyCharTraits::pos_type(MyCharTraits::off_type(-1)) );
+ fb.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-1.cc
new file mode 100644
index 000000000..b889f1bf5
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-1.cc
@@ -0,0 +1,78 @@
+// Copyright (C) 2003, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <locale>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+class Cvt : public std::codecvt<wchar_t, char, std::mbstate_t>
+{
+public:
+ mutable bool unshift_called;
+
+ Cvt()
+ : unshift_called(false)
+ { }
+
+protected:
+ bool
+ do_always_noconv() const throw()
+ { return false; }
+
+ int
+ do_encoding() const throw()
+ { return -1; }
+
+ std::codecvt_base::result
+ do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const
+ {
+ unshift_called = true;
+ to_next = to;
+ return std::codecvt_base::ok;
+ }
+};
+
+// libstdc++/12790
+// basic_filebuf::seekoff() should call codecvt::unshift()
+void test01()
+{
+ using namespace std;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_seekoff_12790";
+
+ Cvt* cvt = new Cvt;
+ locale loc(locale::classic(), cvt);
+
+ wfilebuf fb;
+ fb.pubimbue(loc);
+
+ fb.open(name, ios_base::out);
+ fb.sputc(L'a');
+
+ VERIFY( !cvt->unshift_called );
+ fb.pubseekoff(0, ios_base::cur);
+ VERIFY( cvt->unshift_called );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-2.cc
new file mode 100644
index 000000000..d38952586
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-2.cc
@@ -0,0 +1,79 @@
+// Copyright (C) 2003, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <locale>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+class Cvt : public std::codecvt<wchar_t, char, std::mbstate_t>
+{
+public:
+ mutable bool unshift_called;
+
+ Cvt()
+ : unshift_called(false)
+ { }
+
+protected:
+ bool
+ do_always_noconv() const throw()
+ { return false; }
+
+ int
+ do_encoding() const throw()
+ { return -1; }
+
+ std::codecvt_base::result
+ do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const
+ {
+ unshift_called = true;
+ to_next = to;
+ return std::codecvt_base::ok;
+ }
+};
+
+// libstdc++/12790
+// basic_filebuf::seekoff() should call codecvt::unshift()
+void test01()
+{
+ using namespace std;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_seekoff_12790";
+
+ Cvt* cvt = new Cvt;
+ locale loc(locale::classic(), cvt);
+
+ wfilebuf fb;
+ fb.pubsetbuf(0, 0);
+ fb.pubimbue(loc);
+
+ fb.open(name, ios_base::out);
+ fb.sputc(L'a');
+
+ VERIFY( !cvt->unshift_called );
+ fb.pubseekoff(0, ios_base::cur);
+ VERIFY( cvt->unshift_called );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-3.cc
new file mode 100644
index 000000000..4057cd418
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-3.cc
@@ -0,0 +1,78 @@
+// Copyright (C) 2003, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <locale>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+class Cvt : public std::codecvt<wchar_t, char, std::mbstate_t>
+{
+public:
+ mutable bool unshift_called;
+
+ Cvt()
+ : unshift_called(false)
+ { }
+
+protected:
+ bool
+ do_always_noconv() const throw()
+ { return false; }
+
+ int
+ do_encoding() const throw()
+ { return -1; }
+
+ std::codecvt_base::result
+ do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const
+ {
+ unshift_called = true;
+ to_next = to;
+ return std::codecvt_base::ok;
+ }
+};
+
+// libstdc++/12790
+// basic_filebuf::seekoff() should call codecvt::unshift(),
+// but only if writing
+void test01()
+{
+ using namespace std;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_seekoff_12790";
+
+ Cvt* cvt = new Cvt;
+ locale loc(locale::classic(), cvt);
+
+ wfilebuf fb;
+ fb.pubimbue(loc);
+
+ fb.open(name, ios_base::out);
+
+ VERIFY( !cvt->unshift_called );
+ fb.pubseekoff(0, ios_base::cur);
+ VERIFY( !cvt->unshift_called );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-4.cc
new file mode 100644
index 000000000..c04b4e79b
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-4.cc
@@ -0,0 +1,79 @@
+// Copyright (C) 2003, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <locale>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+class Cvt : public std::codecvt<wchar_t, char, std::mbstate_t>
+{
+public:
+ mutable bool unshift_called;
+
+ Cvt()
+ : unshift_called(false)
+ { }
+
+protected:
+ bool
+ do_always_noconv() const throw()
+ { return false; }
+
+ int
+ do_encoding() const throw()
+ { return -1; }
+
+ std::codecvt_base::result
+ do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const
+ {
+ unshift_called = true;
+ to_next = to;
+ return std::codecvt_base::ok;
+ }
+};
+
+// libstdc++/12790
+// basic_filebuf::seekoff() should call codecvt::unshift()
+void test01()
+{
+ using namespace std;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_seekoff_12790";
+
+ Cvt* cvt = new Cvt;
+ locale loc(locale::classic(), cvt);
+
+ wfilebuf fb;
+ fb.pubimbue(loc);
+
+ fb.open(name, ios_base::out);
+ fb.sputc(L'a');
+ fb.pubsync(); // Does not call unshift()
+
+ VERIFY( !cvt->unshift_called );
+ fb.pubseekoff(0, ios_base::cur);
+ VERIFY( cvt->unshift_called );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/2.cc
new file mode 100644
index 000000000..cc9c4e22a
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/2.cc
@@ -0,0 +1,90 @@
+// { dg-require-namedlocale "se_NO.UTF-8" }
+
+// 2003-09-08 Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <cstdio>
+#include <testsuite_hooks.h>
+
+// Check that basic_filebuf::seekoff handles UTF-8 when open for input and
+// output.
+void test02()
+{
+ using namespace std;
+ typedef wfilebuf::int_type int_type;
+ bool test __attribute__((unused)) = true;
+ const char name[] = "tmp_seekoff-2.tst";
+
+ locale loc = locale("se_NO.UTF-8");
+
+ const size_t size = 10;
+ wchar_t buf[size];
+ streamsize n;
+
+ wfilebuf fb;
+ fb.pubimbue(loc);
+ fb.open(name, ios_base::in | ios_base::out | ios_base::trunc);
+
+ n = fb.sputn(L"\xa0st", 3);
+ VERIFY( n == 3 );
+
+ fb.pubseekoff(0, ios_base::beg);
+ n = fb.sgetn(buf, 2);
+ VERIFY( n == 2 );
+ VERIFY( !wmemcmp(buf, L"\xa0s", 2) );
+
+ fb.pubseekoff(0, ios_base::cur);
+ n = fb.sputn(L"\xb2R", 2);
+ VERIFY( n == 2 );
+
+ fb.pubseekoff(0, ios_base::beg);
+ n = fb.sgetn(buf, size);
+ VERIFY( n == 4 );
+ VERIFY( !wmemcmp(buf, L"\xa0s\xb2R", 4) );
+
+ fb.pubseekoff(0, ios_base::beg);
+ n = fb.sputn(L"\x90m\x92n\x94", 5);
+ VERIFY( n == 5 );
+
+ fb.pubseekoff(0, ios_base::beg);
+ n = fb.sgetn(buf, 2);
+ VERIFY( n == 2 );
+ VERIFY( !wmemcmp(buf, L"\x90m", 2) );
+
+ fb.pubseekoff(0, ios_base::end);
+ n = fb.sputn(L"I\xbfJ", 3);
+ VERIFY( n == 3 );
+
+ fb.pubseekoff(0, ios_base::beg);
+ n = fb.sgetn(buf, size);
+ VERIFY( n == 8 );
+ VERIFY( !wmemcmp(buf, L"\x90m\x92n\x94I\xbfJ", 8) );
+
+ fb.close();
+}
+
+int main()
+{
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/3.cc
new file mode 100644
index 000000000..435ebcc3e
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/3.cc
@@ -0,0 +1,51 @@
+// Copyright (C) 2003, 2004, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void test03()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ const char* name = "tmp_seekoff_3";
+
+ wfilebuf fb;
+
+ fb.open(name, ios_base::out);
+ fb.sputc(0xf001);
+
+ try
+ {
+ // seekoff should flush the output sequence, which will fail
+ // if the output buffer contains illegal characters.
+ fb.pubseekoff(0, ios_base::cur);
+ VERIFY( false );
+ }
+ catch (std::exception&)
+ {
+ }
+}
+
+int main()
+{
+ test03();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/4.cc
new file mode 100644
index 000000000..245f18f48
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/4.cc
@@ -0,0 +1,94 @@
+// { dg-require-fileio "" }
+
+// Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <cwchar>
+#include <cstring>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ typedef wfilebuf::pos_type pos_type;
+ const char name[] = "tmp_seekoff-4.tst";
+
+ const size_t size = 12;
+ wchar_t buf[size];
+ streamsize n;
+
+ wfilebuf fb;
+ fb.open(name, ios_base::in | ios_base::out | ios_base::trunc);
+
+ n = fb.sputn(L"abcd", 4);
+ VERIFY( n == 4 );
+
+ fb.pubseekoff(0, ios_base::beg);
+ n = fb.sgetn(buf, 3);
+ VERIFY( n == 3 );
+ VERIFY( !wmemcmp(buf, L"abc", 3) );
+
+ // Check read => write without pubseekoff(0, ios_base::cur)
+
+ n = fb.sputn(L"ef", 2);
+ VERIFY( n == 2 );
+
+ fb.pubseekoff(0, ios_base::beg);
+
+ n = fb.sgetn(buf, size);
+ VERIFY( n == 5 );
+ VERIFY( !wmemcmp(buf, L"abcef", 5) );
+
+ fb.pubseekoff(0, ios_base::beg);
+ n = fb.sputn(L"gh", 2);
+ VERIFY( n == 2 );
+
+ // Check write => read without pubseekoff(0, ios_base::cur)
+
+ n = fb.sgetn( buf, 3 );
+ VERIFY( !memcmp(buf, L"cef", 3) );
+
+ n = fb.sputn(L"ijkl", 4);
+ VERIFY( n == 4 );
+
+ fb.pubseekoff(0, ios_base::beg);
+ n = fb.sgetn(buf, 2);
+ VERIFY( n == 2 );
+ VERIFY( !wmemcmp(buf, L"gh", 2) );
+
+ fb.pubseekoff(0, ios_base::end);
+ n = fb.sputn(L"mno", 3);
+ VERIFY( n == 3 );
+
+ fb.pubseekoff(0, ios_base::beg);
+ n = fb.sgetn(buf, size);
+ VERIFY( n == 12 );
+ VERIFY( !wmemcmp(buf, L"ghcefijklmno", 12) );
+
+ fb.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/9875_seekoff.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/9875_seekoff.cc
new file mode 100644
index 000000000..312386a24
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/9875_seekoff.cc
@@ -0,0 +1,99 @@
+// Copyright (C) 2003, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <algorithm>
+#include <cstring>
+#include <testsuite_hooks.h>
+
+class Cvt : public std::codecvt<wchar_t, char, mbstate_t>
+{
+protected:
+ virtual std::codecvt_base::result
+ do_out(std::mbstate_t&, const wchar_t* from, const wchar_t* from_end,
+ const wchar_t*& from_next, char* to, char* to_end,
+ char*& to_next) const
+ {
+ std::size_t from_len = from_end - from;
+ std::size_t to_len = (to_end - to) / sizeof(wchar_t);
+ std::size_t len = std::min(from_len, to_len);
+ std::memcpy(to, from, len * sizeof(wchar_t));
+ from_next = from + len;
+ to_next = to + len * sizeof(wchar_t);
+ return from_next == from_end ? std::codecvt_base::ok :
+ std::codecvt_base::partial;
+ }
+
+ virtual std::codecvt_base::result
+ do_in(std::mbstate_t&, const char* from, const char* from_end,
+ const char*& from_next, wchar_t* to, wchar_t* to_end,
+ wchar_t*& to_next) const
+ {
+ std::size_t from_len =
+ (from_end - from) / sizeof(wchar_t);
+ std::size_t to_len = to_end - to;
+ std::size_t len = std::min(from_len, to_len);
+ std::memcpy(to, from, len * sizeof(wchar_t));
+ from_next = from + len * sizeof(wchar_t);
+ to_next = to + len;
+ return from_next == from_end ? std::codecvt_base::ok :
+ std::codecvt_base::partial;
+ }
+
+ virtual std::codecvt_base::result
+ do_unshift(std::mbstate_t&, char*, char*, char*&) const
+ { return std::codecvt_base::noconv; }
+
+ virtual int do_encoding() const throw() { return sizeof(wchar_t); }
+ virtual bool do_always_noconv() const throw() { return false; }
+
+ virtual int
+ do_length(std::mbstate_t&, const char* from, const char* end,
+ std::size_t max)
+ {
+ std::size_t len = (end - from) / sizeof(wchar_t);
+ return std::min(len, max) * sizeof(wchar_t);
+ }
+
+ virtual int do_max_length() const throw() { return sizeof(wchar_t); }
+};
+
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ // seekoff
+ wfilebuf fb;
+ fb.pubimbue(locale(locale::classic(), new Cvt));
+ fb.open("tmp_9875_seekoff", ios_base::out | ios_base::in | ios_base::trunc);
+ fb.sputn(L"0123456789", 10);
+ fb.pubseekoff(-3, ios_base::cur);
+ VERIFY( fb.sgetc() == L'7' );
+ fb.pubseekoff(-3, ios_base::cur);
+ VERIFY( fb.sgetc() == L'4' );
+ fb.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}