Listing 1: Fix for iostreams bug

template<class _E, class _TYPE>
 class basic_fixedfilebuf
  : public basic_filebuf<_E, _TYPE>
 {
public:
 typedef basic_filebuf<_E, _TYPE> _Mysb;
 basic_fixedfilebuf(_Filet *_F = 0) : _Mysb(_F) { }
 virtual ~basic_fixedfilebuf() { }
protected:
 virtual streamsize xsputn(const _E *_S,
                         streamsize _N)
  { streamsize _M, _Ns;
  for (_Ns = 0; 0 < _N; )
   if (pptr() != 0 && 0 < (_M = epptr() - pptr())) {
    if (_N < _M)
     _M = _N;
    _TYPE::copy(pptr(), _S, _M);
    _S += _M, _Ns += _M, _N -= _M, pbump(_M);
   } else if (_TYPE::eq_int_type(_TYPE::eof(),
    overflow(_TYPE::to_int_type(*_S))))
    break;
  else
   ++_S, ++_Ns, --_N;
  return (_Ns);
  }
 };

typedef basic_fixedfilebuf<char, char_traits<char> >
 fixedfilebuf;
/* End of File */