]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/filefn.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: File- and directory-related functions
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "filefn.h"
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
34 #if !defined(__WXMAC__) || defined(__UNIX__) || defined(__MACH__)
35 #include <sys/types.h>
40 #if defined(__VISUALC__) || ( defined(__MWERKS__) && defined( __INTEL__) )
42 #elif defined(__BORLANDC__) && defined(__WIN16__)
44 #elif defined(__SYMANTEC__)
46 #elif defined(__MWERKS__) && !defined(__INTEL__) && !defined(__MACH__)
52 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
54 // VisualAge C++ V4.0 cannot have any external linkage const decs
55 // in headers included by more than one primary source
57 extern const off_t wxInvalidOffset
;
59 const off_t wxInvalidOffset
= (off_t
)-1;
69 WXDLLEXPORT_DATA(extern const wxChar
*) wxEmptyString
;
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 // ----------------------------------------------------------------------------
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__) )
84 #define wxClose _close
86 #define wxWrite _write
87 #define wxLseek _lseek
88 #define wxFsync _commit
94 #if wxUSE_UNICODE_MSLU
95 #define wxOpen wxMSLU__wopen
97 #define wxAccess wxMSLU__waccess
98 #define wxMkDir wxMSLU__wmkdir
99 #define wxRmDir wxMSLU__wrmdir
100 #define wxStat wxMSLU__wstat
102 #define wxOpen _wopen
103 #define wxAccess _waccess
104 #define wxMkDir _wmkdir
105 #define wxRmDir _wrmdir
106 #define wxStat _wstat
108 #else // !wxUSE_UNICODE
114 #define wxAccess _access
115 #define wxMkDir _mkdir
116 #define wxRmDir _rmdir
121 #define wxStructStat struct _stat
123 // constants (unless already defined by the user code)
124 #if !defined(O_RDONLY) && !defined(__BORLANDC__)
125 #define O_RDONLY _O_RDONLY
126 #define O_WRONLY _O_WRONLY
127 #define O_RDWR _O_RDWR
128 #define O_EXCL _O_EXCL
129 #define O_CREAT _O_CREAT
130 #define O_BINARY _O_BINARY
134 #define S_IFMT _S_IFMT
135 #define S_IFDIR _S_IFDIR
136 #define S_IFREG _S_IFREG
140 #define wxClose close
142 #define wxWrite write
143 #define wxLseek lseek
144 #define wxFsync commit
147 #define wxMkDir mkdir
148 #define wxRmDir rmdir
150 #define wxTell(fd) lseek(fd, 0, SEEK_CUR)
152 #define wxStructStat struct stat
155 # define wxNEED_WX_UNISTD_H
156 #if defined(__MWERKS__) && defined(macintosh)
157 #include <sys/stat.h>
159 WXDLLEXPORT
int wxStat( const wxChar
*file_name
, wxStructStat
*buf
);
160 WXDLLEXPORT
int wxAccess( const wxChar
*pathname
, int mode
);
161 WXDLLEXPORT
int wxOpen( const wxChar
*pathname
, int flags
, mode_t mode
);
165 #define wxAccess access
170 // ----------------------------------------------------------------------------
172 // ----------------------------------------------------------------------------
173 WXDLLEXPORT
bool wxFileExists(const wxString
& filename
);
175 // does the path exist? (may have or not '/' or '\\' at the end)
176 WXDLLEXPORT
bool wxPathExists(const wxChar
*pszPathName
);
178 WXDLLEXPORT
bool wxIsAbsolutePath(const wxString
& filename
);
181 WXDLLEXPORT wxChar
* wxFileNameFromPath(wxChar
*path
);
182 WXDLLEXPORT wxString
wxFileNameFromPath(const wxString
& path
);
185 WXDLLEXPORT wxString
wxPathOnly(const wxString
& path
);
188 WXDLLEXPORT wxString
wxRealPath(const wxString
& path
);
190 WXDLLEXPORT
void wxDos2UnixFilename(wxChar
*s
);
192 WXDLLEXPORT
void wxUnix2DosFilename(wxChar
*s
);
194 // Strip the extension, in situ
195 WXDLLEXPORT
void wxStripExtension(wxChar
*buffer
);
196 WXDLLEXPORT
void wxStripExtension(wxString
& buffer
);
198 // Get a temporary filename
199 WXDLLEXPORT wxChar
* wxGetTempFileName(const wxString
& prefix
, wxChar
*buf
= (wxChar
*) NULL
);
200 WXDLLEXPORT
bool wxGetTempFileName(const wxString
& prefix
, wxString
& buf
);
202 // Expand file name (~/ and ${OPENWINHOME}/ stuff)
203 WXDLLEXPORT wxChar
* wxExpandPath(wxChar
*dest
, const wxChar
*path
);
204 WXDLLEXPORT
bool wxExpandPath(wxString
& dest
, const wxChar
*path
);
206 // Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
207 // and make (if under the home tree) relative to home
208 // [caller must copy-- volatile]
209 WXDLLEXPORT wxChar
* wxContractPath(const wxString
& filename
,
210 const wxString
& envname
= wxEmptyString
,
211 const wxString
& user
= wxEmptyString
);
213 // Destructive removal of /./ and /../ stuff
214 WXDLLEXPORT wxChar
* wxRealPath(wxChar
*path
);
216 // Allocate a copy of the full absolute path
217 WXDLLEXPORT wxChar
* wxCopyAbsolutePath(const wxString
& path
);
219 // Get first file name matching given wild card.
220 // Flags are reserved for future use.
223 WXDLLEXPORT wxString
wxFindFirstFile(const wxChar
*spec
, int flags
= wxFILE
);
224 WXDLLEXPORT wxString
wxFindNextFile();
226 // Does the pattern contain wildcards?
227 WXDLLEXPORT
bool wxIsWild(const wxString
& pattern
);
229 // Does the pattern match the text (usually a filename)?
230 // If dot_special is TRUE, doesn't match * against . (eliminating
231 // `hidden' dot files)
232 WXDLLEXPORT
bool wxMatchWild(const wxString
& pattern
, const wxString
& text
, bool dot_special
= TRUE
);
234 // Concatenate two files to form third
235 WXDLLEXPORT
bool wxConcatFiles(const wxString
& file1
, const wxString
& file2
, const wxString
& file3
);
237 // Copy file1 to file2
238 WXDLLEXPORT
bool wxCopyFile(const wxString
& file1
, const wxString
& file2
,
239 bool overwrite
= TRUE
);
242 WXDLLEXPORT
bool wxRemoveFile(const wxString
& file
);
245 WXDLLEXPORT
bool wxRenameFile(const wxString
& file1
, const wxString
& file2
);
247 // Get current working directory.
248 // If buf is NULL, allocates space using new, else
250 // IMPORTANT NOTE getcwd is know not to work under some releases
251 // of Win32s 1.3, according to MS release notes!
252 WXDLLEXPORT wxChar
* wxGetWorkingDirectory(wxChar
*buf
= (wxChar
*) NULL
, int sz
= 1000);
253 // new and preferred version of wxGetWorkingDirectory
254 // NB: can't have the same name because of overloading ambiguity
255 WXDLLEXPORT wxString
wxGetCwd();
257 // Set working directory
258 WXDLLEXPORT
bool wxSetWorkingDirectory(const wxString
& d
);
261 WXDLLEXPORT
bool wxMkdir(const wxString
& dir
, int perm
= 0777);
263 // Remove directory. Flags reserved for future use.
264 WXDLLEXPORT
bool wxRmdir(const wxString
& dir
, int flags
= 0);
266 // compatibility defines, don't use in new code
267 #define wxDirExists wxPathExists
269 #if WXWIN_COMPATIBILITY_2
270 #define FileExists wxFileExists
271 #define DirExists wxDirExists
272 #define IsAbsolutePath wxIsAbsolutePath
273 #define FileNameFromPath wxFileNameFromPath
274 #define PathOnly wxPathOnly
275 #define Dos2UnixFilename wxDos2UnixFilename
276 #define Unix2DosFilename wxUnix2DosFilename
279 // ----------------------------------------------------------------------------
280 // separators in file names
281 // ----------------------------------------------------------------------------
283 // between file name and extension
284 #define wxFILE_SEP_EXT wxT('.')
286 // between drive/volume name and the path
287 #define wxFILE_SEP_DSK wxT(':')
289 // between the path components
290 #define wxFILE_SEP_PATH_DOS wxT('\\')
291 #define wxFILE_SEP_PATH_UNIX wxT('/')
292 #define wxFILE_SEP_PATH_MAC wxT(':')
293 #define wxFILE_SEP_PATH_VMS wxT('.') // VMS also uses '[' and ']'
295 // separator in the path list (as in PATH environment variable)
296 // there is no PATH variable in Classic Mac OS so just use the
297 // semicolon (it must be different from the file name separator)
298 // NB: these are strings and not characters on purpose!
299 #define wxPATH_SEP_DOS wxT(";")
300 #define wxPATH_SEP_UNIX wxT(":")
301 #define wxPATH_SEP_MAC wxT(";")
303 // platform independent versions
304 #if defined(__UNIX__) && !defined(__CYGWIN__)
305 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_UNIX
306 #define wxPATH_SEP wxPATH_SEP_UNIX
307 #elif defined(__MAC__)
308 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_MAC
309 #define wxPATH_SEP wxPATH_SEP_MAC
310 #elif defined(__CYGWIN__) // Cygwin
311 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_DOS
312 #define wxPATH_SEP wxPATH_SEP_UNIX
313 #else // Windows and OS/2
314 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_DOS
315 #define wxPATH_SEP wxPATH_SEP_DOS
316 #endif // Unix/Windows
318 // this is useful for wxString::IsSameAs(): to compare two file names use
319 // filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
320 #if defined(__UNIX__) && !defined(__DARWIN__)
321 #define wxARE_FILENAMES_CASE_SENSITIVE TRUE
322 #else // Windows, Mac OS and OS/2
323 #define wxARE_FILENAMES_CASE_SENSITIVE FALSE
324 #endif // Unix/Windows
326 // is the char a path separator?
327 inline bool wxIsPathSeparator(wxChar c
)
329 // under DOS/Windows we should understand both Unix and DOS file separators
330 #if defined(__UNIX__) || defined(__MAC__)
331 return c
== wxFILE_SEP_PATH
;
333 return c
== wxFILE_SEP_PATH_DOS
|| c
== wxFILE_SEP_PATH_UNIX
;
337 // does the string ends with path separator?
338 WXDLLEXPORT
bool wxEndsWithPathSeparator(const wxChar
*pszFileName
);
340 // split the full path into path (including drive for DOS), name and extension
341 // (understands both '/' and '\\')
342 WXDLLEXPORT
void wxSplitPath(const wxChar
*pszFileName
,
347 // find a file in a list of directories, returns false if not found
348 WXDLLEXPORT
bool wxFindFileInPath(wxString
*pStr
, const wxChar
*pszPath
, const wxChar
*pszFile
);
350 // Get the OS directory if appropriate (such as the Windows directory).
351 // On non-Windows platform, probably just return the empty string.
352 WXDLLEXPORT wxString
wxGetOSDirectory();
354 // Get file modification time
355 WXDLLEXPORT
time_t wxFileModificationTime(const wxString
& filename
);
357 // ----------------------------------------------------------------------------
359 // ----------------------------------------------------------------------------
362 class WXDLLEXPORT wxPathList
: public wxStringList
365 // Adds all paths in environment variable
366 void AddEnvList(const wxString
& envVariable
);
368 void Add(const wxString
& path
);
369 // Avoid compiler warning
370 wxNode
*Add(const wxChar
*s
) { return wxStringList::Add(s
); }
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
);
382 DECLARE_DYNAMIC_CLASS(wxPathList
)