- wxNotebookSizer and wxBookCtrlSizer are now deprecated -- the are no longer
needed, you can treat wxNotebook as any other control and put it directly
into the sizer that was wxNotebookSizer's parent sizer in old code.
-
+- wxFile methods now return wxFileOffset which may be a 64 bit integer type,
+ even on 32 bit platforms, instead of off_t and so the return value of
+ wxFile::Length(), for example, shouldn't be assigned to off_t variable any
+ more (the compiler might warn you about this).
DEPRECATED METHODS SINCE 2.4.x
All:
+- support for huge (>2 Gb) files (Tim Kosse)
- number of fixes to wxPluginManager (Rick Brice, Hans Van Leemputten)
- fixed memory leak in wxURL when using a proxy (Steven Van Ingelgem)
- fixed bug in wxDateTime::Set(jdn) when DST was in effect
wxFile is a wrapper around {\tt file descriptor.} - see also
\helpref{wxFFile}{wxffile} for a wrapper around {\tt FILE} structure.
+{\tt wxFileOffset} is used by the wxFile functions which require offsets as
+parameter or return them. If the platform supports it, wxFileOffset if a typedef
+for a native 64 bit integer, else a 32 bit integer is used for wxFileOffset.
+
\wxheading{Derived from}
None.
\end{twocollist}
Other constants defined elsewhere but used by wxFile functions are wxInvalidOffset which represents an
-invalid value of type {\it off\_t} and is returned by functions returning {\it off\_t} on error and the seek
+invalid value of type {\it wxFileOffset} and is returned by functions returning {\it wxFileOffset} on error and the seek
mode constants used with \helpref{Seek()}{wxfileseek}:
\twocolwidtha{7cm}
\membersection{wxFile::Length}\label{wxfilelength}
-\constfunc{off\_t}{Length}{\void}
+\constfunc{wxFileOffset}{Length}{\void}
Returns the length of the file.
\membersection{wxFile::Read}\label{wxfileread}
-\func{off\_t}{Read}{\param{void*}{ buffer}, \param{off\_t}{ count}}
+\func{size\_t}{Read}{\param{void*}{ buffer}, \param{size\_t}{ count}}
Reads the specified number of bytes into a buffer, returning the actual number read.
\membersection{wxFile::Seek}\label{wxfileseek}
-\func{off\_t}{Seek}{\param{off\_t }{ofs}, \param{wxSeekMode }{mode = wxFromStart}}
+\func{wxFileOffset}{Seek}{\param{wxFileOffset }{ofs}, \param{wxSeekMode }{mode = wxFromStart}}
Seeks to the specified position.
\membersection{wxFile::SeekEnd}\label{wxfileseekend}
-\func{off\_t}{SeekEnd}{\param{off\_t }{ofs = 0}}
+\func{wxFileOffset}{SeekEnd}{\param{wxFileOffset }{ofs = 0}}
Moves the file pointer to the specified number of bytes before the end of the file.
\membersection{wxFile::Tell}\label{wxfiletell}
-\constfunc{off\_t}{Tell}{\void}
+\constfunc{wxFileOffset}{Tell}{\void}
Returns the current position or wxInvalidOffset if file is not opened or if another
error occurred.
\membersection{wxFile::Write}\label{wxfilewrite}
-\func{size\_t}{Write}{\param{const void*}{ buffer}, \param{off\_t}{ count}}
+\func{size\_t}{Write}{\param{const void*}{ buffer}, \param{wxFileOffset}{ count}}
Writes the specified number of bytes from a buffer.
// read/write (unbuffered)
// returns number of bytes read or ofsInvalid on error
- off_t Read(void *pBuf, off_t nCount);
+ size_t Read(void *pBuf, size_t nCount);
// returns the number of bytes written
size_t Write(const void *pBuf, size_t nCount);
// returns true on success
// file pointer operations (return ofsInvalid on failure)
// move ptr ofs bytes related to start/current off_t/end of file
- off_t Seek(off_t ofs, wxSeekMode mode = wxFromStart);
+ wxFileOffset Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart);
// move ptr to ofs bytes before the end
- off_t SeekEnd(off_t ofs = 0) { return Seek(ofs, wxFromEnd); }
+ wxFileOffset SeekEnd(wxFileOffset ofs = 0) { return Seek(ofs, wxFromEnd); }
// get current off_t
- off_t Tell() const;
+ wxFileOffset Tell() const;
// get current file length
- off_t Length() const;
+ wxFileOffset Length() const;
// simple accessors
// is file opened?
#include "wx/list.h"
#include "wx/arrstr.h"
-#ifndef __WXWINCE__
-#include <time.h>
+#ifdef __WXWINCE__
+ #include "wx/msw/wince/time.h"
+ #include "wx/msw/private.h"
+#else
+ #include <time.h>
+#endif
+
+#ifdef __WXWINCE__
+// Nothing
+#elif !defined(__MWERKS__)
+ #include <sys/types.h>
+ #include <sys/stat.h>
+#else
+ #ifdef __MACH__
+ #include <sys/types.h>
+ #include <utime.h>
+ #include <sys/stat.h>
+ #include <unistd.h>
+ #else
+ #include <stat.h>
+ #include <unistd.h>
+ #include <unix.h>
+ #endif
+#endif
+
+#ifdef __OS2__
+// need to check for __OS2__ first since currently both
+// __OS2__ and __UNIX__ are defined.
+ #include <process.h>
+ #include "wx/os2/private.h"
+ #include <io.h>
+ #ifdef __EMX__
+ #include <unistd.h>
+ #endif
+#elif defined(__UNIX__)
+ #include <unistd.h>
+ #include <dirent.h>
#endif
+#if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
+#if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__) && !defined(__WXWINCE__)
+ #include <direct.h>
+ #include <dos.h>
+ #include <io.h>
+#endif // __WINDOWS__
+#endif // native Win compiler
+
+#if defined(__DOS__)
+ #ifdef __WATCOMC__
+ #include <direct.h>
+ #include <dos.h>
+ #include <io.h>
+ #endif
+ #ifdef __DJGPP__
+ #include <io.h>
+ #include <unistd.h>
+ #endif
+#endif
+
+#ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
+ // this (3.1 I believe) and how to test for it.
+ // If this works for Borland 4.0 as well, then no worries.
+ #include <dir.h>
+#endif
+
+#ifdef __SALFORDC__
+ #include <dir.h>
+ #include <unix.h>
+#endif
+
+#ifndef __WXWINCE__
+ #include <fcntl.h> // O_RDONLY &c
+#endif
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
#ifdef __WXWINCE__
typedef long off_t;
#else
-
-// define off_t
-#if !defined(__WXMAC__) || defined(__UNIX__) || defined(__MACH__)
- #include <sys/types.h>
-#else
- typedef long off_t;
+ // define off_t
+ #if !defined(__WXMAC__) || defined(__UNIX__) || defined(__MACH__)
+ #include <sys/types.h>
+ #else
+ typedef long off_t;
+ #endif
#endif
#if defined(__VISUALC__) || ( defined(__MWERKS__) && defined( __INTEL__) )
typedef long off_t;
#endif
-#endif
-
#if defined(__VISAGECPP__) && __IBMCPP__ >= 400
//
// VisualAge C++ V4.0 cannot have any external linkage const decs
// underscores to the usual names, some also have Unicode versions of them
// ----------------------------------------------------------------------------
+// Wrappers around Win32 api functions like CreateFile, ReadFile and such
+// Implemented in filefnwce.cpp
+#if defined( __WINCE__)
+ typedef __int64 wxFileOffset;
+ #define wxFileOffsetFmtSpec _("I64")
+ int wxOpen(const wxChar *filename, int oflag, int WXUNUSED(pmode));
+ int wxAccess(const wxChar *name, int WXUNUSED(how));
+ int wxClose(int fd);
+ int wxFsync(int WXUNUSED(fd));
+ int wxRead(int fd, void *buf, unsigned int count);
+ int wxWrite(int fd, const void *buf, unsigned int count);
+ int wxEof(int fd);
+ wxFileOffset wxSeek(int fd, wxFileOffset offset, int origin);
+ #define wxLSeek wxSeek
+ wxFileOffset wxTell(int fd);
+
+ #if wxUSE_UNICODE
+ #if wxUSE_UNICODE_MSLU
+ #define wxMkDir wxMSLU__wmkdir
+ #define wxRmDir wxMSLU__wrmdir
+ #define wxStat wxMSLU__wstat
+ #else
+ #define wxMkDir _wmkdir
+ #define wxRmDir _wrmdir
+ #define wxStat _wstat
+ #endif
+ #else // !wxUSE_UNICODE
+ #define wxMkDir _mkdir
+ #ifdef __WATCOMC__
+ #define wxRmDir rmdir
+ #else
+ #define wxRmDir _rmdir
+ #endif
+ #define wxStat _stat
+ #endif
+ #define wxStructStat struct _stat
+
// Microsoft compiler loves underscores, feed them to it
-#if defined( __VISUALC__ ) \
+#elif defined( __VISUALC__ ) \
|| ( defined(__MINGW32__) && !defined(__WINE__) && wxCHECK_W32API_VERSION( 0, 5 ) ) \
|| ( defined(__MWERKS__) && defined(__WXMSW__) ) \
|| ( defined(__DMC__) && defined(__WXMSW__) ) \
|| ( defined(__WATCOMC__) && defined(__WXMSW__) )
+
+ // Not all of the Win32 compilers do have huge file support, for example
+ // the Digitalmars compiler does not have huge file size support
+ #undef __HUGEFILES_SUPPORTED
+ #if _INTEGRAL_MAX_BITS >= 64 && !defined(__DMC__)
+ #define __HUGEFILES_SUPPORTED 1
+ #else
+ #define __HUGEFILES_SUPPORTED 0
+ #endif
+
// functions
-#if defined(__BORLANDC__) || defined(__WATCOMC__)
- #define _tell tell
-#endif
+ #if defined(__BORLANDC__) || defined(__WATCOMC__)
+ #define _tell tell
+ #endif
+
+ #if __HUGEFILES_SUPPORTED
+ typedef wxLongLong_t wxFileOffset;
+ #define wxFileOffsetFmtSpec wxLongLongFmtSpec
+ #else
+ typedef int wxFileOffset;
+ #define wxFileOffsetFmtSpec _("")
+ #endif
+
#define wxClose _close
- #define wxRead _read
- #define wxWrite _write
- #define wxLseek _lseek
+
+ #if defined(__MWERKS__)
+ #if __MSL__ >= 0x6000
+ #define wxRead _read(fd, (void *)buf, nCount)
+ #define wxWrite _write(fd, (void *)buf, nCount)
+ #else
+ #define wxRead _read(fd, (const char *)buf, nCount)
+ #define wxWrite _write(fd, (const char *)buf, nCount)
+ #endif
+ #else
+ #ifdef __DMC__
+ #define wxRead ::read
+ #define wxWrite ::write
+ #else
+ #define wxRead _read
+ #define wxWrite _write
+ #endif
+ #endif
+ #if __HUGEFILES_SUPPORTED
+ #define wxSeek _lseeki64
+ #define wxLseek _lseeki64
+ #define wxTell _telli64
+ #else
+ #define wxSeek _lseek
+ #define wxLseek _lseek
+ #define wxTell _tell
+ #endif
#define wxFsync _commit
#define wxEof _eof
- #define wxTell _tell
-
#if wxUSE_UNICODE
#if wxUSE_UNICODE_MSLU
#define wxOpen wxMSLU__wopen
#define wxAccess wxMSLU__waccess
#define wxMkDir wxMSLU__wmkdir
#define wxRmDir wxMSLU__wrmdir
- #define wxStat wxMSLU__wstat
+ #if __HUGEFILES_SUPPORTED
+ #define wxStat wxMSLU__wstati64
+ #else
+ #define wxStat wxMSLU__wstat
+ #endif
#else
#define wxOpen _wopen
#define wxAccess _waccess
#define wxMkDir _wmkdir
#define wxRmDir _wrmdir
- #define wxStat _wstat
+ #if __HUGEFILES_SUPPORTED
+ #define wxStat _wstati64
+ #else
+ #define wxStat _wstat
+ #endif
#endif
#else // !wxUSE_UNICODE
-#ifdef __BORLANDC__
- #define wxOpen open
-#else
- #define wxOpen _open
-#endif
+ #ifdef __BORLANDC__
+ #define wxOpen open
+ #else
+ #define wxOpen _open
+ #endif
#define wxAccess _access
#define wxMkDir _mkdir
-#ifdef __WATCOMC__
- #define wxRmDir rmdir
-#else
- #define wxRmDir _rmdir
-#endif
- #define wxStat _stat
+ #ifdef __WATCOMC__
+ #define wxRmDir rmdir
+ #else
+ #define wxRmDir _rmdir
+ #endif
+ #if __HUGEFILES_SUPPORTED
+ #define wxStat _stati64
+ #else
+ #define wxStat _stat
+ #endif
#endif
// types
-#if defined(__WATCOMC__)&& wxUSE_UNICODE
- #define wxStructStat struct _wstat
-#else
- #define wxStructStat struct _stat
-#endif
+ #if __HUGEFILES_SUPPORTED
+ #if wxUSE_UNICODE
+ #define wxStructStat struct _wstati64
+ #else
+ #define wxStructStat struct _stati64
+ #endif
+ #else
+ #if wxUSE_UNICODE
+ #define wxStructStat struct _wstat
+ #else
+ #define wxStructStat struct _stat
+ #endif
+ #endif
// constants (unless already defined by the user code)
#if !defined(O_RDONLY) && !defined(__BORLANDC__) && !defined(__WATCOMC__)
#define S_IFDIR _S_IFDIR
#define S_IFREG _S_IFREG
#endif // O_RDONLY
+
+ // It's a private define, undefine it so nobody gets tempted to use it
+ #undef __HUGEFILES_SUPPORTED
#else
+ typedef off_t wxFileOffset;
+ #ifdef _LARGE_FILES
+ #define wxFileOffsetFmtSpec wxLongLongFmtSpec
+ #else
+ #define wxFileOffsetFmtSpec _T("")
+ #endif
// functions
#define wxClose close
- #define wxRead read
- #define wxWrite write
+ #define wxRead ::read
+ #define wxWrite ::write
#define wxLseek lseek
+ #define wxSeek lseek
#define wxFsync commit
#define wxEof eof
#define wxStructStat struct stat
-#if wxUSE_UNICODE
-# define wxNEED_WX_UNISTD_H
-#if defined(__MWERKS__) && defined(macintosh)
- #include <sys/stat.h>
-#endif
-#if defined(__DMC__)
- typedef unsigned long mode_t;
-#endif
-WXDLLIMPEXP_BASE int wxStat( const wxChar *file_name, wxStructStat *buf );
-WXDLLIMPEXP_BASE int wxAccess( const wxChar *pathname, int mode );
-WXDLLIMPEXP_BASE int wxOpen( const wxChar *pathname, int flags, mode_t mode );
-#else
- #define wxOpen open
- #define wxStat stat
- #define wxAccess access
-#endif
+ #if wxUSE_UNICODE
+ #define wxNEED_WX_UNISTD_H
+ #if defined(__DMC__)
+ typedef unsigned long mode_t;
+ #endif
+ WXDLLIMPEXP_BASE int wxStat( const wxChar *file_name, wxStructStat *buf );
+ WXDLLIMPEXP_BASE int wxAccess( const wxChar *pathname, int mode );
+ WXDLLIMPEXP_BASE int wxOpen( const wxChar *pathname, int flags, mode_t mode );
+ #else
+ #define wxOpen open
+ #define wxStat stat
+ #define wxAccess access
+ #endif
#endif // VC++
WXDLLIMPEXP_BASE int wxMSLU__wmkdir(const wxChar *name);
WXDLLIMPEXP_BASE int wxMSLU__wrmdir(const wxChar *name);
WXDLLIMPEXP_BASE int wxMSLU__wstat(const wxChar *name, struct _stat *buffer);
+WXDLLIMPEXP_BASE int wxMSLU__wstati64(const wxChar *name, struct _stati64 *buffer);
#endif
#endif // wxUSE_UNICODE_MSLU
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-/*
- TODO: remove all the WinCE ugliness from here, implement the wxOpen(),
- wxSeek(), ... functions in a separate file for WinCE instead!!!
- */
-
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// standard
#if defined(__WXMSW__) && !defined(__GNUWIN32__) && !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
- #include <io.h>
#ifndef __SALFORDC__
#define WIN32_LEAN_AND_MEAN
#endif
char* mktemp( char * path ) { return path ;}
#include <stat.h>
- #include <unistd.h>
+ #include <unistd.h>
#else
#error "Please specify the header with file functions declarations."
#endif //Win/UNIX
#include <stdio.h> // SEEK_xxx constants
-#ifndef __WXWINCE__
-#include <fcntl.h> // O_RDONLY &c
-#endif
-
-#ifdef __WXWINCE__
-// Nothing
-#elif !defined(__MWERKS__)
- #include <sys/types.h> // needed for stat
- #include <sys/stat.h> // stat
-#elif defined(__MWERKS__) && ( defined(__WXMSW__) || defined(__MACH__) )
- #include <sys/types.h> // needed for stat
- #include <sys/stat.h> // stat
-#endif
-
// Windows compilers don't have these constants
#ifndef W_OK
enum
break;
}
-#ifdef __WXWINCE__
- // FIXME: use CreateFile with 0 access to query the file
- return true;
-#else
return wxAccess(name, how) == 0;
-#endif
}
// ----------------------------------------------------------------------------
// Dominic Mazzoni [dmazzoni+@cs.cmu.edu] reports that open is still broken on the mac, so we replace
// int fd = open( szFileName , O_CREAT | (bOverwrite ? O_TRUNC : O_EXCL), access);
int fd = creat( szFileName , accessMode);
-#else
-#ifdef __WXWINCE__
- HANDLE fileHandle = ::CreateFile(szFileName, GENERIC_WRITE, 0, NULL,
- bOverwrite ? CREATE_ALWAYS : CREATE_NEW, FILE_ATTRIBUTE_NORMAL,
- 0);
- int fd = 0;
- if (fileHandle == INVALID_HANDLE_VALUE)
- fd = (int) fileHandle;
- else
- fd = -1;
#else
int fd = wxOpen( szFileName,
O_BINARY | O_WRONLY | O_CREAT |
(bOverwrite ? O_TRUNC : O_EXCL)
ACCESS(accessMode) );
-#endif
#endif
if ( fd == -1 )
{
// open the file
bool wxFile::Open(const wxChar *szFileName, OpenMode mode, int accessMode)
{
-#ifdef __WXWINCE__
- DWORD access = 0;
- DWORD shareMode = 0;
- DWORD disposition = 0;
-
- switch ( mode )
- {
- case read:
- access = GENERIC_READ;
- shareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;
- disposition = OPEN_EXISTING;
- break;
-
- case write_append:
- if ( wxFile::Exists(szFileName) )
- {
- access = GENERIC_READ|GENERIC_WRITE;
- shareMode = FILE_SHARE_READ;
- disposition = 0;
- break;
- }
- //else: fall through as write_append is the same as write if the
- // file doesn't exist
-
- case write:
- access = GENERIC_WRITE;
- shareMode = 0;
- disposition = TRUNCATE_EXISTING;
- break;
-
- case write_excl:
- access = GENERIC_WRITE;
- shareMode = 0;
- disposition = TRUNCATE_EXISTING;
- break;
-
- case read_write:
- access = GENERIC_READ|GENERIC_WRITE;
- shareMode = 0;
- disposition = 0;
- break;
- }
-
- int fd = 0;
- HANDLE fileHandle = ::CreateFile(szFileName, access, shareMode, NULL,
- disposition, FILE_ATTRIBUTE_NORMAL, 0);
- if (fileHandle == INVALID_HANDLE_VALUE)
- fd = -1;
- else
- fd = (int) fileHandle;
-#else
int flags = O_BINARY;
switch ( mode )
#endif // __WINDOWS__
int fd = wxOpen( szFileName, flags ACCESS(accessMode));
-#endif
+
if ( fd == -1 )
{
wxLogSysError(_("can't open file '%s'"), szFileName);
bool wxFile::Close()
{
if ( IsOpened() ) {
-#ifdef __WXWINCE__
- if (!CloseHandle((HANDLE) m_fd))
-#else
- if ( close(m_fd) == -1 )
-#endif
+ if (wxClose(m_fd) == -1)
{
wxLogSysError(_("can't close file descriptor %d"), m_fd);
m_fd = fd_invalid;
// ----------------------------------------------------------------------------
// read
-off_t wxFile::Read(void *pBuf, off_t nCount)
+size_t wxFile::Read(void *pBuf, size_t nCount)
{
wxCHECK( (pBuf != NULL) && IsOpened(), 0 );
-#ifdef __WXWINCE__
- DWORD bytesRead = 0;
- int iRc = 0;
- if (ReadFile((HANDLE) m_fd, pBuf, (DWORD) nCount, & bytesRead, NULL))
- iRc = bytesRead;
- else
- iRc = -1;
-#elif defined(__MWERKS__)
- int iRc = ::read(m_fd, (char*) pBuf, nCount);
-#else
- int iRc = ::read(m_fd, pBuf, nCount);
-#endif
+ int iRc = wxRead(m_fd, pBuf, nCount);
+
if ( iRc == -1 ) {
wxLogSysError(_("can't read from file descriptor %d"), m_fd);
- return wxInvalidOffset;
+ return (size_t)wxInvalidOffset;
}
else
return (size_t)iRc;
{
wxCHECK( (pBuf != NULL) && IsOpened(), 0 );
-#ifdef __WXWINCE__
- DWORD bytesWritten = 0;
- int iRc = 0;
- if (WriteFile((HANDLE) m_fd, pBuf, (DWORD) nCount, & bytesWritten, NULL))
- iRc = bytesWritten;
- else
- iRc = -1;
-#elif defined(__MWERKS__)
-#if __MSL__ >= 0x6000
- int iRc = ::write(m_fd, (void*) pBuf, nCount);
-#else
- int iRc = ::write(m_fd, (const char*) pBuf, nCount);
-#endif
-#else
- int iRc = ::write(m_fd, pBuf, nCount);
-#endif
+ int iRc = wxWrite(m_fd, pBuf, nCount);
+
if ( iRc == -1 ) {
wxLogSysError(_("can't write to file descriptor %d"), m_fd);
m_error = true;
bool wxFile::Flush()
{
if ( IsOpened() ) {
-#ifdef __WXWINCE__
- // Do nothing
-#elif defined(__VISUALC__) || wxHAVE_FSYNC
+#if defined(__VISUALC__) || wxHAVE_FSYNC
if ( wxFsync(m_fd) == -1 )
{
wxLogSysError(_("can't flush file descriptor %d"), m_fd);
// ----------------------------------------------------------------------------
// seek
-off_t wxFile::Seek(off_t ofs, wxSeekMode mode)
+wxFileOffset wxFile::Seek(wxFileOffset ofs, wxSeekMode mode)
{
wxASSERT( IsOpened() );
-#ifdef __WXWINCE__
- int origin;
- switch ( mode ) {
- default:
- wxFAIL_MSG(_("unknown seek origin"));
-
- case wxFromStart:
- origin = FILE_BEGIN;
- break;
-
- case wxFromCurrent:
- origin = FILE_CURRENT;
- break;
-
- case wxFromEnd:
- origin = FILE_END;
- break;
- }
-
- DWORD res = SetFilePointer((HANDLE) m_fd, ofs, 0, origin) ;
- if (res == 0xFFFFFFFF && GetLastError() != NO_ERROR)
- {
- wxLogSysError(_("can't seek on file descriptor %d"), m_fd);
- return wxInvalidOffset;
- }
- else
- return (off_t)res;
-#else
int origin;
switch ( mode ) {
default:
break;
}
- int iRc = lseek(m_fd, ofs, origin);
+ 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 == -1 ) {
wxLogSysError(_("can't seek on file descriptor %d"), m_fd);
return wxInvalidOffset;
}
else
- return (off_t)iRc;
-#endif
+ return iRc;
}
-// get current off_t
-off_t wxFile::Tell() const
+// get current wxFileOffset
+wxFileOffset wxFile::Tell() const
{
wxASSERT( IsOpened() );
-#ifdef __WXWINCE__
- DWORD res = SetFilePointer((HANDLE) m_fd, 0, 0, FILE_CURRENT) ;
- if (res == 0xFFFFFFFF && GetLastError() != NO_ERROR)
- {
- wxLogSysError(_("can't get seek position on file descriptor %d"), m_fd);
- return wxInvalidOffset;
- }
- else
- return (off_t)res;
-#else
- int iRc = wxTell(m_fd);
+ wxFileOffset iRc = wxTell(m_fd);
if ( iRc == -1 ) {
wxLogSysError(_("can't get seek position on file descriptor %d"), m_fd);
return wxInvalidOffset;
}
else
- return (off_t)iRc;
-#endif
+ return iRc;
}
// get current file length
-off_t wxFile::Length() const
+wxFileOffset wxFile::Length() const
{
wxASSERT( IsOpened() );
-#ifdef __WXWINCE__
- DWORD off0 = SetFilePointer((HANDLE) m_fd, 0, 0, FILE_CURRENT);
- DWORD off1 = SetFilePointer((HANDLE) m_fd, 0, 0, FILE_END);
- off_t len = off1;
-
- // Restore position
- SetFilePointer((HANDLE) m_fd, off0, 0, FILE_BEGIN);
- return len;
-#else
-#ifdef __VISUALC__
- int iRc = _filelength(m_fd);
-#else // !VC++
- int iRc = wxTell(m_fd);
+ wxFileOffset iRc = Tell();
if ( iRc != -1 ) {
// @ have to use const_cast :-(
- int iLen = ((wxFile *)this)->SeekEnd();
+ wxFileOffset iLen = ((wxFile *)this)->SeekEnd();
if ( iLen != -1 ) {
// restore old position
if ( ((wxFile *)this)->Seek(iRc) == -1 ) {
iRc = iLen;
}
-#endif // VC++
if ( iRc == -1 ) {
wxLogSysError(_("can't find length of file on file descriptor %d"), m_fd);
return wxInvalidOffset;
}
else
- return (off_t)iRc;
-#endif
+ return iRc;
}
// is end of file reached?
{
wxASSERT( IsOpened() );
-#ifdef __WXWINCE__
- DWORD off0 = SetFilePointer((HANDLE) m_fd, 0, 0, FILE_CURRENT);
- DWORD off1 = SetFilePointer((HANDLE) m_fd, 0, 0, FILE_END);
- if (off0 == off1)
- return true;
- else
- {
- SetFilePointer((HANDLE) m_fd, off0, 0, FILE_BEGIN);
- return false;
- }
-#else
int iRc;
#if defined(__DOS__) || defined(__UNIX__) || defined(__GNUWIN32__) || defined( __MWERKS__ ) || defined(__SALFORDC__)
// @@ this doesn't work, of course, on unseekable file descriptors
- off_t ofsCur = Tell(),
+ wxFileOffset ofsCur = Tell(),
ofsMax = Length();
if ( ofsCur == wxInvalidOffset || ofsMax == wxInvalidOffset )
iRc = -1;
else
iRc = ofsCur == ofsMax;
#else // Windows and "native" compiler
- iRc = eof(m_fd);
+ iRc = wxEof(m_fd);
#endif // Windows/Unix
switch ( iRc ) {
}
return true;
-#endif
}
// ============================================================================
#include "wx/utils.h"
#include "wx/intl.h"
-#include "wx/file.h"
+#include "wx/file.h" // This does include filefn.h
#include "wx/filename.h"
#include "wx/dir.h"
#include "wx/mac/private.h" // includes mac headers
#endif
-#ifdef __WXWINCE__
-#include "wx/msw/wince/time.h"
-#include "wx/msw/private.h"
-#else
-#include <time.h>
-#endif
-
-#ifdef __WXWINCE__
-// Nothing
-#elif !defined(__MWERKS__)
- #include <sys/types.h>
- #include <sys/stat.h>
-#else
-#ifdef __MACH__
-#include <sys/types.h>
-#include <utime.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#else
- #include <stat.h>
- #include <unistd.h>
- #include <unix.h>
- #include <fcntl.h>
-#endif
-#endif
-
-#ifdef __OS2__
-// need to check for __OS2__ first since currently both
-// __OS2__ and __UNIX__ are defined.
- #include <process.h>
- #include "wx/os2/private.h"
-#ifdef __EMX__
- #include <unistd.h>
-#endif
-#elif defined(__UNIX__)
- #include <unistd.h>
- #include <dirent.h>
- #include <fcntl.h>
-#endif
-
-#if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
-#if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__) && !defined(__WXWINCE__)
- #include <direct.h>
- #include <dos.h>
- #include <io.h>
-#endif // __WINDOWS__
-#endif // native Win compiler
-
-#if defined(__DOS__)
- #ifdef __WATCOMC__
- #include <direct.h>
- #include <dos.h>
- #include <io.h>
- #endif
- #ifdef __DJGPP__
- #include <unistd.h>
- #endif
-#endif
-
-#ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
- // this (3.1 I believe) and how to test for it.
- // If this works for Borland 4.0 as well, then no worries.
- #include <dir.h>
-#endif
-
-#ifdef __SALFORDC__
- #include <dir.h>
- #include <unix.h>
-#endif
-
#include "wx/log.h"
// No, Cygwin doesn't appear to have fnmatch.h after all.
#include "wx/msw/wrapwin.h"
#include "wx/msw/mslu.h"
- // for _getcwd
- #ifdef __MINGW32__
- #include <io.h>
- #endif
-
// sys/cygwin.h is needed for cygwin_conv_to_full_win32_path()
//
// note that it must be included after <windows.h>
return _wstat(name, buffer);
}
+WXDLLIMPEXP_BASE int wxMSLU__wstati64(const wxChar *name, struct _stati64 *buffer)
+{
+ if ( wxUsingUnicowsDll() )
+ return _stati64((const char*)wxConvFile.cWX2MB(name), buffer);
+ else
+ return _wstati64(name, buffer);
+}
+
#endif // compilers having wopen() &c
#endif // wxUSE_BASE
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: filefn.cpp
+// Purpose: File- and directory-related functions
+// Author: Julian Smart
+// Modified by:
+// Created: 29/01/98
+// RCS-ID: $Id$
+// Copyright: (c) 1998 Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
+ #pragma implementation "filefn.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+#include "wx/defs.h"
+#include "wx/file.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+#ifdef __WINCE__
+
+int wxOpen(const wxChar *filename, int oflag, int WXUNUSED(pmode))
+{
+ DWORD access = 0;
+ DWORD shareMode = 0;
+ DWORD disposition = 0;
+
+ if ((oflag & (O_RDONLY | O_WRONLY | O_RDWR)) == O_RDONLY)
+ {
+ access = GENERIC_READ;
+ shareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;
+ disposition |= OPEN_EXISTING;
+ }
+ else if ((oflag & (O_RDONLY | O_WRONLY | O_RDWR)) == O_WRONLY)
+ {
+ access = GENERIC_WRITE;
+ }
+ else if ((oflag & (O_RDONLY | O_WRONLY | O_RDWR)) == O_RDWR)
+ {
+ access = GENERIC_READ|GENERIC_WRITE;
+ }
+ if (oflag & O_APPEND)
+ {
+ if ( wxFile::Exists(filename) )
+ {
+ access |= GENERIC_WRITE;
+ shareMode = FILE_SHARE_READ;
+ disposition = OPEN_EXISTING;
+ }
+ //else: fall through as write_append is the same as write if the
+ // file doesn't exist
+ else
+ oflag |= O_TRUNC;
+ }
+ if (oflag & O_TRUNC)
+ {
+ access |= GENERIC_WRITE;
+ shareMode = 0;
+ disposition = (oflag & O_CREAT) ? CREATE_ALWAYS : TRUNCATE_EXISTING;
+ }
+ else if (oflag & O_CREAT)
+ {
+ access |= GENERIC_WRITE;
+ shareMode = 0;
+ disposition = CREATE_NEW;
+ }
+ else if (oflag & O_EXCL)
+ {
+ access |= GENERIC_WRITE;
+ shareMode = 0;
+ disposition = TRUNCATE_EXISTING;
+ }
+
+ int fd = 0;
+ HANDLE fileHandle = ::CreateFile(filename, access, shareMode, NULL,
+ disposition, FILE_ATTRIBUTE_NORMAL, 0);
+ if (fileHandle == INVALID_HANDLE_VALUE)
+ fd = -1;
+ else
+ fd = (int) fileHandle;
+
+ return fd;
+}
+
+int wxAccess(const wxChar *name, int WXUNUSED(how))
+{
+ HANDLE fileHandle = ::CreateFile(name, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
+
+ if (fileHandle == INVALID_HANDLE_VALUE)
+ return -1;
+
+ CloseHandle(fileHandle);
+
+ return 0;
+}
+
+int wxClose(int fd)
+{
+ if (CloseHandle((HANDLE)fd))
+ return 0;
+ return -1;
+}
+
+int wxEof(int fd)
+{
+ LONG high0 = 0;
+ DWORD off0 = SetFilePointer((HANDLE) fd, 0, &high0, FILE_CURRENT);
+ if (off0 == 0xFFFFFFFF && GetLastError() != NO_ERROR)
+ return -1;
+
+ LONG high1 = 0;
+ DWORD off1 = SetFilePointer((HANDLE) fd, 0, &high0, FILE_END);
+ if (off1 == 0xFFFFFFFF && GetLastError() != NO_ERROR)
+ return -1;
+
+ if (off0 == off1 && high0 == high1)
+ return 1;
+ else
+ {
+ SetFilePointer((HANDLE) fd, off0, &high0, FILE_BEGIN);
+ return 0;
+ }
+}
+
+int wxRead(int fd, void *buf, unsigned int count)
+{
+ DWORD bytesRead = 0;
+
+ if (ReadFile((HANDLE) fd, buf, (DWORD) count, &bytesRead, NULL))
+ return bytesRead;
+ else
+ return -1;
+}
+
+int wxWrite(int fd, const void *buf, unsigned int count)
+{
+ DWORD bytesWritten = 0;
+
+ if (WriteFile((HANDLE) fd, buf, (DWORD) count, &bytesWritten, NULL))
+ return bytesWritten;
+ else
+ return -1;
+}
+
+__int64 wxSeek(int fd, __int64 offset, int origin)
+{
+ int method;
+ switch ( origin ) {
+ default:
+ wxFAIL_MSG(_("unknown seek origin"));
+
+ case SEEK_SET:
+ method = FILE_BEGIN;
+ break;
+
+ case SEEK_CUR:
+ method = FILE_CURRENT;
+ break;
+
+ case SEEK_END:
+ method = FILE_END;
+ break;
+ }
+
+ LONG high = 0;
+ DWORD res = SetFilePointer((HANDLE) fd, offset, &high, method) ;
+ if (res == 0xFFFFFFFF && GetLastError() != NO_ERROR)
+ {
+ wxLogSysError(_("can't seek on file descriptor %d"), fd);
+ return wxInvalidOffset;
+ }
+ else
+ return (off_t)res;
+}
+
+__int64 wxTell(int fd)
+{
+ LONG high = 0;
+ DWORD res = SetFilePointer((HANDLE) fd, 0, &high, FILE_CURRENT) ;
+ if (res == 0xFFFFFFFF && GetLastError() != NO_ERROR)
+ {
+ wxLogSysError(_("can't get seek position on file descriptor %d"), fd);
+ return wxInvalidOffset;
+ }
+ else
+ return res + (((__int64)high) << 32);
+}
+
+int wxFsync(int WXUNUSED(fd))
+{
+ return 0;
+}
+
+#endif //__WINCE__