support for huge files (patch 1002226)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29355 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -150,7 +150,10 @@ INCOMPATIBLE CHANGES SINCE 2.4.x
|
|||||||
- wxNotebookSizer and wxBookCtrlSizer are now deprecated -- the are no longer
|
- wxNotebookSizer and wxBookCtrlSizer are now deprecated -- the are no longer
|
||||||
needed, you can treat wxNotebook as any other control and put it directly
|
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.
|
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
|
DEPRECATED METHODS SINCE 2.4.x
|
||||||
@@ -198,6 +201,7 @@ OTHER CHANGES
|
|||||||
|
|
||||||
All:
|
All:
|
||||||
|
|
||||||
|
- support for huge (>2 Gb) files (Tim Kosse)
|
||||||
- number of fixes to wxPluginManager (Rick Brice, Hans Van Leemputten)
|
- number of fixes to wxPluginManager (Rick Brice, Hans Van Leemputten)
|
||||||
- fixed memory leak in wxURL when using a proxy (Steven Van Ingelgem)
|
- fixed memory leak in wxURL when using a proxy (Steven Van Ingelgem)
|
||||||
- fixed bug in wxDateTime::Set(jdn) when DST was in effect
|
- fixed bug in wxDateTime::Set(jdn) when DST was in effect
|
||||||
|
@@ -19,6 +19,10 @@ its destructor making it unnecessary to worry about forgetting to do it.
|
|||||||
wxFile is a wrapper around {\tt file descriptor.} - see also
|
wxFile is a wrapper around {\tt file descriptor.} - see also
|
||||||
\helpref{wxFFile}{wxffile} for a wrapper around {\tt FILE} structure.
|
\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}
|
\wxheading{Derived from}
|
||||||
|
|
||||||
None.
|
None.
|
||||||
@@ -70,7 +74,7 @@ Will fail if the file already exists, else create and open it atomically. Usefu
|
|||||||
\end{twocollist}
|
\end{twocollist}
|
||||||
|
|
||||||
Other constants defined elsewhere but used by wxFile functions are wxInvalidOffset which represents an
|
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}:
|
mode constants used with \helpref{Seek()}{wxfileseek}:
|
||||||
|
|
||||||
\twocolwidtha{7cm}
|
\twocolwidtha{7cm}
|
||||||
@@ -204,7 +208,7 @@ Returns true if the file has been opened.
|
|||||||
|
|
||||||
\membersection{wxFile::Length}\label{wxfilelength}
|
\membersection{wxFile::Length}\label{wxfilelength}
|
||||||
|
|
||||||
\constfunc{off\_t}{Length}{\void}
|
\constfunc{wxFileOffset}{Length}{\void}
|
||||||
|
|
||||||
Returns the length of the file.
|
Returns the length of the file.
|
||||||
|
|
||||||
@@ -222,7 +226,7 @@ Opens the file, returning true if successful.
|
|||||||
|
|
||||||
\membersection{wxFile::Read}\label{wxfileread}
|
\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.
|
Reads the specified number of bytes into a buffer, returning the actual number read.
|
||||||
|
|
||||||
@@ -238,7 +242,7 @@ The number of bytes read, or the symbol {\bf wxInvalidOffset} (-1) if there was
|
|||||||
|
|
||||||
\membersection{wxFile::Seek}\label{wxfileseek}
|
\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.
|
Seeks to the specified position.
|
||||||
|
|
||||||
@@ -254,7 +258,7 @@ The actual offset position achieved, or wxInvalidOffset on failure.
|
|||||||
|
|
||||||
\membersection{wxFile::SeekEnd}\label{wxfileseekend}
|
\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.
|
Moves the file pointer to the specified number of bytes before the end of the file.
|
||||||
|
|
||||||
@@ -268,14 +272,14 @@ The actual offset position achieved, or wxInvalidOffset on failure.
|
|||||||
|
|
||||||
\membersection{wxFile::Tell}\label{wxfiletell}
|
\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
|
Returns the current position or wxInvalidOffset if file is not opened or if another
|
||||||
error occurred.
|
error occurred.
|
||||||
|
|
||||||
\membersection{wxFile::Write}\label{wxfilewrite}
|
\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.
|
Writes the specified number of bytes from a buffer.
|
||||||
|
|
||||||
|
@@ -95,7 +95,7 @@ public:
|
|||||||
|
|
||||||
// read/write (unbuffered)
|
// read/write (unbuffered)
|
||||||
// returns number of bytes read or ofsInvalid on error
|
// 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
|
// returns the number of bytes written
|
||||||
size_t Write(const void *pBuf, size_t nCount);
|
size_t Write(const void *pBuf, size_t nCount);
|
||||||
// returns true on success
|
// returns true on success
|
||||||
@@ -110,13 +110,13 @@ public:
|
|||||||
|
|
||||||
// file pointer operations (return ofsInvalid on failure)
|
// file pointer operations (return ofsInvalid on failure)
|
||||||
// move ptr ofs bytes related to start/current off_t/end of file
|
// 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
|
// 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
|
// get current off_t
|
||||||
off_t Tell() const;
|
wxFileOffset Tell() const;
|
||||||
// get current file length
|
// get current file length
|
||||||
off_t Length() const;
|
wxFileOffset Length() const;
|
||||||
|
|
||||||
// simple accessors
|
// simple accessors
|
||||||
// is file opened?
|
// is file opened?
|
||||||
|
@@ -19,10 +19,79 @@
|
|||||||
#include "wx/list.h"
|
#include "wx/list.h"
|
||||||
#include "wx/arrstr.h"
|
#include "wx/arrstr.h"
|
||||||
|
|
||||||
#ifndef __WXWINCE__
|
#ifdef __WXWINCE__
|
||||||
#include <time.h>
|
#include "wx/msw/wince/time.h"
|
||||||
|
#include "wx/msw/private.h"
|
||||||
|
#else
|
||||||
|
#include <time.h>
|
||||||
#endif
|
#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
|
// constants
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -30,12 +99,12 @@
|
|||||||
#ifdef __WXWINCE__
|
#ifdef __WXWINCE__
|
||||||
typedef long off_t;
|
typedef long off_t;
|
||||||
#else
|
#else
|
||||||
|
// define off_t
|
||||||
// define off_t
|
#if !defined(__WXMAC__) || defined(__UNIX__) || defined(__MACH__)
|
||||||
#if !defined(__WXMAC__) || defined(__UNIX__) || defined(__MACH__)
|
#include <sys/types.h>
|
||||||
#include <sys/types.h>
|
#else
|
||||||
#else
|
typedef long off_t;
|
||||||
typedef long off_t;
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__VISUALC__) || ( defined(__MWERKS__) && defined( __INTEL__) )
|
#if defined(__VISUALC__) || ( defined(__MWERKS__) && defined( __INTEL__) )
|
||||||
@@ -46,8 +115,6 @@
|
|||||||
typedef long off_t;
|
typedef long off_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__VISAGECPP__) && __IBMCPP__ >= 400
|
#if defined(__VISAGECPP__) && __IBMCPP__ >= 400
|
||||||
//
|
//
|
||||||
// VisualAge C++ V4.0 cannot have any external linkage const decs
|
// VisualAge C++ V4.0 cannot have any external linkage const decs
|
||||||
@@ -70,25 +137,103 @@ enum wxSeekMode
|
|||||||
// underscores to the usual names, some also have Unicode versions of them
|
// 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
|
// Microsoft compiler loves underscores, feed them to it
|
||||||
#if defined( __VISUALC__ ) \
|
#elif defined( __VISUALC__ ) \
|
||||||
|| ( defined(__MINGW32__) && !defined(__WINE__) && wxCHECK_W32API_VERSION( 0, 5 ) ) \
|
|| ( defined(__MINGW32__) && !defined(__WINE__) && wxCHECK_W32API_VERSION( 0, 5 ) ) \
|
||||||
|| ( defined(__MWERKS__) && defined(__WXMSW__) ) \
|
|| ( defined(__MWERKS__) && defined(__WXMSW__) ) \
|
||||||
|| ( defined(__DMC__) && defined(__WXMSW__) ) \
|
|| ( defined(__DMC__) && defined(__WXMSW__) ) \
|
||||||
|| ( defined(__WATCOMC__) && 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
|
// functions
|
||||||
#if defined(__BORLANDC__) || defined(__WATCOMC__)
|
#if defined(__BORLANDC__) || defined(__WATCOMC__)
|
||||||
#define _tell tell
|
#define _tell tell
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __HUGEFILES_SUPPORTED
|
||||||
|
typedef wxLongLong_t wxFileOffset;
|
||||||
|
#define wxFileOffsetFmtSpec wxLongLongFmtSpec
|
||||||
|
#else
|
||||||
|
typedef int wxFileOffset;
|
||||||
|
#define wxFileOffsetFmtSpec _("")
|
||||||
|
#endif
|
||||||
|
|
||||||
#define wxClose _close
|
#define wxClose _close
|
||||||
#define wxRead _read
|
|
||||||
#define wxWrite _write
|
#if defined(__MWERKS__)
|
||||||
#define wxLseek _lseek
|
#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 wxFsync _commit
|
||||||
#define wxEof _eof
|
#define wxEof _eof
|
||||||
|
|
||||||
#define wxTell _tell
|
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
#if wxUSE_UNICODE_MSLU
|
#if wxUSE_UNICODE_MSLU
|
||||||
#define wxOpen wxMSLU__wopen
|
#define wxOpen wxMSLU__wopen
|
||||||
@@ -96,36 +241,56 @@ enum wxSeekMode
|
|||||||
#define wxAccess wxMSLU__waccess
|
#define wxAccess wxMSLU__waccess
|
||||||
#define wxMkDir wxMSLU__wmkdir
|
#define wxMkDir wxMSLU__wmkdir
|
||||||
#define wxRmDir wxMSLU__wrmdir
|
#define wxRmDir wxMSLU__wrmdir
|
||||||
#define wxStat wxMSLU__wstat
|
#if __HUGEFILES_SUPPORTED
|
||||||
|
#define wxStat wxMSLU__wstati64
|
||||||
|
#else
|
||||||
|
#define wxStat wxMSLU__wstat
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#define wxOpen _wopen
|
#define wxOpen _wopen
|
||||||
#define wxAccess _waccess
|
#define wxAccess _waccess
|
||||||
#define wxMkDir _wmkdir
|
#define wxMkDir _wmkdir
|
||||||
#define wxRmDir _wrmdir
|
#define wxRmDir _wrmdir
|
||||||
#define wxStat _wstat
|
#if __HUGEFILES_SUPPORTED
|
||||||
|
#define wxStat _wstati64
|
||||||
|
#else
|
||||||
|
#define wxStat _wstat
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#else // !wxUSE_UNICODE
|
#else // !wxUSE_UNICODE
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
#define wxOpen open
|
#define wxOpen open
|
||||||
#else
|
#else
|
||||||
#define wxOpen _open
|
#define wxOpen _open
|
||||||
#endif
|
#endif
|
||||||
#define wxAccess _access
|
#define wxAccess _access
|
||||||
#define wxMkDir _mkdir
|
#define wxMkDir _mkdir
|
||||||
#ifdef __WATCOMC__
|
#ifdef __WATCOMC__
|
||||||
#define wxRmDir rmdir
|
#define wxRmDir rmdir
|
||||||
#else
|
#else
|
||||||
#define wxRmDir _rmdir
|
#define wxRmDir _rmdir
|
||||||
#endif
|
#endif
|
||||||
#define wxStat _stat
|
#if __HUGEFILES_SUPPORTED
|
||||||
|
#define wxStat _stati64
|
||||||
|
#else
|
||||||
|
#define wxStat _stat
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// types
|
// types
|
||||||
#if defined(__WATCOMC__)&& wxUSE_UNICODE
|
#if __HUGEFILES_SUPPORTED
|
||||||
#define wxStructStat struct _wstat
|
#if wxUSE_UNICODE
|
||||||
#else
|
#define wxStructStat struct _wstati64
|
||||||
#define wxStructStat struct _stat
|
#else
|
||||||
#endif
|
#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)
|
// constants (unless already defined by the user code)
|
||||||
#if !defined(O_RDONLY) && !defined(__BORLANDC__) && !defined(__WATCOMC__)
|
#if !defined(O_RDONLY) && !defined(__BORLANDC__) && !defined(__WATCOMC__)
|
||||||
@@ -142,12 +307,22 @@ enum wxSeekMode
|
|||||||
#define S_IFDIR _S_IFDIR
|
#define S_IFDIR _S_IFDIR
|
||||||
#define S_IFREG _S_IFREG
|
#define S_IFREG _S_IFREG
|
||||||
#endif // O_RDONLY
|
#endif // O_RDONLY
|
||||||
|
|
||||||
|
// It's a private define, undefine it so nobody gets tempted to use it
|
||||||
|
#undef __HUGEFILES_SUPPORTED
|
||||||
#else
|
#else
|
||||||
|
typedef off_t wxFileOffset;
|
||||||
|
#ifdef _LARGE_FILES
|
||||||
|
#define wxFileOffsetFmtSpec wxLongLongFmtSpec
|
||||||
|
#else
|
||||||
|
#define wxFileOffsetFmtSpec _T("")
|
||||||
|
#endif
|
||||||
// functions
|
// functions
|
||||||
#define wxClose close
|
#define wxClose close
|
||||||
#define wxRead read
|
#define wxRead ::read
|
||||||
#define wxWrite write
|
#define wxWrite ::write
|
||||||
#define wxLseek lseek
|
#define wxLseek lseek
|
||||||
|
#define wxSeek lseek
|
||||||
#define wxFsync commit
|
#define wxFsync commit
|
||||||
#define wxEof eof
|
#define wxEof eof
|
||||||
|
|
||||||
@@ -158,22 +333,19 @@ enum wxSeekMode
|
|||||||
|
|
||||||
#define wxStructStat struct stat
|
#define wxStructStat struct stat
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
# define wxNEED_WX_UNISTD_H
|
#define wxNEED_WX_UNISTD_H
|
||||||
#if defined(__MWERKS__) && defined(macintosh)
|
#if defined(__DMC__)
|
||||||
#include <sys/stat.h>
|
typedef unsigned long mode_t;
|
||||||
#endif
|
#endif
|
||||||
#if defined(__DMC__)
|
WXDLLIMPEXP_BASE int wxStat( const wxChar *file_name, wxStructStat *buf );
|
||||||
typedef unsigned long mode_t;
|
WXDLLIMPEXP_BASE int wxAccess( const wxChar *pathname, int mode );
|
||||||
#endif
|
WXDLLIMPEXP_BASE int wxOpen( const wxChar *pathname, int flags, mode_t mode );
|
||||||
WXDLLIMPEXP_BASE int wxStat( const wxChar *file_name, wxStructStat *buf );
|
#else
|
||||||
WXDLLIMPEXP_BASE int wxAccess( const wxChar *pathname, int mode );
|
#define wxOpen open
|
||||||
WXDLLIMPEXP_BASE int wxOpen( const wxChar *pathname, int flags, mode_t mode );
|
#define wxStat stat
|
||||||
#else
|
#define wxAccess access
|
||||||
#define wxOpen open
|
#endif
|
||||||
#define wxStat stat
|
|
||||||
#define wxAccess access
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // VC++
|
#endif // VC++
|
||||||
|
|
||||||
|
@@ -65,6 +65,7 @@ WXDLLIMPEXP_BASE int wxMSLU__waccess(const wxChar *name, int mode);
|
|||||||
WXDLLIMPEXP_BASE int wxMSLU__wmkdir(const wxChar *name);
|
WXDLLIMPEXP_BASE int wxMSLU__wmkdir(const wxChar *name);
|
||||||
WXDLLIMPEXP_BASE int wxMSLU__wrmdir(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__wstat(const wxChar *name, struct _stat *buffer);
|
||||||
|
WXDLLIMPEXP_BASE int wxMSLU__wstati64(const wxChar *name, struct _stati64 *buffer);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // wxUSE_UNICODE_MSLU
|
#endif // wxUSE_UNICODE_MSLU
|
||||||
|
@@ -10,11 +10,6 @@
|
|||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: remove all the WinCE ugliness from here, implement the wxOpen(),
|
|
||||||
wxSeek(), ... functions in a separate file for WinCE instead!!!
|
|
||||||
*/
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// headers
|
// headers
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -34,7 +29,6 @@
|
|||||||
|
|
||||||
// standard
|
// standard
|
||||||
#if defined(__WXMSW__) && !defined(__GNUWIN32__) && !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
|
#if defined(__WXMSW__) && !defined(__GNUWIN32__) && !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
|
||||||
#include <io.h>
|
|
||||||
|
|
||||||
#ifndef __SALFORDC__
|
#ifndef __SALFORDC__
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
@@ -91,27 +85,13 @@
|
|||||||
#endif
|
#endif
|
||||||
char* mktemp( char * path ) { return path ;}
|
char* mktemp( char * path ) { return path ;}
|
||||||
#include <stat.h>
|
#include <stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#else
|
#else
|
||||||
#error "Please specify the header with file functions declarations."
|
#error "Please specify the header with file functions declarations."
|
||||||
#endif //Win/UNIX
|
#endif //Win/UNIX
|
||||||
|
|
||||||
#include <stdio.h> // SEEK_xxx constants
|
#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
|
// Windows compilers don't have these constants
|
||||||
#ifndef W_OK
|
#ifndef W_OK
|
||||||
enum
|
enum
|
||||||
@@ -200,12 +180,7 @@ bool wxFile::Access(const wxChar *name, OpenMode mode)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __WXWINCE__
|
|
||||||
// FIXME: use CreateFile with 0 access to query the file
|
|
||||||
return true;
|
|
||||||
#else
|
|
||||||
return wxAccess(name, how) == 0;
|
return wxAccess(name, how) == 0;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -230,22 +205,11 @@ bool wxFile::Create(const wxChar *szFileName, bool bOverwrite, int accessMode)
|
|||||||
// Dominic Mazzoni [dmazzoni+@cs.cmu.edu] reports that open is still broken on the mac, so we replace
|
// 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 = open( szFileName , O_CREAT | (bOverwrite ? O_TRUNC : O_EXCL), access);
|
||||||
int fd = creat( szFileName , accessMode);
|
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
|
#else
|
||||||
int fd = wxOpen( szFileName,
|
int fd = wxOpen( szFileName,
|
||||||
O_BINARY | O_WRONLY | O_CREAT |
|
O_BINARY | O_WRONLY | O_CREAT |
|
||||||
(bOverwrite ? O_TRUNC : O_EXCL)
|
(bOverwrite ? O_TRUNC : O_EXCL)
|
||||||
ACCESS(accessMode) );
|
ACCESS(accessMode) );
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
if ( fd == -1 )
|
if ( fd == -1 )
|
||||||
{
|
{
|
||||||
@@ -262,57 +226,6 @@ bool wxFile::Create(const wxChar *szFileName, bool bOverwrite, int accessMode)
|
|||||||
// open the file
|
// open the file
|
||||||
bool wxFile::Open(const wxChar *szFileName, OpenMode mode, int accessMode)
|
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;
|
int flags = O_BINARY;
|
||||||
|
|
||||||
switch ( mode )
|
switch ( mode )
|
||||||
@@ -351,7 +264,7 @@ bool wxFile::Open(const wxChar *szFileName, OpenMode mode, int accessMode)
|
|||||||
#endif // __WINDOWS__
|
#endif // __WINDOWS__
|
||||||
|
|
||||||
int fd = wxOpen( szFileName, flags ACCESS(accessMode));
|
int fd = wxOpen( szFileName, flags ACCESS(accessMode));
|
||||||
#endif
|
|
||||||
if ( fd == -1 )
|
if ( fd == -1 )
|
||||||
{
|
{
|
||||||
wxLogSysError(_("can't open file '%s'"), szFileName);
|
wxLogSysError(_("can't open file '%s'"), szFileName);
|
||||||
@@ -367,11 +280,7 @@ bool wxFile::Open(const wxChar *szFileName, OpenMode mode, int accessMode)
|
|||||||
bool wxFile::Close()
|
bool wxFile::Close()
|
||||||
{
|
{
|
||||||
if ( IsOpened() ) {
|
if ( IsOpened() ) {
|
||||||
#ifdef __WXWINCE__
|
if (wxClose(m_fd) == -1)
|
||||||
if (!CloseHandle((HANDLE) m_fd))
|
|
||||||
#else
|
|
||||||
if ( close(m_fd) == -1 )
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
wxLogSysError(_("can't close file descriptor %d"), m_fd);
|
wxLogSysError(_("can't close file descriptor %d"), m_fd);
|
||||||
m_fd = fd_invalid;
|
m_fd = fd_invalid;
|
||||||
@@ -389,25 +298,15 @@ bool wxFile::Close()
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
// read
|
// read
|
||||||
off_t wxFile::Read(void *pBuf, off_t nCount)
|
size_t wxFile::Read(void *pBuf, size_t nCount)
|
||||||
{
|
{
|
||||||
wxCHECK( (pBuf != NULL) && IsOpened(), 0 );
|
wxCHECK( (pBuf != NULL) && IsOpened(), 0 );
|
||||||
|
|
||||||
#ifdef __WXWINCE__
|
int iRc = wxRead(m_fd, pBuf, nCount);
|
||||||
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
|
|
||||||
if ( iRc == -1 ) {
|
if ( iRc == -1 ) {
|
||||||
wxLogSysError(_("can't read from file descriptor %d"), m_fd);
|
wxLogSysError(_("can't read from file descriptor %d"), m_fd);
|
||||||
return wxInvalidOffset;
|
return (size_t)wxInvalidOffset;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return (size_t)iRc;
|
return (size_t)iRc;
|
||||||
@@ -418,22 +317,8 @@ size_t wxFile::Write(const void *pBuf, size_t nCount)
|
|||||||
{
|
{
|
||||||
wxCHECK( (pBuf != NULL) && IsOpened(), 0 );
|
wxCHECK( (pBuf != NULL) && IsOpened(), 0 );
|
||||||
|
|
||||||
#ifdef __WXWINCE__
|
int iRc = wxWrite(m_fd, pBuf, nCount);
|
||||||
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
|
|
||||||
if ( iRc == -1 ) {
|
if ( iRc == -1 ) {
|
||||||
wxLogSysError(_("can't write to file descriptor %d"), m_fd);
|
wxLogSysError(_("can't write to file descriptor %d"), m_fd);
|
||||||
m_error = true;
|
m_error = true;
|
||||||
@@ -447,9 +332,7 @@ size_t wxFile::Write(const void *pBuf, size_t nCount)
|
|||||||
bool wxFile::Flush()
|
bool wxFile::Flush()
|
||||||
{
|
{
|
||||||
if ( IsOpened() ) {
|
if ( IsOpened() ) {
|
||||||
#ifdef __WXWINCE__
|
#if defined(__VISUALC__) || wxHAVE_FSYNC
|
||||||
// Do nothing
|
|
||||||
#elif defined(__VISUALC__) || wxHAVE_FSYNC
|
|
||||||
if ( wxFsync(m_fd) == -1 )
|
if ( wxFsync(m_fd) == -1 )
|
||||||
{
|
{
|
||||||
wxLogSysError(_("can't flush file descriptor %d"), m_fd);
|
wxLogSysError(_("can't flush file descriptor %d"), m_fd);
|
||||||
@@ -468,38 +351,10 @@ bool wxFile::Flush()
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
// seek
|
// seek
|
||||||
off_t wxFile::Seek(off_t ofs, wxSeekMode mode)
|
wxFileOffset wxFile::Seek(wxFileOffset ofs, wxSeekMode mode)
|
||||||
{
|
{
|
||||||
wxASSERT( IsOpened() );
|
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;
|
int origin;
|
||||||
switch ( mode ) {
|
switch ( mode ) {
|
||||||
default:
|
default:
|
||||||
@@ -518,62 +373,43 @@ off_t wxFile::Seek(off_t ofs, wxSeekMode mode)
|
|||||||
break;
|
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 ) {
|
if ( iRc == -1 ) {
|
||||||
wxLogSysError(_("can't seek on file descriptor %d"), m_fd);
|
wxLogSysError(_("can't seek on file descriptor %d"), m_fd);
|
||||||
return wxInvalidOffset;
|
return wxInvalidOffset;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return (off_t)iRc;
|
return iRc;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get current off_t
|
// get current wxFileOffset
|
||||||
off_t wxFile::Tell() const
|
wxFileOffset wxFile::Tell() const
|
||||||
{
|
{
|
||||||
wxASSERT( IsOpened() );
|
wxASSERT( IsOpened() );
|
||||||
|
|
||||||
#ifdef __WXWINCE__
|
wxFileOffset iRc = wxTell(m_fd);
|
||||||
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);
|
|
||||||
if ( iRc == -1 ) {
|
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 wxInvalidOffset;
|
return wxInvalidOffset;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return (off_t)iRc;
|
return iRc;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get current file length
|
// get current file length
|
||||||
off_t wxFile::Length() const
|
wxFileOffset wxFile::Length() const
|
||||||
{
|
{
|
||||||
wxASSERT( IsOpened() );
|
wxASSERT( IsOpened() );
|
||||||
|
|
||||||
#ifdef __WXWINCE__
|
wxFileOffset iRc = Tell();
|
||||||
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);
|
|
||||||
if ( iRc != -1 ) {
|
if ( iRc != -1 ) {
|
||||||
// @ have to use const_cast :-(
|
// @ have to use const_cast :-(
|
||||||
int iLen = ((wxFile *)this)->SeekEnd();
|
wxFileOffset iLen = ((wxFile *)this)->SeekEnd();
|
||||||
if ( iLen != -1 ) {
|
if ( iLen != -1 ) {
|
||||||
// restore old position
|
// restore old position
|
||||||
if ( ((wxFile *)this)->Seek(iRc) == -1 ) {
|
if ( ((wxFile *)this)->Seek(iRc) == -1 ) {
|
||||||
@@ -584,15 +420,13 @@ off_t wxFile::Length() const
|
|||||||
|
|
||||||
iRc = iLen;
|
iRc = iLen;
|
||||||
}
|
}
|
||||||
#endif // VC++
|
|
||||||
|
|
||||||
if ( iRc == -1 ) {
|
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 wxInvalidOffset;
|
return wxInvalidOffset;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return (off_t)iRc;
|
return iRc;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// is end of file reached?
|
// is end of file reached?
|
||||||
@@ -600,29 +434,18 @@ bool wxFile::Eof() const
|
|||||||
{
|
{
|
||||||
wxASSERT( IsOpened() );
|
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;
|
int iRc;
|
||||||
|
|
||||||
#if defined(__DOS__) || defined(__UNIX__) || defined(__GNUWIN32__) || defined( __MWERKS__ ) || defined(__SALFORDC__)
|
#if defined(__DOS__) || defined(__UNIX__) || defined(__GNUWIN32__) || defined( __MWERKS__ ) || defined(__SALFORDC__)
|
||||||
// @@ this doesn't work, of course, on unseekable file descriptors
|
// @@ this doesn't work, of course, on unseekable file descriptors
|
||||||
off_t ofsCur = Tell(),
|
wxFileOffset ofsCur = Tell(),
|
||||||
ofsMax = Length();
|
ofsMax = Length();
|
||||||
if ( ofsCur == wxInvalidOffset || ofsMax == wxInvalidOffset )
|
if ( ofsCur == wxInvalidOffset || ofsMax == wxInvalidOffset )
|
||||||
iRc = -1;
|
iRc = -1;
|
||||||
else
|
else
|
||||||
iRc = ofsCur == ofsMax;
|
iRc = ofsCur == ofsMax;
|
||||||
#else // Windows and "native" compiler
|
#else // Windows and "native" compiler
|
||||||
iRc = eof(m_fd);
|
iRc = wxEof(m_fd);
|
||||||
#endif // Windows/Unix
|
#endif // Windows/Unix
|
||||||
|
|
||||||
switch ( iRc ) {
|
switch ( iRc ) {
|
||||||
@@ -641,7 +464,6 @@ bool wxFile::Eof() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
#include "wx/utils.h"
|
#include "wx/utils.h"
|
||||||
#include "wx/intl.h"
|
#include "wx/intl.h"
|
||||||
#include "wx/file.h"
|
#include "wx/file.h" // This does include filefn.h
|
||||||
#include "wx/filename.h"
|
#include "wx/filename.h"
|
||||||
#include "wx/dir.h"
|
#include "wx/dir.h"
|
||||||
|
|
||||||
@@ -54,76 +54,6 @@
|
|||||||
#include "wx/mac/private.h" // includes mac headers
|
#include "wx/mac/private.h" // includes mac headers
|
||||||
#endif
|
#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"
|
#include "wx/log.h"
|
||||||
|
|
||||||
// No, Cygwin doesn't appear to have fnmatch.h after all.
|
// No, Cygwin doesn't appear to have fnmatch.h after all.
|
||||||
@@ -135,11 +65,6 @@
|
|||||||
#include "wx/msw/wrapwin.h"
|
#include "wx/msw/wrapwin.h"
|
||||||
#include "wx/msw/mslu.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()
|
// sys/cygwin.h is needed for cygwin_conv_to_full_win32_path()
|
||||||
//
|
//
|
||||||
// note that it must be included after <windows.h>
|
// note that it must be included after <windows.h>
|
||||||
|
@@ -199,6 +199,14 @@ WXDLLIMPEXP_BASE int wxMSLU__wstat(const wxChar *name, struct _stat *buffer)
|
|||||||
return _wstat(name, buffer);
|
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 // compilers having wopen() &c
|
||||||
|
|
||||||
#endif // wxUSE_BASE
|
#endif // wxUSE_BASE
|
||||||
|
214
src/msw/wince/filefnwce.cpp
Normal file
214
src/msw/wince/filefnwce.cpp
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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__
|
Reference in New Issue
Block a user