X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1311c7a9bbaefda6b68eee5c32c3309f163a8861..9406d962ccf50d63f163896a2dd94123a2a8664a:/src/common/file.cpp diff --git a/src/common/file.cpp b/src/common/file.cpp index e6a8a9c878..f2f047c345 100644 --- a/src/common/file.cpp +++ b/src/common/file.cpp @@ -27,8 +27,30 @@ #endif // standard -#if defined(__WINDOWS__) && !defined(__GNUWIN32__) +#if defined(__WXMSW__) && !defined(__GNUWIN32__) #include + + #define WIN32_LEAN_AND_MEAN + #define NOSERVICE + #define NOIME + #define NOATOM + #define NOGDI + #define NOGDICAPMASKS + #define NOMETAFILE + #define NOMINMAX + #define NOMSG + #define NOOPENFILE + #define NORASTEROPS + #define NOSCROLL + #define NOSOUND + #define NOSYSMETRICS + #define NOTEXTMETRIC + #define NOWH + #define NOCOMM + #define NOKANJI + #define NOCRYPT + #define NOMCX + #include // for GetTempFileName #elif (defined(__UNIX__) || defined(__GNUWIN32__)) #include #else @@ -105,6 +127,7 @@ bool wxFile::Exists(const char *sz) wxFile::wxFile(const char *szFileName, OpenMode mode) { m_fd = fd_invalid; + m_error = FALSE; Open(szFileName, mode); } @@ -123,7 +146,7 @@ bool wxFile::Create(const char *szFileName, bool bOverwrite) int fd = open(szFileName, O_CREAT | (bOverwrite ? O_TRUNC : O_EXCL)); if ( fd == -1 ) { - wxLogSysError("can't create file '%s'", szFileName); + wxLogSysError(_("can't create file '%s'"), szFileName); return FALSE; } else { @@ -158,7 +181,7 @@ bool wxFile::Open(const char *szFileName, OpenMode mode) int fd = open(szFileName, flags, S_IREAD | S_IWRITE); if ( fd == -1 ) { - wxLogSysError("can't open file '%s'", szFileName); + wxLogSysError(_("can't open file '%s'"), szFileName); return FALSE; } else { @@ -172,7 +195,7 @@ bool wxFile::Close() { if ( IsOpened() ) { if ( close(m_fd) == -1 ) { - wxLogSysError("can't close file descriptor %d", m_fd); + wxLogSysError(_("can't close file descriptor %d"), m_fd); m_fd = fd_invalid; return FALSE; } @@ -194,7 +217,7 @@ off_t wxFile::Read(void *pBuf, off_t nCount) int iRc = ::read(m_fd, pBuf, nCount); if ( iRc == -1 ) { - wxLogSysError("can't read from file descriptor %d", m_fd); + wxLogSysError(_("can't read from file descriptor %d"), m_fd); return ofsInvalid; } else @@ -202,27 +225,28 @@ off_t wxFile::Read(void *pBuf, off_t nCount) } // write -bool wxFile::Write(const void *pBuf, uint nCount) +uint wxFile::Write(const void *pBuf, uint nCount) { wxCHECK( (pBuf != NULL) && IsOpened(), 0 ); int iRc = ::write(m_fd, pBuf, nCount); if ( iRc == -1 ) { - wxLogSysError("can't write to file descriptor %d", m_fd); - return FALSE; + wxLogSysError(_("can't write to file descriptor %d"), m_fd); + m_error = TRUE; + return 0; } else - return TRUE; + return (uint)iRc; } // flush bool wxFile::Flush() { if ( IsOpened() ) { - // @@@ fsync() is not ANSI (BSDish) +// @@@ fsync() is not ANSI (BSDish) // if ( fsync(m_fd) == -1 ) { // TODO if (TRUE) { - wxLogSysError("can't flush file descriptor %d", m_fd); + wxLogSysError(_("can't flush file descriptor %d"), m_fd); return FALSE; } } @@ -235,21 +259,21 @@ bool wxFile::Flush() // ---------------------------------------------------------------------------- // seek -off_t wxFile::Seek(off_t ofs, SeekMode mode) +off_t wxFile::Seek(off_t ofs, wxSeekMode mode) { wxASSERT( IsOpened() ); int flag = -1; switch ( mode ) { - case FromStart: + case wxFromStart: flag = SEEK_SET; break; - case FromCurrent: + case wxFromCurrent: flag = SEEK_CUR; break; - case FromEnd: + case wxFromEnd: flag = SEEK_END; break; @@ -259,7 +283,7 @@ off_t wxFile::Seek(off_t ofs, SeekMode mode) int iRc = lseek(m_fd, ofs, flag); if ( iRc == -1 ) { - wxLogSysError("can't seek on file descriptor %d", m_fd); + wxLogSysError(_("can't seek on file descriptor %d"), m_fd); return ofsInvalid; } else @@ -273,7 +297,7 @@ off_t wxFile::Tell() const int iRc = tell(m_fd); if ( iRc == -1 ) { - wxLogSysError("can't get seek position on file descriptor %d", m_fd); + wxLogSysError(_("can't get seek position on file descriptor %d"), m_fd); return ofsInvalid; } else @@ -306,7 +330,7 @@ off_t wxFile::Length() const #endif //_MSC_VER if ( iRc == -1 ) { - wxLogSysError("can't find length of file on file descriptor %d", m_fd); + wxLogSysError(_("can't find length of file on file descriptor %d"), m_fd); return ofsInvalid; } else @@ -340,8 +364,8 @@ bool wxFile::Eof() const return FALSE; case -1: - wxLogSysError("can't determine if the end of file is reached on " - "descriptor %d", m_fd); + wxLogSysError(_("can't determine if the end of file is reached on " + "descriptor %d"), m_fd); break; default: @@ -374,10 +398,15 @@ bool wxTempFile::Open(const wxString& strName) #ifdef __UNIX__ static const char *szMktempSuffix = "XXXXXX"; m_strTemp << strName << szMktempSuffix; - mktemp((char *)m_strTemp.c_str()); // @@@ even if the length doesn't change - //m_strTemp.UngetWriteBuf(); + mktemp((char *)m_strTemp.c_str()); // will do because length doesn't change #else // Windows - m_strTemp = tmpnam(NULL); + wxString strPath; + wxSplitPath(strName, &strPath, NULL, NULL); + if ( strPath.IsEmpty() ) + strPath = '.'; // GetTempFileName will fail if we give it empty string + if ( !GetTempFileName(strPath, "wx_",0, m_strTemp.GetWriteBuf(MAX_PATH)) ) + wxLogLastError("GetTempFileName"); + m_strTemp.UngetWriteBuf(); #endif // Windows/Unix return m_file.Open(m_strTemp, wxFile::write); @@ -398,12 +427,12 @@ bool wxTempFile::Commit() m_file.Close(); if ( wxFile::Exists(m_strName) && remove(m_strName) != 0 ) { - wxLogSysError("can't remove file '%s'", m_strName.c_str()); + wxLogSysError(_("can't remove file '%s'"), m_strName.c_str()); return FALSE; } if ( rename(m_strTemp, m_strName) != 0 ) { - wxLogSysError("can't commit changes to file '%s'", m_strName.c_str()); + wxLogSysError(_("can't commit changes to file '%s'"), m_strName.c_str()); return FALSE; } @@ -414,5 +443,5 @@ void wxTempFile::Discard() { m_file.Close(); if ( remove(m_strTemp) != 0 ) - wxLogSysError("can't remove temporary file '%s'", m_strTemp.c_str()); + wxLogSysError(_("can't remove temporary file '%s'"), m_strTemp.c_str()); }