#endif
// standard
-#if defined(__WINDOWS__) && !defined(__GNUWIN32__)
+#if defined(__WXMSW__) && !defined(__GNUWIN32__)
#include <io.h>
+
+ #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 <windows.h> // for GetTempFileName
#elif (defined(__UNIX__) || defined(__GNUWIN32__))
#include <unistd.h>
#else
wxFile::wxFile(const char *szFileName, OpenMode mode)
{
m_fd = fd_invalid;
+ m_error = FALSE;
Open(szFileName, mode);
}
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 {
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 {
{
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;
}
// read
off_t wxFile::Read(void *pBuf, off_t nCount)
{
- wxCHECK_RET( (pBuf != NULL) && IsOpened(), 0 );
+ wxCHECK( (pBuf != NULL) && IsOpened(), 0 );
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
}
// write
-bool wxFile::Write(const void *pBuf, uint nCount)
+uint wxFile::Write(const void *pBuf, uint nCount)
{
- wxCHECK_RET( (pBuf != NULL) && IsOpened(), 0 );
+ 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;
}
}
// ----------------------------------------------------------------------------
// 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;
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
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
#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
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:
bool wxTempFile::Open(const wxString& strName)
{
m_strName = strName;
- m_strTemp = tmpnam(NULL);
+
+ // we want to create the file in the same directory as strName because
+ // otherwise rename() in Commit() might not work (if the files are on
+ // different partitions for example). Unfortunately, the only standard
+ // (POSIX) temp file creation function tmpnam() can't do it.
+ #ifdef __UNIX__
+ static const char *szMktempSuffix = "XXXXXX";
+ m_strTemp << strName << szMktempSuffix;
+ mktemp((char *)m_strTemp.c_str()); // will do because length doesn't change
+ #else // Windows
+ 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);
}
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;
}
{
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());
}