]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[multiple changes]
authorBenjamin Kosnik <bkoz@gcc.gnu.org>
Sun, 11 May 2003 04:20:57 +0000 (04:20 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Sun, 11 May 2003 04:20:57 +0000 (04:20 +0000)
2003-05-10  Petur Runolfsson  <peturr02@ru.is>

PR libstdc++/9027
PR libstdc++/9520
PR libstdc++/10096
* include/bits/fstream.tcc (basic_file::_M_underflow):  Add generic
implementation, based on old wchar_t specialization, add support
for codecvt::in() return value of codecvt_base::noconv, remove
_M_file.sys_ungetc() call.
* include/std/std_fstream.h (basic_file::underflow,
basic_file::uflow, basic_file::_M_underflow):  Remove
specialization declarations, call _M_underflow from generic versions
of underflow and uflow.
* src/fstream.cc (basic_file::underflow, basic_file::uflow,
basic_file::_M_underflow):  Remove specializations.
* src/Makefile.am (sources):  Remove fstream.cc.
* src/Makefile.in:  Regenerated.
* testsuite/27_io/basic_filebuf/underflow/10096.cc:  New test.
* testsuite/27_io/basic_filebuf/underflow/char/1.cc:  New test.
* testsuite/27_io/basic_filebuf/underflow/char/9027.cc:  New test.
* testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc:  New test.

2003-05-10  Benjamin Kosnik  <bkoz@redhat.com>

* include/ext/stdio_filebuf.h (__stdio_filebuf): Remove stack
buffer.
* config/io/basic_file_stdio.h (__basic_file::xsgetn): Remove
unbuffered bits.
(__basic_file::xsputn): Same.
(__basic_file::seekoff): Same.
(__basic_file::seekpos): Same.
(__basic_file::showmanyc): Same.
* config/io/basic_file_stdio.cc: Same.
* include/std/std_fstream.h: Same.
* include/bits/fstream.tcc: Same.
* src/fstream.cc: Same.
* testsuite/27_io/basic_filebuf/sgetn/char/1.cc (test05): Tidy.

2003-05-10  Petur Runolfsson  <peturr02@ru.is>

PR libstdc++/9520
PR libstdc++/9661
PR libstdc++/9662
* include/ext/stdio_sync_filebuf.h:  New file.
(basic_stdiobuf):  New.
* include/Makefile.am (ext_headers): Add ext/stdio_sync_filebuf.h
* include/Makefile.in: Regenerate.
* include/bits/ios_base.h (Init::_S_create_buffers,
Init::_S_destroy_buffers):  Remove declarations.
* src/globals.cc (buf_cout_sync, buf_cin_sync, buf_cerr_sync,
buf_wcout_sync, buf_wcin_sync, buf_wcerr_sync):  Define.
* src/ios.cc (Init::_S_create_buffers,
Init::_S_destroy_buffers):  Remove.
(Init::Init):  Create and use syncronized buffers.
(ios_base::sync_with_stdio):  Destroy syncronized buffers,
create and install unsyncronized buffers.
* testsuite/27_io/objects/char/10.cc:  New test.
* testsuite/27_io/objects/char/9.cc:  New test.
* testsuite/27_io/objects/char/9661-1.cc:  New test.
* testsuite/27_io/objects/char/9661-2_xin.cc:  New test.
* testsuite/27_io/objects/char/9661-2_xin.in:  New.
* testsuite/27_io/objects/wchar_t/1.cc:  New test.
* testsuite/27_io/objects/wchar_t/10.cc:  New test.
* testsuite/27_io/objects/wchar_t/2.cc:  New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.cc:  New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.in:  New.
* testsuite/27_io/objects/wchar_t/2523-2_xin.cc:  New test.
* testsuite/27_io/objects/wchar_t/2523-2_xin.in:  New.
* testsuite/27_io/objects/wchar_t/3045.cc:  New test.
* testsuite/27_io/objects/wchar_t/3647.cc:  New test.
* testsuite/27_io/objects/wchar_t/3_xin.cc:  New test.
* testsuite/27_io/objects/wchar_t/3_xin.in:  New.
* testsuite/27_io/objects/wchar_t/4_xin.cc:  New test.
* testsuite/27_io/objects/wchar_t/4_xin.in:  New.
* testsuite/27_io/objects/wchar_t/5.cc:  New test.
* testsuite/27_io/objects/wchar_t/5268.cc:  New test.
* testsuite/27_io/objects/wchar_t/5280_xin.cc:  New test.
* testsuite/27_io/objects/wchar_t/5280_xin.in:  New.
* testsuite/27_io/objects/wchar_t/6.cc:  New test.
* testsuite/27_io/objects/wchar_t/6548_xin.cc:  New test.
* testsuite/27_io/objects/wchar_t/6548_xin.in:  New.
* testsuite/27_io/objects/wchar_t/6648-1_xin.cc:  New test.
* testsuite/27_io/objects/wchar_t/6648-1_xin.in:  New.
* testsuite/27_io/objects/wchar_t/6648-2_xin.cc:  New test.
* testsuite/27_io/objects/wchar_t/6648-2_xin.in:  New.
* testsuite/27_io/objects/wchar_t/7.cc:  New test.
* testsuite/27_io/objects/wchar_t/7744_xin.cc:  New test.
* testsuite/27_io/objects/wchar_t/7744_xin.in:  New.
* testsuite/27_io/objects/wchar_t/8.cc:  New test.
* testsuite/27_io/objects/wchar_t/9_xin.cc:  New test.
* testsuite/27_io/objects/wchar_t/9_xin.in:  New.
* testsuite/27_io/objects/wchar_t/9520.cc:  New test.
* testsuite/27_io/objects/wchar_t/9661-1.cc:  New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.cc:  New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.in:  New.
* testsuite/27_io/objects/wchar_t/9662.cc:  New test.
* testsuite/ext/stdiobuf_char.cc:  New test.
* testsuite/ext/stdiobuf_wchar_t.cc:  New test.

From-SVN: r66678

63 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/config/io/basic_file_stdio.cc
libstdc++-v3/config/io/basic_file_stdio.h
libstdc++-v3/include/Makefile.am
libstdc++-v3/include/Makefile.in
libstdc++-v3/include/bits/fstream.tcc
libstdc++-v3/include/bits/ios_base.h
libstdc++-v3/include/ext/stdio_filebuf.h
libstdc++-v3/include/ext/stdio_sync_filebuf.h [new file with mode: 0644]
libstdc++-v3/include/std/std_fstream.h
libstdc++-v3/src/Makefile.am
libstdc++-v3/src/Makefile.in
libstdc++-v3/src/fstream.cc [deleted file]
libstdc++-v3/src/globals.cc
libstdc++-v3/src/ios.cc
libstdc++-v3/src/misc-inst.cc
libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1.cc
libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/10096.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/9027.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/char/10.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/char/9.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/char/9661-1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/char/9661-2_xin.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/char/9661-2_xin.in [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/1.cc
libstdc++-v3/testsuite/27_io/objects/wchar_t/10.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/2.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-1_xin.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-1_xin.in [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-2_xin.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-2_xin.in [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/3045.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/3647.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/3_xin.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/3_xin.in [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/4_xin.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/4_xin.in [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/5.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/5268.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/5280_xin.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/5280_xin.in [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/6.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/6548_xin.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/6548_xin.in [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-1_xin.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-1_xin.in [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-2_xin.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-2_xin.in [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/7.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/7744_xin.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/7744_xin.in [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/8.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/9520.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-2_xin.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-2_xin.in [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/9662.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/9_xin.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/9_xin.in [new file with mode: 0644]
libstdc++-v3/testsuite/ext/stdio_sync_filebuf_char.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/stdio_sync_filebuf_wchar_t.cc [new file with mode: 0644]

index 5ee9e59bd18e41e81476b1e735325ee9a33eccc5..2123a81de7a46e7f54dfdf78b8f2c460ee476308 100644 (file)
@@ -1,3 +1,102 @@
+2003-05-10  Petur Runolfsson  <peturr02@ru.is>
+
+       PR libstdc++/9027
+       PR libstdc++/9520
+       PR libstdc++/10096
+       * include/bits/fstream.tcc (basic_file::_M_underflow):  Add generic
+       implementation, based on old wchar_t specialization, add support
+       for codecvt::in() return value of codecvt_base::noconv, remove
+       _M_file.sys_ungetc() call.
+       * include/std/std_fstream.h (basic_file::underflow,
+       basic_file::uflow, basic_file::_M_underflow):  Remove
+       specialization declarations, call _M_underflow from generic versions
+       of underflow and uflow.
+       * src/fstream.cc (basic_file::underflow, basic_file::uflow,
+       basic_file::_M_underflow):  Remove specializations.
+       * src/Makefile.am (sources):  Remove fstream.cc.
+       * src/Makefile.in:  Regenerated.
+       * testsuite/27_io/basic_filebuf/underflow/10096.cc:  New test.
+       * testsuite/27_io/basic_filebuf/underflow/char/1.cc:  New test.
+       * testsuite/27_io/basic_filebuf/underflow/char/9027.cc:  New test.
+       * testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc:  New test.
+
+2003-05-10  Benjamin Kosnik  <bkoz@redhat.com>
+
+       * include/ext/stdio_filebuf.h (__stdio_filebuf): Remove stack
+       buffer.
+       * config/io/basic_file_stdio.h (__basic_file::xsgetn): Remove
+       unbuffered bits.
+       (__basic_file::xsputn): Same.
+       (__basic_file::seekoff): Same.
+       (__basic_file::seekpos): Same.
+       (__basic_file::showmanyc): Same.
+       * config/io/basic_file_stdio.cc: Same.
+       * include/std/std_fstream.h: Same.
+       * include/bits/fstream.tcc: Same.
+       * src/fstream.cc: Same.
+       * testsuite/27_io/basic_filebuf/sgetn/char/1.cc (test05): Tidy.
+       
+2003-05-10  Petur Runolfsson  <peturr02@ru.is>
+
+       PR libstdc++/9520
+       PR libstdc++/9661
+       PR libstdc++/9662
+       * include/ext/stdio_sync_filebuf.h:  New file.
+       (basic_stdiobuf):  New.
+       * include/Makefile.am (ext_headers): Add ext/stdio_sync_filebuf.h
+       * include/Makefile.in: Regenerate.
+       * include/bits/ios_base.h (Init::_S_create_buffers,
+       Init::_S_destroy_buffers):  Remove declarations.
+       * src/globals.cc (buf_cout_sync, buf_cin_sync, buf_cerr_sync, 
+       buf_wcout_sync, buf_wcin_sync, buf_wcerr_sync):  Define.
+       * src/ios.cc (Init::_S_create_buffers,
+       Init::_S_destroy_buffers):  Remove.
+       (Init::Init):  Create and use syncronized buffers.
+       (ios_base::sync_with_stdio):  Destroy syncronized buffers,
+       create and install unsyncronized buffers.
+       * testsuite/27_io/objects/char/10.cc:  New test.
+       * testsuite/27_io/objects/char/9.cc:  New test.
+       * testsuite/27_io/objects/char/9661-1.cc:  New test.
+       * testsuite/27_io/objects/char/9661-2_xin.cc:  New test.
+       * testsuite/27_io/objects/char/9661-2_xin.in:  New.
+       * testsuite/27_io/objects/wchar_t/1.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/10.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/2.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/2523-1_xin.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/2523-1_xin.in:  New.
+       * testsuite/27_io/objects/wchar_t/2523-2_xin.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/2523-2_xin.in:  New.
+       * testsuite/27_io/objects/wchar_t/3045.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/3647.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/3_xin.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/3_xin.in:  New.
+       * testsuite/27_io/objects/wchar_t/4_xin.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/4_xin.in:  New.
+       * testsuite/27_io/objects/wchar_t/5.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/5268.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/5280_xin.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/5280_xin.in:  New.
+       * testsuite/27_io/objects/wchar_t/6.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/6548_xin.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/6548_xin.in:  New.
+       * testsuite/27_io/objects/wchar_t/6648-1_xin.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/6648-1_xin.in:  New.
+       * testsuite/27_io/objects/wchar_t/6648-2_xin.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/6648-2_xin.in:  New.
+       * testsuite/27_io/objects/wchar_t/7.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/7744_xin.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/7744_xin.in:  New.
+       * testsuite/27_io/objects/wchar_t/8.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/9_xin.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/9_xin.in:  New.
+       * testsuite/27_io/objects/wchar_t/9520.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/9661-1.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/9661-2_xin.cc:  New test.
+       * testsuite/27_io/objects/wchar_t/9661-2_xin.in:  New.
+       * testsuite/27_io/objects/wchar_t/9662.cc:  New test.
+       * testsuite/ext/stdiobuf_char.cc:  New test.
+       * testsuite/ext/stdiobuf_wchar_t.cc:  New test.
+
 2003-05-10  Paolo Carlini  <pcarlini@unitus.it>
 
        * testsuite/27_io/basic_filebuf/close/char/3.cc: Remove
index 7f9c18bf05af60c67d4c794c426b38e4b8ced885..eaddd3a2bbaf920fc7ba77f13cf38c756f3be41e 100644 (file)
@@ -205,77 +205,41 @@ namespace std
     return __retval;
   }
  
-  // In the next four functions we want to use stdio functions only
-  // when synced with stdio (_M_buf_size == 1): I/O primitives do not
-  // block until the asked number of bytes are available.
   streamsize 
-  __basic_file<char>::xsgetn(char* __s, streamsize __n, bool __stdio)
+  __basic_file<char>::xsgetn(char* __s, streamsize __n)
   {
-    if (__stdio)
-      return fread(__s, 1, __n, _M_cfile);
-    else
-      {
-       streamsize __ret;
-        do
-         __ret = read(this->fd(), __s, __n);
-       while (__ret == -1L && errno == EINTR);
-       return __ret;
-      }
+    streamsize __ret;
+    do
+      __ret = read(this->fd(), __s, __n);
+    while (__ret == -1L && errno == EINTR);
+    return __ret;
   }
     
   streamsize 
-  __basic_file<char>::xsputn(const char* __s, streamsize __n, bool __stdio)
+  __basic_file<char>::xsputn(const char* __s, streamsize __n)
   {
-    if (__stdio)
-      return fwrite(__s, 1, __n, _M_cfile);
-    else
-      {
-       streamsize __ret;
-        do
-         __ret = write(this->fd(), __s, __n);
-       while (__ret == -1L && errno == EINTR);
-       return __ret;
-      }
+    streamsize __ret;
+    do
+      __ret = write(this->fd(), __s, __n);
+    while (__ret == -1L && errno == EINTR);
+    return __ret;
   }
   
   streamoff
   __basic_file<char>::seekoff(streamoff __off, ios_base::seekdir __way, 
-                             bool __stdio, ios_base::openmode /*__mode*/)
-  { 
-    if (!__stdio)
-      return lseek(this->fd(), __off, __way);
-    else
-      {
-       if (!fseek(_M_cfile, __off, __way))
-         return ftell(_M_cfile); 
-       else
-         // Fseek failed.
-         return -1L;
-      }
-  }
+                             ios_base::openmode /*__mode*/)
+  { return lseek(this->fd(), __off, __way); }
 
   streamoff
-  __basic_file<char>::seekpos(streamoff __pos, bool __stdio,
-                             ios_base::openmode /*__mode*/)
-  { 
-    if (!__stdio)
-      return lseek(this->fd(), __pos, ios_base::beg);
-    else
-      {
-       if (!fseek(_M_cfile, __pos, ios_base::beg))
-         return ftell(_M_cfile);
-       else
-         // Fseek failed.
-         return -1L;
-      }
-  }
+  __basic_file<char>::seekpos(streamoff __pos, ios_base::openmode /*__mode*/)
+  { return lseek(this->fd(), __pos, ios_base::beg); }
   
   int 
   __basic_file<char>::sync() 
   { return fflush(_M_cfile); }
 
   streamsize
-  __basic_file<char>::showmanyc_helper(bool __stdio)
+  __basic_file<char>::showmanyc()
   {
 #ifdef FIONREAD
     // Pipes and sockets.    
@@ -299,9 +263,6 @@ namespace std
     struct stat __buffer;
     int __ret = fstat(this->fd(), &__buffer);
     if (!__ret && _GLIBCPP_ISREG(__buffer.st_mode))
-      if (__stdio)
-       return __buffer.st_size - ftell(_M_cfile);
-      else
        return __buffer.st_size - lseek(this->fd(), 0, ios_base::cur);
 #endif
     return 0;
index b6a05697612a1fa1cac54a6e9bd171cc7be3a912..e46407d8bc608bd6979ec0b62a32c31e8c181be4 100644 (file)
@@ -56,6 +56,7 @@ namespace std
     {
       // Underlying data source/sink.
       __c_file*        _M_cfile;
+
       // True iff we opened _M_cfile, and thus must close it ourselves.
       bool             _M_cfile_created;
 
@@ -93,25 +94,25 @@ namespace std
       ~__basic_file();
 
       streamsize 
-      xsputn(const char* __s, streamsize __n, bool __stdio);
+      xsputn(const char* __s, streamsize __n);
 
       streamsize 
-      xsgetn(char* __s, streamsize __n, bool __stdio);
+      xsgetn(char* __s, streamsize __n);
 
       streamoff
-      seekoff(streamoff __off, ios_base::seekdir __way, bool __stdio,
+      seekoff(streamoff __off, ios_base::seekdir __way, 
              ios_base::openmode __mode = ios_base::in | ios_base::out);
 
       streamoff
-      seekpos(streamoff __pos, bool __stdio,
+      seekpos(streamoff __pos, 
              ios_base::openmode __mode = ios_base::in | ios_base::out);
 
       int 
       sync();
 
       streamsize
-      showmanyc_helper(bool __stdio);
+      showmanyc();
     };
 }  // namespace std
 
-#endif // _CPP_BASIC_FILE
+#endif 
index 9d4b0b7c6d89e39039f26f50f3da91521c9cd897..1a462aed417504044b58b6d93d32a7f9703c6f3f 100644 (file)
@@ -217,6 +217,7 @@ ext_headers = \
        ${ext_srcdir}/algorithm \
        ${ext_srcdir}/enc_filebuf.h \
        ${ext_srcdir}/stdio_filebuf.h \
+       ${ext_srcdir}/stdio_sync_filebuf.h \
        ${ext_srcdir}/functional \
        ${ext_srcdir}/hash_map \
        ${ext_srcdir}/hash_set \
index 076770f8dff3322b294e2f751d69049222e37baa..bfa88a8ab0cb17a6afdf61701b3ae20d5de1d48a 100644 (file)
@@ -337,6 +337,7 @@ ext_headers = \
        ${ext_srcdir}/algorithm \
        ${ext_srcdir}/enc_filebuf.h \
        ${ext_srcdir}/stdio_filebuf.h \
+       ${ext_srcdir}/stdio_sync_filebuf.h \
        ${ext_srcdir}/functional \
        ${ext_srcdir}/hash_map \
        ${ext_srcdir}/hash_set \
index c15d6ded4d244461c4cb39685935dee0f7419cf1..cec57ffffc08d4bfdfe059f18ba8674fe96e61ca 100644 (file)
@@ -165,7 +165,6 @@ namespace std
       const bool __testin = this->_M_mode & ios_base::in;
       const locale __loc = this->getloc();
       const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
-      const bool __testsync = this->_M_buf_size <= 1;
 
       if (__testin && this->is_open())
        {
@@ -174,13 +173,100 @@ namespace std
          // For a stateful encoding (-1) the pending sequence might be just
          // shift and unshift prefixes with no actual character.
          if (__cvt.encoding() >= 0)
-           __ret += _M_file.showmanyc_helper(__testsync) / __cvt.max_length();
+           __ret += _M_file.showmanyc() / __cvt.max_length();
        }
 
       _M_last_overflowed = false;      
       return __ret;
     }
   
+  template<typename _CharT, typename _Traits>
+    typename basic_filebuf<_CharT, _Traits>::int_type 
+    basic_filebuf<_CharT, _Traits>::_M_underflow(bool __bump)
+    {
+      int_type __ret = traits_type::eof();
+      const bool __testin = this->_M_mode & ios_base::in;
+      const bool __testout = this->_M_mode & ios_base::out;
+
+      if (__testin)
+       {
+         // Check for pback madness, and if so swich back to the
+         // normal buffers and jet outta here before expensive
+         // fileops happen...
+         if (_M_pback_init)
+           _M_destroy_pback();
+
+         if (this->_M_in_cur < this->_M_in_end)
+           {
+             __ret = traits_type::to_int_type(*this->_M_in_cur);
+             if (__bump)
+               _M_move_in_cur(1);
+             return __ret;
+           }
+
+         // Sync internal and external buffers.
+         // NB: __testget -> __testput as _M_buf_unified here.
+         if (this->_M_in_cur > this->_M_in_beg)
+           {
+             if (__testout)
+               _M_overflow();
+             else if (this->_M_in_cur != _M_filepos)
+               _M_file.seekoff(this->_M_in_cur - _M_filepos, ios_base::cur, 
+                               ios_base::in);
+           }
+
+         if (_M_buf_size)
+           {
+             streamsize __elen = 0;
+             streamsize __ilen = 0;
+             const locale __loc = this->getloc();
+             const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
+             if (__cvt.always_noconv())
+               {
+                 __elen = _M_file.xsgetn(reinterpret_cast<char*>(this->_M_in_beg), _M_buf_size);
+                 __ilen = __elen;
+               }
+             else
+               {
+                 char* __buf = static_cast<char*>(__builtin_alloca(_M_buf_size));
+                 __elen = _M_file.xsgetn(__buf, _M_buf_size);
+                 
+                 const char* __eend;
+                 char_type* __iend;
+                 codecvt_base::result __r;
+                 __r = __cvt.in(_M_state_cur, __buf, __buf + __elen, __eend, 
+                                this->_M_in_beg, 
+                                this->_M_in_beg + _M_buf_size, __iend);
+                 if (__r == codecvt_base::ok)
+                   __ilen = __iend - this->_M_in_beg;
+                 else if (__r == codecvt_base::noconv)
+                   {
+                     traits_type::copy(this->_M_in_beg,
+                                       reinterpret_cast<char_type*>(__buf), 
+                                       __elen);
+                     __ilen = __elen;
+                   }
+                 else 
+                   {
+                     // Unwind.
+                     __ilen = 0;
+                     _M_file.seekoff(-__elen, ios_base::cur, ios_base::in);
+                   }
+               }
+
+             if (0 < __ilen)
+               {
+                 _M_set_determinate(__ilen);
+                 __ret = traits_type::to_int_type(*this->_M_in_cur);
+                 if (__bump)
+                   _M_move_in_cur(1);
+               }          
+           }
+       }
+      _M_last_overflowed = false;      
+      return __ret;
+    }
+
   template<typename _CharT, typename _Traits>
     typename basic_filebuf<_CharT, _Traits>::int_type 
     basic_filebuf<_CharT, _Traits>::
@@ -277,14 +363,12 @@ namespace std
     _M_convert_to_external(_CharT* __ibuf, streamsize __ilen,
                           streamsize& __elen, streamsize& __plen)
     {
-      const bool __testsync = this->_M_buf_size <= 1;
       const locale __loc = this->getloc();
       const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
 
       if (__cvt.always_noconv() && __ilen)
        {
-         __elen += _M_file.xsputn(reinterpret_cast<char*>(__ibuf), 
-                                  __ilen, __testsync);
+         __elen += _M_file.xsputn(reinterpret_cast<char*>(__ibuf), __ilen);
          __plen += __ilen;
        }
       else
@@ -317,7 +401,7 @@ namespace std
          
          if (__blen)
            {
-             __elen += _M_file.xsputn(__buf, __blen, __testsync);
+             __elen += _M_file.xsputn(__buf, __blen);
              __plen += __blen;
            }
          
@@ -331,7 +415,7 @@ namespace std
              if (__r != codecvt_base::error)
                {
                  __rlen = __bend - __buf;
-                 __elen += _M_file.xsputn(__buf, __rlen, __testsync);
+                 __elen += _M_file.xsputn(__buf, __rlen);
                  __plen += __rlen;
                }
            }
@@ -346,7 +430,6 @@ namespace std
       int_type __ret = traits_type::eof();
       const bool __testput = this->_M_out_beg < this->_M_out_lim;
       const bool __testunbuffered = _M_file.is_open() && !this->_M_buf_size;
-      const bool __testsync = this->_M_buf_size <= 1;
 
       if (__testput || __testunbuffered)
        {
@@ -360,7 +443,7 @@ namespace std
          if (_M_filepos && _M_filepos != this->_M_out_beg)
            {
              off_type __off = this->_M_out_beg - _M_filepos;
-             _M_file.seekoff(__off, ios_base::cur, __testsync);
+             _M_file.seekoff(__off, ios_base::cur);
            }
 
          // Convert internal buffer to external representation, output.
@@ -434,7 +517,6 @@ namespace std
       pos_type __ret =  pos_type(off_type(-1)); 
       const bool __testin = (ios_base::in & this->_M_mode & __mode) != 0;
       const bool __testout = (ios_base::out & this->_M_mode & __mode) != 0;
-      const bool __testsync = this->_M_buf_size <= 1;
       
       int __width = 0;
       if (has_facet<__codecvt_type>(this->_M_buf_locale))
@@ -468,16 +550,14 @@ namespace std
                __computed_off += this->_M_in_cur - _M_filepos;
 
              // Return pos_type(off_type(-1)) in case of failure.
-             __ret = _M_file.seekoff(__computed_off, __way, __testsync, 
-                                     __mode);
+             __ret = _M_file.seekoff(__computed_off, __way, __mode);
              _M_set_indeterminate();
            }
          // NB: Need to do this in case _M_file in indeterminate
          // state, ie _M_file._offset == -1
          else
            {
-             pos_type __tmp = _M_file.seekoff(__off, ios_base::cur, 
-                                              __testsync, __mode);
+             pos_type __tmp = _M_file.seekoff(__off, ios_base::cur, __mode);
              if (__tmp >= 0)
                {
                  // Seek successful.
index 6657aea959edcc940d47769fef7450168871f9bb..37a02a43dddf956a686381c25fe3256f08d5f5f4 100644 (file)
@@ -452,12 +452,6 @@ namespace std
       Init();
       ~Init();
       
-      static void
-      _S_create_buffers(bool __sync);
-      
-      static void
-      _S_destroy_buffers();
-
       // NB: Allows debugger applications use of the standard streams
       // from operator new. _S_ios_base_init must be incremented in
       // _S_ios_create _after_ initialization is completed.
index 90031963631fa4a55509aa84c7b6162d32b37b64..4d3c9d07eeec85140672a5782e67475dcdf4c2c4 100644 (file)
@@ -35,6 +35,7 @@
 #define _EXT_STDIO_FILEBUF
 
 #pragma GCC system_header
+
 #include <fstream>
 
 namespace __gnu_cxx
@@ -60,10 +61,6 @@ namespace __gnu_cxx
       typedef typename traits_type::off_type           off_type;
       typedef std::size_t                               size_t;
       
-    protected:
-      // Stack-based buffer for unbuffered input.
-      char_type                        _M_unbuf[4];
-      
     public:
       /**
        *  @param  fd  An open file descriptor.
@@ -125,11 +122,7 @@ namespace __gnu_cxx
        {
          this->_M_mode = __mode;
          this->_M_buf_size = __size;
-         if (__size > 0 && __size < 4)
-           // Specify not to use an allocated buffer.
-           this->_M_buf = _M_unbuf;
-         else
-           _M_allocate_internal_buffer();
+         _M_allocate_internal_buffer();
          _M_set_indeterminate();
        }
     }
@@ -144,14 +137,10 @@ namespace __gnu_cxx
        {
          this->_M_mode = __mode;
          this->_M_buf_size = __size;
-         if (__size > 0 && __size < 4)
-           // Specify not to use an allocated buffer.
-           this->_M_buf = _M_unbuf;
-         else
-           _M_allocate_internal_buffer();
+         _M_allocate_internal_buffer();
          _M_set_indeterminate();
        }
     }
 } // namespace __gnu_cxx
 
-#endif /* _EXT_STDIO_FILEBUF */
+#endif 
diff --git a/libstdc++-v3/include/ext/stdio_sync_filebuf.h b/libstdc++-v3/include/ext/stdio_sync_filebuf.h
new file mode 100644 (file)
index 0000000..5e110c4
--- /dev/null
@@ -0,0 +1,247 @@
+// Iostreams wrapper for stdio FILE* -*- C++ -*-
+
+// Copyright (C) 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+/** @file ext/stdiostream.h
+ *  This file is a GNU extension to the Standard C++ Library.
+ */
+
+#ifndef _EXT_STDIO_SYNC_FILEBUF
+#define _EXT_STDIO_SYNC_FILEBUF
+
+#pragma GCC system_header
+
+#include <fstream>
+#include <unistd.h>
+
+#if defined(_GLIBCPP_HAVE_S_ISREG) || defined(_GLIBCPP_HAVE_S_IFREG)
+# include <sys/stat.h>
+# ifdef _GLIBCPP_HAVE_S_ISREG
+#  define _GLIBCPP_ISREG(x) S_ISREG(x)
+# else
+#  define _GLIBCPP_ISREG(x) (((x) & S_IFMT) == S_IFREG)
+# endif
+#endif
+
+#ifdef _GLIBCPP_USE_WCHAR_T
+#include <cwchar>
+#endif
+
+namespace __gnu_cxx
+{
+  template<typename _CharT, typename _Traits = std::char_traits<_CharT> >
+    class stdio_sync_filebuf : public std::basic_streambuf<_CharT, _Traits>
+    {
+    private:
+      std::__c_file* const _M_file;
+
+     public:
+      // Types:
+      typedef _CharT                                   char_type;
+      typedef _Traits                                  traits_type;
+      typedef typename traits_type::int_type           int_type;
+      typedef typename traits_type::pos_type           pos_type;
+      typedef typename traits_type::off_type           off_type;
+
+      explicit 
+      stdio_sync_filebuf(std::__c_file* __f) : _M_file(__f) { }
+
+    protected:
+
+      int_type
+      syncgetc();
+
+      int_type
+      syncungetc(int_type __c);
+
+      int_type
+      syncputc(int_type __c);
+
+      virtual int_type
+      underflow()
+      {
+       int_type __c = this->syncgetc();
+       return this->syncungetc(__c);
+      }
+
+      virtual int_type
+      uflow()
+      { return this->syncgetc(); }
+
+      virtual int_type
+      pbackfail(int_type __c = traits_type::eof())
+      { return this->syncungetc(__c); }
+
+      virtual std::streamsize
+      xsgetn(char_type* __s, std::streamsize __n);
+      
+      virtual std::streamsize
+      showmanyc()
+      { 
+#if defined(_GLIBCPP_HAVE_S_ISREG) || defined(_GLIBCPP_HAVE_S_IFREG)
+       // Regular files.
+       struct stat __buffer;
+       int __ret = fstat(fileno(_M_file), &__buffer);
+       if (!__ret && _GLIBCPP_ISREG(__buffer.st_mode))
+         return __buffer.st_size - ftell(_M_file);
+#endif
+       return 0; 
+      }
+
+      virtual int_type
+      overflow(int_type __c = traits_type::eof())
+      {
+       int_type __ret;
+       if (traits_type::eq_int_type(__c, traits_type::eof()))
+         {
+           if (std::fflush(_M_file))
+             __ret = traits_type::eof();
+           else
+             __ret = traits_type::not_eof(__c);
+         }
+       else
+         __ret = this->syncputc(__c);
+       return __ret;
+      }
+
+      virtual std::streamsize
+      xsputn(const char_type* __s, std::streamsize __n);
+
+      virtual int
+      sync()
+      { return std::fflush(_M_file); }
+
+      virtual std::streampos
+      seekoff(std::streamoff __off, std::ios_base::seekdir __dir,
+             std::ios_base::openmode = std::ios_base::in | std::ios_base::out)
+      {
+       std::streampos __ret(std::streamoff(-1));
+       int __whence;
+       if (__dir == std::ios_base::beg)
+         __whence = SEEK_SET;
+       else if (__dir == std::ios_base::cur)
+         __whence = SEEK_CUR;
+       else
+         __whence = SEEK_END;
+       
+       if (!fseek(_M_file, __off, __whence))
+         __ret = std::streampos(std::ftell(_M_file));
+       return __ret;
+      }
+
+      virtual std::streampos
+      seekpos(std::streampos __pos,
+             std::ios_base::openmode __mode =
+             std::ios_base::in | std::ios_base::out)
+      { return seekoff(std::streamoff(__pos), std::ios_base::beg, __mode); }
+    };
+
+  template<>
+    inline stdio_sync_filebuf<char>::int_type
+    stdio_sync_filebuf<char>::syncgetc()
+    { return std::getc(_M_file); }
+
+  template<>
+    inline stdio_sync_filebuf<char>::int_type
+    stdio_sync_filebuf<char>::syncungetc(int_type __c)
+    { return std::ungetc(__c, _M_file); }
+
+  template<>
+    inline stdio_sync_filebuf<char>::int_type
+    stdio_sync_filebuf<char>::syncputc(int_type __c)
+    { return std::putc(__c, _M_file); }
+
+  template<>
+    inline std::streamsize
+    stdio_sync_filebuf<char>::xsgetn(char* __s, std::streamsize __n)
+    { return std::fread(__s, 1, __n, _M_file); }
+
+  template<>
+    inline std::streamsize
+    stdio_sync_filebuf<char>::xsputn(const char* __s, std::streamsize __n)
+    { return std::fwrite(__s, 1, __n, _M_file); }
+
+#ifdef _GLIBCPP_USE_WCHAR_T
+  template<>
+    inline stdio_sync_filebuf<wchar_t>::int_type
+    stdio_sync_filebuf<wchar_t>::syncgetc()
+    { return std::getwc(_M_file); }
+
+  template<>
+    inline stdio_sync_filebuf<wchar_t>::int_type
+    stdio_sync_filebuf<wchar_t>::syncungetc(int_type __c)
+    { return std::ungetwc(__c, _M_file); }
+
+  template<>
+    inline stdio_sync_filebuf<wchar_t>::int_type
+    stdio_sync_filebuf<wchar_t>::syncputc(int_type __c)
+    { return std::putwc(__c, _M_file); }
+
+  template<>
+    inline std::streamsize
+    stdio_sync_filebuf<wchar_t>::xsgetn(wchar_t* __s, std::streamsize __n)
+    {  
+      std::streamsize __ret = 0;
+      const int_type __eof = traits_type::eof();
+      while (__n--)
+       {
+         int_type __c = this->syncgetc();
+         if (traits_type::eq_int_type(__c, __eof))
+           break;
+         *__s++ = __c;
+         ++__ret;
+       }
+      return __ret;
+    }
+      
+  template<>
+    inline std::streamsize
+    stdio_sync_filebuf<wchar_t>::xsputn(const wchar_t* __s, 
+                                       std::streamsize __n)
+    {
+      std::streamsize __ret = 0;
+      const int_type __eof = traits_type::eof();
+      while (__n--)
+       {
+         if (traits_type::eq_int_type(this->syncputc(*__s++), __eof))
+           break;
+         ++__ret;
+       }
+      return __ret;
+    }
+#endif
+
+#if _GLIBCPP_EXTERN_TEMPLATE
+  extern template class stdio_sync_filebuf<char>;
+#ifdef _GLIBCPP_USE_WCHAR_T
+  extern template class stdio_sync_filebuf<wchar_t>;
+#endif
+#endif
+} // namespace __gnu_cxx
+
+#endif 
index b8704f4e0d4c16b6dca8acbe94c4ccbd92ca3781..0de74e6252d213b776352c8fd3434d5b80ab3bcc 100644 (file)
@@ -306,11 +306,13 @@ namespace std
 
       // [documentation is inherited]
       virtual int_type
-      underflow();
+      underflow()
+      { return _M_underflow(false); }
 
       // [documentation is inherited]
       virtual int_type
-      uflow();
+      uflow()
+      { return _M_underflow(true); }
 
       // [documentation is inherited]
       virtual int_type
@@ -385,8 +387,6 @@ namespace std
       {
        int __ret = 0;
        const bool __testput = this->_M_out_beg < this->_M_out_lim;
-       // Sync with stdio.
-       const bool __sync = this->_M_buf_size <= 1;
 
        // Make sure that the internal buffer resyncs its idea of
        // the file position with the external file.
@@ -399,7 +399,7 @@ namespace std
            if (traits_type::eq_int_type(_M_overflow(), traits_type::eof()))
              __ret = -1;
            else if (__off)
-             _M_file.seekoff(__off, ios_base::cur, __sync);
+             _M_file.seekoff(__off, ios_base::cur);
          }
        else
          _M_file.sync();
@@ -487,44 +487,6 @@ namespace std
       }
     };
 
-  // Explicit specialization declarations, defined in src/fstream.cc.
-  template<> 
-    basic_filebuf<char>::int_type 
-    basic_filebuf<char>::_M_underflow(bool __bump);
-
-  template<>
-    basic_filebuf<char>::int_type
-    basic_filebuf<char>::underflow(); 
-
-  template<>
-    basic_filebuf<char>::int_type
-    basic_filebuf<char>::uflow(); 
-
- #ifdef _GLIBCPP_USE_WCHAR_T
-  template<> 
-    basic_filebuf<wchar_t>::int_type 
-    basic_filebuf<wchar_t>::_M_underflow(bool __bump);
-
-  template<>
-    basic_filebuf<wchar_t>::int_type
-    basic_filebuf<wchar_t>::underflow(); 
-
-  template<>
-    basic_filebuf<wchar_t>::int_type
-    basic_filebuf<wchar_t>::uflow(); 
- #endif
-
-  // Generic definitions do nothing.
-  template <typename _CharT, typename _Traits>
-    typename basic_filebuf<_CharT, _Traits>::int_type
-    basic_filebuf<_CharT, _Traits>::underflow() 
-    { return int_type(); }
-
-  template <typename _CharT, typename _Traits>
-    typename basic_filebuf<_CharT, _Traits>::int_type
-    basic_filebuf<_CharT, _Traits>::uflow() 
-    { return int_type(); }
-
   // [27.8.1.5] Template class basic_ifstream
   /**
    *  @brief  Controlling input for files.
index 3800860ca1efa505c3447782301fd462433a3bb4..a788cb9369bd68004f3f8837143d9172fd64a98d 100644 (file)
@@ -123,7 +123,6 @@ sources = \
        ctype.cc \
        demangle.cc \
        ext-inst.cc \
-       fstream.cc \
        fstream-inst.cc \
        functexcept.cc \
        globals.cc \
index 4212497a4c69a633a562a2a2ce418931836386dc..8e01572be71a7be700b31af0af5fe6ac17426310 100644 (file)
@@ -1,4 +1,4 @@
-# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
+# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
 
 # Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
@@ -205,7 +205,6 @@ sources = \
        ctype.cc \
        demangle.cc \
        ext-inst.cc \
-       fstream.cc \
        fstream-inst.cc \
        functexcept.cc \
        globals.cc \
@@ -306,9 +305,9 @@ CPPFLAGS = @CPPFLAGS@
 LDFLAGS = @LDFLAGS@
 LIBS = @LIBS@
 libstdc___la_OBJECTS =  codecvt.lo complex_io.lo concept-inst.lo \
-ctype.lo demangle.lo ext-inst.lo fstream.lo fstream-inst.lo \
-functexcept.lo globals.lo io-inst.lo ios.lo istream-inst.lo limits.lo \
-locale.lo locale-inst.lo localename.lo misc-inst.lo ostream-inst.lo \
+ctype.lo demangle.lo ext-inst.lo fstream-inst.lo functexcept.lo \
+globals.lo io-inst.lo ios.lo istream-inst.lo limits.lo locale.lo \
+locale-inst.lo localename.lo misc-inst.lo ostream-inst.lo \
 sstream-inst.lo stdexcept.lo stl-inst.lo streambuf-inst.lo \
 string-inst.lo strstream.lo valarray-inst.lo wstring-inst.lo \
 codecvt_members.lo collate_members.lo ctype_members.lo \
diff --git a/libstdc++-v3/src/fstream.cc b/libstdc++-v3/src/fstream.cc
deleted file mode 100644 (file)
index 41ca770..0000000
+++ /dev/null
@@ -1,218 +0,0 @@
-// File based streams -*- C++ -*-
-
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
-// Free Software Foundation, Inc.
-//
-// This file is part of the GNU ISO C++ Library.  This library is free
-// 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 2, 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 COPYING.  If not, write to the Free
-// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-// USA.
-
-// As a special exception, you may use this file as part of a free software
-// library without restriction.  Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License.  This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
-
-//
-// ISO C++ 14882: 27.8  File-based streams
-//
-
-#include <fstream>
-
-namespace std 
-{
-  template<> 
-    basic_filebuf<char>::int_type 
-    basic_filebuf<char>::_M_underflow(bool __bump)
-    {
-      int_type __ret = traits_type::eof();
-      const bool __testin = _M_mode & ios_base::in;
-      const bool __testout = _M_mode & ios_base::out;
-      const bool __testsync = _M_buf_size <= 1;
-
-      if (__testin)
-       {
-         // Check for pback madness, and if so swich back to the
-         // normal buffers and jet outta here before expensive
-         // fileops happen...
-         if (_M_pback_init)
-           _M_destroy_pback();
-
-         if (_M_in_cur < _M_in_end)
-           {
-             __ret = traits_type::to_int_type(*_M_in_cur);
-             if (__bump)
-               _M_move_in_cur(1);
-             return __ret;
-           }
-
-         // Sync internal and external buffers.
-         // NB: __testget -> __testput as _M_buf_unified here.
-         const bool __testget = _M_in_beg < _M_in_cur;
-         if (__testget)
-           {
-             if (__testout)
-               _M_overflow();
-             else if (_M_in_cur != _M_filepos)
-               _M_file.seekoff(_M_in_cur - _M_filepos,
-                               ios_base::cur, __testsync, ios_base::in);
-           }
-
-         if (_M_buf_size)
-           {
-             streamsize __elen = 0;
-             streamsize __ilen = 0;
-
-             __elen = _M_file.xsgetn(reinterpret_cast<char*>(_M_in_beg), 
-                                     _M_buf_size, __testsync);
-             __ilen = __elen;
-
-             if (0 < __ilen)
-               {
-                 _M_set_determinate(__ilen);
-                 __ret = traits_type::to_int_type(*_M_in_cur);
-                 if (__bump)
-                   _M_move_in_cur(1);
-                 else if (__testsync)
-                   {
-                     // If we are synced with stdio, we have to unget the
-                     // character we just read so that the file pointer
-                     // doesn't move.
-                     _M_file.sys_ungetc(traits_type::to_int_type(*_M_in_cur));
-                     _M_set_indeterminate();
-                   }
-               }          
-           }
-       }
-      _M_last_overflowed = false;      
-      return __ret;
-    }
-
-  template<>
-    basic_filebuf<char>::int_type
-    basic_filebuf<char>::underflow() 
-    { return _M_underflow(false); }
-
-  template<>
-    basic_filebuf<char>::int_type
-    basic_filebuf<char>::uflow() 
-    { return _M_underflow(true); }
-
-#ifdef _GLIBCPP_USE_WCHAR_T
-  template<> 
-    basic_filebuf<wchar_t>::int_type 
-    basic_filebuf<wchar_t>::_M_underflow(bool __bump)
-    {
-      int_type __ret = traits_type::eof();
-      const bool __testin = _M_mode & ios_base::in;
-      const bool __testout = _M_mode & ios_base::out;
-      const bool __testsync = _M_buf_size <= 1;
-
-      if (__testin)
-       {
-         // Check for pback madness, and if so swich back to the
-         // normal buffers and jet outta here before expensive
-         // fileops happen...
-         if (_M_pback_init)
-           _M_destroy_pback();
-
-         if (_M_in_cur < _M_in_end)
-           {
-             __ret = traits_type::to_int_type(*_M_in_cur);
-             if (__bump)
-               _M_move_in_cur(1);
-             return __ret;
-           }
-
-         // Sync internal and external buffers.
-         // NB: __testget -> __testput as _M_buf_unified here.
-         const bool __testget = _M_in_beg < _M_in_cur;
-         if (__testget)
-           {
-             if (__testout)
-               _M_overflow();
-             else if (_M_in_cur != _M_filepos)
-               _M_file.seekoff(_M_in_cur - _M_filepos,
-                               ios_base::cur, __testsync, ios_base::in);
-           }
-
-         if (_M_buf_size)
-           {
-             streamsize __elen = 0;
-             streamsize __ilen = 0;
-             const locale __loc = this->getloc();
-             const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
-             if (__cvt.always_noconv())
-               {
-                 __elen = _M_file.xsgetn(reinterpret_cast<char*>(_M_in_beg), 
-                                         _M_buf_size, __testsync);
-                 __ilen = __elen;
-               }
-             else
-               {
-                 char* __buf = static_cast<char*>(__builtin_alloca(_M_buf_size));
-                 __elen = _M_file.xsgetn(__buf, _M_buf_size, __testsync);
-                 
-                 const char* __eend;
-                 char_type* __iend;
-                 codecvt_base::result __r;
-                 __r = __cvt.in(_M_state_cur, __buf, __buf + __elen, __eend, 
-                                _M_in_beg, _M_in_beg + _M_buf_size, __iend);
-                 if (__r == codecvt_base::ok)
-                   __ilen = __iend - _M_in_beg;
-                 else 
-                   {
-                     // Unwind.
-                     __ilen = 0;
-                     _M_file.seekoff(-__elen, ios_base::cur, __testsync, 
-                                     ios_base::in);
-                   }
-               }
-
-             if (0 < __ilen)
-               {
-                 _M_set_determinate(__ilen);
-                 __ret = traits_type::to_int_type(*_M_in_cur);
-                 if (__bump)
-                   _M_move_in_cur(1);
-                 else if (__testsync)
-                   {
-                     // If we are synced with stdio, we have to unget the
-                     // character we just read so that the file pointer
-                     // doesn't move.
-                     _M_file.sys_ungetc(traits_type::to_int_type(*_M_in_cur));
-                     _M_set_indeterminate();
-                   }
-               }          
-           }
-       }
-      _M_last_overflowed = false;      
-      return __ret;
-    }
-
-  template<>
-    basic_filebuf<wchar_t>::int_type
-    basic_filebuf<wchar_t>::underflow() 
-    { return _M_underflow(false); }
-
-  template<>
-    basic_filebuf<wchar_t>::int_type
-    basic_filebuf<wchar_t>::uflow() 
-    { return _M_underflow(true); }
-#endif
-} // namespace std
index 31c1371ad58360cc89849eee1109612bf19cda45..a0220f1cd8e17b099844a30f0133f22dbfe4d4f5 100644 (file)
@@ -32,6 +32,7 @@
 #include <ostream>
 #include <locale>
 #include <ext/stdio_filebuf.h>
+#include <ext/stdio_sync_filebuf.h>
 
 // On AIX, and perhaps other systems, library initialization order is
 // not guaranteed.  For example, the static initializers for the main
@@ -78,9 +79,14 @@ namespace __gnu_cxx
 {
   using namespace std;
 
-  // Because <iostream> declares the standard streams to be [io]stream
-  // types instead of say [io]fstream types, it is also necessary to
-  // allocate the actual file buffers in this file.
+  // We use different stream buffer types depending on whether
+  // ios_base::sync_with_stdio(false) has been called.
+  typedef char fake_stdiobuf[sizeof(stdio_sync_filebuf<char>)]
+  __attribute__ ((aligned(__alignof__(stdio_sync_filebuf<char>))));
+  fake_stdiobuf buf_cout_sync;
+  fake_stdiobuf buf_cin_sync;
+  fake_stdiobuf buf_cerr_sync;
+
   typedef char fake_filebuf[sizeof(stdio_filebuf<char>)]
   __attribute__ ((aligned(__alignof__(stdio_filebuf<char>))));
   fake_filebuf buf_cout;
@@ -88,6 +94,12 @@ namespace __gnu_cxx
   fake_filebuf buf_cerr;
 
 #ifdef _GLIBCPP_USE_WCHAR_T
+  typedef char fake_wstdiobuf[sizeof(stdio_sync_filebuf<wchar_t>)]
+  __attribute__ ((aligned(__alignof__(stdio_sync_filebuf<wchar_t>))));
+  fake_wstdiobuf buf_wcout_sync;
+  fake_wstdiobuf buf_wcin_sync;
+  fake_wstdiobuf buf_wcerr_sync;
+
   typedef char fake_wfilebuf[sizeof(stdio_filebuf<wchar_t>)]
   __attribute__ ((aligned(__alignof__(stdio_filebuf<wchar_t>))));
   fake_wfilebuf buf_wcout;
index b3acc493264cf1a57a852c153d13055ea04fd1ee..ee4fd24cc54a259bafb65637b500ed39ad9d9c9e 100644 (file)
 #include <fstream>
 #include <bits/atomicity.h>
 #include <ext/stdio_filebuf.h>
+#include <ext/stdio_sync_filebuf.h>
 
 namespace __gnu_cxx
 {
   // Extern declarations for global objects in src/globals.cc.
+  extern stdio_sync_filebuf<char> buf_cout_sync;
+  extern stdio_sync_filebuf<char> buf_cin_sync;
+  extern stdio_sync_filebuf<char> buf_cerr_sync;
+
   extern stdio_filebuf<char> buf_cout;
   extern stdio_filebuf<char> buf_cin;
   extern stdio_filebuf<char> buf_cerr;
 
 #ifdef _GLIBCPP_USE_WCHAR_T
+  extern stdio_sync_filebuf<wchar_t> buf_wcout_sync;
+  extern stdio_sync_filebuf<wchar_t> buf_wcin_sync;
+  extern stdio_sync_filebuf<wchar_t> buf_wcerr_sync;
+
   extern stdio_filebuf<wchar_t> buf_wcout;
   extern stdio_filebuf<wchar_t> buf_wcin;
   extern stdio_filebuf<wchar_t> buf_wcerr;
@@ -153,50 +162,6 @@ namespace std
   ios_base::failure::what() const throw()
   { return _M_name; }
 
-  void
-  ios_base::Init::_S_create_buffers(bool __sync)
-  {
-    size_t __out_size = __sync ? 0 : static_cast<size_t>(BUFSIZ);
-    size_t __in_size = __sync ? 1 : static_cast<size_t>(BUFSIZ);
-
-    // Create stream buffers for the standard streams and use those
-    // buffers without destroying and recreating the streams.
-    new (&buf_cout) stdio_filebuf<char>(stdout, ios_base::out, __out_size);
-    new (&buf_cin) stdio_filebuf<char>(stdin, ios_base::in, __in_size);
-    new (&buf_cerr) stdio_filebuf<char>(stderr, ios_base::out, __out_size);
-    cout.rdbuf(&buf_cout);
-    cin.rdbuf(&buf_cin);
-    cerr.rdbuf(&buf_cerr);
-    clog.rdbuf(&buf_cerr);
-    
-#ifdef _GLIBCPP_USE_WCHAR_T
-    new (&buf_wcout) stdio_filebuf<wchar_t>(stdout, ios_base::out, __out_size);
-    new (&buf_wcin) stdio_filebuf<wchar_t>(stdin, ios_base::in, __in_size);
-    new (&buf_wcerr) stdio_filebuf<wchar_t>(stderr, ios_base::out, __out_size);
-    wcout.rdbuf(&buf_wcout);
-    wcin.rdbuf(&buf_wcin);
-    wcerr.rdbuf(&buf_wcerr);
-    wclog.rdbuf(&buf_wcerr);
-#endif
-  }
-
-  void
-  ios_base::Init::_S_destroy_buffers()
-  {
-    // Explicitly call dtors to free any memory that is dynamically
-    // allocated by filebuf ctor or member functions, but don't
-    // deallocate all memory by calling operator delete.
-    buf_cout.~stdio_filebuf();
-    buf_cin.~stdio_filebuf();
-    buf_cerr.~stdio_filebuf();
-
-#ifdef _GLIBCPP_USE_WCHAR_T
-    buf_wcout.~stdio_filebuf();
-    buf_wcin.~stdio_filebuf();
-    buf_wcerr.~stdio_filebuf();
-#endif
-  }
-
   ios_base::Init::Init()
   {
     if (_S_ios_base_init == 0)
@@ -204,25 +169,32 @@ namespace std
        // Standard streams default to synced with "C" operations.
        ios_base::Init::_S_synced_with_stdio = true;
 
-       // The standard streams are constructed once only and never destroyed.
-       // The stream buffers are set in _S_create_buffers below.
-       new (&cout) ostream(NULL);
-       new (&cin) istream(NULL);
-       new (&cerr) ostream(NULL);
-       new (&clog) ostream(NULL);
+       new (&buf_cout_sync) stdio_sync_filebuf<char>(stdout);
+       new (&buf_cin_sync) stdio_sync_filebuf<char>(stdin);
+       new (&buf_cerr_sync) stdio_sync_filebuf<char>(stderr);
+
+       // The standard streams are constructed once only and never
+       // destroyed.
+       new (&cout) ostream(&buf_cout_sync);
+       new (&cin) istream(&buf_cin_sync);
+       new (&cerr) ostream(&buf_cerr_sync);
+       new (&clog) ostream(&buf_cerr_sync);
        cin.tie(&cout);
        cerr.flags(ios_base::unitbuf);
        
 #ifdef _GLIBCPP_USE_WCHAR_T
-       new (&wcout) wostream(NULL);
-       new (&wcin) wistream(NULL);
-       new (&wcerr) wostream(NULL);
-       new (&wclog) wostream(NULL);
+       new (&buf_wcout_sync) stdio_sync_filebuf<wchar_t>(stdout);
+       new (&buf_wcin_sync) stdio_sync_filebuf<wchar_t>(stdin);
+       new (&buf_wcerr_sync) stdio_sync_filebuf<wchar_t>(stderr);
+
+       new (&wcout) wostream(&buf_wcout_sync);
+       new (&wcin) wistream(&buf_wcin_sync);
+       new (&wcerr) wostream(&buf_wcerr_sync);
+       new (&wclog) wostream(&buf_wcerr_sync);
        wcin.tie(&wcout);
        wcerr.flags(ios_base::unitbuf);
 #endif
 
-       _S_create_buffers(ios_base::Init::_S_synced_with_stdio);
        _S_ios_base_init = 1;
       }
     ++_S_ios_base_init;
@@ -389,8 +361,40 @@ namespace std
     if (!__sync && __ret)
       {
        ios_base::Init::_S_synced_with_stdio = __sync;
-       ios_base::Init::_S_destroy_buffers();
-       ios_base::Init::_S_create_buffers(__sync);
+
+       // Explicitly call dtors to free any memory that is
+       // dynamically allocated by filebuf ctor or member functions,
+       // but don't deallocate all memory by calling operator delete.
+       buf_cout_sync.~stdio_sync_filebuf<char>();
+       buf_cin_sync.~stdio_sync_filebuf<char>();
+       buf_cerr_sync.~stdio_sync_filebuf<char>();
+
+#ifdef _GLIBCPP_USE_WCHAR_T
+       buf_wcout_sync.~stdio_sync_filebuf<wchar_t>();
+       buf_wcin_sync.~stdio_sync_filebuf<wchar_t>();
+       buf_wcerr_sync.~stdio_sync_filebuf<wchar_t>();
+#endif
+
+       // Create stream buffers for the standard streams and use
+       // those buffers without destroying and recreating the
+       // streams.
+       new (&buf_cout) stdio_filebuf<char>(stdout, ios_base::out);
+       new (&buf_cin) stdio_filebuf<char>(stdin, ios_base::in);
+       new (&buf_cerr) stdio_filebuf<char>(stderr, ios_base::out);
+       cout.rdbuf(&buf_cout);
+       cin.rdbuf(&buf_cin);
+       cerr.rdbuf(&buf_cerr);
+       clog.rdbuf(&buf_cerr);
+    
+#ifdef _GLIBCPP_USE_WCHAR_T
+       new (&buf_wcout) stdio_filebuf<wchar_t>(stdout, ios_base::out);
+       new (&buf_wcin) stdio_filebuf<wchar_t>(stdin, ios_base::in);
+       new (&buf_wcerr) stdio_filebuf<wchar_t>(stderr, ios_base::out);
+       wcout.rdbuf(&buf_wcout);
+       wcin.rdbuf(&buf_wcin);
+       wcerr.rdbuf(&buf_wcerr);
+       wclog.rdbuf(&buf_wcerr);
+#endif
       }
     return __ret; 
   }
index df2949d04cac453856b188a116288109bc3eade1..ab5979759001d85f66e6f69018ba77eb6aec971f 100644 (file)
@@ -38,6 +38,7 @@
 #include <algorithm>
 #include <vector>
 #include <bits/atomicity.h>
+#include <ext/stdio_sync_filebuf.h>
 
 namespace std
 {
@@ -73,9 +74,10 @@ namespace std
 #endif
 } // namespace std
 
-#ifdef _GLIBCPP_NEED_GENERIC_MUTEX
+
 namespace __gnu_cxx
 {
+#ifdef _GLIBCPP_NEED_GENERIC_MUTEX
 #ifdef __GTHREAD_MUTEX_INIT
   __gthread_mutex_t _Atomic_add_mutex = __GTHREAD_MUTEX_INIT;
 #else
@@ -87,6 +89,12 @@ namespace __gnu_cxx
     __GTHREAD_MUTEX_INIT_FUNCTION (&_Atomic_add_mutex);
   }
 #endif
-} // namespace __gnu_cxx
 #endif // _GLIBCPP_NEED_GLOBAL_MUTEX
 
+  template class stdio_sync_filebuf<char>;
+#ifdef _GLIBCPP_USE_WCHAR_T
+  template class stdio_sync_filebuf<wchar_t>;
+#endif
+} // namespace __gnu_cxx
+
+
index 634d41bec399a9f8e7550dc3e138feed70bea9b7..05fbd23a573874c47203333b8b005cee5abd6999 100644 (file)
@@ -76,28 +76,31 @@ void test05()
   fb_01.open(name_01, ios_base::in);
   fb_02.open(name_02, ios_base::out | ios_base::trunc);
   fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); 
-  strmof_1 = fb_01.in_avail();
-  strmof_2 = fb_02.in_avail();
-  strmof_1 = fb_03.in_avail(); 
 
+  strmof_1 = fb_01.in_avail();
   int_type c1 = fb_01.sbumpc();
-  int_type c2 = fb_02.sbumpc();
   int_type c3 = fb_01.sbumpc();
-  int_type c4 = fb_02.sbumpc();
-  int_type c5 = fb_03.sbumpc();
-
   int_type c6 = fb_01.sgetc();
-  int_type c7 = fb_02.sgetc();
   int_type c8 = fb_01.sgetc();
+
+  strmof_2 = fb_02.in_avail();
+  int_type c2 = fb_02.sbumpc();
+  int_type c4 = fb_02.sbumpc();
+  int_type c7 = fb_02.sgetc();
   int_type c9 = fb_02.sgetc();
+
+  strmof_1 = fb_03.in_avail(); 
+  int_type c5 = fb_03.sbumpc();
   c5 = fb_03.sgetc();
 
   // int_type snextc()
   // calls sbumpc and if sbumpc != eof, return sgetc
   c6 = fb_01.snextc();
-  c7 = fb_02.snextc();
   c6 = fb_01.snextc();
+
   c7 = fb_02.snextc();
+  c7 = fb_02.snextc();
+
   c5 = fb_03.snextc();
 
   // streamsize sgetn(char_type *s, streamsize n)
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/10096.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/10096.cc
new file mode 100644 (file)
index 0000000..8dd2434
--- /dev/null
@@ -0,0 +1,70 @@
+// 2003-05-03  Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <string>
+#include <testsuite_hooks.h>
+
+class MyTraits : public std::char_traits<char>
+{
+};
+
+// libstdc++/10096
+void test01()
+{
+  using namespace std;
+
+  const char* name = "filebuf_virtuals-1.txt";
+
+  string str;
+  filebuf fb1;
+  fb1.open(name, ios_base::in);
+  
+  filebuf::int_type c1;
+  while ((c1 = fb1.sbumpc()) != filebuf::traits_type::eof())
+    str.push_back(filebuf::traits_type::to_char_type(c1));
+  fb1.close();
+
+  basic_filebuf<char, MyTraits> fb;
+  VERIFY( fb.sgetc() == MyTraits::eof() );
+
+  fb.open(name, ios_base::in);
+  VERIFY( fb.is_open() );
+
+  for (string::iterator i = str.begin(); i != str.end(); ++i)
+    {
+      MyTraits::int_type c2 = fb.sbumpc();
+      VERIFY( c2 != MyTraits::eof() );
+      VERIFY( c2 == MyTraits::to_int_type(*i) );
+    }
+
+  VERIFY( fb.sgetc() == MyTraits::eof() );
+  fb.close();
+  VERIFY( !fb.is_open() );
+  VERIFY( fb.sgetc() == MyTraits::eof() );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/1.cc
new file mode 100644 (file)
index 0000000..40e5137
--- /dev/null
@@ -0,0 +1,84 @@
+// 2003-05-03  Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <string>
+#include <testsuite_hooks.h>
+
+// Check that basic_filebuf::underflow() handles
+// codecvt::always_noconv() == false and codecvt::in() == noconv.
+class NoconvCvt : public std::codecvt<char, char, std::mbstate_t>
+{
+protected:
+  virtual bool
+  do_always_noconv() const throw()
+  { return false; }
+
+  virtual result
+  do_in(state_type&, const char* from, const char*, const char*& from_next,
+       char* to, char*, char*& to_next)
+  {
+    from_next = from;
+    to_next = to;
+    return noconv;
+  }
+};
+
+void test01()
+{
+  using namespace std;
+  bool test = true;
+  const char* name = "filebuf_virtuals-1.txt";
+
+  string str;
+  filebuf fb;
+  filebuf::int_type c1;
+
+  if (fb.open(name, ios_base::in))
+    {  
+      while ((c1 = fb.sbumpc()) != EOF)
+       str.push_back(filebuf::traits_type::to_char_type(c1));
+      fb.close();
+    }
+
+  locale loc(locale::classic(), new NoconvCvt);
+  fb.pubimbue(loc);
+
+  if (fb.open(name, ios_base::in))
+    {
+      for (string::iterator i = str.begin(); i != str.end(); ++i)
+       {
+         c1 = fb.sbumpc();
+         VERIFY( c1 != filebuf::traits_type::eof() );
+         VERIFY( c1 == filebuf::traits_type::to_int_type(*i) );
+       }
+      VERIFY( fb.sgetc() == filebuf::traits_type::eof() );
+      fb.close();
+    }
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/9027.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/9027.cc
new file mode 100644 (file)
index 0000000..0e4c077
--- /dev/null
@@ -0,0 +1,86 @@
+// 2003-05-03  Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <locale>
+#include <fstream>
+#include <cctype>
+#include <testsuite_hooks.h>
+
+class Cvt_to_upper : public std::codecvt<char, char, std::mbstate_t>
+{
+  typedef std::codecvt<char, char, std::mbstate_t> Base;
+
+public:
+  explicit Cvt_to_upper(std::size_t refs = 0)
+  : Base(refs)
+  { }
+
+protected:
+  virtual result
+  do_in(state_type&,
+       const extern_type* from, const extern_type* from_end,
+       const extern_type*& from_next,
+       intern_type* to, intern_type* to_end,
+       intern_type*& to_next) const
+  {
+    while (from < from_end && to < to_end)
+      *to++ = std::toupper(*from++);
+    
+    to_next = to;
+    from_next = from;
+    return from == from_end ? ok : partial;
+  }
+
+  virtual bool
+  do_always_noconv() const throw()
+  {
+    return false;
+  }
+};
+
+// libstdc++/9027
+void test01()
+{
+  using namespace std;
+
+  bool test = true;
+  const char* name = "filebuf_virtuals-1.txt";
+  locale loc (locale::classic(), new Cvt_to_upper);    
+
+  filebuf fbin;
+  fbin.pubimbue(loc);
+  fbin.open(name, ios_base::in);
+
+  int c;
+  while ((c = fbin.sbumpc()) != EOF)
+    {
+      VERIFY( !islower(c) );
+    }
+  
+  fbin.close();
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc
new file mode 100644 (file)
index 0000000..a764bb2
--- /dev/null
@@ -0,0 +1,60 @@
+// 2003-05-03  Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <testsuite_hooks.h>
+#include <fstream>
+#include <cstdio>
+
+// libstdc++/9520
+void test01()
+{
+  using namespace std;
+
+  bool test = true;
+  const char* name = "tmp_9520";
+
+  FILE* file = fopen(name, "w");
+  for (int i = 1; i < 256; ++i)
+    putc(static_cast<unsigned char>(i), file);
+  fclose(file);
+
+  locale loc (__gnu_cxx_test::try_named_locale("de_DE.ISO-8859-15@euro"));
+  wchar_t buf[1];
+  wfilebuf fb;
+  fb.pubimbue(loc);
+  fb.pubsetbuf(buf, 1);
+  fb.open(name, ios_base::in);
+
+  for (int j = 1; j < 256; ++j)
+    {
+      wfilebuf::int_type c1 = fb.sgetc();
+      VERIFY( c1 != wfilebuf::traits_type::eof() );
+      wfilebuf::int_type c2 = fb.sbumpc();
+      VERIFY( c1 == c2 );
+    }
+
+  fb.close();
+}
+
+int main()
+{
+  test01();  
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/char/10.cc b/libstdc++-v3/testsuite/27_io/objects/char/10.cc
new file mode 100644 (file)
index 0000000..4990a58
--- /dev/null
@@ -0,0 +1,73 @@
+// 2003-05-01  Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+#include <iostream>
+#include <cstdio>
+#include <testsuite_hooks.h>
+
+void test10()
+{
+  using namespace std;
+
+  bool test = true;
+  const char* name = "filebuf_virtuals-1.txt";
+
+  FILE* ret = freopen(name, "r", stdin);
+  VERIFY( ret != NULL );
+
+  streampos p1 = cin.tellg();
+  VERIFY( p1 != streampos(-1) );
+  VERIFY( streamoff(p1) == 0 );
+
+  cin.seekg(0, ios::end);
+  VERIFY( cin.good() );
+
+  streampos p2 = cin.tellg();
+  VERIFY( p2 != streampos(-1) );
+  VERIFY( p2 != p1 );
+  VERIFY( streamoff(p2) == ftell(stdin) );
+
+  cin.seekg(p1);
+  VERIFY( cin.good() );
+
+  streamoff n = p2 - p1;
+  VERIFY( n > 0 );
+       
+  for (streamoff i = 0; i < n; ++i)
+    {
+      streampos p3 = cin.tellg();
+      VERIFY( streamoff(p3) == i );
+      VERIFY( ftell(stdin) == i );
+      cin.get();
+      VERIFY( cin.good() );
+    }
+
+  streampos p4 = cin.tellg();
+  VERIFY( streamoff(p4) == n );
+  VERIFY( ftell(stdin) == n );
+  cin.get();
+  VERIFY( cin.eof() );
+}
+
+int main()
+{
+  test10();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/char/9.cc b/libstdc++-v3/testsuite/27_io/objects/char/9.cc
new file mode 100644 (file)
index 0000000..faa05e6
--- /dev/null
@@ -0,0 +1,47 @@
+// 2003-05-01  Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+#include <iostream>
+#include <cstdio>
+#include <testsuite_hooks.h>
+
+void test09()
+{
+  using namespace std;
+
+  bool test = true;
+  const char* name = "tmp_09";
+
+  FILE* fout = fopen(name, "w");
+  fputs("abc\n", fout);
+  fclose(fout);
+
+  freopen(name, "r", stdin);
+  // The number of unread characters should be 4 (a, b, c, \\n)
+  VERIFY( 4 == std::cin.rdbuf()->in_avail() );
+}
+
+int 
+main()
+{
+  test09();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/char/9661-1.cc b/libstdc++-v3/testsuite/27_io/objects/char/9661-1.cc
new file mode 100644 (file)
index 0000000..d404cd0
--- /dev/null
@@ -0,0 +1,85 @@
+// 2003-04-30  Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <testsuite_hooks.h>
+#include <cstdio>
+#include <iostream>
+#include <unistd.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+// Check that cin.rdbuf()->sputbackc() puts characters back to stdin.
+// If cin.rdbuf() is a filebuf, this succeeds when stdin is a regular
+// file, but fails otherwise, hence the named fifo.
+void test01()
+{
+  using namespace std;
+
+  bool test = true;
+
+  const char* name = "tmp_fifo5";
+
+  signal(SIGPIPE, SIG_IGN);
+
+  unlink(name);  
+  mkfifo(name, S_IRWXU);
+  
+  int child = fork();
+  VERIFY( child != -1 );
+
+  if (child == 0)
+    {
+      sleep(1);
+      FILE* file = fopen(name, "w");
+      fputs("Whatever\n", file);
+      fflush(file);
+      sleep(2);
+      fclose(file);
+      exit(0);
+    }
+  
+  freopen(name, "r", stdin);
+  sleep(2);
+
+  int c1 = fgetc(stdin);
+  VERIFY( c1 != EOF );
+  int c2 = cin.rdbuf()->sputbackc('a');
+  VERIFY( c2 != EOF );
+  VERIFY( c2 == 'a' );
+  
+  int c3 = fgetc(stdin);
+  VERIFY( c3 != EOF );
+  VERIFY( c3 == c2 );
+  int c4 = ungetc('b', stdin);
+  VERIFY( c4 != EOF );
+  VERIFY( c4 == 'b' );
+  
+  int c5 = cin.rdbuf()->sgetc();
+  VERIFY( c5 != EOF );
+  VERIFY( c5 == c4 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/char/9661-2_xin.cc b/libstdc++-v3/testsuite/27_io/objects/char/9661-2_xin.cc
new file mode 100644 (file)
index 0000000..6b61746
--- /dev/null
@@ -0,0 +1,47 @@
+// 2003-04-30  Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <testsuite_hooks.h>
+#include <cstdio>
+#include <iostream>
+
+void test02()
+{
+  using namespace std;
+
+  bool test = true;
+
+  int c1 = fgetc(stdin);
+  int c2 = cin.rdbuf()->sputbackc(c1);
+  VERIFY( c2 == c1 );
+  
+  int c3 = fgetc(stdin);
+  VERIFY( c3 == c1 );
+  ungetc(c3, stdin);
+  
+  int c4 = cin.rdbuf()->sgetc();
+  VERIFY( c4 == c3 );
+}
+
+int main()
+{
+  test02();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/char/9661-2_xin.in b/libstdc++-v3/testsuite/27_io/objects/char/9661-2_xin.in
new file mode 100644 (file)
index 0000000..ad90130
--- /dev/null
@@ -0,0 +1 @@
+For what you dream of
index bd946edd721b6e06394bee86eea99b7e2f14bee3..c766cd6fa5b990a6b55b3272a836fe7a7f97aa62 100644 (file)
@@ -1,4 +1,4 @@
-// 2000-08-02 bkoz
+// 2003-05-01 Petur Runolfsson  <peturr02@ru.is>
 
 // Copyright (C) 2000, 2003 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/10.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/10.cc
new file mode 100644 (file)
index 0000000..f0a7868
--- /dev/null
@@ -0,0 +1,121 @@
+// 2003-05-01  Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <iostream>
+#include <cstdio>
+#include <testsuite_hooks.h>
+
+// Test handling of UTF-8 in wcin and wcout
+void test10()
+{
+  using namespace std;
+  
+  bool test = true;
+  const char* name = "tmp_10";
+
+  locale loc(__gnu_cxx_test::try_named_locale("se_NO.UTF-8"));
+  locale::global(loc);
+  wcin.imbue(loc);
+  wcout.imbue(loc);
+
+  const char* e_lit =
+    "\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";
+  size_t e_size = strlen(e_lit);
+
+  const wchar_t i_lit[] = {
+    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
+  };
+  size_t i_size = wcslen(i_lit);
+
+  freopen(name, "w", stdout);
+  
+  wcout.write(i_lit, i_size);
+  wcout.flush();
+  VERIFY( wcout.good() );
+
+  FILE* file = fopen(name, "r");
+  char* buf = new char[e_size + 10];
+  size_t n = fread(buf, 1, e_size + 10, file);
+  VERIFY( n == e_size );
+  VERIFY( !memcmp(buf, e_lit, e_size) );
+  delete[] buf;
+  fclose(file);
+
+  freopen(name, "r", stdin);
+  
+  wchar_t* wbuf = new wchar_t[i_size + 10];
+  wcin.read(wbuf, i_size + 10);
+  n = wcin.gcount();
+  VERIFY( n == i_size );
+  VERIFY( !wmemcmp(wbuf, i_lit, i_size) );
+  VERIFY( wcin.eof() );
+  VERIFY( wcin.fail() );
+  VERIFY( !wcin.bad() );
+  delete[] wbuf;
+}
+
+int main()
+{
+  test10();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/2.cc
new file mode 100644 (file)
index 0000000..ed85932
--- /dev/null
@@ -0,0 +1,47 @@
+// 2003-05-01 Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2000, 2001, 2002, 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+#include <iostream>
+
+// Interactive test, to be exercised as follows:
+// assign stderr to stdout in shell command line,
+// pipe stdout to cat process and/or redirect stdout to file.
+// a.out >& output
+// "hello fine world\n" should be written to stdout, and output, in
+// proper order.  This is a version of the scott snyder test taken
+// from: http://gcc.gnu.org/ml/libstdc++/1999-q4/msg00108.html
+void test04()
+{
+  using namespace std;
+
+  wcout << L"hello ";
+  wcout.flush();
+  wcerr << L"fine ";
+  wcerr.flush();
+  wcout << L"world" << endl;
+  wcout.flush();
+}
+
+int 
+main()
+{
+  test04();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-1_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-1_xin.cc
new file mode 100644 (file)
index 0000000..58b1de6
--- /dev/null
@@ -0,0 +1,89 @@
+// 2003-05-01 Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2000, 2001, 2002, 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// Include all the headers except for iostream.
+#include <algorithm>
+#include <bitset>
+#include <complex>
+#include <deque>
+#include <exception>
+#include <fstream>
+#include <functional>
+#include <iomanip>
+#include <ios>
+#include <iosfwd>
+#include <istream>
+#include <iterator>
+#include <limits>
+#include <list>
+#include <locale>
+#include <map>
+#include <memory>
+#include <new>
+#include <numeric>
+#include <ostream>
+#include <queue>
+#include <set>
+#include <sstream>
+#include <stack>
+#include <stdexcept>
+#include <streambuf>
+#include <string>
+#include <typeinfo>
+#include <utility>
+#include <valarray>
+#include <vector>
+#include <cassert>
+#include <cctype>
+#include <cerrno>
+#include <cfloat>
+#include <ciso646>
+#include <climits>
+#include <clocale>
+#include <cmath>
+#include <csetjmp>
+#include <csignal>
+#include <cstdarg>
+#include <cstddef>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+#include <testsuite_hooks.h>
+
+// Include iostream last, just to make is as difficult as possible to
+// properly initialize the standard iostream objects.
+#include <iostream>
+
+// libstdc++/2523
+void test02()
+{
+  using namespace std;
+  int i;
+  wcin >> i;
+  wcout << "i == " << i << endl;
+}
+
+int 
+main()
+{
+  test02();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-1_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-1_xin.in
new file mode 100644 (file)
index 0000000..ec30809
--- /dev/null
@@ -0,0 +1 @@
+5588885 
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-2_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-2_xin.cc
new file mode 100644 (file)
index 0000000..cea4001
--- /dev/null
@@ -0,0 +1,39 @@
+// 2003-05-01 Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2000, 2001, 2002, 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <iostream>
+
+// libstdc++/2523
+void test03()
+{
+  using namespace std;
+  ios_base::sync_with_stdio(false);
+
+  int i;
+  wcin >> i;
+  wcout << "i == " << i << endl;
+}
+
+int 
+main()
+{
+  test03();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-2_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-2_xin.in
new file mode 100644 (file)
index 0000000..aaee5e5
--- /dev/null
@@ -0,0 +1 @@
+33332
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/3045.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/3045.cc
new file mode 100644 (file)
index 0000000..acc45b2
--- /dev/null
@@ -0,0 +1,86 @@
+// 2003-05-01 Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2001, 2002, 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <fstream>
+#include <iostream>
+#include <testsuite_hooks.h>
+
+class gnu_filebuf: public std::wfilebuf
+{
+  int i;
+public:
+  gnu_filebuf(int j = 1): i(j) { }
+  ~gnu_filebuf() { --i; }
+  int get_i() { return i;}
+};
+
+const int initial = 4;
+gnu_filebuf buf(initial);
+
+// libstdc++/3045, in a vague way.
+void test01()
+{
+  bool test = true;
+  int k1;
+
+  // 1 normal
+  k1 = buf.get_i();
+  VERIFY( k1 == initial );
+  {
+    std::wcout.rdbuf(&buf);
+  }
+  k1 = buf.get_i();
+  VERIFY( k1 == initial );
+
+  // 2 syncd off
+  k1 = buf.get_i();
+  VERIFY( k1 == initial );
+  {
+    std::wcout.rdbuf(&buf);
+    std::ios_base::sync_with_stdio(false); // make sure doesn't clobber buf
+  }
+  k1 = buf.get_i();
+  VERIFY( k1 == initial );
+
+  // 3 callling init
+  k1 = buf.get_i();
+  VERIFY( k1 == initial );
+  {
+    std::wcout.rdbuf(&buf);
+    std::ios_base::Init make_sure_initialized;
+  }
+  k1 = buf.get_i();
+  VERIFY( k1 == initial );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/3647.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/3647.cc
new file mode 100644 (file)
index 0000000..5a00cc8
--- /dev/null
@@ -0,0 +1,46 @@
+// 2003-05-01 Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2002, 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// 27.6.1.5 - Template class basic_iostream
+// NB: This file is for testing iostream with NO OTHER INCLUDES.
+
+#include <iostream>
+
+// libstdc++/3647
+void test07()
+{
+  // Should not block.
+  std::wcout << std::wcin.rdbuf()->in_avail() << std::endl;
+}
+
+int main() 
+{
+  test07();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/3_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/3_xin.cc
new file mode 100644 (file)
index 0000000..83d30f5
--- /dev/null
@@ -0,0 +1,42 @@
+// 2003-05-01 Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2000, 2001, 2002, 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <iostream>
+
+// Interactive test, to be exercised as follows:
+// run test under truss(1) or strace(1).  Look at
+// size and pattern of write system calls.
+// Should be 2 or 3 write(1,[...]) calls when run interactively
+// depending upon buffering mode enforced.
+void test05()
+{
+  std::wcout << L"hello" << L' ' << L"world" << std::endl;
+  std::wcout << L"Enter your name: ";
+  std::wstring s;
+  std::wcin >> s;
+  std::wcout << L"hello " << s << std::endl;
+}
+
+int 
+main()
+{
+  test05();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/3_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/3_xin.in
new file mode 100644 (file)
index 0000000..a26c126
--- /dev/null
@@ -0,0 +1 @@
+JOHN HUME and DAVID TRIMBLE
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/4_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/4_xin.cc
new file mode 100644 (file)
index 0000000..b8c650c
--- /dev/null
@@ -0,0 +1,39 @@
+// 2003-05-01 Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2000, 2001, 2002, 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <iostream>
+
+// http://gcc.gnu.org/ml/libstdc++/2002-08/msg00060.html
+// Should only have to hit enter once.
+void
+test10()
+{
+  using namespace std;
+  wcout << L"Press ENTER once\n";
+  wcin.ignore(1);
+  wcout << L"_M_gcount: " << wcin.gcount() << endl;
+}
+
+int 
+main()
+{
+  test10();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/4_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/4_xin.in
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/5.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/5.cc
new file mode 100644 (file)
index 0000000..267bc79
--- /dev/null
@@ -0,0 +1,85 @@
+// 2003-05-01 Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2003 Free Software Foundation
+//
+// 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.3 Standard iostream objects
+
+// Check that standard streams can be used from constructors and
+// destructors of static objects, provided that an instance of 
+// ios_base::Init has been constructed.
+
+void init_standard_streams();
+int use_standard_streams();
+
+struct Strange
+{
+  int i;
+
+  Strange()
+  {
+    init_standard_streams();
+    i = use_standard_streams();
+  }
+
+  ~Strange()
+  {
+    use_standard_streams();
+    init_standard_streams();
+  }
+};
+
+static Strange static_ob;
+
+#include <testsuite_hooks.h>
+#include <iostream>
+
+void init_standard_streams()
+{
+  std::ios_base::Init init;
+}
+
+int use_standard_streams()
+{
+  std::wcout << L"Hello, world!" << std::endl;
+  std::wcerr << L"World, hello!" << std::endl;
+
+  int ret = std::ios_base::xalloc();
+  std::wcin.iword(ret) = ret + 1;
+  std::wcout.iword(ret) = ret + 2;
+  std::wcerr.iword(ret) = ret + 3;
+  std::wclog.iword(ret) = ret + 4;
+  return ret;
+}
+
+void test05()
+{
+  bool test = true;
+  int i = static_ob.i;
+
+  VERIFY( std::wcin.iword(i) == i + 1 );
+  VERIFY( std::wcout.iword(i) == i + 2 );
+  VERIFY( std::wcerr.iword(i) == i + 3 );
+  VERIFY( std::wclog.iword(i) == i + 4 );
+}
+
+int main()
+{
+  test05();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/5268.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/5268.cc
new file mode 100644 (file)
index 0000000..14051d9
--- /dev/null
@@ -0,0 +1,46 @@
+// 2003-05-01 Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2001, 2002, 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <sstream>
+#include <iostream>
+
+// libstdc++/5268
+void test04()
+{
+  std::wstringbuf b1;
+  std::wcout.rdbuf( &b1 );
+  std::wcout << L"hello\n";
+  std::wcout.rdbuf(NULL);
+}
+
+int main()
+{
+  test04();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/5280_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/5280_xin.cc
new file mode 100644 (file)
index 0000000..7fcdf32
--- /dev/null
@@ -0,0 +1,48 @@
+// 2003-05-01 Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2000, 2001, 2002, 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <iostream>
+
+// libstdc++/5280
+// Interactive test: input "1234^D^D" for i should terminate for EOF.
+void test06()
+{
+  using namespace std;
+  int i;
+  wcin >> i;
+  if (!wcin.good()) 
+    {
+      wcerr << endl;
+      wcerr << L"i == " << i << endl;
+      wcerr << L"wcin.rdstate() == " << wcin.rdstate() << endl;
+      wcerr << L"wcin.bad() == " << wcin.bad() << endl;      
+      wcerr << L"wcin.fail() == " << wcin.fail() << endl;      
+      wcerr << L"wcin.eof() == " << wcin.eof() << endl;
+    }   
+  else
+    wcerr << L"i == " << i << endl;
+}
+
+int 
+main()
+{
+  test06();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/5280_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/5280_xin.in
new file mode 100644 (file)
index 0000000..81c545e
--- /dev/null
@@ -0,0 +1 @@
+1234
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/6.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6.cc
new file mode 100644 (file)
index 0000000..6b4e3e2
--- /dev/null
@@ -0,0 +1,50 @@
+// 2003-05-01  Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2003 Free Software Foundation
+//
+// 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.3 Standard iostream objects
+
+// ios_base::Init::~Init() calls wcout.flush(), which may call
+// wcout.setstate(badbit), which may throw an exception. Check that
+// the exception doesn't escape from the destructor.
+
+#include <iostream>
+#include <streambuf>
+
+class Badbuf : public std::wstreambuf
+{
+protected:
+  virtual int sync()
+  {
+    return -1;
+  }
+};
+
+void test06()
+{
+  std::ios_base::Init init;
+  std::wcout.rdbuf(new Badbuf);
+  std::wcout.exceptions(std::ios_base::badbit);
+}
+
+int main()
+{
+  test06();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/6548_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6548_xin.cc
new file mode 100644 (file)
index 0000000..0466b67
--- /dev/null
@@ -0,0 +1,39 @@
+// 2003-05-01 Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2000, 2001, 2002, 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <iostream>
+#include <testsuite_hooks.h>
+
+// libstdc++/6548
+void test07()
+{
+  bool test = true;
+  std::wcout << L"Enter 'test':";
+  std::wstring s;
+  std::getline(std::wcin, s, L'\n');
+  VERIFY( s == L"test" );
+}
+
+int 
+main()
+{
+  test07();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/6548_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6548_xin.in
new file mode 100644 (file)
index 0000000..9daeafb
--- /dev/null
@@ -0,0 +1 @@
+test
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-1_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-1_xin.cc
new file mode 100644 (file)
index 0000000..4db05d1
--- /dev/null
@@ -0,0 +1,38 @@
+// 2003-05-01 Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2000, 2001, 2002, 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <iostream>
+
+// libstdc++/6648
+// Interactive tests: each one (run alone) must terminate upon a single '\n'.
+void test08()
+{
+  bool test = true;
+  wchar_t buff[2048];
+  std::wcout << "Enter name: ";
+  std::wcin.getline(buff, 2048);
+}
+
+int 
+main()
+{
+  test08();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-1_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-1_xin.in
new file mode 100644 (file)
index 0000000..9dd5f1f
--- /dev/null
@@ -0,0 +1 @@
+Kofi A. Annan
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-2_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-2_xin.cc
new file mode 100644 (file)
index 0000000..778c58f
--- /dev/null
@@ -0,0 +1,35 @@
+// 2003-05-01  Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2000, 2001, 2002, 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <iostream>
+
+void test09()
+{
+  bool test = true;
+  std::wcout << L"Enter favorite beach: ";
+  std::wcin.ignore(2048, '\n');
+}
+
+int 
+main()
+{
+  test09();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-2_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-2_xin.in
new file mode 100644 (file)
index 0000000..0b2c7cf
--- /dev/null
@@ -0,0 +1 @@
+Oak St. Beach, Chicago
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/7.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/7.cc
new file mode 100644 (file)
index 0000000..fcdeaba
--- /dev/null
@@ -0,0 +1,75 @@
+// 2003-05-01 Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.3 Standard iostream objects
+
+#include <fstream>
+#include <iostream>
+#include <unistd.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <testsuite_hooks.h>
+
+// Check that wcout.flush() is called when last ios_base::Init is destroyed.
+void test07()
+{
+  using namespace std;
+  bool test = true;
+
+  const char* name = "tmp_fifo4";
+
+  signal(SIGPIPE, SIG_IGN);
+
+  unlink(name);  
+  mkfifo(name, S_IRWXU);
+  
+  int child = fork();
+  VERIFY( child != -1 );
+
+  if (child == 0)
+    {
+      wfilebuf fbout;
+      sleep(1);
+      fbout.open(name, ios_base::out);
+      wcout.rdbuf(&fbout);
+      fbout.sputc(L'a');
+      sleep(2);
+      // NB: fbout is *not* destroyed here!
+      exit(0);
+    }
+  
+  wfilebuf fbin;
+  fbin.open(name, ios_base::in);
+  sleep(2);
+  wfilebuf::int_type c = fbin.sbumpc();
+  VERIFY( c != wfilebuf::traits_type::eof() );
+  VERIFY( c == wfilebuf::traits_type::to_int_type(L'a') );
+
+  fbin.close();
+}
+
+int
+main()
+{
+  test07();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/7744_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/7744_xin.cc
new file mode 100644 (file)
index 0000000..e4ca3b9
--- /dev/null
@@ -0,0 +1,42 @@
+// 2003-05-01  Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2000, 2001, 2002, 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+#include <iostream>
+#include <testsuite_hooks.h>
+
+// libstdc++/7744
+void test11()
+{
+  bool test = true;
+  std::ios::sync_with_stdio(false);
+
+  std::wcout << "Type in the characters 'abc' and press <ENTER>: ";
+  std::wcin.peek();
+  // The number of unread characters should be 4 (a, b, c, \\n)
+  VERIFY( 4 == std::wcin.rdbuf()->in_avail() );
+}
+
+int 
+main()
+{
+  test11();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/7744_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/7744_xin.in
new file mode 100644 (file)
index 0000000..8baef1b
--- /dev/null
@@ -0,0 +1 @@
+abc
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/8.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/8.cc
new file mode 100644 (file)
index 0000000..346d0fc
--- /dev/null
@@ -0,0 +1,51 @@
+// 2003-05-01  Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2003 Free Software Foundation
+//
+// 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+  // 27.3 - Standard iostream objects p 2
+
+#include <iostream>
+#include <testsuite_hooks.h>
+
+void test02() 
+{
+  bool test = true;
+  
+  // 27.3 - Standard iostream objects p 2
+  // The objects are not destroyed during program execution.
+  void* p1 = &std::wcout;
+  void* p2 = &std::wcin;
+  void* p3 = &std::wcerr;
+  void* p4 = &std::wclog;
+  std::ios_base::sync_with_stdio(false); 
+  void* p1s = &std::wcout;
+  void* p2s = &std::wcin;
+  void* p3s = &std::wcerr;
+  void* p4s = &std::wclog;
+  VERIFY( p1 == p1s );
+  VERIFY( p2 == p2s );
+  VERIFY( p3 == p3s );
+  VERIFY( p4 == p4s );
+}
+
+int main(void)
+{
+  test02();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/9520.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9520.cc
new file mode 100644 (file)
index 0000000..835282f
--- /dev/null
@@ -0,0 +1,57 @@
+// 2003-04-30  Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <testsuite_hooks.h>
+#include <iostream>
+#include <cstdio>
+
+void test01()
+{
+  using namespace std;
+
+  bool test = true;
+  const char* name = "tmp_9520";
+
+  FILE* file = fopen(name, "w");
+  for (int i = 1; i < 256; ++i)
+    putc(static_cast<unsigned char>(i), file);
+  fclose(file);
+
+  locale loc (__gnu_cxx_test::try_named_locale("de_DE.ISO-8859-15@euro"));
+  locale::global(loc); // Set locale for stdin
+
+  freopen(name, "r", stdin);
+
+  wcin.imbue(loc);
+
+  for (int j = 1; j < 256; ++j)
+    {
+      wint_t c1 = wcin.rdbuf()->sgetc();
+      VERIFY( c1 != WEOF );
+      wint_t c2 = wcin.rdbuf()->sbumpc();
+      VERIFY( c1 == c2 );
+    }
+}
+
+int main()
+{
+  test01();  
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-1.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-1.cc
new file mode 100644 (file)
index 0000000..0d8d628
--- /dev/null
@@ -0,0 +1,85 @@
+// 2003-04-30  Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <testsuite_hooks.h>
+#include <cstdio>
+#include <iostream>
+#include <unistd.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+// Check that wcin.rdbuf()->sputbackc() puts characters back to stdin.
+// If wcin.rdbuf() is a filebuf, this succeeds when stdin is a regular
+// file, but fails otherwise, hence the named fifo.
+void test01()
+{
+  using namespace std;
+
+  bool test = true;
+
+  const char* name = "tmp_fifo5";
+
+  signal(SIGPIPE, SIG_IGN);
+
+  unlink(name);  
+  mkfifo(name, S_IRWXU);
+  
+  int child = fork();
+  VERIFY( child != -1 );
+
+  if (child == 0)
+    {
+      sleep(1);
+      FILE* file = fopen(name, "w");
+      fputs("Whatever\n", file);
+      fflush(file);
+      sleep(2);
+      fclose(file);
+      exit(0);
+    }
+  
+  freopen(name, "r", stdin);
+  sleep(2);
+
+  wint_t c1 = fgetwc(stdin);
+  VERIFY( c1 != WEOF );
+  wint_t c2 = wcin.rdbuf()->sputbackc(L'a');
+  VERIFY( c2 != WEOF );
+  VERIFY( c2 == L'a' );
+  
+  wint_t c3 = fgetwc(stdin);
+  VERIFY( c3 != WEOF );
+  VERIFY( c3 == c2 );
+  wint_t c4 = ungetwc(L'b', stdin);
+  VERIFY( c4 != WEOF );
+  VERIFY( c4 == L'b' );
+  
+  wint_t c5 = wcin.rdbuf()->sgetc();
+  VERIFY( c5 != WEOF );
+  VERIFY( c5 == c4 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-2_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-2_xin.cc
new file mode 100644 (file)
index 0000000..351a91b
--- /dev/null
@@ -0,0 +1,48 @@
+// 2003-04-30  Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <testsuite_hooks.h>
+#include <cstdio>
+#include <iostream>
+#include <cwchar>
+
+void test02()
+{
+  using namespace std;
+
+  bool test = true;
+
+  wint_t c1 = fgetwc(stdin);
+  wint_t c2 = wcin.rdbuf()->sputbackc(c1);
+  VERIFY( c2 == c1 );
+  
+  wint_t c3 = fgetwc(stdin);
+  VERIFY( c3 == c1 );
+  ungetwc(c3, stdin);
+  
+  wint_t c4 = wcin.rdbuf()->sgetc();
+  VERIFY( c4 == c3 );
+}
+
+int main()
+{
+  test02();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-2_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-2_xin.in
new file mode 100644 (file)
index 0000000..ad90130
--- /dev/null
@@ -0,0 +1 @@
+For what you dream of
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/9662.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9662.cc
new file mode 100644 (file)
index 0000000..27c7ff7
--- /dev/null
@@ -0,0 +1,42 @@
+// 2003-04-30  Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <testsuite_hooks.h>
+#include <iostream>
+#include <cstdio>
+#include <cwchar>
+
+// Check that operations on wcout can be mixed with wide operations
+// on stdout.
+void test01()
+{
+  bool test = true;
+
+  std::wcout << L"Hello, ";
+  VERIFY( std::fwide(stdout, 0) >= 0 );
+  int ret = std::fputws(L"world!\n", stdout);
+  VERIFY( ret >= 0 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/9_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9_xin.cc
new file mode 100644 (file)
index 0000000..6de8bd2
--- /dev/null
@@ -0,0 +1,65 @@
+// 2003-05-01  Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2003 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <iostream>
+#include <locale>
+#include <string>
+#include <cwchar>
+#include <cwctype>
+#include <iterator>
+#include <algorithm>
+#include <testsuite_hooks.h>
+
+// This tests the handling of multibyte characters by wcin and wcout.
+void test09()
+{
+  using namespace std;
+
+  locale loc("");
+  locale::global(loc);
+       
+  wcout.imbue(loc);
+  wcin.imbue(loc);
+
+  wcout << L"Current locale is: \'" << loc.name().c_str() << L"\'\n";
+  wcout << L"Please enter your name: ";
+
+  wstring str;
+  getline(wcin, str);
+
+  wcout << str << endl;
+  wcout << str.size() << endl;
+
+  transform(str.begin(), str.end(),
+           ostream_iterator<wchar_t, wchar_t>(wcout), towupper);
+  wcout << endl;
+  transform(str.begin(), str.end(),
+           ostream_iterator<wchar_t, wchar_t>(wcout), towlower);
+  wcout << endl << hex << showbase;
+  copy(str.begin(), str.end(),
+       ostream_iterator<wint_t, wchar_t>(wcout, L" "));
+  wcout << endl;
+}
+
+int main()
+{
+  test09();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/9_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9_xin.in
new file mode 100644 (file)
index 0000000..a26c126
--- /dev/null
@@ -0,0 +1 @@
+JOHN HUME and DAVID TRIMBLE
diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf_char.cc b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf_char.cc
new file mode 100644 (file)
index 0000000..cffcf37
--- /dev/null
@@ -0,0 +1,64 @@
+// 2003-05-01 Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 2003 Free Software Foundation
+//
+// 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <ext/stdio_sync_filebuf.h>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  using namespace std;
+
+  bool test = true;
+  const char* c_lit = "black pearl jasmine tea";
+  int size = strlen(c_lit);
+  const char* name = "stdiobuf-1.txt";
+
+  FILE* fout = fopen(name, "w");
+  fwrite(c_lit, 1, size, fout);
+  fclose(fout);
+
+  FILE* fin = fopen(name, "r");
+  __gnu_cxx::stdio_sync_filebuf<char> sbuf(fin);
+
+  VERIFY( sbuf.sgetc() == c_lit[0] );
+  VERIFY( getc(fin) == c_lit[0] );
+  VERIFY( sbuf.sgetc() == c_lit[1] );
+  VERIFY( sbuf.sbumpc() == c_lit[1] );
+  VERIFY( ungetc('Z', fin) == 'Z' );
+  VERIFY( sbuf.sbumpc() == 'Z' );
+  VERIFY( getc(fin) == c_lit[2] );
+  VERIFY( sbuf.sputbackc('X') == 'X' );
+  VERIFY( getc(fin) == 'X' );
+
+  char buf[5];
+  memset(buf, 'x', 5);
+  VERIFY( sbuf.sgetn(buf, 5) == 5 );
+  VERIFY( !memcmp(buf, c_lit + 3, 5) );
+  VERIFY( getc(fin) == c_lit[8] );
+  VERIFY( sbuf.sungetc() == EOF );
+
+  fclose(fin);
+}
+
+int main ()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf_wchar_t.cc b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf_wchar_t.cc
new file mode 100644 (file)
index 0000000..a8cde4a
--- /dev/null
@@ -0,0 +1,65 @@
+// 2003-05-01 Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 2003 Free Software Foundation
+//
+// 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <ext/stdio_sync_filebuf.h>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  using namespace std;
+
+  bool test = true;
+  const char* c_lit = "black pearl jasmine tea";
+  const wchar_t* w_lit = L"black pearl jasmine tea";
+  int size = strlen(c_lit);
+  const char* name = "stdiobuf-1.txt";
+
+  FILE* fout = fopen(name, "w");
+  fwrite(c_lit, 1, size, fout);
+  fclose(fout);
+
+  FILE* fin = fopen(name, "r");
+  __gnu_cxx::stdio_sync_filebuf<wchar_t> wsbuf(fin);
+
+  VERIFY( wsbuf.sgetc() == w_lit[0] );
+  VERIFY( getwc(fin) == w_lit[0] );
+  VERIFY( wsbuf.sgetc() == w_lit[1] );
+  VERIFY( wsbuf.sbumpc() == w_lit[1] );
+  VERIFY( ungetwc(L'Z', fin) == L'Z' );
+  VERIFY( wsbuf.sbumpc() == L'Z' );
+  VERIFY( getwc(fin) == w_lit[2] );
+  VERIFY( wsbuf.sputbackc(L'X') == L'X' );
+  VERIFY( getwc(fin) == L'X' );
+
+  wchar_t buf[5];
+  wmemset(buf, 0xdeadbeef, 5);
+  VERIFY( wsbuf.sgetn(buf, 5) == 5 );
+  VERIFY( !wmemcmp(buf, w_lit + 3, 5) );
+  VERIFY( getwc(fin) == w_lit[8] );
+  VERIFY( wsbuf.sungetc() == WEOF );
+
+  fclose(fin);
+}
+
+int main ()
+{
+  test01();
+  return 0;
+}