X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/65fe93d8a500833e0acd3ff64161b85a204b8dbf..c18621dd43b4b540d91145d25fcf3504c5f663a3:/src/common/file.cpp?ds=inline diff --git a/src/common/file.cpp b/src/common/file.cpp index f3f5025973..d6b4620e7d 100644 --- a/src/common/file.cpp +++ b/src/common/file.cpp @@ -24,7 +24,7 @@ #if wxUSE_FILE // standard -#if defined(__WXMSW__) && !defined(__GNUWIN32__) && !defined(__WXMICROWIN__) && !defined(__WXWINCE__) +#if defined(__WINDOWS__) && !defined(__GNUWIN32__) && !defined(__WXMICROWIN__) && !defined(__WXWINCE__) #define WIN32_LEAN_AND_MEAN #define NOSERVICE @@ -47,7 +47,7 @@ #define NOCRYPT #define NOMCX -#elif defined(__WXMSW__) && defined(__WXWINCE__) +#elif defined(__WINDOWS__) && defined(__WXWINCE__) #include "wx/msw/missing.h" #elif (defined(__OS2__)) #include @@ -80,8 +80,6 @@ char* mktemp( char * path ) { return path ;} #include #include -#elif defined(__WXPALMOS__) - #include "wx/palmos/missing.h" #else #error "Please specify the header with file functions declarations." #endif //Win/UNIX @@ -121,7 +119,7 @@ #define O_BINARY (0) #endif //__UNIX__ -#ifdef __WXMSW__ +#ifdef __WINDOWS__ #include "wx/msw/mslu.h" #endif @@ -206,17 +204,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; } @@ -260,15 +258,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; } @@ -293,6 +291,38 @@ bool wxFile::Close() // read/write // ---------------------------------------------------------------------------- +bool wxFile::ReadAll(wxString *str, const wxMBConv& conv) +{ + wxCHECK_MSG( str, false, wxS("Output string must be non-NULL") ); + + 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 ssize_t READSIZE = 4096; + + ssize_t nread = Read(p, length > READSIZE ? READSIZE : length); + if ( nread == wxInvalidOffset ) + return false; + + p += nread; + if ( length <= nread ) + break; + + length -= nread; + } + + *p = 0; + + wxString strTmp(buf, conv); + str->swap(strTmp); + + return true; +} + // read ssize_t wxFile::Read(void *pBuf, size_t nCount) { @@ -462,7 +492,7 @@ bool wxFile::Eof() const wxFileOffset iRc; -#if defined(__DOS__) || defined(__UNIX__) || defined(__GNUWIN32__) || defined( __MWERKS__ ) +#if defined(__DOS__) || defined(__UNIX__) || defined(__GNUWIN32__) // @@ this doesn't work, of course, on unseekable file descriptors wxFileOffset ofsCur = Tell(), ofsMax = Length(); @@ -481,10 +511,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; }