From 4c4809c175d40cfe30020c00e31959147005b411 Mon Sep 17 00:00:00 2001
From: Benjamin Kosnik <bkoz@gcc.gnu.org>
Date: Thu, 16 Oct 2003 22:37:53 +0000
Subject: [multiple changes]

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

	PR libstdc++/8610
	PR libstdc++/11450
	PR libstdc++/11543
	PR libstdc++/12065
	* config/io/basic_file_stdio.cc (__basic_file::seekoff):
	Change return value from streampos to streamoff.
	(__basic_file::seekpos): Delete.
	* config/io/basic_file_stdio.h: Same.
	* config/io/c_io_stdio.h: Remove streamoff and wstreamsize typedefs.
	* include/Makefile.am (bits_headers): Add bits/postypes.h.
	* include/bits/char_traits.h: Include bits/postypes.h instead of
	bits/fpos.h.
	* include/bits/fstream.tcc (basic_filebuf::open,
	basic_filebuf::pbackfail): Don't use < or >= to compare pos_type
	values, use == and != instead.
	(basic_filebuf::_M_seek): Use explicit conversion from streamoff
	to pos_type.
	(basic_filebuf::imbue):  Don't use ! on pos_type values, use
	== instead. Don't use __check_facet(_M_codecvt) unless is_open().
	* include/bits/postypes.h: New file.
	Add __streamoff_base_type typedef, streamsize.
	(streamoff, streampos, wstreampos): Define typedefs, with
	streamoff defined as...
	(streamoff): New class. Document implementation defined
	aspects.
	(fpos): New implementation. Document implementation defined
	aspects.
	* include/bits/sstream.tcc (basic_stringbuf::seekpos): Use
	explicit conversion from pos_type to off_type.
	* include/std/std_iosfwd.h: Include bits/postypes.h instead
	of bits/fpos.h.
	* testsuite/27_io/basic_filebuf/seekoff/char/11543.cc: New test.
	* testsuite/27_io/basic_filebuf/seekoff/wchar_t/11543.cc: New test.
	* testsuite/27_io/fpos/11450.cc: New test.
	* testsuite/27_io/fpos/mbstate_t/12065.cc: New test.
	* testsuite/27_io/fpos/mbstate_t/4_neg.cc: New test.
	* testsuite/27_io/types/3.cc: New test.

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

        * configure.host: Remove fpos_include_dir.
        * configure.ac: Remove FPOS_INC_SRCDIR.
        * configure: Regenerate.
        * acinclude.m4 (GLIBCXX_ENABLE_CSTDIO): Remove FPOS_H.
        * aclocal.m4: Regenerate.
        * include/Makefile.am (host_headers): Remove fpos.h.
        (bits_headers): Add postypes.h.
        * include/Makefile.in: Regenerate.
        * config/os/gnu-linux/fposh: Remove.
        * config/os/generic/fpos.h: Remove.

        * testsuite/27_io/basic_filebuf/seekoff/char/1-in.cc: Fixup.
        * testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc: Same.
        * testsuite/27_io/basic_filebuf/seekoff/char/1-out.cc: Same.
        * testsuite/27_io/basic_filebuf/seekoff/char/2-in.cc: Same.
        * testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc: Same.
        * testsuite/27_io/basic_filebuf/seekoff/char/2-out.cc: Same.
        * testsuite/27_io/basic_filebuf/seekpos/char/1-in.cc: Same.
        * testsuite/27_io/basic_filebuf/seekpos/char/1-io.cc: Same.
        * testsuite/27_io/basic_filebuf/seekpos/char/1-out.cc: Same.
        * testsuite/27_io/basic_filebuf/seekpos/char/2-in.cc: Same.
        * testsuite/27_io/basic_filebuf/seekpos/char/2-io.cc: Same.
        * testsuite/27_io/basic_filebuf/seekpos/char/2-out.cc: Same.
        * testsuite/27_io/basic_istream/seekg/char/2.cc: Same.
        * testsuite/27_io/basic_stringbuf/seekoff/char/1.cc: Same.
        * testsuite/27_io/basic_stringbuf/seekpos/char/1.cc: Same.
        * testsuite/27_io/fpos/mbstate_t/3.cc: Same.
        * testsuite/27_io/objects/char/10.cc: Same.

