+#endif // wxUSE_FILE
+
+#if wxUSE_FFILE
+
+// ----------------------------------------------------------------------------
+// wxFFileInputStream
+// ----------------------------------------------------------------------------
+
+wxFFileInputStream::wxFFileInputStream(const wxString& fileName,
+ const wxString& mode)
+ : wxInputStream()
+{
+ m_file = new wxFFile(fileName, mode);
+ m_file_destroy = true;
+
+ if (!m_file->IsOpened())
+ m_lasterror = wxSTREAM_WRITE_ERROR;
+}
+
+wxFFileInputStream::wxFFileInputStream()
+ : wxInputStream()
+{
+ m_file = NULL;
+ m_file_destroy = false;
+}
+
+wxFFileInputStream::wxFFileInputStream(wxFFile& file)
+{
+ m_file = &file;
+ m_file_destroy = false;
+}
+
+wxFFileInputStream::wxFFileInputStream(FILE *file)
+{
+ m_file = new wxFFile(file);
+ m_file_destroy = true;
+}
+
+wxFFileInputStream::~wxFFileInputStream()
+{
+ if (m_file_destroy)
+ delete m_file;
+}
+
+wxFileOffset wxFFileInputStream::GetLength() const
+{
+ return m_file->Length();
+}
+
+size_t wxFFileInputStream::OnSysRead(void *buffer, size_t size)
+{
+ ssize_t ret = m_file->Read(buffer, size);
+
+ // It is not safe to call Eof() if the file is not opened.
+ if (!m_file->IsOpened() || m_file->Eof())
+ m_lasterror = wxSTREAM_EOF;
+ if (ret == wxInvalidOffset)
+ {
+ m_lasterror = wxSTREAM_READ_ERROR;
+ ret = 0;
+ }
+
+ return ret;
+}
+
+wxFileOffset wxFFileInputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode)
+{
+ return m_file->Seek(pos, mode) ? m_file->Tell() : wxInvalidOffset;
+}
+
+wxFileOffset wxFFileInputStream::OnSysTell() const
+{
+ return m_file->Tell();
+}
+
+bool wxFFileInputStream::IsOk() const
+{
+ return wxStreamBase::IsOk() && m_file->IsOpened();
+}
+
+// ----------------------------------------------------------------------------
+// wxFFileOutputStream
+// ----------------------------------------------------------------------------
+
+wxFFileOutputStream::wxFFileOutputStream(const wxString& fileName,
+ const wxString& mode)
+{
+ m_file = new wxFFile(fileName, mode);
+ m_file_destroy = true;
+
+ if (!m_file->IsOpened())
+ {
+ m_lasterror = wxSTREAM_WRITE_ERROR;
+ }
+ else
+ {
+ if (m_file->Error())
+ m_lasterror = wxSTREAM_WRITE_ERROR;
+ }
+}
+
+wxFFileOutputStream::wxFFileOutputStream(wxFFile& file)
+{
+ m_file = &file;
+ m_file_destroy = false;
+}
+
+wxFFileOutputStream::wxFFileOutputStream()
+ : wxOutputStream()
+{
+ m_file = NULL;
+ m_file_destroy = false;
+}
+
+wxFFileOutputStream::wxFFileOutputStream(FILE *file)
+{
+ m_file = new wxFFile(file);
+ m_file_destroy = true;
+}
+
+wxFFileOutputStream::~wxFFileOutputStream()
+{
+ if (m_file_destroy)
+ {
+ Sync();
+ delete m_file;
+ }
+}
+
+size_t wxFFileOutputStream::OnSysWrite(const void *buffer, size_t size)
+{
+ size_t ret = m_file->Write(buffer, size);
+ // It is not safe to call Error() if the file is not opened.
+ if (!m_file->IsOpened() || m_file->Error())
+ m_lasterror = wxSTREAM_WRITE_ERROR;
+ else
+ m_lasterror = wxSTREAM_NO_ERROR;
+ return ret;
+}
+
+wxFileOffset wxFFileOutputStream::OnSysTell() const
+{
+ return m_file->Tell();
+}
+
+wxFileOffset wxFFileOutputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode)
+{
+ return m_file->Seek(pos, mode) ? m_file->Tell() : wxInvalidOffset;
+}
+
+void wxFFileOutputStream::Sync()
+{
+ wxOutputStream::Sync();
+ m_file->Flush();
+}
+
+wxFileOffset wxFFileOutputStream::GetLength() const
+{
+ return m_file->Length();
+}
+
+bool wxFFileOutputStream::IsOk() const
+{
+ return wxStreamBase::IsOk() && m_file->IsOpened();
+}
+
+// ----------------------------------------------------------------------------
+// wxFFileStream
+// ----------------------------------------------------------------------------
+
+wxFFileStream::wxFFileStream(const wxString& fileName, const wxString& mode)
+ : wxFFileInputStream(),
+ wxFFileOutputStream()
+{
+ wxASSERT_MSG( mode.find_first_of('+') != wxString::npos,
+ "must be opened in read-write mode for this class to work" );
+
+ wxFFileOutputStream::m_file =
+ wxFFileInputStream::m_file = new wxFFile(fileName, mode);
+
+ // see comment in wxFileStream ctor
+ wxFFileInputStream::m_file_destroy = true;
+}
+
+bool wxFFileStream::IsOk() const
+{
+ return wxFFileOutputStream::IsOk() && wxFFileInputStream::IsOk();
+}
+
+#endif //wxUSE_FFILE
+
+#endif // wxUSE_STREAMS