@@ -225,7 +225,7 @@ class RemoteInputStreamBuffer : public std::streambuf {
225225 std::streampos seekoff (std::streamoff off, std::ios_base::seekdir way,
226226 std::ios_base::openmode mode) {
227227 // short-circuit for tellg
228- if (off == 0 && way == std::ios_base::cur)
228+ if ((mode & std::ios_base::in) && off == 0 && way == std::ios_base::cur)
229229 return bytes_;
230230 log_fatal (" Seek not implemented for remote stream" );
231231 }
@@ -403,6 +403,8 @@ class InputStreamCounter : public std::streambuf {
403403
404404 std::streampos seekoff (std::streamoff off, std::ios_base::seekdir way,
405405 std::ios_base::openmode mode) {
406+ if (!(mode & std::ios_base::in))
407+ log_fatal (" Seek not implemented for output stream" );
406408 // short-circuit for tellg
407409 if (off == 0 && way == std::ios_base::cur)
408410 return bytes_;
@@ -413,6 +415,8 @@ class InputStreamCounter : public std::streambuf {
413415 }
414416
415417 std::streampos seekpos (std::streampos pos, std::ios_base::openmode mode) {
418+ if (!(mode & std::ios_base::in))
419+ log_fatal (" Seek not implemented for output stream" );
416420 std::streampos n = buffer_->pubseekpos (pos, mode);
417421 if (n != std::streampos (std::streamoff (-1 )))
418422 bytes_ = n;
@@ -524,20 +528,34 @@ class OutputStreamCounter : public std::streambuf {
524528
525529protected:
526530 virtual int_type overflow (int_type c) {
527- if (buffer_->sputc (c) != traits_type::eof ()) {
531+ if (buffer_ && buffer_ ->sputc (c) != traits_type::eof ()) {
528532 bytes_++;
529533 return c;
530534 }
531535 return traits_type::eof ();
532536 }
533537
534538 virtual std::streamsize xsputn (const char * s, std::streamsize n) {
539+ if (!buffer_)
540+ return 0 ;
535541 std::streamsize nput = buffer_->sputn (s, n);
536542 if (nput > 0 )
537543 bytes_ += nput;
538544 return nput;
539545 }
540546
547+ std::streampos seekoff (std::streamoff off, std::ios_base::seekdir way,
548+ std::ios_base::openmode mode) {
549+ // short-circuit for tellp
550+ if ((mode & std::ios_base::out) && off == 0 && way == std::ios_base::cur)
551+ return bytes_;
552+ log_fatal (" Seek not implemented for output stream" );
553+ }
554+
555+ std::streampos seekpos (std::streampos pos, std::ios_base::openmode mode) {
556+ log_fatal (" Seek not implemented for output stream" );
557+ }
558+
541559 size_t bytes_;
542560
543561private:
@@ -721,16 +739,6 @@ g3_ostream_to_path(std::ostream &stream, const std::string &path, bool append,
721739 stream.pword (1 ) = sbuf;
722740}
723741
724- size_t
725- g3_ostream_count (std::ostream &stream)
726- {
727- OutputStreamCounter* cbuf = static_cast <OutputStreamCounter*>(stream.rdbuf ());
728- if (!cbuf)
729- log_fatal (" Could not get stream counter" );
730-
731- return cbuf->bytes ();
732- }
733-
734742void
735743g3_ostream_flush (std::ostream &stream)
736744{
0 commit comments