Corrected wxFFileStream to use binary mode.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7561 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -33,65 +33,66 @@
|
|||||||
wxFileInputStream::wxFileInputStream(const wxString& fileName)
|
wxFileInputStream::wxFileInputStream(const wxString& fileName)
|
||||||
: wxInputStream()
|
: wxInputStream()
|
||||||
{
|
{
|
||||||
m_file = new wxFile(fileName, wxFile::read);
|
m_file = new wxFile(fileName, wxFile::read);
|
||||||
m_file_destroy = TRUE;
|
m_file_destroy = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileInputStream::wxFileInputStream()
|
wxFileInputStream::wxFileInputStream()
|
||||||
: wxInputStream()
|
: wxInputStream()
|
||||||
{
|
{
|
||||||
m_file_destroy = FALSE;
|
m_file_destroy = FALSE;
|
||||||
m_file = NULL;
|
m_file = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileInputStream::wxFileInputStream(wxFile& file)
|
wxFileInputStream::wxFileInputStream(wxFile& file)
|
||||||
{
|
{
|
||||||
m_file = &file;
|
m_file = &file;
|
||||||
m_file_destroy = FALSE;
|
m_file_destroy = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileInputStream::wxFileInputStream(int fd)
|
wxFileInputStream::wxFileInputStream(int fd)
|
||||||
{
|
{
|
||||||
m_file = new wxFile(fd);
|
m_file = new wxFile(fd);
|
||||||
m_file_destroy = TRUE;
|
m_file_destroy = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileInputStream::~wxFileInputStream()
|
wxFileInputStream::~wxFileInputStream()
|
||||||
{
|
{
|
||||||
if (m_file_destroy)
|
if (m_file_destroy)
|
||||||
delete m_file;
|
delete m_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxFileInputStream::GetSize() const
|
size_t wxFileInputStream::GetSize() const
|
||||||
{
|
{
|
||||||
return m_file->Length();
|
return m_file->Length();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxFileInputStream::OnSysRead(void *buffer, size_t size)
|
size_t wxFileInputStream::OnSysRead(void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
off_t ret;
|
off_t ret;
|
||||||
|
|
||||||
ret = m_file->Read(buffer, size);
|
ret = m_file->Read(buffer, size);
|
||||||
|
|
||||||
m_lasterror = wxStream_NOERROR;
|
m_lasterror = wxStream_NOERROR;
|
||||||
if (m_file->Eof())
|
if (m_file->Eof())
|
||||||
m_lasterror = wxStream_EOF;
|
m_lasterror = wxStream_EOF;
|
||||||
if (ret == wxInvalidOffset) {
|
if (ret == wxInvalidOffset)
|
||||||
m_lasterror = wxStream_READ_ERR;
|
{
|
||||||
ret = 0;
|
m_lasterror = wxStream_READ_ERR;
|
||||||
}
|
ret = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t wxFileInputStream::OnSysSeek(off_t pos, wxSeekMode mode)
|
off_t wxFileInputStream::OnSysSeek(off_t pos, wxSeekMode mode)
|
||||||
{
|
{
|
||||||
return m_file->Seek(pos, mode);
|
return m_file->Seek(pos, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t wxFileInputStream::OnSysTell() const
|
off_t wxFileInputStream::OnSysTell() const
|
||||||
{
|
{
|
||||||
return m_file->Tell();
|
return m_file->Tell();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -100,66 +101,67 @@ off_t wxFileInputStream::OnSysTell() const
|
|||||||
|
|
||||||
wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
|
wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
|
||||||
{
|
{
|
||||||
m_file = new wxFile(fileName, wxFile::write);
|
m_file = new wxFile(fileName, wxFile::write);
|
||||||
m_file_destroy = TRUE;
|
m_file_destroy = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileOutputStream::wxFileOutputStream(wxFile& file)
|
wxFileOutputStream::wxFileOutputStream(wxFile& file)
|
||||||
{
|
{
|
||||||
m_file = &file;
|
m_file = &file;
|
||||||
m_file_destroy = FALSE;
|
m_file_destroy = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileOutputStream::wxFileOutputStream()
|
wxFileOutputStream::wxFileOutputStream()
|
||||||
: wxOutputStream()
|
: wxOutputStream()
|
||||||
{
|
{
|
||||||
m_file_destroy = FALSE;
|
m_file_destroy = FALSE;
|
||||||
m_file = NULL;
|
m_file = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileOutputStream::wxFileOutputStream(int fd)
|
wxFileOutputStream::wxFileOutputStream(int fd)
|
||||||
{
|
{
|
||||||
m_file = new wxFile(fd);
|
m_file = new wxFile(fd);
|
||||||
m_file_destroy = TRUE;
|
m_file_destroy = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileOutputStream::~wxFileOutputStream()
|
wxFileOutputStream::~wxFileOutputStream()
|
||||||
{
|
{
|
||||||
if (m_file_destroy) {
|
if (m_file_destroy)
|
||||||
Sync();
|
{
|
||||||
delete m_file;
|
Sync();
|
||||||
}
|
delete m_file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxFileOutputStream::OnSysWrite(const void *buffer, size_t size)
|
size_t wxFileOutputStream::OnSysWrite(const void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
size_t ret = m_file->Write(buffer, size);
|
size_t ret = m_file->Write(buffer, size);
|
||||||
if (m_file->Error())
|
if (m_file->Error())
|
||||||
m_lasterror = wxStream_WRITE_ERR;
|
m_lasterror = wxStream_WRITE_ERR;
|
||||||
else
|
else
|
||||||
m_lasterror = wxStream_NOERROR;
|
m_lasterror = wxStream_NOERROR;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t wxFileOutputStream::OnSysTell() const
|
off_t wxFileOutputStream::OnSysTell() const
|
||||||
{
|
{
|
||||||
return m_file->Tell();
|
return m_file->Tell();
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t wxFileOutputStream::OnSysSeek(off_t pos, wxSeekMode mode)
|
off_t wxFileOutputStream::OnSysSeek(off_t pos, wxSeekMode mode)
|
||||||
{
|
{
|
||||||
return m_file->Seek(pos, mode);
|
return m_file->Seek(pos, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFileOutputStream::Sync()
|
void wxFileOutputStream::Sync()
|
||||||
{
|
{
|
||||||
wxOutputStream::Sync();
|
wxOutputStream::Sync();
|
||||||
m_file->Flush();
|
m_file->Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxFileOutputStream::GetSize() const
|
size_t wxFileOutputStream::GetSize() const
|
||||||
{
|
{
|
||||||
return m_file->Length();
|
return m_file->Length();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -179,64 +181,65 @@ wxFileStream::wxFileStream(const wxString& fileName)
|
|||||||
wxFFileInputStream::wxFFileInputStream(const wxString& fileName)
|
wxFFileInputStream::wxFFileInputStream(const wxString& fileName)
|
||||||
: wxInputStream()
|
: wxInputStream()
|
||||||
{
|
{
|
||||||
m_file = new wxFFile(fileName, "r");
|
m_file = new wxFFile(fileName, "r");
|
||||||
m_file_destroy = TRUE;
|
m_file_destroy = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFFileInputStream::wxFFileInputStream()
|
wxFFileInputStream::wxFFileInputStream()
|
||||||
: wxInputStream()
|
: wxInputStream()
|
||||||
{
|
{
|
||||||
m_file_destroy = FALSE;
|
m_file_destroy = FALSE;
|
||||||
m_file = NULL;
|
m_file = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFFileInputStream::wxFFileInputStream(wxFFile& file)
|
wxFFileInputStream::wxFFileInputStream(wxFFile& file)
|
||||||
{
|
{
|
||||||
m_file = &file;
|
m_file = &file;
|
||||||
m_file_destroy = FALSE;
|
m_file_destroy = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFFileInputStream::wxFFileInputStream(FILE *file)
|
wxFFileInputStream::wxFFileInputStream(FILE *file)
|
||||||
{
|
{
|
||||||
m_file = new wxFFile(file);
|
m_file = new wxFFile(file);
|
||||||
m_file_destroy = TRUE;
|
m_file_destroy = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFFileInputStream::~wxFFileInputStream()
|
wxFFileInputStream::~wxFFileInputStream()
|
||||||
{
|
{
|
||||||
if (m_file_destroy)
|
if (m_file_destroy)
|
||||||
delete m_file;
|
delete m_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxFFileInputStream::GetSize() const
|
size_t wxFFileInputStream::GetSize() const
|
||||||
{
|
{
|
||||||
return m_file->Length();
|
return m_file->Length();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxFFileInputStream::OnSysRead(void *buffer, size_t size)
|
size_t wxFFileInputStream::OnSysRead(void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
off_t ret;
|
off_t ret;
|
||||||
|
|
||||||
ret = m_file->Read(buffer, size);
|
ret = m_file->Read(buffer, size);
|
||||||
|
|
||||||
if (m_file->Eof())
|
if (m_file->Eof())
|
||||||
m_lasterror = wxStream_EOF;
|
m_lasterror = wxStream_EOF;
|
||||||
if (ret == wxInvalidOffset) {
|
if (ret == wxInvalidOffset)
|
||||||
m_lasterror = wxStream_READ_ERR;
|
{
|
||||||
ret = 0;
|
m_lasterror = wxStream_READ_ERR;
|
||||||
}
|
ret = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t wxFFileInputStream::OnSysSeek(off_t pos, wxSeekMode mode)
|
off_t wxFFileInputStream::OnSysSeek(off_t pos, wxSeekMode mode)
|
||||||
{
|
{
|
||||||
return m_file->Seek(pos, mode);
|
return m_file->Seek(pos, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t wxFFileInputStream::OnSysTell() const
|
off_t wxFFileInputStream::OnSysTell() const
|
||||||
{
|
{
|
||||||
return m_file->Tell();
|
return m_file->Tell();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -245,66 +248,67 @@ off_t wxFFileInputStream::OnSysTell() const
|
|||||||
|
|
||||||
wxFFileOutputStream::wxFFileOutputStream(const wxString& fileName)
|
wxFFileOutputStream::wxFFileOutputStream(const wxString& fileName)
|
||||||
{
|
{
|
||||||
m_file = new wxFFile(fileName, "w+");
|
m_file = new wxFFile(fileName, "w+b");
|
||||||
m_file_destroy = TRUE;
|
m_file_destroy = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFFileOutputStream::wxFFileOutputStream(wxFFile& file)
|
wxFFileOutputStream::wxFFileOutputStream(wxFFile& file)
|
||||||
{
|
{
|
||||||
m_file = &file;
|
m_file = &file;
|
||||||
m_file_destroy = FALSE;
|
m_file_destroy = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFFileOutputStream::wxFFileOutputStream()
|
wxFFileOutputStream::wxFFileOutputStream()
|
||||||
: wxOutputStream()
|
: wxOutputStream()
|
||||||
{
|
{
|
||||||
m_file_destroy = FALSE;
|
m_file_destroy = FALSE;
|
||||||
m_file = NULL;
|
m_file = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFFileOutputStream::wxFFileOutputStream(FILE *file)
|
wxFFileOutputStream::wxFFileOutputStream(FILE *file)
|
||||||
{
|
{
|
||||||
m_file = new wxFFile(file);
|
m_file = new wxFFile(file);
|
||||||
m_file_destroy = TRUE;
|
m_file_destroy = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFFileOutputStream::~wxFFileOutputStream()
|
wxFFileOutputStream::~wxFFileOutputStream()
|
||||||
{
|
{
|
||||||
if (m_file_destroy) {
|
if (m_file_destroy)
|
||||||
Sync();
|
{
|
||||||
delete m_file;
|
Sync();
|
||||||
}
|
delete m_file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxFFileOutputStream::OnSysWrite(const void *buffer, size_t size)
|
size_t wxFFileOutputStream::OnSysWrite(const void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
size_t ret = m_file->Write(buffer, size);
|
size_t ret = m_file->Write(buffer, size);
|
||||||
if (m_file->Error())
|
if (m_file->Error())
|
||||||
m_lasterror = wxStream_WRITE_ERR;
|
m_lasterror = wxStream_WRITE_ERR;
|
||||||
else
|
else
|
||||||
m_lasterror = wxStream_NOERROR;
|
m_lasterror = wxStream_NOERROR;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t wxFFileOutputStream::OnSysTell() const
|
off_t wxFFileOutputStream::OnSysTell() const
|
||||||
{
|
{
|
||||||
return m_file->Tell();
|
return m_file->Tell();
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t wxFFileOutputStream::OnSysSeek(off_t pos, wxSeekMode mode)
|
off_t wxFFileOutputStream::OnSysSeek(off_t pos, wxSeekMode mode)
|
||||||
{
|
{
|
||||||
return m_file->Seek(pos, mode);
|
return m_file->Seek(pos, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFFileOutputStream::Sync()
|
void wxFFileOutputStream::Sync()
|
||||||
{
|
{
|
||||||
wxOutputStream::Sync();
|
wxOutputStream::Sync();
|
||||||
m_file->Flush();
|
m_file->Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxFFileOutputStream::GetSize() const
|
size_t wxFFileOutputStream::GetSize() const
|
||||||
{
|
{
|
||||||
return m_file->Length();
|
return m_file->Length();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user