filefn.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/filefn.h
  3. // Purpose: File- and directory-related functions
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 29/01/98
  7. // Copyright: (c) 1998 Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _FILEFN_H_
  11. #define _FILEFN_H_
  12. #include "wx/list.h"
  13. #include "wx/arrstr.h"
  14. #ifdef __WXWINCE__
  15. #include "wx/msw/wince/time.h"
  16. #include "wx/msw/private.h"
  17. #else
  18. #include <time.h>
  19. #endif
  20. #ifndef __WXWINCE__
  21. #include <sys/types.h>
  22. #include <sys/stat.h>
  23. #endif
  24. #ifdef __OS2__
  25. // need to check for __OS2__ first since currently both
  26. // __OS2__ and __UNIX__ are defined.
  27. #include <process.h>
  28. #include "wx/os2/private.h"
  29. #ifdef __WATCOMC__
  30. #include <direct.h>
  31. #endif
  32. #include <io.h>
  33. #ifdef __EMX__
  34. #include <unistd.h>
  35. #endif
  36. #elif defined(__UNIX__)
  37. #include <unistd.h>
  38. #include <dirent.h>
  39. #endif
  40. #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
  41. #if !defined( __GNUWIN32__ ) && !defined(__WXWINCE__) && !defined(__CYGWIN__)
  42. #include <direct.h>
  43. #include <dos.h>
  44. #include <io.h>
  45. #endif // __WINDOWS__
  46. #endif // native Win compiler
  47. #if defined(__DOS__)
  48. #ifdef __WATCOMC__
  49. #include <direct.h>
  50. #include <dos.h>
  51. #include <io.h>
  52. #endif
  53. #ifdef __DJGPP__
  54. #include <io.h>
  55. #include <unistd.h>
  56. #endif
  57. #endif
  58. #ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
  59. // this (3.1 I believe) and how to test for it.
  60. // If this works for Borland 4.0 as well, then no worries.
  61. #include <dir.h>
  62. #endif
  63. #ifndef __WXWINCE__
  64. #include <fcntl.h> // O_RDONLY &c
  65. #endif
  66. // ----------------------------------------------------------------------------
  67. // constants
  68. // ----------------------------------------------------------------------------
  69. #if defined(__VISUALC__) || defined(__DIGITALMARS__)
  70. typedef int mode_t;
  71. #endif
  72. #ifdef __WXWINCE__
  73. typedef long off_t;
  74. #else
  75. // define off_t
  76. #if !defined(__WXMAC__) || defined(__UNIX__) || defined(__MACH__)
  77. #include <sys/types.h>
  78. #else
  79. typedef long off_t;
  80. #endif
  81. #endif
  82. #if defined(__VISUALC__) && !defined(__WXWINCE__)
  83. typedef _off_t off_t;
  84. #elif defined(__SYMANTEC__)
  85. typedef long off_t;
  86. #endif
  87. enum wxSeekMode
  88. {
  89. wxFromStart,
  90. wxFromCurrent,
  91. wxFromEnd
  92. };
  93. enum wxFileKind
  94. {
  95. wxFILE_KIND_UNKNOWN,
  96. wxFILE_KIND_DISK, // a file supporting seeking to arbitrary offsets
  97. wxFILE_KIND_TERMINAL, // a tty
  98. wxFILE_KIND_PIPE // a pipe
  99. };
  100. // we redefine these constants here because S_IREAD &c are _not_ standard
  101. // however, we do assume that the values correspond to the Unix umask bits
  102. enum wxPosixPermissions
  103. {
  104. // standard Posix names for these permission flags:
  105. wxS_IRUSR = 00400,
  106. wxS_IWUSR = 00200,
  107. wxS_IXUSR = 00100,
  108. wxS_IRGRP = 00040,
  109. wxS_IWGRP = 00020,
  110. wxS_IXGRP = 00010,
  111. wxS_IROTH = 00004,
  112. wxS_IWOTH = 00002,
  113. wxS_IXOTH = 00001,
  114. // longer but more readable synonyms for the constants above:
  115. wxPOSIX_USER_READ = wxS_IRUSR,
  116. wxPOSIX_USER_WRITE = wxS_IWUSR,
  117. wxPOSIX_USER_EXECUTE = wxS_IXUSR,
  118. wxPOSIX_GROUP_READ = wxS_IRGRP,
  119. wxPOSIX_GROUP_WRITE = wxS_IWGRP,
  120. wxPOSIX_GROUP_EXECUTE = wxS_IXGRP,
  121. wxPOSIX_OTHERS_READ = wxS_IROTH,
  122. wxPOSIX_OTHERS_WRITE = wxS_IWOTH,
  123. wxPOSIX_OTHERS_EXECUTE = wxS_IXOTH,
  124. // default mode for the new files: allow reading/writing them to everybody but
  125. // the effective file mode will be set after anding this value with umask and
  126. // so won't include wxS_IW{GRP,OTH} for the default 022 umask value
  127. wxS_DEFAULT = (wxPOSIX_USER_READ | wxPOSIX_USER_WRITE | \
  128. wxPOSIX_GROUP_READ | wxPOSIX_GROUP_WRITE | \
  129. wxPOSIX_OTHERS_READ | wxPOSIX_OTHERS_WRITE),
  130. // default mode for the new directories (see wxFileName::Mkdir): allow
  131. // reading/writing/executing them to everybody, but just like wxS_DEFAULT
  132. // the effective directory mode will be set after anding this value with umask
  133. wxS_DIR_DEFAULT = (wxPOSIX_USER_READ | wxPOSIX_USER_WRITE | wxPOSIX_USER_EXECUTE | \
  134. wxPOSIX_GROUP_READ | wxPOSIX_GROUP_WRITE | wxPOSIX_GROUP_EXECUTE | \
  135. wxPOSIX_OTHERS_READ | wxPOSIX_OTHERS_WRITE | wxPOSIX_OTHERS_EXECUTE)
  136. };
  137. // ----------------------------------------------------------------------------
  138. // declare our versions of low level file functions: some compilers prepend
  139. // underscores to the usual names, some also have Unicode versions of them
  140. // ----------------------------------------------------------------------------
  141. // Wrappers around Win32 api functions like CreateFile, ReadFile and such
  142. // Implemented in filefnwce.cpp
  143. #if defined( __WXWINCE__)
  144. typedef __int64 wxFileOffset;
  145. #define wxFileOffsetFmtSpec wxT("I64")
  146. WXDLLIMPEXP_BASE int wxCRT_Open(const wxChar *filename, int oflag, int WXUNUSED(pmode));
  147. WXDLLIMPEXP_BASE int wxCRT_Access(const wxChar *name, int WXUNUSED(how));
  148. WXDLLIMPEXP_BASE int wxCRT_Chmod(const wxChar *name, int WXUNUSED(how));
  149. WXDLLIMPEXP_BASE int wxClose(int fd);
  150. WXDLLIMPEXP_BASE int wxFsync(int WXUNUSED(fd));
  151. WXDLLIMPEXP_BASE int wxRead(int fd, void *buf, unsigned int count);
  152. WXDLLIMPEXP_BASE int wxWrite(int fd, const void *buf, unsigned int count);
  153. WXDLLIMPEXP_BASE int wxEof(int fd);
  154. WXDLLIMPEXP_BASE wxFileOffset wxSeek(int fd, wxFileOffset offset, int origin);
  155. #define wxLSeek wxSeek
  156. WXDLLIMPEXP_BASE wxFileOffset wxTell(int fd);
  157. // always Unicode under WinCE
  158. #define wxCRT_MkDir _wmkdir
  159. #define wxCRT_RmDir _wrmdir
  160. #define wxCRT_Stat _wstat
  161. #define wxStructStat struct _stat
  162. #elif (defined(__WINDOWS__) || defined(__OS2__)) && \
  163. ( \
  164. defined(__VISUALC__) || \
  165. defined(__MINGW64_TOOLCHAIN__) || \
  166. (defined(__MINGW32__) && !defined(__WINE__) && \
  167. wxCHECK_W32API_VERSION(0, 5)) || \
  168. defined(__DMC__) || \
  169. defined(__WATCOMC__) || \
  170. defined(__BORLANDC__) \
  171. )
  172. // temporary defines just used immediately below
  173. #undef wxHAS_HUGE_FILES
  174. #undef wxHAS_HUGE_STDIO_FILES
  175. // detect compilers which have support for huge files
  176. #if defined(__VISUALC__)
  177. #define wxHAS_HUGE_FILES 1
  178. #elif defined(__MINGW32__)
  179. #define wxHAS_HUGE_FILES 1
  180. #elif defined(_LARGE_FILES)
  181. #define wxHAS_HUGE_FILES 1
  182. #endif
  183. // detect compilers which have support for huge stdio files
  184. #if wxCHECK_VISUALC_VERSION(8)
  185. #define wxHAS_HUGE_STDIO_FILES
  186. #define wxFseek _fseeki64
  187. #define wxFtell _ftelli64
  188. #elif wxCHECK_MINGW32_VERSION(3, 5) // mingw-runtime version (not gcc)
  189. #define wxHAS_HUGE_STDIO_FILES
  190. #define wxFseek fseeko64
  191. #define wxFtell ftello64
  192. #endif
  193. // other Windows compilers (DMC, Watcom, and Borland) don't have huge file
  194. // support (or at least not all functions needed for it by wx) currently
  195. // types
  196. #ifdef wxHAS_HUGE_FILES
  197. typedef wxLongLong_t wxFileOffset;
  198. #define wxFileOffsetFmtSpec wxLongLongFmtSpec
  199. #else
  200. typedef off_t wxFileOffset;
  201. #endif
  202. // at least Borland 5.5 doesn't like "struct ::stat" so don't use the scope
  203. // resolution operator present in wxPOSIX_IDENT for it
  204. #ifdef __BORLANDC__
  205. #define wxPOSIX_STRUCT(s) struct s
  206. #else
  207. #define wxPOSIX_STRUCT(s) struct wxPOSIX_IDENT(s)
  208. #endif
  209. // Notice that Watcom is the only compiler to have a wide char
  210. // version of struct stat as well as a wide char stat function variant.
  211. // This was dropped since OW 1.4 "for consistency across platforms".
  212. //
  213. // Borland is also special in that it uses _stat with Unicode functions
  214. // (for MSVC compatibility?) but stat with ANSI ones
  215. #ifdef __BORLANDC__
  216. #if wxHAS_HUGE_FILES
  217. #define wxStructStat struct stati64
  218. #else
  219. #if wxUSE_UNICODE
  220. #define wxStructStat struct _stat
  221. #else
  222. #define wxStructStat struct stat
  223. #endif
  224. #endif
  225. #else // !__BORLANDC__
  226. #ifdef wxHAS_HUGE_FILES
  227. #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
  228. #define wxStructStat struct _wstati64
  229. #else
  230. #define wxStructStat struct _stati64
  231. #endif
  232. #else
  233. #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
  234. #define wxStructStat struct _wstat
  235. #else
  236. #define wxStructStat struct _stat
  237. #endif
  238. #endif
  239. #endif // __BORLANDC__/!__BORLANDC__
  240. // functions
  241. // MSVC and compatible compilers prepend underscores to the POSIX function
  242. // names, other compilers don't and even if their later versions usually do
  243. // define the versions with underscores for MSVC compatibility, it's better
  244. // to avoid using them as they're not present in earlier versions and
  245. // always using the native functions spelling is easier than testing for
  246. // the versions
  247. #if defined(__BORLANDC__) || defined(__DMC__) || defined(__WATCOMC__) || defined(__MINGW64_TOOLCHAIN__)
  248. #define wxPOSIX_IDENT(func) ::func
  249. #else // by default assume MSVC-compatible names
  250. #define wxPOSIX_IDENT(func) _ ## func
  251. #define wxHAS_UNDERSCORES_IN_POSIX_IDENTS
  252. #endif
  253. // first functions not working with strings, i.e. without ANSI/Unicode
  254. // complications
  255. #define wxClose wxPOSIX_IDENT(close)
  256. #define wxRead wxPOSIX_IDENT(read)
  257. #define wxWrite wxPOSIX_IDENT(write)
  258. #ifdef wxHAS_HUGE_FILES
  259. #ifndef __MINGW64_TOOLCHAIN__
  260. #define wxSeek wxPOSIX_IDENT(lseeki64)
  261. #define wxLseek wxPOSIX_IDENT(lseeki64)
  262. #define wxTell wxPOSIX_IDENT(telli64)
  263. #else
  264. // unfortunately, mingw-W64 is somewhat inconsistent...
  265. #define wxSeek _lseeki64
  266. #define wxLseek _lseeki64
  267. #define wxTell _telli64
  268. #endif
  269. #else // !wxHAS_HUGE_FILES
  270. #define wxSeek wxPOSIX_IDENT(lseek)
  271. #define wxLseek wxPOSIX_IDENT(lseek)
  272. #define wxTell wxPOSIX_IDENT(tell)
  273. #endif // wxHAS_HUGE_FILES/!wxHAS_HUGE_FILES
  274. #ifndef __WATCOMC__
  275. #if !defined(__BORLANDC__) || (__BORLANDC__ > 0x540)
  276. // NB: this one is not POSIX and always has the underscore
  277. #define wxFsync _commit
  278. // could be already defined by configure (Cygwin)
  279. #ifndef HAVE_FSYNC
  280. #define HAVE_FSYNC
  281. #endif
  282. #endif // BORLANDC
  283. #endif
  284. #define wxEof wxPOSIX_IDENT(eof)
  285. // then the functions taking strings
  286. // first the ANSI versions
  287. #define wxCRT_OpenA wxPOSIX_IDENT(open)
  288. #define wxCRT_AccessA wxPOSIX_IDENT(access)
  289. #define wxCRT_ChmodA wxPOSIX_IDENT(chmod)
  290. #define wxCRT_MkDirA wxPOSIX_IDENT(mkdir)
  291. #define wxCRT_RmDirA wxPOSIX_IDENT(rmdir)
  292. #ifdef wxHAS_HUGE_FILES
  293. // MinGW-64 provides underscore-less versions of all file functions
  294. // except for this one.
  295. #ifdef __MINGW64_TOOLCHAIN__
  296. #define wxCRT_StatA _stati64
  297. #else
  298. #define wxCRT_StatA wxPOSIX_IDENT(stati64)
  299. #endif
  300. #else
  301. // Unfortunately Watcom is not consistent
  302. #if defined(__OS2__) && defined(__WATCOMC__)
  303. #define wxCRT_StatA _stat
  304. #else
  305. #define wxCRT_StatA wxPOSIX_IDENT(stat)
  306. #endif
  307. #endif
  308. // then wide char ones
  309. #if wxUSE_UNICODE
  310. // special workaround for buggy wopen() in bcc 5.5
  311. #if defined(__BORLANDC__) && \
  312. (__BORLANDC__ >= 0x550 && __BORLANDC__ <= 0x551)
  313. WXDLLIMPEXP_BASE int wxCRT_OpenW(const wxChar *pathname,
  314. int flags, mode_t mode);
  315. #else
  316. #define wxCRT_OpenW _wopen
  317. #endif
  318. #define wxCRT_AccessW _waccess
  319. #define wxCRT_ChmodW _wchmod
  320. #define wxCRT_MkDirW _wmkdir
  321. #define wxCRT_RmDirW _wrmdir
  322. #ifdef wxHAS_HUGE_FILES
  323. #define wxCRT_StatW _wstati64
  324. #else
  325. #define wxCRT_StatW _wstat
  326. #endif
  327. #endif // wxUSE_UNICODE
  328. // finally the default char-type versions
  329. #if wxUSE_UNICODE
  330. #if wxUSE_UNICODE_MSLU || defined(__WX_STRICT_ANSI_GCC__)
  331. // implement the missing file functions in Win9x ourselves
  332. WXDLLIMPEXP_BASE int wxMSLU__wopen(const wxChar *name,
  333. int flags, int mode);
  334. WXDLLIMPEXP_BASE int wxMSLU__waccess(const wxChar *name,
  335. int mode);
  336. WXDLLIMPEXP_BASE int wxMSLU__wchmod(const wxChar *name,
  337. int mode);
  338. WXDLLIMPEXP_BASE int wxMSLU__wmkdir(const wxChar *name);
  339. WXDLLIMPEXP_BASE int wxMSLU__wrmdir(const wxChar *name);
  340. WXDLLIMPEXP_BASE int
  341. wxMSLU__wstat(const wxChar *name, wxStructStat *buffer);
  342. #define wxCRT_Open wxMSLU__wopen
  343. #define wxCRT_Access wxMSLU__waccess
  344. #define wxCRT_Chmod wxMSLU__wchmod
  345. #define wxCRT_MkDir wxMSLU__wmkdir
  346. #define wxCRT_RmDir wxMSLU__wrmdir
  347. #define wxCRT_Stat wxMSLU__wstat
  348. #else // !wxUSE_UNICODE_MSLU
  349. #define wxCRT_Open wxCRT_OpenW
  350. #define wxCRT_Access wxCRT_AccessW
  351. #define wxCRT_Chmod wxCRT_ChmodW
  352. #define wxCRT_MkDir wxCRT_MkDirW
  353. #define wxCRT_RmDir wxCRT_RmDirW
  354. #define wxCRT_Stat wxCRT_StatW
  355. #endif // wxUSE_UNICODE_MSLU/!wxUSE_UNICODE_MSLU
  356. #else // !wxUSE_UNICODE
  357. #define wxCRT_Open wxCRT_OpenA
  358. #define wxCRT_Access wxCRT_AccessA
  359. #define wxCRT_Chmod wxCRT_ChmodA
  360. #define wxCRT_MkDir wxCRT_MkDirA
  361. #define wxCRT_RmDir wxCRT_RmDirA
  362. #define wxCRT_Stat wxCRT_StatA
  363. #endif // wxUSE_UNICODE/!wxUSE_UNICODE
  364. // constants (unless already defined by the user code)
  365. #ifdef wxHAS_UNDERSCORES_IN_POSIX_IDENTS
  366. #ifndef O_RDONLY
  367. #define O_RDONLY _O_RDONLY
  368. #define O_WRONLY _O_WRONLY
  369. #define O_RDWR _O_RDWR
  370. #define O_EXCL _O_EXCL
  371. #define O_CREAT _O_CREAT
  372. #define O_BINARY _O_BINARY
  373. #endif
  374. #ifndef S_IFMT
  375. #define S_IFMT _S_IFMT
  376. #define S_IFDIR _S_IFDIR
  377. #define S_IFREG _S_IFREG
  378. #endif
  379. #endif // wxHAS_UNDERSCORES_IN_POSIX_IDENTS
  380. #ifdef wxHAS_HUGE_FILES
  381. // wxFile is present and supports large files.
  382. #if wxUSE_FILE
  383. #define wxHAS_LARGE_FILES
  384. #endif
  385. // wxFFile is present and supports large files
  386. #if wxUSE_FFILE && defined wxHAS_HUGE_STDIO_FILES
  387. #define wxHAS_LARGE_FFILES
  388. #endif
  389. #endif
  390. // private defines, undefine so that nobody gets tempted to use
  391. #undef wxHAS_HUGE_FILES
  392. #undef wxHAS_HUGE_STDIO_FILES
  393. #else // Unix or Windows using unknown compiler, assume POSIX supported
  394. typedef off_t wxFileOffset;
  395. #ifdef HAVE_LARGEFILE_SUPPORT
  396. #define wxFileOffsetFmtSpec wxLongLongFmtSpec
  397. wxCOMPILE_TIME_ASSERT( sizeof(off_t) == sizeof(wxLongLong_t),
  398. BadFileSizeType );
  399. // wxFile is present and supports large files
  400. #if wxUSE_FILE
  401. #define wxHAS_LARGE_FILES
  402. #endif
  403. // wxFFile is present and supports large files
  404. #if wxUSE_FFILE && (SIZEOF_LONG == 8 || defined HAVE_FSEEKO)
  405. #define wxHAS_LARGE_FFILES
  406. #endif
  407. #ifdef HAVE_FSEEKO
  408. #define wxFseek fseeko
  409. #define wxFtell ftello
  410. #endif
  411. #else
  412. #define wxFileOffsetFmtSpec wxT("")
  413. #endif
  414. // functions
  415. #define wxClose close
  416. #define wxRead ::read
  417. #define wxWrite ::write
  418. #define wxLseek lseek
  419. #define wxSeek lseek
  420. #define wxFsync fsync
  421. #define wxEof eof
  422. #define wxCRT_MkDir mkdir
  423. #define wxCRT_RmDir rmdir
  424. #define wxTell(fd) lseek(fd, 0, SEEK_CUR)
  425. #define wxStructStat struct stat
  426. #define wxCRT_Open open
  427. #define wxCRT_Stat stat
  428. #define wxCRT_Lstat lstat
  429. #define wxCRT_Access access
  430. #define wxCRT_Chmod chmod
  431. #define wxHAS_NATIVE_LSTAT
  432. #endif // platforms
  433. // if the platform doesn't have symlinks, define wxCRT_Lstat to be the same as
  434. // wxCRT_Stat to avoid #ifdefs in the code using it
  435. #ifndef wxHAS_NATIVE_LSTAT
  436. #define wxCRT_Lstat wxCRT_Stat
  437. #endif
  438. // define wxFseek/wxFtell to large file versions if available (done above) or
  439. // to fseek/ftell if not, to save ifdefs in using code
  440. #ifndef wxFseek
  441. #define wxFseek fseek
  442. #endif
  443. #ifndef wxFtell
  444. #define wxFtell ftell
  445. #endif
  446. inline int wxAccess(const wxString& path, mode_t mode)
  447. { return wxCRT_Access(path.fn_str(), mode); }
  448. inline int wxChmod(const wxString& path, mode_t mode)
  449. { return wxCRT_Chmod(path.fn_str(), mode); }
  450. inline int wxOpen(const wxString& path, int flags, mode_t mode)
  451. { return wxCRT_Open(path.fn_str(), flags, mode); }
  452. // FIXME-CE: provide our own implementations of the missing CRT functions
  453. #ifndef __WXWINCE__
  454. inline int wxStat(const wxString& path, wxStructStat *buf)
  455. { return wxCRT_Stat(path.fn_str(), buf); }
  456. inline int wxLstat(const wxString& path, wxStructStat *buf)
  457. { return wxCRT_Lstat(path.fn_str(), buf); }
  458. inline int wxRmDir(const wxString& path)
  459. { return wxCRT_RmDir(path.fn_str()); }
  460. #if (defined(__WINDOWS__) && !defined(__CYGWIN__)) \
  461. || (defined(__OS2__) && defined(__WATCOMC__))
  462. inline int wxMkDir(const wxString& path, mode_t WXUNUSED(mode) = 0)
  463. { return wxCRT_MkDir(path.fn_str()); }
  464. #else
  465. inline int wxMkDir(const wxString& path, mode_t mode)
  466. { return wxCRT_MkDir(path.fn_str(), mode); }
  467. #endif
  468. #endif // !__WXWINCE__
  469. #ifdef O_BINARY
  470. #define wxO_BINARY O_BINARY
  471. #else
  472. #define wxO_BINARY 0
  473. #endif
  474. #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
  475. //
  476. // VisualAge C++ V4.0 cannot have any external linkage const decs
  477. // in headers included by more than one primary source
  478. //
  479. extern const int wxInvalidOffset;
  480. #else
  481. const int wxInvalidOffset = -1;
  482. #endif
  483. // ----------------------------------------------------------------------------
  484. // functions
  485. // ----------------------------------------------------------------------------
  486. WXDLLIMPEXP_BASE bool wxFileExists(const wxString& filename);
  487. // does the path exist? (may have or not '/' or '\\' at the end)
  488. WXDLLIMPEXP_BASE bool wxDirExists(const wxString& pathName);
  489. WXDLLIMPEXP_BASE bool wxIsAbsolutePath(const wxString& filename);
  490. // Get filename
  491. WXDLLIMPEXP_BASE wxChar* wxFileNameFromPath(wxChar *path);
  492. WXDLLIMPEXP_BASE wxString wxFileNameFromPath(const wxString& path);
  493. // Get directory
  494. WXDLLIMPEXP_BASE wxString wxPathOnly(const wxString& path);
  495. // all deprecated functions below are deprecated in favour of wxFileName's methods
  496. #if WXWIN_COMPATIBILITY_2_8
  497. wxDEPRECATED( WXDLLIMPEXP_BASE void wxDos2UnixFilename(char *s) );
  498. wxDEPRECATED( WXDLLIMPEXP_BASE void wxDos2UnixFilename(wchar_t *s) );
  499. wxDEPRECATED_BUT_USED_INTERNALLY(
  500. WXDLLIMPEXP_BASE void wxUnix2DosFilename(char *s) );
  501. wxDEPRECATED_BUT_USED_INTERNALLY(
  502. WXDLLIMPEXP_BASE void wxUnix2DosFilename(wchar_t *s) );
  503. // Strip the extension, in situ
  504. // Deprecated in favour of wxFileName::StripExtension() but notice that their
  505. // behaviour is slightly different, see the manual
  506. wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(char *buffer) );
  507. wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wchar_t *buffer) );
  508. wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wxString& buffer) );
  509. // Get a temporary filename
  510. wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxChar* wxGetTempFileName(const wxString& prefix, wxChar *buf = NULL) );
  511. wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE bool wxGetTempFileName(const wxString& prefix, wxString& buf) );
  512. // Expand file name (~/ and ${OPENWINHOME}/ stuff)
  513. wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE char* wxExpandPath(char *dest, const wxString& path) );
  514. wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wchar_t* wxExpandPath(wchar_t *dest, const wxString& path) );
  515. // DEPRECATED: use wxFileName::Normalize(wxPATH_NORM_ENV_VARS)
  516. // Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
  517. // and make (if under the home tree) relative to home
  518. // [caller must copy-- volatile]
  519. wxDEPRECATED(
  520. WXDLLIMPEXP_BASE wxChar* wxContractPath(const wxString& filename,
  521. const wxString& envname = wxEmptyString,
  522. const wxString& user = wxEmptyString) );
  523. // DEPRECATED: use wxFileName::ReplaceEnvVariable and wxFileName::ReplaceHomeDir
  524. // Destructive removal of /./ and /../ stuff
  525. wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE char* wxRealPath(char *path) );
  526. wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wchar_t* wxRealPath(wchar_t *path) );
  527. wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxString wxRealPath(const wxString& path) );
  528. // DEPRECATED: use wxFileName::Normalize instead
  529. // Allocate a copy of the full absolute path
  530. wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* wxCopyAbsolutePath(const wxString& path) );
  531. // DEPRECATED: use wxFileName::MakeAbsolute instead
  532. #endif
  533. // Get first file name matching given wild card.
  534. // Flags are reserved for future use.
  535. #define wxFILE 1
  536. #define wxDIR 2
  537. WXDLLIMPEXP_BASE wxString wxFindFirstFile(const wxString& spec, int flags = wxFILE);
  538. WXDLLIMPEXP_BASE wxString wxFindNextFile();
  539. // Does the pattern contain wildcards?
  540. WXDLLIMPEXP_BASE bool wxIsWild(const wxString& pattern);
  541. // Does the pattern match the text (usually a filename)?
  542. // If dot_special is true, doesn't match * against . (eliminating
  543. // `hidden' dot files)
  544. WXDLLIMPEXP_BASE bool wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = true);
  545. // Concatenate two files to form third
  546. WXDLLIMPEXP_BASE bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
  547. // Copy file1 to file2
  548. WXDLLIMPEXP_BASE bool wxCopyFile(const wxString& file1, const wxString& file2,
  549. bool overwrite = true);
  550. // Remove file
  551. WXDLLIMPEXP_BASE bool wxRemoveFile(const wxString& file);
  552. // Rename file
  553. WXDLLIMPEXP_BASE bool wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite = true);
  554. // Get current working directory.
  555. #if WXWIN_COMPATIBILITY_2_6
  556. // If buf is NULL, allocates space using new, else
  557. // copies into buf.
  558. // IMPORTANT NOTE getcwd is know not to work under some releases
  559. // of Win32s 1.3, according to MS release notes!
  560. wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* wxGetWorkingDirectory(wxChar *buf = NULL, int sz = 1000) );
  561. // new and preferred version of wxGetWorkingDirectory
  562. // NB: can't have the same name because of overloading ambiguity
  563. #endif // WXWIN_COMPATIBILITY_2_6
  564. WXDLLIMPEXP_BASE wxString wxGetCwd();
  565. // Set working directory
  566. WXDLLIMPEXP_BASE bool wxSetWorkingDirectory(const wxString& d);
  567. // Make directory
  568. WXDLLIMPEXP_BASE bool wxMkdir(const wxString& dir, int perm = wxS_DIR_DEFAULT);
  569. // Remove directory. Flags reserved for future use.
  570. WXDLLIMPEXP_BASE bool wxRmdir(const wxString& dir, int flags = 0);
  571. // Return the type of an open file
  572. WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(int fd);
  573. WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(FILE *fp);
  574. #if WXWIN_COMPATIBILITY_2_6
  575. // compatibility defines, don't use in new code
  576. wxDEPRECATED( inline bool wxPathExists(const wxChar *pszPathName) );
  577. inline bool wxPathExists(const wxChar *pszPathName)
  578. {
  579. return wxDirExists(pszPathName);
  580. }
  581. #endif //WXWIN_COMPATIBILITY_2_6
  582. // permissions; these functions work both on files and directories:
  583. WXDLLIMPEXP_BASE bool wxIsWritable(const wxString &path);
  584. WXDLLIMPEXP_BASE bool wxIsReadable(const wxString &path);
  585. WXDLLIMPEXP_BASE bool wxIsExecutable(const wxString &path);
  586. // ----------------------------------------------------------------------------
  587. // separators in file names
  588. // ----------------------------------------------------------------------------
  589. // between file name and extension
  590. #define wxFILE_SEP_EXT wxT('.')
  591. // between drive/volume name and the path
  592. #define wxFILE_SEP_DSK wxT(':')
  593. // between the path components
  594. #define wxFILE_SEP_PATH_DOS wxT('\\')
  595. #define wxFILE_SEP_PATH_UNIX wxT('/')
  596. #define wxFILE_SEP_PATH_MAC wxT(':')
  597. #define wxFILE_SEP_PATH_VMS wxT('.') // VMS also uses '[' and ']'
  598. // separator in the path list (as in PATH environment variable)
  599. // there is no PATH variable in Classic Mac OS so just use the
  600. // semicolon (it must be different from the file name separator)
  601. // NB: these are strings and not characters on purpose!
  602. #define wxPATH_SEP_DOS wxT(";")
  603. #define wxPATH_SEP_UNIX wxT(":")
  604. #define wxPATH_SEP_MAC wxT(";")
  605. // platform independent versions
  606. #if defined(__UNIX__) && !defined(__OS2__)
  607. // CYGWIN also uses UNIX settings
  608. #define wxFILE_SEP_PATH wxFILE_SEP_PATH_UNIX
  609. #define wxPATH_SEP wxPATH_SEP_UNIX
  610. #elif defined(__MAC__)
  611. #define wxFILE_SEP_PATH wxFILE_SEP_PATH_MAC
  612. #define wxPATH_SEP wxPATH_SEP_MAC
  613. #else // Windows and OS/2
  614. #define wxFILE_SEP_PATH wxFILE_SEP_PATH_DOS
  615. #define wxPATH_SEP wxPATH_SEP_DOS
  616. #endif // Unix/Windows
  617. // this is useful for wxString::IsSameAs(): to compare two file names use
  618. // filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
  619. #if defined(__UNIX__) && !defined(__DARWIN__) && !defined(__OS2__)
  620. #define wxARE_FILENAMES_CASE_SENSITIVE true
  621. #else // Windows, Mac OS and OS/2
  622. #define wxARE_FILENAMES_CASE_SENSITIVE false
  623. #endif // Unix/Windows
  624. // is the char a path separator?
  625. inline bool wxIsPathSeparator(wxChar c)
  626. {
  627. // under DOS/Windows we should understand both Unix and DOS file separators
  628. #if ( defined(__UNIX__) && !defined(__OS2__) )|| defined(__MAC__)
  629. return c == wxFILE_SEP_PATH;
  630. #else
  631. return c == wxFILE_SEP_PATH_DOS || c == wxFILE_SEP_PATH_UNIX;
  632. #endif
  633. }
  634. // does the string ends with path separator?
  635. WXDLLIMPEXP_BASE bool wxEndsWithPathSeparator(const wxString& filename);
  636. #if WXWIN_COMPATIBILITY_2_8
  637. // split the full path into path (including drive for DOS), name and extension
  638. // (understands both '/' and '\\')
  639. // Deprecated in favour of wxFileName::SplitPath
  640. wxDEPRECATED( WXDLLIMPEXP_BASE void wxSplitPath(const wxString& fileName,
  641. wxString *pstrPath,
  642. wxString *pstrName,
  643. wxString *pstrExt) );
  644. #endif
  645. // find a file in a list of directories, returns false if not found
  646. WXDLLIMPEXP_BASE bool wxFindFileInPath(wxString *pStr, const wxString& szPath, const wxString& szFile);
  647. // Get the OS directory if appropriate (such as the Windows directory).
  648. // On non-Windows platform, probably just return the empty string.
  649. WXDLLIMPEXP_BASE wxString wxGetOSDirectory();
  650. #if wxUSE_DATETIME
  651. // Get file modification time
  652. WXDLLIMPEXP_BASE time_t wxFileModificationTime(const wxString& filename);
  653. #endif // wxUSE_DATETIME
  654. // Parses the wildCard, returning the number of filters.
  655. // Returns 0 if none or if there's a problem,
  656. // The arrays will contain an equal number of items found before the error.
  657. // wildCard is in the form:
  658. // "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
  659. WXDLLIMPEXP_BASE int wxParseCommonDialogsFilter(const wxString& wildCard, wxArrayString& descriptions, wxArrayString& filters);
  660. // ----------------------------------------------------------------------------
  661. // classes
  662. // ----------------------------------------------------------------------------
  663. #ifdef __UNIX__
  664. // set umask to the given value in ctor and reset it to the old one in dtor
  665. class WXDLLIMPEXP_BASE wxUmaskChanger
  666. {
  667. public:
  668. // change the umask to the given one if it is not -1: this allows to write
  669. // the same code whether you really want to change umask or not, as is in
  670. // wxFileConfig::Flush() for example
  671. wxUmaskChanger(int umaskNew)
  672. {
  673. m_umaskOld = umaskNew == -1 ? -1 : (int)umask((mode_t)umaskNew);
  674. }
  675. ~wxUmaskChanger()
  676. {
  677. if ( m_umaskOld != -1 )
  678. umask((mode_t)m_umaskOld);
  679. }
  680. private:
  681. int m_umaskOld;
  682. };
  683. // this macro expands to an "anonymous" wxUmaskChanger object under Unix and
  684. // nothing elsewhere
  685. #define wxCHANGE_UMASK(m) wxUmaskChanger wxMAKE_UNIQUE_NAME(umaskChanger_)(m)
  686. #else // !__UNIX__
  687. #define wxCHANGE_UMASK(m)
  688. #endif // __UNIX__/!__UNIX__
  689. // Path searching
  690. class WXDLLIMPEXP_BASE wxPathList : public wxArrayString
  691. {
  692. public:
  693. wxPathList() {}
  694. wxPathList(const wxArrayString &arr)
  695. { Add(arr); }
  696. // Adds all paths in environment variable
  697. void AddEnvList(const wxString& envVariable);
  698. // Adds given path to this list
  699. bool Add(const wxString& path);
  700. void Add(const wxArrayString &paths);
  701. // Find the first full path for which the file exists
  702. wxString FindValidPath(const wxString& filename) const;
  703. // Find the first full path for which the file exists; ensure it's an
  704. // absolute path that gets returned.
  705. wxString FindAbsoluteValidPath(const wxString& filename) const;
  706. // Given full path and filename, add path to list
  707. bool EnsureFileAccessible(const wxString& path);
  708. #if WXWIN_COMPATIBILITY_2_6
  709. // Returns true if the path is in the list
  710. wxDEPRECATED( bool Member(const wxString& path) const );
  711. #endif
  712. };
  713. #endif // _WX_FILEFN_H_