X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/614108e211ecb6e11d32b646a91437061116b518..931d6a47c32a5b4c283243cb553ce71ee2b535d5:/src/common/file.cpp diff --git a/src/common/file.cpp b/src/common/file.cpp index 02a15cb2ca..b2a5aca736 100644 --- a/src/common/file.cpp +++ b/src/common/file.cpp @@ -5,7 +5,6 @@ // Author: Vadim Zeitlin // Modified by: // Created: 29/01/98 -// RCS-ID: $Id$ // Copyright: (c) 1998 Vadim Zeitlin // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -204,17 +203,17 @@ bool wxFile::Create(const wxString& fileName, bool bOverwrite, int accessMode) { // if bOverwrite we create a new file or truncate the existing one, // otherwise we only create the new file and fail if it already exists - int fd = wxOpen( fileName, + int fildes = wxOpen( fileName, O_BINARY | O_WRONLY | O_CREAT | (bOverwrite ? O_TRUNC : O_EXCL), accessMode ); - if ( CheckForError(fd) ) + if ( CheckForError(fildes) ) { wxLogSysError(_("can't create file '%s'"), fileName); return false; } - Attach(fd); + Attach(fildes); return true; } @@ -258,15 +257,15 @@ bool wxFile::Open(const wxString& fileName, OpenMode mode, int accessMode) accessMode &= wxS_IRUSR | wxS_IWUSR; #endif // __WINDOWS__ - int fd = wxOpen( fileName, flags, accessMode); + int fildes = wxOpen( fileName, flags, accessMode); - if ( CheckForError(fd) ) + if ( CheckForError(fildes) ) { wxLogSysError(_("can't open file '%s'"), fileName); return false; } - Attach(fd); + Attach(fildes); return true; } @@ -295,20 +294,24 @@ bool wxFile::ReadAll(wxString *str, const wxMBConv& conv) { wxCHECK_MSG( str, false, wxS("Output string must be non-NULL") ); - size_t length = wx_truncate_cast(size_t, Length()); + ssize_t length = Length(); wxCHECK_MSG( (wxFileOffset)length == Length(), false, wxT("huge file not supported") ); wxCharBuffer buf(length); char* p = buf.data(); for ( ;; ) { - static const unsigned READSIZE = 4096; + static const ssize_t READSIZE = 4096; - ssize_t read = Read(p, length > READSIZE ? READSIZE : length); - if ( read == wxInvalidOffset ) + ssize_t nread = Read(p, length > READSIZE ? READSIZE : length); + if ( nread == wxInvalidOffset ) return false; - p += read; + p += nread; + if ( length <= nread ) + break; + + length -= nread; } *p = 0; @@ -507,10 +510,6 @@ bool wxFile::Eof() const { wxLogSysError(_("can't determine if the end of file is reached on descriptor %d"), m_fd); } - else if ( iRc != 1 ) - { - wxFAIL_MSG(wxT("invalid eof() return value.")); - } return true; }