// read/write (unbuffered)
// returns number of bytes read or ofsInvalid on error
- wxFileSize_t Read(void *pBuf, wxFileSize_t nCount);
+ size_t Read(void *pBuf, size_t nCount);
// returns the number of bytes written
- wxFileSize_t Write(const void *pBuf, wxFileSize_t nCount);
+ size_t Write(const void *pBuf, size_t nCount);
// returns true on success
bool Write(const wxString& s, wxMBConv& conv = wxConvUTF8)
{
const wxWX2MBbuf buf = s.mb_str(conv);
- wxFileSize_t size = strlen(buf);
+ size_t size = strlen(buf);
return Write((const char *) buf, size) == size;
}
// flush data not yet written
bool Flush();
- // file pointer operations (return ofsInvalid on failure)
- // move ptr ofs bytes related to start/current off_t/end of file
- wxFileSize_t Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart);
+ // file pointer operations (return wxInvalidOffset on failure)
+ // move ptr ofs bytes related to start/current offset/end of file
+ wxFileOffset Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart);
// move ptr to ofs bytes before the end
- wxFileSize_t SeekEnd(wxFileOffset ofs = 0) { return Seek(ofs, wxFromEnd); }
- // get current off_t
- wxFileSize_t Tell() const;
+ wxFileOffset SeekEnd(wxFileOffset ofs = 0) { return Seek(ofs, wxFromEnd); }
+ // get current offset
+ wxFileOffset Tell() const;
// get current file length
- wxFileSize_t Length() const;
+ wxFileOffset Length() const;
// simple accessors
// is file opened?
bool IsOpened() const { return m_file.IsOpened(); }
// I/O (both functions return true on success, false on failure)
- bool Write(const void *p, wxFileSize_t n) { return m_file.Write(p, n) == n; }
+ bool Write(const void *p, size_t n) { return m_file.Write(p, n) == n; }
bool Write(const wxString& str, wxMBConv& conv = wxConvUTF8)
{ return m_file.Write(str, conv); }
// Implemented in filefnwce.cpp
#if defined( __WXWINCE__)
typedef __int64 wxFileOffset;
- typedef unsigned __int64 wxFileSize_t;
#define wxFileOffsetFmtSpec _("I64")
int wxOpen(const wxChar *filename, int oflag, int WXUNUSED(pmode));
int wxAccess(const wxChar *name, int WXUNUSED(how));
#if wxHAS_HUGE_FILES
typedef wxLongLong_t wxFileOffset;
- typedef unsigned wxLongLong_t wxFileSize_t;
#define wxFileOffsetFmtSpec wxLongLongFmtSpec
#else
typedef off_t wxFileOffset;
- typedef unsigned long wxFileSize_t;
#endif
#define wxClose _close
_write(fd, (const char *)buf, nCount)
#endif
#else
- #if defined(__WATCOMC__)
- inline wxFileSize_t wxRead( int handle, void *buffer, wxFileSize_t len )
- { return ::read( handle, buffer, (unsigned int)len ); }
- inline wxFileSize_t wxWrite( int handle, const void *buffer, wxFileSize_t len )
- { return ::write( handle, buffer, (unsigned int)len ); }
- #elif defined(__DMC__)
+ #if defined(__DMC__) || defined(__WATCOMC__)
#define wxRead ::read
#define wxWrite ::write
#else
#define wxFileOffsetFmtSpec wxLongLongFmtSpec
wxCOMPILE_TIME_ASSERT( sizeof(off_t) == sizeof(wxLongLong_t),
BadFileSizeType );
- typedef unsigned wxLongLong_t wxFileSize_t;
#else
#define wxFileOffsetFmtSpec _T("")
- typedef unsigned long wxFileSize_t;
#endif
// functions
#define wxClose close
// VisualAge C++ V4.0 cannot have any external linkage const decs
// in headers included by more than one primary source
//
-extern const wxFileSize_t wxInvalidOffset;
+extern const int wxInvalidOffset;
#else
-const wxFileSize_t wxInvalidOffset = (wxFileSize_t)-1;
+const int wxInvalidOffset = -1;
#endif
// ----------------------------------------------------------------------------
#include <stdio.h>
#include "wx/object.h"
#include "wx/string.h"
-#include "wx/filefn.h" // for off_t, wxInvalidOffset and wxSeekMode
+#include "wx/filefn.h" // for wxFileOffset, wxInvalidOffset and wxSeekMode
class WXDLLIMPEXP_BASE wxStreamBase;
class WXDLLIMPEXP_BASE wxInputStream;
wxPuts(_T("File dump:\n----------"));
- static const off_t len = 1024;
+ static const size_t len = 1024;
wxChar buf[len];
for ( ;; )
{
- off_t nRead = file.Read(buf, len);
- if ( nRead == wxInvalidOffset )
+ size_t nRead = file.Read(buf, len);
+ if ( nRead == (size_t)wxInvalidOffset )
{
wxPrintf(_T("Failed to read the file."));
break;
#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
// ============================================================================
// ----------------------------------------------------------------------------
// read
-wxFileSize_t wxFile::Read(void *pBuf, wxFileSize_t nCount)
+size_t wxFile::Read(void *pBuf, size_t nCount)
{
wxCHECK( (pBuf != NULL) && IsOpened(), 0 );
- wxFileSize_t iRc = wxRead(m_fd, pBuf, nCount);
+ ssize_t iRc = wxRead(m_fd, pBuf, nCount);
- if ( iRc == wxInvalidOffset )
+ if ( iRc == -1 )
{
wxLogSysError(_("can't read from file descriptor %d"), m_fd);
+ return (size_t)wxInvalidOffset;
}
return iRc;
}
// write
-wxFileSize_t wxFile::Write(const void *pBuf, wxFileSize_t nCount)
+size_t wxFile::Write(const void *pBuf, size_t nCount)
{
wxCHECK( (pBuf != NULL) && IsOpened(), 0 );
- wxFileSize_t iRc = wxWrite(m_fd, pBuf, nCount);
+ ssize_t iRc = wxWrite(m_fd, pBuf, nCount);
- if ( iRc == wxInvalidOffset )
+ if ( iRc == -1 )
{
wxLogSysError(_("can't write to file descriptor %d"), m_fd);
m_error = true;
iRc = 0;
}
- return (wxFileSize_t)iRc;
+ return iRc;
}
// flush
// ----------------------------------------------------------------------------
// seek
-wxFileSize_t wxFile::Seek(wxFileOffset ofs, wxSeekMode mode)
+wxFileOffset wxFile::Seek(wxFileOffset ofs, wxSeekMode mode)
{
wxASSERT( IsOpened() );
break;
}
- if (ofs == (wxFileOffset) wxInvalidOffset)
+ if (ofs == wxInvalidOffset)
{
wxLogSysError(_("can't seek on file descriptor %d, large files support is not enabled."), m_fd);
return wxInvalidOffset;
}
- wxFileSize_t iRc = wxSeek(m_fd, ofs, origin);
+ wxFileOffset iRc = wxSeek(m_fd, ofs, origin);
if ( iRc == wxInvalidOffset )
{
wxLogSysError(_("can't seek on file descriptor %d"), m_fd);
}
// get current file offset
-wxFileSize_t wxFile::Tell() const
+wxFileOffset wxFile::Tell() const
{
wxASSERT( IsOpened() );
- wxFileSize_t iRc = wxTell(m_fd);
+ wxFileOffset iRc = wxTell(m_fd);
if ( iRc == wxInvalidOffset )
{
wxLogSysError(_("can't get seek position on file descriptor %d"), m_fd);
}
// get current file length
-wxFileSize_t wxFile::Length() const
+wxFileOffset wxFile::Length() const
{
wxASSERT( IsOpened() );
- wxFileSize_t iRc = Tell();
+ wxFileOffset iRc = Tell();
if ( iRc != wxInvalidOffset ) {
// have to use const_cast :-(
- wxFileSize_t iLen = ((wxFile *)this)->SeekEnd();
+ wxFileOffset iLen = ((wxFile *)this)->SeekEnd();
if ( iLen != wxInvalidOffset ) {
// restore old position
if ( ((wxFile *)this)->Seek(iRc) == wxInvalidOffset ) {
{
wxASSERT( IsOpened() );
- wxFileSize_t iRc;
+ wxFileOffset iRc;
#if defined(__DOS__) || defined(__UNIX__) || defined(__GNUWIN32__) || defined( __MWERKS__ ) || defined(__SALFORDC__)
// @@ this doesn't work, of course, on unseekable file descriptors
- wxFileSize_t ofsCur = Tell(),
+ wxFileOffset ofsCur = Tell(),
ofsMax = Length();
if ( ofsCur == wxInvalidOffset || ofsMax == wxInvalidOffset )
iRc = wxInvalidOffset;
// VisualAge C++ V4.0 cannot have any external linkage const decs
// in headers included by more than one primary source
//
-const wxFileSize_t wxInvalidOffset = (wxFileSize_t)-1;
+const int wxInvalidOffset = -1;
#endif
// ----------------------------------------------------------------------------
if ( !m_f->Read(buf, WXSIZEOF(buf)) )
return false;
- m_f->SeekI(-(off_t)WXSIZEOF(buf), wxFromCurrent);
+ m_f->SeekI(-(wxFileOffset)WXSIZEOF(buf), wxFromCurrent);
return memcmp(buf, "GIF", WXSIZEOF(buf)) == 0;
}
wxInt32 dbuf[4];
wxInt8 bbuf[4];
- wxFileSize_t offset = 0; // keep gcc quiet
+ wxFileOffset offset = 0; // keep gcc quiet
if ( IsBmp )
{
// read the header off the .BMP format file
bool wxImageHandler::CallDoCanRead(wxInputStream& stream)
{
- wxFileSize_t posOld = stream.TellI();
+ wxFileOffset posOld = stream.TellI();
if ( posOld == wxInvalidOffset )
{
// can't test unseekable stream
if ( !m_f->Read(buf, WXSIZEOF(buf)) )
return false;
- m_f->SeekI(-(off_t)WXSIZEOF(buf), wxFromCurrent);
+ m_f->SeekI(-(wxFileOffset)WXSIZEOF(buf), wxFromCurrent);
return (memcmp(buf, "FORM", 4) == 0) && (memcmp(buf+8, "ILBM", 4) == 0);
}
}
// compute file length
- off_t currentPos = m_f->TellI();
+ wxFileOffset currentPos = m_f->TellI();
m_f->SeekI(0, wxFromEnd);
long filesize = m_f->TellI();
m_f->SeekI(currentPos, wxFromStart);
default: mode = wxFromCurrent; break;
}
- return (toff_t)stream->SeekI( (off_t)off, mode );
+ return (toff_t)stream->SeekI( (wxFileOffset)off, mode );
}
toff_t TIFFLINKAGEMODE
default: mode = wxFromCurrent; break;
}
- return (toff_t)stream->SeekO( (off_t)off, mode );
+ return (toff_t)stream->SeekO( (wxFileOffset)off, mode );
}
int TIFFLINKAGEMODE
<< wxPATH_SEP;
}
+ // TODO: use wxStandardPaths instead of all this mess!!
+
// LC_PATH is a standard env var containing the search path for the .mo
// files
#ifndef __WXWINCE__
// then take the current directory
// FIXME it should be the directory of the executable
-#ifdef __WXMAC__
- wxChar cwd[512] ;
- wxGetWorkingDirectory( cwd , sizeof( cwd ) ) ;
- searchPath << GetAllMsgCatalogSubdirs(cwd, lang);
+#if defined(__WXMAC__)
+ searchPath << GetAllMsgCatalogSubdirs(wxGetCwd(), lang);
// generic search paths could be somewhere in the system folder preferences
-#else // !Mac
+#elif defined(__WXMSW__)
+ // look in the directory of the executable
+ wxString path;
+ wxSplitPath(wxGetFullModuleName(), &path, NULL, NULL);
+ searchPath << GetAllMsgCatalogSubdirs(path, lang);
+#else // !Mac, !MSW
searchPath << GetAllMsgCatalogSubdirs(wxT("."), lang);
-
#endif // platform
return searchPath;
return false;
// get the file size (assume it is less than 4Gb...)
- wxFileSize_t nSize = fileMsg.Length();
+ wxFileOffset nSize = fileMsg.Length();
if ( nSize == wxInvalidOffset )
return false;
// read the whole file in memory
m_pData = new size_t8[nSize];
- if ( fileMsg.Read(m_pData, nSize) != nSize ) {
+ if ( fileMsg.Read(m_pData, nSize) != nSize + (size_t)0 ) {
wxDELETEA(m_pData);
return false;
}
// examine header
- bool bValid = nSize > sizeof(wxMsgCatalogHeader);
+ bool bValid = nSize + (size_t)0 > sizeof(wxMsgCatalogHeader);
wxMsgCatalogHeader *pHeader = (wxMsgCatalogHeader *)m_pData;
if ( bValid ) {
default:
wxFAIL_MSG( _T("invalid seek mode") );
- return (wxFileOffset) wxInvalidOffset;
+ return wxInvalidOffset;
}
if (diff < 0 || diff > last_access)
- return (wxFileOffset) wxInvalidOffset;
+ return wxInvalidOffset;
SetIntPosition(diff);
return diff;
}
return ret_off;
}
- return (wxFileOffset) wxInvalidOffset;
+ return wxInvalidOffset;
}
wxFileOffset wxStreamBuffer::Tell() const
{
- wxFileSize_t pos;
+ wxFileOffset pos;
// ask the stream for position if we have a real one
if ( m_stream )
{
pos = m_stream->OnSysTell();
if ( pos == wxInvalidOffset )
- return (wxFileOffset) wxInvalidOffset;
+ return wxInvalidOffset;
}
else // no associated stream
{
wxFileOffset wxStreamBase::OnSysSeek(wxFileOffset WXUNUSED(seek), wxSeekMode WXUNUSED(mode))
{
- return (wxFileOffset) wxInvalidOffset;
+ return wxInvalidOffset;
}
wxFileOffset wxStreamBase::OnSysTell() const
{
- return (wxFileOffset) wxInvalidOffset;
+ return wxInvalidOffset;
}
// ----------------------------------------------------------------------------
wxFileOffset wxInputStream::TellI() const
{
- wxFileSize_t pos = OnSysTell();
+ wxFileOffset pos = OnSysTell();
if (pos != wxInvalidOffset)
pos -= (m_wbacksize - m_wbackcur);
default:
wxFAIL_MSG( _T("invalid seek mode") );
- return (wxFileOffset) wxInvalidOffset;
+ return wxInvalidOffset;
}
if (m_currentPos > m_lastcount)
wxFileOffset wxBufferedInputStream::TellI() const
{
- wxFileSize_t pos = m_i_streambuf->Tell();
+ wxFileOffset pos = m_i_streambuf->Tell();
if (pos != wxInvalidOffset)
pos -= (m_wbacksize - m_wbackcur);
char *strBuf, *strPtr, *strEnd;
char ch, chLast = '\0';
char buf[1024];
- wxFileSize_t nRead;
+ size_t nRead;
strPtr = strBuf = new char[1024];
strEnd = strBuf + 1024;
do
{
nRead = m_file.Read(buf, WXSIZEOF(buf));
- if ( nRead == wxInvalidOffset )
+ if ( nRead == (size_t)wxInvalidOffset )
{
// read error (error message already given in wxFile::Read)
delete[] strBuf;
return false;
}
- for (wxFileSize_t n = 0; n < nRead; n++)
+ for (size_t n = 0; n < nRead; n++)
{
ch = buf[n];
switch ( ch )
size_t wxFileInputStream::OnSysRead(void *buffer, size_t size)
{
- wxFileSize_t ret = m_file->Read(buffer, size);
+ size_t ret = m_file->Read(buffer, size);
// NB: we can't use a switch here because HP-UX CC doesn't allow
- // switching over long long (which off_t is in 64bit mode)
+ // switching over long long (which size_t is in 64bit mode)
if ( !ret )
{
// nothing read, so nothing more to read
m_lasterror = wxSTREAM_EOF;
}
- else if ( ret == wxInvalidOffset )
+ else if ( ret == (size_t)wxInvalidOffset )
{
m_lasterror = wxSTREAM_READ_ERROR;
ret = 0;
size_t wxFFileInputStream::OnSysRead(void *buffer, size_t size)
{
- wxFileSize_t ret = m_file->Read(buffer, size);
+ size_t ret = m_file->Read(buffer, size);
if (m_file->Eof())
m_lasterror = wxSTREAM_EOF;
- if (ret == wxInvalidOffset)
+ if (ret == (size_t)wxInvalidOffset)
{
m_lasterror = wxSTREAM_READ_ERROR;
ret = 0;
#ifdef __VMS
#pragma message disable intsignchange
#endif
- return ( m_file->Seek(pos, mode) ? m_file->Tell() : wxInvalidOffset );
+ return ( m_file->Seek(pos, mode) ? (wxFileOffset)m_file->Tell() : wxInvalidOffset );
#ifdef __VMS
#pragma message enable intsignchange
#endif
#ifdef __VMS
#pragma message disable intsignchange
#endif
- return ( m_file->Seek(pos, mode) ? m_file->Tell() : wxInvalidOffset );
+ return ( m_file->Seek(pos, mode) ? (wxFileOffset)m_file->Tell() : wxInvalidOffset );
#ifdef __VMS
#pragma message enable intsignchange
#endif
if ( !stream.Read(buf, WXSIZEOF(buf)) )
return false;
- stream.SeekI(-(off_t)WXSIZEOF(buf), wxFromCurrent);
+ stream.SeekI(-(wxFileOffset)WXSIZEOF(buf), wxFromCurrent);
return memcmp(buf, "/* XPM */", WXSIZEOF(buf)) == 0;
}
/// See wxInputStream
virtual size_t OnSysRead(void *buffer, size_t bufsize);
/// See wxInputStream
- virtual off_t OnSysSeek(off_t seek, wxSeekMode mode);
+ virtual wxFileOffset OnSysSeek(wxFileOffset seek, wxSeekMode mode);
/// See wxInputStream
- virtual off_t OnSysTell() const { return m_pos; }
+ virtual wxFileOffset OnSysTell() const { return m_pos; }
private:
size_t m_size;
- off_t m_pos;
+ wxFileOffset m_pos;
bool m_simulateHHP;
char * m_content;
-off_t wxChmInputStream::OnSysSeek(off_t seek, wxSeekMode mode)
+wxFileOffset wxChmInputStream::OnSysSeek(wxFileOffset seek, wxSeekMode mode)
{
wxString mode_str = wxEmptyString;
}
m_lasterror = wxSTREAM_NO_ERROR;
- off_t nextpos;
+ wxFileOffset nextpos;
switch ( mode )
{
pBmpInfo->bmiHeader.biClrUsed : 1 << pBmpInfo->bmiHeader.biBitCount;
if (nColors < 1
|| file.Read(pBmpInfo->bmiColors, nColors * sizeof(RGBQUAD))
- == (off_t)(nColors * sizeof(RGBQUAD))) {
+ == nColors * sizeof(RGBQUAD)) {
// So how big the bitmap surface is.
int nBitsSize = BmpFileHdr.bfSize - BmpFileHdr.bfOffBits;
void Attach(HINTERNET hFile);
- off_t SeekI( off_t WXUNUSED(pos), wxSeekMode WXUNUSED(mode) )
+ wxFileOffset SeekI( wxFileOffset WXUNUSED(pos), wxSeekMode WXUNUSED(mode) )
{ return -1; }
- off_t TellI() const
+ wxFileOffset TellI() const
{ return -1; }
protected:
}
char buf[256];
- wxFileSize_t count = file.Read(buf, WXSIZEOF(buf));
- if ( count == wxInvalidOffset )
+ size_t count = file.Read(buf, WXSIZEOF(buf));
+ if ( count == (size_t)wxInvalidOffset )
{
wxLogError(_("Failed to read PID from lock file."));
}
CPPUNIT_ASSERT(stream_in.TellI() == 1);
if (!m_bSimpleTellITest)
{
- off_t pos = stream_in.SeekI(5, wxFromStart);
+ wxFileOffset pos = stream_in.SeekI(5, wxFromStart);
CPPUNIT_ASSERT(stream_in.TellI() == pos);
(void)stream_in.GetC();
CPPUNIT_ASSERT(stream_in.TellI() == 6);
TStreamOut &stream_out = CreateOutStream();
char *buf = "Some text";
- off_t i;
- off_t len = (off_t) strlen(buf);
+ int i;
+ int len = strlen(buf);
for (i = 0; i < len; i++)
stream_out.PutC(buf[i]);
// Do the buffer version.
char *buf = "Some text";
- off_t len = (off_t) strlen(buf);
+ int len = strlen(buf);
(void)stream_out.Write(buf, len);
CPPUNIT_ASSERT(stream_out.TellO() == len);
char *buf = new char[len + 1];
buf[len] = '\0';
- if ( (wxFileOffset)file.Read(buf, len) == wxInvalidOffset ) {
+ if ( file.Read(buf, len) == (size_t)wxInvalidOffset ) {
delete [] buf;
return false;
char *buf = new char[len + 1];
buf[len] = '\0';
- if ( (wxFileOffset)file.Read(buf, len) == wxInvalidOffset ) {
+ if ( file.Read(buf, len) == (size_t)wxInvalidOffset ) {
delete [] buf;
return false;
/*
$Log$
+ Revision 1.32 2004/11/10 21:02:58 VZ
+ new set of fixes for problems due to huge files support: drop wxFileSize_t, use wxFileOffset only, make wxInvalidOffset an int (main part of the patch 1063498)
+
Revision 1.31 2004/10/05 15:38:29 ABX
Warning fixes found under hardest mode of OpenWatcom. Seems clean in Borland, MinGW and DMC.