/////////////////////////////////////////////////////////////////////////////
-// Name: filefn.h
+// Name: wx/filefn.h
// Purpose: File- and directory-related functions
// Author: Julian Smart
// Modified by:
#ifndef _FILEFN_H_
#define _FILEFN_H_
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
- #pragma interface "filefn.h"
-#endif
-
#include "wx/list.h"
#include "wx/arrstr.h"
// __OS2__ and __UNIX__ are defined.
#include <process.h>
#include "wx/os2/private.h"
+ #ifdef __WATCOMC__
+ #include <direct.h>
+ #endif
#include <io.h>
#ifdef __EMX__
#include <unistd.h>
#endif
#if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
-#if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__) && !defined(__WXWINCE__)
+#if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__) && !defined(__WXWINCE__) && !defined(__CYGWIN__)
#include <direct.h>
#include <dos.h>
#include <io.h>
wxFromEnd
};
+enum wxFileKind
+{
+ wxFILE_KIND_UNKNOWN,
+ wxFILE_KIND_DISK, // a file supporting seeking to arbitrary offsets
+ wxFILE_KIND_TERMINAL, // a tty
+ wxFILE_KIND_PIPE // a pipe
+};
+
// ----------------------------------------------------------------------------
// declare our versions of low level file functions: some compilers prepend
// underscores to the usual names, some also have Unicode versions of them
// 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));
#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
+ // always Unicode under WinCE
+ #define wxMkDir _wmkdir
+ #define wxRmDir _wrmdir
+ #define wxStat _wstat
#define wxStructStat struct _stat
// Microsoft compiler loves underscores, feed them to it
// detect compilers which have support for huge files (currently only
// Digital Mars doesn't)
- #ifndef __PALMOS__
+ #ifndef __WXPALMOS__
#include "wx/msw/private.h"
#endif
#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
#endif
#endif
- // types: notice that Watcom is the only compiler to have a wide char
- // version of struct stat as well as a wide char stat function variant
+ // Types: Notice that Watcom is the only compiler to have a wide char
+ // version of struct stat as well as a wide char stat function variant.
+ // This was droped since OW 1.4 "for consistency across platforms".
#if wxHAS_HUGE_FILES
- #if wxUSE_UNICODE && defined(__WATCOMC__)
+ #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
#define wxStructStat struct _wstati64
#else
#define wxStructStat struct _stati64
#endif
#else
- #if wxUSE_UNICODE && defined(__WATCOMC__)
+ #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
#define wxStructStat struct _wstat
#else
#define wxStructStat struct _stat
#endif
// constants (unless already defined by the user code)
- #if !defined(__BORLANDC__) && !defined(__WATCOMC__) && !defined(__PALMOS__)
+ #if !defined(__BORLANDC__) && !defined(__WATCOMC__) && !defined(__WXPALMOS__)
#ifndef O_RDONLY
#define O_RDONLY _O_RDONLY
#define O_WRONLY _O_WRONLY
#endif
#endif
+ #if wxHAS_HUGE_FILES
+ // wxFile is present and supports large files. Currently wxFFile
+ // doesn't have large file support with any Windows compiler (even
+ // Win64 ones).
+ #if wxUSE_FILE
+ #define WXFILE_LARGEFILE 1
+ #endif
+ #endif
+
// It's a private define, undefine it so nobody gets tempted to use it
#undef wxHAS_HUGE_FILES
#else // Unix platforms using configure
#define wxFileOffsetFmtSpec wxLongLongFmtSpec
wxCOMPILE_TIME_ASSERT( sizeof(off_t) == sizeof(wxLongLong_t),
BadFileSizeType );
- typedef unsigned wxLongLong_t wxFileSize_t;
+ // wxFile is present and supports large files
+ #ifdef wxUSE_FILE
+ #define WXFILE_LARGEFILE
+ #endif
+ // wxFFile is present and supports large files
+ #if SIZEOF_LONG == 8 || defined HAVE_FSEEKO
+ #define WXFFILE_LARGEFILE
+ #endif
#else
#define wxFileOffsetFmtSpec _T("")
- typedef unsigned long wxFileSize_t;
#endif
// functions
#define wxClose close
#define wxWrite ::write
#define wxLseek lseek
#define wxSeek lseek
- #define wxFsync commit
+ #define wxFsync fsync
#define wxEof eof
#define wxMkDir mkdir
typedef unsigned long mode_t;
#endif
WXDLLIMPEXP_BASE int wxStat( const wxChar *file_name, wxStructStat *buf );
+ WXDLLIMPEXP_BASE int wxLstat( 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 wxLstat lstat
#define wxAccess access
#endif
+
+ #define wxHAVE_NATIVE_LSTAT
#endif // platforms
+#ifdef O_BINARY
+ #define wxO_BINARY O_BINARY
+#else
+ #define wxO_BINARY 0
+#endif
+
+// if the platform doesn't have symlinks, define wxLstat to be the same as
+// wxStat to avoid #ifdefs in the code using it
+#ifndef wxHAVE_NATIVE_LSTAT
+ #define wxLstat wxStat
+#endif
+
#if defined(__VISAGECPP__) && __IBMCPP__ >= 400
//
// 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
// ----------------------------------------------------------------------------
WXDLLIMPEXP_BASE bool wxFileExists(const wxString& filename);
// does the path exist? (may have or not '/' or '\\' at the end)
-WXDLLIMPEXP_BASE bool wxPathExists(const wxChar *pszPathName);
+WXDLLIMPEXP_BASE bool wxDirExists(const wxChar *pszPathName);
WXDLLIMPEXP_BASE bool wxIsAbsolutePath(const wxString& filename);
WXDLLIMPEXP_BASE bool wxRemoveFile(const wxString& file);
// Rename file
-WXDLLIMPEXP_BASE bool wxRenameFile(const wxString& file1, const wxString& file2);
+WXDLLIMPEXP_BASE bool wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite = true);
// Get current working directory.
+#if WXWIN_COMPATIBILITY_2_6
// If buf is NULL, allocates space using new, else
// copies into buf.
// IMPORTANT NOTE getcwd is know not to work under some releases
// of Win32s 1.3, according to MS release notes!
-WXDLLIMPEXP_BASE wxChar* wxGetWorkingDirectory(wxChar *buf = (wxChar *) NULL, int sz = 1000);
+wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* wxGetWorkingDirectory(wxChar *buf = (wxChar *) NULL, int sz = 1000) );
// new and preferred version of wxGetWorkingDirectory
// NB: can't have the same name because of overloading ambiguity
+#endif // WXWIN_COMPATIBILITY_2_6
WXDLLIMPEXP_BASE wxString wxGetCwd();
// Set working directory
// Remove directory. Flags reserved for future use.
WXDLLIMPEXP_BASE bool wxRmdir(const wxString& dir, int flags = 0);
+// Return the type of an open file
+WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(int fd);
+WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(FILE *fp);
+
+#if WXWIN_COMPATIBILITY_2_6
// compatibility defines, don't use in new code
-#define wxDirExists wxPathExists
+wxDEPRECATED( inline bool wxPathExists(const wxChar *pszPathName) );
+inline bool wxPathExists(const wxChar *pszPathName)
+{
+ return wxDirExists(pszPathName);
+}
+#endif //WXWIN_COMPATIBILITY_2_6
+
+// permissions; these functions work both on files and directories:
+WXDLLIMPEXP_BASE bool wxIsWritable(const wxString &path);
+WXDLLIMPEXP_BASE bool wxIsReadable(const wxString &path);
+WXDLLIMPEXP_BASE bool wxIsExecutable(const wxString &path);
// ----------------------------------------------------------------------------
// separators in file names
// On non-Windows platform, probably just return the empty string.
WXDLLIMPEXP_BASE wxString wxGetOSDirectory();
+#if wxUSE_DATETIME
+
// Get file modification time
WXDLLIMPEXP_BASE time_t wxFileModificationTime(const wxString& filename);
+#endif // wxUSE_DATETIME
+
// Parses the wildCard, returning the number of filters.
// Returns 0 if none or if there's a problem,
// The arrays will contain an equal number of items found before the error.
// Path searching
-class WXDLLIMPEXP_BASE wxPathList : public wxStringList
+class WXDLLIMPEXP_BASE wxPathList : public wxArrayString
{
public:
- // avoid GCC warning about virtual functions w/o virtual dtor
- virtual ~wxPathList() {}
+ wxPathList() {}
+ wxPathList(const wxArrayString &arr)
+ { Add(arr); }
// Adds all paths in environment variable
void AddEnvList(const wxString& envVariable);
+ // Adds given path to this list
void Add(const wxString& path);
+ void Add(const wxArrayString &paths);
+
// Find the first full path for which the file exists
- wxString FindValidPath(const wxString& filename);
+ wxString FindValidPath(const wxString& filename) const;
+
// Find the first full path for which the file exists; ensure it's an
// absolute path that gets returned.
- wxString FindAbsoluteValidPath(const wxString& filename);
+ wxString FindAbsoluteValidPath(const wxString& filename) const;
+
// Given full path and filename, add path to list
void EnsureFileAccessible(const wxString& path);
- // Returns true if the path is in the list
- bool Member(const wxString& path);
-private:
- // DECLARE_DYNAMIC_CLASS(wxPathList)
+ // Returns true if the path is in the list
+ wxDEPRECATED( bool Member(const wxString& path) const );
};
-#endif
- // _WX_FILEFN_H_
+#endif // _WX_FILEFN_H_