]> git.saurik.com Git - wxWidgets.git/blame - include/wx/filefn.h
removed DoGetSize implementation
[wxWidgets.git] / include / wx / filefn.h
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: filefn.h
3// Purpose: File- and directory-related functions
4// Author: Julian Smart
5// Modified by:
6// Created: 29/01/98
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Julian Smart
371a5b4e 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _FILEFN_H_
13#define _FILEFN_H_
c801d85f 14
af49c4b8 15#if defined(__GNUG__) && !defined(__APPLE__)
7af89395 16 #pragma interface "filefn.h"
c801d85f
KB
17#endif
18
ed58dbea 19#include "wx/list.h"
e49f47aa 20
0e0126c2 21#ifndef __WXWINCE__
a47ce4a7 22#include <time.h>
0e0126c2 23#endif
a47ce4a7 24
45ea509a
VZ
25// ----------------------------------------------------------------------------
26// constants
27// ----------------------------------------------------------------------------
c801d85f 28
0e0126c2
RR
29#ifdef __WXWINCE__
30 typedef long off_t;
31#else
32
45ea509a 33// define off_t
2d2ed20f 34#if !defined(__WXMAC__) || defined(__UNIX__) || defined(__MACH__)
7af89395 35 #include <sys/types.h>
17dff81c 36#else
7af89395 37 typedef long off_t;
17dff81c 38#endif
45ea509a 39
8be97d65 40#if defined(__VISUALC__) || ( defined(__MWERKS__) && defined( __INTEL__) )
3f4a0c5b
VZ
41 typedef _off_t off_t;
42#elif defined(__BORLANDC__) && defined(__WIN16__)
43 typedef long off_t;
2bdf7154 44#elif defined(__SYMANTEC__)
3f4a0c5b 45 typedef long off_t;
2d2ed20f 46#elif defined(__MWERKS__) && !defined(__INTEL__) && !defined(__MACH__)
8be97d65 47 typedef long off_t;
2432b92d
JS
48#endif
49
5d19b6ac
CE
50#endif
51
66b6b045
DW
52#if defined(__VISAGECPP__) && __IBMCPP__ >= 400
53//
70862fa8 54// VisualAge C++ V4.0 cannot have any external linkage const decs
66b6b045
DW
55// in headers included by more than one primary source
56//
70862fa8
DW
57extern const off_t wxInvalidOffset;
58#else
1678ad78 59const off_t wxInvalidOffset = (off_t)-1;
66b6b045 60#endif
1678ad78 61
7af89395
VZ
62enum wxSeekMode
63{
45ea509a
VZ
64 wxFromStart,
65 wxFromCurrent,
66 wxFromEnd
7af89395 67};
45ea509a 68
9d2f3c71 69WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
cffee23b 70
f6bcfd97
BP
71// ----------------------------------------------------------------------------
72// declare our versions of low level file functions: some compilers prepend
73// underscores to the usual names, some also have Unicode versions of them
74// ----------------------------------------------------------------------------
75
76// Microsoft compiler loves underscores, feed them to it
fbdb357e 77#if defined( __VISUALC__ ) \
5283098e 78 || ( defined(__MINGW32__) && !defined(__WINE__) && wxCHECK_W32API_VERSION( 0, 5 ) ) \
de85a884 79 || ( defined(__MWERKS__) && defined(__WXMSW__) )
f6bcfd97 80 // functions
a3bb1d14
CE
81#ifdef __BORLANDC__
82 #define _tell tell
83#endif
f6bcfd97
BP
84 #define wxClose _close
85 #define wxRead _read
86 #define wxWrite _write
87 #define wxLseek _lseek
88 #define wxFsync _commit
89 #define wxEof _eof
90
91 #define wxTell _tell
92
93 #if wxUSE_UNICODE
6de5b599 94 #if wxUSE_UNICODE_MSLU
3e6477f4
CE
95 #define wxOpen wxMSLU__wopen
96
3d5231db
VS
97 #define wxAccess wxMSLU__waccess
98 #define wxMkDir wxMSLU__wmkdir
99 #define wxRmDir wxMSLU__wrmdir
100 #define wxStat wxMSLU__wstat
6de5b599
VS
101 #else
102 #define wxOpen _wopen
3d5231db
VS
103 #define wxAccess _waccess
104 #define wxMkDir _wmkdir
105 #define wxRmDir _wrmdir
106 #define wxStat _wstat
6de5b599 107 #endif
f6bcfd97 108 #else // !wxUSE_UNICODE
3e6477f4
CE
109#ifdef __BORLANDC__
110 #define wxOpen open
111#else
f6bcfd97 112 #define wxOpen _open
3e6477f4 113#endif
f6bcfd97 114 #define wxAccess _access
f6bcfd97
BP
115 #define wxMkDir _mkdir
116 #define wxRmDir _rmdir
f6bcfd97
BP
117 #define wxStat _stat
118 #endif
119
120 // types
121 #define wxStructStat struct _stat
122
123 // constants (unless already defined by the user code)
a3bb1d14 124 #if !defined(O_RDONLY) && !defined(__BORLANDC__)
f6bcfd97
BP
125 #define O_RDONLY _O_RDONLY
126 #define O_WRONLY _O_WRONLY
127 #define O_RDWR _O_RDWR
128 #define O_EXCL _O_EXCL
129 #define O_CREAT _O_CREAT
130 #define O_BINARY _O_BINARY
a3bb1d14 131 #endif
f6bcfd97 132
a3bb1d14 133 #ifndef __BORLANDC__
f6bcfd97
BP
134 #define S_IFMT _S_IFMT
135 #define S_IFDIR _S_IFDIR
136 #define S_IFREG _S_IFREG
137 #endif // O_RDONLY
138#else
139 // functions
f6bcfd97
BP
140 #define wxClose close
141 #define wxRead read
142 #define wxWrite write
143 #define wxLseek lseek
144 #define wxFsync commit
f6bcfd97
BP
145 #define wxEof eof
146
147 #define wxMkDir mkdir
148 #define wxRmDir rmdir
149
150 #define wxTell(fd) lseek(fd, 0, SEEK_CUR)
151
f6bcfd97 152 #define wxStructStat struct stat
92980e90
RR
153
154#if wxUSE_UNICODE
155# define wxNEED_WX_UNISTD_H
c4e41ce3
SC
156#if defined(__MWERKS__) && defined(macintosh)
157 #include <sys/stat.h>
158#endif
92980e90
RR
159WXDLLEXPORT int wxStat( const wxChar *file_name, wxStructStat *buf );
160WXDLLEXPORT int wxAccess( const wxChar *pathname, int mode );
161WXDLLEXPORT int wxOpen( const wxChar *pathname, int flags, mode_t mode );
162#else
163 #define wxOpen open
164 #define wxStat stat
165 #define wxAccess access
166#endif
f6bcfd97
BP
167
168#endif // VC++
169
45ea509a
VZ
170// ----------------------------------------------------------------------------
171// functions
172// ----------------------------------------------------------------------------
184b5d99 173WXDLLEXPORT bool wxFileExists(const wxString& filename);
c801d85f
KB
174
175// does the path exist? (may have or not '/' or '\\' at the end)
9d2f3c71 176WXDLLEXPORT bool wxPathExists(const wxChar *pszPathName);
c801d85f 177
184b5d99 178WXDLLEXPORT bool wxIsAbsolutePath(const wxString& filename);
c801d85f
KB
179
180// Get filename
9d2f3c71 181WXDLLEXPORT wxChar* wxFileNameFromPath(wxChar *path);
184b5d99 182WXDLLEXPORT wxString wxFileNameFromPath(const wxString& path);
c801d85f
KB
183
184// Get directory
184b5d99 185WXDLLEXPORT wxString wxPathOnly(const wxString& path);
c801d85f
KB
186
187// wxString version
184b5d99 188WXDLLEXPORT wxString wxRealPath(const wxString& path);
c801d85f 189
9d2f3c71 190WXDLLEXPORT void wxDos2UnixFilename(wxChar *s);
c801d85f 191
9d2f3c71 192WXDLLEXPORT void wxUnix2DosFilename(wxChar *s);
c801d85f
KB
193
194// Strip the extension, in situ
9d2f3c71 195WXDLLEXPORT void wxStripExtension(wxChar *buffer);
184b5d99 196WXDLLEXPORT void wxStripExtension(wxString& buffer);
c801d85f 197
ade35f11 198// Get a temporary filename
9d2f3c71 199WXDLLEXPORT wxChar* wxGetTempFileName(const wxString& prefix, wxChar *buf = (wxChar *) NULL);
c0ab6adf 200WXDLLEXPORT bool wxGetTempFileName(const wxString& prefix, wxString& buf);
c801d85f
KB
201
202// Expand file name (~/ and ${OPENWINHOME}/ stuff)
9d2f3c71 203WXDLLEXPORT wxChar* wxExpandPath(wxChar *dest, const wxChar *path);
c0ab6adf 204WXDLLEXPORT bool wxExpandPath(wxString& dest, const wxChar *path);
c801d85f
KB
205
206// Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
207// and make (if under the home tree) relative to home
208// [caller must copy-- volatile]
9d2f3c71 209WXDLLEXPORT wxChar* wxContractPath(const wxString& filename,
ade35f11
VZ
210 const wxString& envname = wxEmptyString,
211 const wxString& user = wxEmptyString);
c801d85f
KB
212
213// Destructive removal of /./ and /../ stuff
9d2f3c71 214WXDLLEXPORT wxChar* wxRealPath(wxChar *path);
c801d85f
KB
215
216// Allocate a copy of the full absolute path
9d2f3c71 217WXDLLEXPORT wxChar* wxCopyAbsolutePath(const wxString& path);
c801d85f
KB
218
219// Get first file name matching given wild card.
220// Flags are reserved for future use.
221#define wxFILE 1
222#define wxDIR 2
9d2f3c71 223WXDLLEXPORT wxString wxFindFirstFile(const wxChar *spec, int flags = wxFILE);
7af89395 224WXDLLEXPORT wxString wxFindNextFile();
c801d85f
KB
225
226// Does the pattern contain wildcards?
184b5d99 227WXDLLEXPORT bool wxIsWild(const wxString& pattern);
c801d85f
KB
228
229// Does the pattern match the text (usually a filename)?
230// If dot_special is TRUE, doesn't match * against . (eliminating
231// `hidden' dot files)
184b5d99 232WXDLLEXPORT bool wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = TRUE);
c801d85f
KB
233
234// Concatenate two files to form third
184b5d99 235WXDLLEXPORT bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
c801d85f
KB
236
237// Copy file1 to file2
4658c44e
VZ
238WXDLLEXPORT bool wxCopyFile(const wxString& file1, const wxString& file2,
239 bool overwrite = TRUE);
c801d85f
KB
240
241// Remove file
184b5d99 242WXDLLEXPORT bool wxRemoveFile(const wxString& file);
c801d85f
KB
243
244// Rename file
184b5d99 245WXDLLEXPORT bool wxRenameFile(const wxString& file1, const wxString& file2);
c801d85f
KB
246
247// Get current working directory.
248// If buf is NULL, allocates space using new, else
249// copies into buf.
250// IMPORTANT NOTE getcwd is know not to work under some releases
251// of Win32s 1.3, according to MS release notes!
9d2f3c71 252WXDLLEXPORT wxChar* wxGetWorkingDirectory(wxChar *buf = (wxChar *) NULL, int sz = 1000);
7af89395
VZ
253// new and preferred version of wxGetWorkingDirectory
254// NB: can't have the same name because of overloading ambiguity
255WXDLLEXPORT wxString wxGetCwd();
c801d85f
KB
256
257// Set working directory
184b5d99 258WXDLLEXPORT bool wxSetWorkingDirectory(const wxString& d);
c801d85f
KB
259
260// Make directory
1a33c3ba 261WXDLLEXPORT bool wxMkdir(const wxString& dir, int perm = 0777);
c801d85f
KB
262
263// Remove directory. Flags reserved for future use.
184b5d99 264WXDLLEXPORT bool wxRmdir(const wxString& dir, int flags = 0);
c801d85f 265
2b5f62a0
VZ
266// compatibility defines, don't use in new code
267#define wxDirExists wxPathExists
268
269#if WXWIN_COMPATIBILITY_2
270 #define FileExists wxFileExists
271 #define DirExists wxDirExists
272 #define IsAbsolutePath wxIsAbsolutePath
273 #define FileNameFromPath wxFileNameFromPath
274 #define PathOnly wxPathOnly
275 #define Dos2UnixFilename wxDos2UnixFilename
276 #define Unix2DosFilename wxUnix2DosFilename
277#endif
278
ff69a290 279// ----------------------------------------------------------------------------
c801d85f 280// separators in file names
ff69a290
VZ
281// ----------------------------------------------------------------------------
282
283// between file name and extension
223d09f6 284#define wxFILE_SEP_EXT wxT('.')
ff69a290
VZ
285
286// between drive/volume name and the path
223d09f6 287#define wxFILE_SEP_DSK wxT(':')
ff69a290
VZ
288
289// between the path components
223d09f6
KB
290#define wxFILE_SEP_PATH_DOS wxT('\\')
291#define wxFILE_SEP_PATH_UNIX wxT('/')
844f90fb 292#define wxFILE_SEP_PATH_MAC wxT(':')
ff69a290 293#define wxFILE_SEP_PATH_VMS wxT('.') // VMS also uses '[' and ']'
c801d85f
KB
294
295// separator in the path list (as in PATH environment variable)
03e11df5
GD
296// there is no PATH variable in Classic Mac OS so just use the
297// semicolon (it must be different from the file name separator)
c801d85f 298// NB: these are strings and not characters on purpose!
223d09f6
KB
299#define wxPATH_SEP_DOS wxT(";")
300#define wxPATH_SEP_UNIX wxT(":")
03e11df5 301#define wxPATH_SEP_MAC wxT(";")
c801d85f
KB
302
303// platform independent versions
e02e8816 304#if defined(__UNIX__) && !defined(__CYGWIN__)
7af89395
VZ
305 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_UNIX
306 #define wxPATH_SEP wxPATH_SEP_UNIX
844f90fb 307#elif defined(__MAC__)
bedaf53e 308 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_MAC
3369df87 309 #define wxPATH_SEP wxPATH_SEP_MAC
e02e8816 310#elif defined(__CYGWIN__) // Cygwin
3ffbc733
VZ
311 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_DOS
312 #define wxPATH_SEP wxPATH_SEP_UNIX
1777b9bb 313#else // Windows and OS/2
7af89395
VZ
314 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_DOS
315 #define wxPATH_SEP wxPATH_SEP_DOS
c801d85f
KB
316#endif // Unix/Windows
317
92abb45d
VZ
318// this is useful for wxString::IsSameAs(): to compare two file names use
319// filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
3369df87 320#if defined(__UNIX__) && !defined(__DARWIN__)
92abb45d 321 #define wxARE_FILENAMES_CASE_SENSITIVE TRUE
3369df87 322#else // Windows, Mac OS and OS/2
92abb45d
VZ
323 #define wxARE_FILENAMES_CASE_SENSITIVE FALSE
324#endif // Unix/Windows
325
c801d85f 326// is the char a path separator?
9d2f3c71 327inline bool wxIsPathSeparator(wxChar c)
903b61cc
VZ
328{
329 // under DOS/Windows we should understand both Unix and DOS file separators
330#if defined(__UNIX__) || defined(__MAC__)
331 return c == wxFILE_SEP_PATH;
332#else
333 return c == wxFILE_SEP_PATH_DOS || c == wxFILE_SEP_PATH_UNIX;
334#endif
335}
c801d85f
KB
336
337// does the string ends with path separator?
9d2f3c71 338WXDLLEXPORT bool wxEndsWithPathSeparator(const wxChar *pszFileName);
c801d85f 339
92abb45d
VZ
340// split the full path into path (including drive for DOS), name and extension
341// (understands both '/' and '\\')
9d2f3c71 342WXDLLEXPORT void wxSplitPath(const wxChar *pszFileName,
92abb45d
VZ
343 wxString *pstrPath,
344 wxString *pstrName,
345 wxString *pstrExt);
346
c801d85f 347// find a file in a list of directories, returns false if not found
9d2f3c71 348WXDLLEXPORT bool wxFindFileInPath(wxString *pStr, const wxChar *pszPath, const wxChar *pszFile);
c801d85f 349
631f1bfe
JS
350// Get the OS directory if appropriate (such as the Windows directory).
351// On non-Windows platform, probably just return the empty string.
352WXDLLEXPORT wxString wxGetOSDirectory();
353
a47ce4a7
VS
354// Get file modification time
355WXDLLEXPORT time_t wxFileModificationTime(const wxString& filename);
356
45ea509a
VZ
357// ----------------------------------------------------------------------------
358// classes
359// ----------------------------------------------------------------------------
360
c801d85f 361// Path searching
a6f6393c 362class WXDLLEXPORT wxPathList : public wxStringList
c801d85f 363{
a6f6393c 364public:
7af89395
VZ
365 // Adds all paths in environment variable
366 void AddEnvList(const wxString& envVariable);
c330a2cf 367
a6f6393c 368 void Add(const wxString& path);
c330a2cf 369 // Avoid compiler warning
9d2f3c71 370 wxNode *Add(const wxChar *s) { return wxStringList::Add(s); }
7af89395
VZ
371 // Find the first full path for which the file exists
372 wxString FindValidPath(const wxString& filename);
373 // Find the first full path for which the file exists; ensure it's an
374 // absolute path that gets returned.
375 wxString FindAbsoluteValidPath(const wxString& filename);
376 // Given full path and filename, add path to list
377 void EnsureFileAccessible(const wxString& path);
378 // Returns TRUE if the path is in the list
a6f6393c
VZ
379 bool Member(const wxString& path);
380
381private:
382 DECLARE_DYNAMIC_CLASS(wxPathList)
c801d85f
KB
383};
384
385#endif
34138703 386 // _WX_FILEFN_H_