From-SVN: r72582
---
 libstdc++-v3/include/bits/fstream.tcc | 52 +++++++++++++++++++++--------------
 1 file changed, 32 insertions(+), 20 deletions(-)

(limited to 'libstdc++-v3/include/bits/fstream.tcc')

diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc
index f6f1b75..a93459a 100644
--- a/libstdc++-v3/include/bits/fstream.tcc
+++ b/libstdc++-v3/include/bits/fstream.tcc
@@ -106,7 +106,8 @@ namespace std
 
 	      // 27.8.1.3,4
 	      if ((__mode & ios_base::ate) 
-		  && this->seekoff(0, ios_base::end, __mode) < 0)
+		  && this->seekoff(0, ios_base::end, __mode)
+		  == pos_type(off_type(-1)))
 		this->close();
 	      else
 		__ret = this;
@@ -333,7 +334,7 @@ namespace std
 	      this->gbump(-1);
 	      __tmp = traits_type::to_int_type(*this->gptr());
 	    }
-	  else if (this->seekoff(-1, ios_base::cur) >= 0)
+	  else if (this->seekoff(-1, ios_base::cur) != pos_type(off_type(-1)))
 	    {
 	      __tmp = this->underflow();
 	      if (traits_type::eq_int_type(__tmp, __ret))
@@ -653,7 +654,7 @@ namespace std
 	}
 	  
       // Returns pos_type(off_type(-1)) in case of failure.
-      pos_type __ret = _M_file.seekoff(__off, __way);
+      pos_type __ret (_M_file.seekoff(__off, __way));
 	  
       _M_reading = false;
       _M_writing = false;
@@ -673,24 +674,35 @@ namespace std
     basic_filebuf<_CharT, _Traits>::
     imbue(const locale& __loc)
     {
-      const bool __testbeg = !this->seekoff(0, ios_base::cur, this->_M_mode);
-      const bool __teststate = __check_facet(_M_codecvt).encoding() == -1;
-
-      if (this->_M_buf_locale != __loc 
-	  && (!this->is_open() || (__testbeg && !__teststate)))
+      if (this->_M_buf_locale != __loc)
 	{
-	  this->_M_buf_locale = __loc;
-	  if (__builtin_expect(has_facet<__codecvt_type>(__loc), true))
-	    _M_codecvt = &use_facet<__codecvt_type>(__loc);
-	  else
-	    _M_codecvt = 0;
-
-	  // NB This may require the reconversion of previously
-	  // converted chars. This in turn may cause the
-	  // reconstruction of the original file. YIKES!!  This
-	  // implementation interprets this requirement as requiring
-	  // the file position be at the beginning, and a stateless
-	  // encoding, or that the filebuf be closed. Opinions may differ.
+	  bool __testfail = false;
+	  if (this->is_open())
+	    {
+	      const bool __testbeg =
+		this->seekoff(0, ios_base::cur, this->_M_mode) ==
+		pos_type(off_type(0));
+	      const bool __teststate =
+		__check_facet(_M_codecvt).encoding() == -1;
+
+	      __testfail = !__testbeg || __teststate;
+	    }
+
+	  if (!__testfail)
+	    {
+	      this->_M_buf_locale = __loc;
+	      if (__builtin_expect(has_facet<__codecvt_type>(__loc), true))
+		_M_codecvt = &use_facet<__codecvt_type>(__loc);
+	      else
+		_M_codecvt = 0;
+
+	      // NB This may require the reconversion of previously
+	      // converted chars. This in turn may cause the
+	      // reconstruction of the original file. YIKES!!  This
+	      // implementation interprets this requirement as requiring
+	      // the file position be at the beginning, and a stateless
+	      // encoding, or that the filebuf be closed. Opinions may differ.
+	    }
 	}
       _M_last_overflowed = false;	
     }
-- 
cgit v1.1