]> git.saurik.com Git - wxWidgets.git/blob - include/wx/filefn.h
SF patch [ 708702 ] Wide character filename support for BCC
[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(__APPLE__)
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(__SC__)
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 WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
70
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
77 #if defined( __VISUALC__ ) \
78 || ( defined(__MINGW32__) && !defined(__WINE__) && wxCHECK_W32API_VERSION( 0, 5 ) ) \
79 || ( defined(__MWERKS__) && defined(__WXMSW__) )
80 // functions
81 #ifdef __BORLANDC__
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 #ifdef __BORLANDC__
96 #define wxOpen open
97 #else
98 #define wxOpen _open
99 #endif
100 #define wxAccess wxMSLU__waccess
101 #define wxMkDir wxMSLU__wmkdir
102 #define wxRmDir wxMSLU__wrmdir
103 #define wxStat wxMSLU__wstat
104 #else
105 #define wxOpen _wopen
106 #define wxAccess _waccess
107 #define wxMkDir _wmkdir
108 #define wxRmDir _wrmdir
109 #define wxStat _wstat
110 #endif
111 #else // !wxUSE_UNICODE
112 #define wxOpen _open
113 #define wxAccess _access
114 #define wxMkDir _mkdir
115 #define wxRmDir _rmdir
116 #define wxStat _stat
117 #endif
118
119 // types
120 #define wxStructStat struct _stat
121
122 // constants (unless already defined by the user code)
123 #if !defined(O_RDONLY) && !defined(__BORLANDC__)
124 #define O_RDONLY _O_RDONLY
125 #define O_WRONLY _O_WRONLY
126 #define O_RDWR _O_RDWR
127 #define O_EXCL _O_EXCL
128 #define O_CREAT _O_CREAT
129 #define O_BINARY _O_BINARY
130 #endif
131
132 #ifndef __BORLANDC__
133 #define S_IFMT _S_IFMT
134 #define S_IFDIR _S_IFDIR
135 #define S_IFREG _S_IFREG
136 #endif // O_RDONLY
137 #else
138 // functions
139 #define wxClose close
140 #define wxRead read
141 #define wxWrite write
142 #define wxLseek lseek
143 #define wxFsync commit
144 #define wxEof eof
145
146 #define wxMkDir mkdir
147 #define wxRmDir rmdir
148
149 #define wxTell(fd) lseek(fd, 0, SEEK_CUR)
150
151 #define wxStructStat struct stat
152
153 #if wxUSE_UNICODE
154 # define wxNEED_WX_UNISTD_H
155 #if defined(__MWERKS__) && defined(macintosh)
156 #include <sys/stat.h>
157 #endif
158 WXDLLEXPORT int wxStat( const wxChar *file_name, wxStructStat *buf );
159 WXDLLEXPORT int wxAccess( const wxChar *pathname, int mode );
160 WXDLLEXPORT int wxOpen( const wxChar *pathname, int flags, mode_t mode );
161 #else
162 #define wxOpen open
163 #define wxStat stat
164 #define wxAccess access
165 #endif
166
167 #endif // VC++
168
169 // ----------------------------------------------------------------------------
170 // functions
171 // ----------------------------------------------------------------------------
172 WXDLLEXPORT bool wxFileExists(const wxString& filename);
173
174 // does the path exist? (may have or not '/' or '\\' at the end)
175 WXDLLEXPORT bool wxPathExists(const wxChar *pszPathName);
176
177 WXDLLEXPORT bool wxIsAbsolutePath(const wxString& filename);
178
179 // Get filename
180 WXDLLEXPORT wxChar* wxFileNameFromPath(wxChar *path);
181 WXDLLEXPORT wxString wxFileNameFromPath(const wxString& path);
182
183 // Get directory
184 WXDLLEXPORT wxString wxPathOnly(const wxString& path);
185
186 // wxString version
187 WXDLLEXPORT wxString wxRealPath(const wxString& path);
188
189 WXDLLEXPORT void wxDos2UnixFilename(wxChar *s);
190
191 WXDLLEXPORT void wxUnix2DosFilename(wxChar *s);
192
193 // Strip the extension, in situ
194 WXDLLEXPORT void wxStripExtension(wxChar *buffer);
195 WXDLLEXPORT void wxStripExtension(wxString& buffer);
196
197 // Get a temporary filename
198 WXDLLEXPORT wxChar* wxGetTempFileName(const wxString& prefix, wxChar *buf = (wxChar *) NULL);
199 WXDLLEXPORT bool wxGetTempFileName(const wxString& prefix, wxString& buf);
200
201 // Expand file name (~/ and ${OPENWINHOME}/ stuff)
202 WXDLLEXPORT wxChar* wxExpandPath(wxChar *dest, const wxChar *path);
203 WXDLLEXPORT bool wxExpandPath(wxString& dest, const wxChar *path);
204
205 // Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
206 // and make (if under the home tree) relative to home
207 // [caller must copy-- volatile]
208 WXDLLEXPORT wxChar* wxContractPath(const wxString& filename,
209 const wxString& envname = wxEmptyString,
210 const wxString& user = wxEmptyString);
211
212 // Destructive removal of /./ and /../ stuff
213 WXDLLEXPORT wxChar* wxRealPath(wxChar *path);
214
215 // Allocate a copy of the full absolute path
216 WXDLLEXPORT wxChar* wxCopyAbsolutePath(const wxString& path);
217
218 // Get first file name matching given wild card.
219 // Flags are reserved for future use.
220 #define wxFILE 1
221 #define wxDIR 2
222 WXDLLEXPORT wxString wxFindFirstFile(const wxChar *spec, int flags = wxFILE);
223 WXDLLEXPORT wxString wxFindNextFile();
224
225 // Does the pattern contain wildcards?
226 WXDLLEXPORT bool wxIsWild(const wxString& pattern);
227
228 // Does the pattern match the text (usually a filename)?
229 // If dot_special is TRUE, doesn't match * against . (eliminating
230 // `hidden' dot files)
231 WXDLLEXPORT bool wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = TRUE);
232
233 // Concatenate two files to form third
234 WXDLLEXPORT bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
235
236 // Copy file1 to file2
237 WXDLLEXPORT bool wxCopyFile(const wxString& file1, const wxString& file2,
238 bool overwrite = TRUE);
239
240 // Remove file
241 WXDLLEXPORT bool wxRemoveFile(const wxString& file);
242
243 // Rename file
244 WXDLLEXPORT bool wxRenameFile(const wxString& file1, const wxString& file2);
245
246 // Get current working directory.
247 // If buf is NULL, allocates space using new, else
248 // copies into buf.
249 // IMPORTANT NOTE getcwd is know not to work under some releases
250 // of Win32s 1.3, according to MS release notes!
251 WXDLLEXPORT wxChar* wxGetWorkingDirectory(wxChar *buf = (wxChar *) NULL, int sz = 1000);
252 // new and preferred version of wxGetWorkingDirectory
253 // NB: can't have the same name because of overloading ambiguity
254 WXDLLEXPORT wxString wxGetCwd();
255
256 // Set working directory
257 WXDLLEXPORT bool wxSetWorkingDirectory(const wxString& d);
258
259 // Make directory
260 WXDLLEXPORT bool wxMkdir(const wxString& dir, int perm = 0777);
261
262 // Remove directory. Flags reserved for future use.
263 WXDLLEXPORT bool wxRmdir(const wxString& dir, int flags = 0);
264
265 // compatibility defines, don't use in new code
266 #define wxDirExists wxPathExists
267
268 #if WXWIN_COMPATIBILITY_2
269 #define FileExists wxFileExists
270 #define DirExists wxDirExists
271 #define IsAbsolutePath wxIsAbsolutePath
272 #define FileNameFromPath wxFileNameFromPath
273 #define PathOnly wxPathOnly
274 #define Dos2UnixFilename wxDos2UnixFilename
275 #define Unix2DosFilename wxUnix2DosFilename
276 #endif
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__)
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__)
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(__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 WXDLLEXPORT 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 WXDLLEXPORT 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 WXDLLEXPORT 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 WXDLLEXPORT wxString wxGetOSDirectory();
352
353 // Get file modification time
354 WXDLLEXPORT time_t wxFileModificationTime(const wxString& filename);
355
356 // ----------------------------------------------------------------------------
357 // classes
358 // ----------------------------------------------------------------------------
359
360 // Path searching
361 class WXDLLEXPORT wxPathList : public wxStringList
362 {
363 public:
364 // Adds all paths in environment variable
365 void AddEnvList(const wxString& envVariable);
366
367 void Add(const wxString& path);
368 // Avoid compiler warning
369 wxNode *Add(const wxChar *s) { return wxStringList::Add(s); }
370 // Find the first full path for which the file exists
371 wxString FindValidPath(const wxString& filename);
372 // Find the first full path for which the file exists; ensure it's an
373 // absolute path that gets returned.
374 wxString FindAbsoluteValidPath(const wxString& filename);
375 // Given full path and filename, add path to list
376 void EnsureFileAccessible(const wxString& path);
377 // Returns TRUE if the path is in the list
378 bool Member(const wxString& path);
379
380 private:
381 DECLARE_DYNAMIC_CLASS(wxPathList)
382 };
383
384 #endif
385 // _WX_FILEFN_H_