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