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