X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ce4169a4d129fc6cd165b2e9ccc5cf5d48356020..a58d5df4ef7fbbbb1c385ac63038608d49f8dfa5:/src/common/wfstream.cpp diff --git a/src/common/wfstream.cpp b/src/common/wfstream.cpp index e4da5d94df..3bf2a080ba 100644 --- a/src/common/wfstream.cpp +++ b/src/common/wfstream.cpp @@ -20,15 +20,11 @@ #pragma hdrstop #endif -#ifndef WX_PRECOMP - #include "wx/defs.h" -#endif - #if wxUSE_STREAMS && wxUSE_FILE #include -#include -#include +#include "wx/stream.h" +#include "wx/wfstream.h" // ---------------------------------------------------------------------------- // wxFileInputStream @@ -39,7 +35,6 @@ wxFileInputStream::wxFileInputStream(const wxString& fileName) { m_file = new wxFile(fileName, wxFile::read); m_file_destroy = TRUE; - m_i_streambuf->SetBufferIO(1024); } wxFileInputStream::wxFileInputStream() @@ -53,14 +48,12 @@ wxFileInputStream::wxFileInputStream(wxFile& file) { m_file = &file; m_file_destroy = FALSE; - m_i_streambuf->SetBufferIO(1024); } wxFileInputStream::wxFileInputStream(int fd) { m_file = new wxFile(fd); m_file_destroy = TRUE; - m_i_streambuf->SetBufferIO(1024); } wxFileInputStream::~wxFileInputStream() @@ -74,14 +67,25 @@ char wxFileInputStream::Peek() return 0; } -size_t wxFileInputStream::StreamSize() const +size_t wxFileInputStream::GetSize() const { return m_file->Length(); } size_t wxFileInputStream::OnSysRead(void *buffer, size_t size) { - return m_file->Read(buffer, size); + off_t ret; + + ret = m_file->Read(buffer, size); + + if (m_file->Eof()) + m_lasterror = wxStream_EOF; + if (ret == wxInvalidOffset) { + m_lasterror = wxStream_READ_ERR; + ret = 0; + } + + return ret; } off_t wxFileInputStream::OnSysSeek(off_t pos, wxSeekMode mode) @@ -102,20 +106,17 @@ wxFileOutputStream::wxFileOutputStream(const wxString& fileName) { m_file = new wxFile(fileName, wxFile::write); m_file_destroy = TRUE; - m_o_streambuf->SetBufferIO(1024); } wxFileOutputStream::wxFileOutputStream(wxFile& file) { m_file = &file; m_file_destroy = FALSE; - m_o_streambuf->SetBufferIO(1024); } wxFileOutputStream::wxFileOutputStream() : wxOutputStream() { - m_o_streambuf->SetBufferIO(1024); m_file_destroy = FALSE; m_file = NULL; } @@ -124,7 +125,6 @@ wxFileOutputStream::wxFileOutputStream(int fd) { m_file = new wxFile(fd); m_file_destroy = TRUE; - m_o_streambuf->SetBufferIO(1024); } wxFileOutputStream::~wxFileOutputStream() @@ -138,7 +138,10 @@ wxFileOutputStream::~wxFileOutputStream() size_t wxFileOutputStream::OnSysWrite(const void *buffer, size_t size) { size_t ret = m_file->Write(buffer, size); - m_lasterror = wxStream_EOF; // TODO + if (m_file->Error()) + m_lasterror = wxStream_WRITE_ERR; + else + m_lasterror = wxStream_NOERROR; return ret; } @@ -158,7 +161,7 @@ void wxFileOutputStream::Sync() m_file->Flush(); } -size_t wxFileOutputStream::StreamSize() const +size_t wxFileOutputStream::GetSize() const { return m_file->Length(); } @@ -173,3 +176,4 @@ wxFileStream::wxFileStream(const wxString& fileName) #endif // wxUSE_STREAMS && wxUSE_FILE +