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