X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/82b99cf952504cd5c6e6c1f6f93756c609f2905c..81533a3af6ed598c32a35e1c1c2b60f4908f5541:/src/common/fileback.cpp?ds=sidebyside diff --git a/src/common/fileback.cpp b/src/common/fileback.cpp index 23d60c349a..5544ee7b54 100644 --- a/src/common/fileback.cpp +++ b/src/common/fileback.cpp @@ -14,15 +14,15 @@ #pragma hdrstop #endif -#if wxUSE_BACKINGFILE +#if wxUSE_FILESYSTEM + +#include "wx/private/fileback.h" #ifndef WX_PRECOMP - #include "wx/stream.h" #include "wx/utils.h" #include "wx/log.h" #endif -#include "wx/fileback.h" #include "wx/private/filename.h" // Prefer wxFFile unless wxFile has large file support but wxFFile does not. @@ -82,8 +82,8 @@ wxBackingFileImpl::wxBackingFileImpl(wxInputStream *stream, { wxFileOffset len = m_stream->GetLength(); - if (len >= 0 && len + size_t(0) < m_bufsize) - m_bufsize = len; + if (len >= 0 && len + size_t(1) < m_bufsize) + m_bufsize = size_t(len + 1); if (m_bufsize) m_buf = new char[m_bufsize]; @@ -114,7 +114,7 @@ wxStreamError wxBackingFileImpl::ReadAt(wxFileOffset pos, size1 = reqestedSize; size2 = 0; } else if (pos < m_filelen) { - size1 = m_filelen - pos; + size1 = size_t(m_filelen - pos); size2 = reqestedSize - size1; } else { size1 = 0; @@ -171,7 +171,7 @@ wxStreamError wxBackingFileImpl::ReadAt(wxFileOffset pos, delete m_stream; m_stream = NULL; if (count > 0) { - delete m_buf; + delete[] m_buf; m_buf = NULL; m_buflen = 0; } @@ -182,7 +182,7 @@ wxStreamError wxBackingFileImpl::ReadAt(wxFileOffset pos, m_buflen = 0; if (!m_stream) { - delete m_buf; + delete[] m_buf; m_buf = NULL; } } @@ -203,7 +203,7 @@ wxStreamError wxBackingFileImpl::ReadAt(wxFileOffset pos, } // copy to the user's buffer - size_t start = pos - m_filelen; + size_t start = size_t(pos - m_filelen); size_t len = wxMin(m_buflen - start, reqestedSize - *size); memcpy((char*)buffer + *size, m_buf + start, len); @@ -271,6 +271,29 @@ wxBackedInputStream::wxBackedInputStream(const wxBackingFile& backer) { } +wxFileOffset wxBackedInputStream::GetLength() const +{ + return m_backer.m_impl->GetLength(); +} + +wxFileOffset wxBackedInputStream::FindLength() const +{ + wxFileOffset len = GetLength(); + + if (len == wxInvalidOffset && IsOk()) { + // read a byte at 7ff...ffe + wxFileOffset pos = 1; + pos <<= sizeof(pos) * 8 - 1; + pos = ~pos - 1; + char ch; + size_t size = 1; + m_backer.m_impl->ReadAt(pos, &ch, &size); + len = GetLength(); + } + + return len; +} + size_t wxBackedInputStream::OnSysRead(void *buffer, size_t size) { if (!IsOk()) @@ -281,11 +304,6 @@ size_t wxBackedInputStream::OnSysRead(void *buffer, size_t size) return size; } -wxFileOffset wxBackedInputStream::GetLength() const -{ - return m_backer.m_impl->GetLength(); -} - wxFileOffset wxBackedInputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode) { switch (mode) { @@ -317,4 +335,4 @@ wxFileOffset wxBackedInputStream::OnSysTell() const return m_pos; } -#endif // wxUSE_BACKINGFILE +#endif // wxUSE_FILESYSTEM