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