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