X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/30984deafc05d7c6f88db736336fe73d23a08e19..ce7208d49d5ce2ca1dc0b3b83f14f1d04f29c4bf:/src/common/file.cpp diff --git a/src/common/file.cpp b/src/common/file.cpp index 55d70d03db..7c494b4d71 100644 --- a/src/common/file.cpp +++ b/src/common/file.cpp @@ -14,10 +14,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "file.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -144,14 +140,6 @@ #include "wx/msw/private.h" #endif -#if !defined __UNIX__ && !defined __DJGPP__ - #ifdef __WXWINCE__ - typedef int ssize_t; - #else - typedef ptrdiff_t ssize_t; - #endif -#endif -wxCOMPILE_TIME_ASSERT(sizeof(ssize_t) == sizeof(size_t), ssize_t_wrong_size); // ============================================================================ // implementation of wxFile @@ -225,11 +213,9 @@ bool wxFile::Create(const wxChar *szFileName, bool bOverwrite, int accessMode) wxLogSysError(_("can't create file '%s'"), szFileName); return false; } - else - { - Attach(fd); - return true; - } + + Attach(fd); + return true; } // open the file @@ -279,10 +265,9 @@ bool wxFile::Open(const wxChar *szFileName, OpenMode mode, int accessMode) wxLogSysError(_("can't open file '%s'"), szFileName); return false; } - else { - Attach(fd); - return true; - } + + Attach(fd); + return true; } // close @@ -307,7 +292,7 @@ bool wxFile::Close() // ---------------------------------------------------------------------------- // read -size_t wxFile::Read(void *pBuf, size_t nCount) +ssize_t wxFile::Read(void *pBuf, size_t nCount) { wxCHECK( (pBuf != NULL) && IsOpened(), 0 ); @@ -316,7 +301,7 @@ size_t wxFile::Read(void *pBuf, size_t nCount) if ( iRc == -1 ) { wxLogSysError(_("can't read from file descriptor %d"), m_fd); - return (size_t)wxInvalidOffset; + return wxInvalidOffset; } return iRc; @@ -342,17 +327,18 @@ size_t wxFile::Write(const void *pBuf, size_t nCount) // flush bool wxFile::Flush() { - if ( IsOpened() ) { -#if defined(__VISUALC__) || wxHAVE_FSYNC +#ifdef HAVE_FSYNC + // fsync() only works on disk files and returns errors for pipes, don't + // call it then + if ( IsOpened() && GetKind() == wxFILE_KIND_DISK ) + { if ( wxFsync(m_fd) == -1 ) { wxLogSysError(_("can't flush file descriptor %d"), m_fd); return false; } -#else // no fsync - // just do nothing -#endif // fsync } +#endif // HAVE_FSYNC return true; } @@ -364,7 +350,10 @@ bool wxFile::Flush() // seek wxFileOffset wxFile::Seek(wxFileOffset ofs, wxSeekMode mode) { - wxASSERT( IsOpened() ); + wxASSERT_MSG( IsOpened(), _T("can't seek on closed file") ); + wxCHECK_MSG( ofs != wxInvalidOffset || mode != wxFromStart, + wxInvalidOffset, + _T("invalid absolute file offset") ); int origin; switch ( mode ) { @@ -384,11 +373,6 @@ wxFileOffset wxFile::Seek(wxFileOffset ofs, wxSeekMode mode) break; } - if (ofs == wxInvalidOffset) - { - wxLogSysError(_("can't seek on file descriptor %d, large files support is not enabled."), m_fd); - return wxInvalidOffset; - } wxFileOffset iRc = wxSeek(m_fd, ofs, origin); if ( iRc == wxInvalidOffset ) {