X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/588066b7a39629e44bb39f1ab436b80f38c13f33..f8fbc92bdb84f34fc7306266b116ebd2da28c950:/src/common/wfstream.cpp diff --git a/src/common/wfstream.cpp b/src/common/wfstream.cpp index 8e731791bf..f660552426 100644 --- a/src/common/wfstream.cpp +++ b/src/common/wfstream.cpp @@ -69,7 +69,7 @@ wxFileOffset wxFileInputStream::GetLength() const size_t wxFileInputStream::OnSysRead(void *buffer, size_t size) { - size_t ret = m_file->Read(buffer, size); + ssize_t ret = m_file->Read(buffer, size); // NB: we can't use a switch here because HP-UX CC doesn't allow // switching over long long (which size_t is in 64bit mode) @@ -79,7 +79,7 @@ size_t wxFileInputStream::OnSysRead(void *buffer, size_t size) // nothing read, so nothing more to read m_lasterror = wxSTREAM_EOF; } - else if ( ret == (size_t)wxInvalidOffset ) + else if ( ret == wxInvalidOffset ) { m_lasterror = wxSTREAM_READ_ERROR; ret = 0; @@ -234,11 +234,12 @@ wxFileOffset wxFFileInputStream::GetLength() const size_t wxFFileInputStream::OnSysRead(void *buffer, size_t size) { - size_t ret = m_file->Read(buffer, size); + ssize_t ret = m_file->Read(buffer, size); - if (m_file->Eof()) + // 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 == (size_t)wxInvalidOffset) + if (ret == wxInvalidOffset) { m_lasterror = wxSTREAM_READ_ERROR; ret = 0; @@ -249,13 +250,7 @@ size_t wxFFileInputStream::OnSysRead(void *buffer, size_t size) wxFileOffset wxFFileInputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode) { -#ifdef __VMS -#pragma message disable intsignchange -#endif - return ( m_file->Seek(pos, mode) ? (wxFileOffset)m_file->Tell() : wxInvalidOffset ); -#ifdef __VMS -#pragma message enable intsignchange -#endif + return m_file->Seek(pos, mode) ? m_file->Tell() : wxInvalidOffset; } wxFileOffset wxFFileInputStream::OnSysTell() const @@ -314,7 +309,8 @@ wxFFileOutputStream::~wxFFileOutputStream() size_t wxFFileOutputStream::OnSysWrite(const void *buffer, size_t size) { size_t ret = m_file->Write(buffer, size); - if (m_file->Error()) + // 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; @@ -328,13 +324,7 @@ wxFileOffset wxFFileOutputStream::OnSysTell() const wxFileOffset wxFFileOutputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode) { -#ifdef __VMS -#pragma message disable intsignchange -#endif - return ( m_file->Seek(pos, mode) ? (wxFileOffset)m_file->Tell() : wxInvalidOffset ); -#ifdef __VMS -#pragma message enable intsignchange -#endif + return m_file->Seek(pos, mode) ? m_file->Tell() : wxInvalidOffset; } void wxFFileOutputStream::Sync()