]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: file.cpp | |
3 | // Purpose: wxFile - encapsulates low-level "file descriptor" | |
4 | // wxTempFile | |
5 | // Author: Vadim Zeitlin | |
6 | // Modified by: | |
7 | // Created: 29/01/98 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
246037e2 | 10 | // Licence: wxWindows license |
c801d85f KB |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
13 | // ---------------------------------------------------------------------------- | |
14 | // headers | |
15 | // ---------------------------------------------------------------------------- | |
16 | ||
17 | #ifdef __GNUG__ | |
3f4a0c5b | 18 | #pragma implementation "file.h" |
c801d85f KB |
19 | #endif |
20 | ||
21 | // For compilers that support precompilation, includes "wx.h". | |
22 | #include "wx/wxprec.h" | |
c801d85f KB |
23 | |
24 | #ifdef __BORLANDC__ | |
ce4169a4 | 25 | #pragma hdrstop |
c801d85f KB |
26 | #endif |
27 | ||
ce4169a4 RR |
28 | #if wxUSE_FILE |
29 | ||
c801d85f | 30 | // standard |
b4da152e | 31 | #if defined(__WXMSW__) && !defined(__GNUWIN32__) && !defined(__WXMICROWIN__) |
c801d85f | 32 | #include <io.h> |
30a5be97 | 33 | |
a3ef5bf5 | 34 | #ifndef __SALFORDC__ |
49d5d881 VZ |
35 | #define WIN32_LEAN_AND_MEAN |
36 | #define NOSERVICE | |
37 | #define NOIME | |
38 | #define NOATOM | |
39 | #define NOGDI | |
40 | #define NOGDICAPMASKS | |
41 | #define NOMETAFILE | |
42 | #define NOMINMAX | |
43 | #define NOMSG | |
44 | #define NOOPENFILE | |
45 | #define NORASTEROPS | |
46 | #define NOSCROLL | |
47 | #define NOSOUND | |
48 | #define NOSYSMETRICS | |
49 | #define NOTEXTMETRIC | |
50 | #define NOWH | |
51 | #define NOCOMM | |
52 | #define NOKANJI | |
53 | #define NOCRYPT | |
54 | #define NOMCX | |
a3ef5bf5 JS |
55 | #endif |
56 | ||
c801d85f | 57 | #elif (defined(__UNIX__) || defined(__GNUWIN32__)) |
3f4a0c5b | 58 | #include <unistd.h> |
732b8386 | 59 | #include <sys/stat.h> |
3f4a0c5b VZ |
60 | #ifdef __GNUWIN32__ |
61 | #include <windows.h> | |
62 | #endif | |
d3b4d710 VS |
63 | #elif defined(__DOS__) |
64 | #if defined(__WATCOMC__) | |
65 | #include <io.h> | |
66 | #elif defined(__DJGPP__) | |
67 | #include <io.h> | |
68 | #include <unistd.h> | |
69 | #include <stdio.h> | |
70 | #else | |
71 | #error "Please specify the header with file functions declarations." | |
72 | #endif | |
c2ff79b1 DW |
73 | #elif (defined(__WXPM__)) |
74 | #include <io.h> | |
34138703 | 75 | #elif (defined(__WXSTUBS__)) |
3f4a0c5b VZ |
76 | // Have to ifdef this for different environments |
77 | #include <io.h> | |
17dff81c | 78 | #elif (defined(__WXMAC__)) |
5b781a67 | 79 | #if __MSL__ < 0x6000 |
3f4a0c5b | 80 | int access( const char *path, int mode ) { return 0 ; } |
5b781a67 SC |
81 | #else |
82 | int _access( const char *path, int mode ) { return 0 ; } | |
83 | #endif | |
3f4a0c5b | 84 | char* mktemp( char * path ) { return path ;} |
5b781a67 | 85 | #include <stat.h> |
5b781a67 | 86 | #include <unistd.h> |
c801d85f | 87 | #else |
3f4a0c5b | 88 | #error "Please specify the header with file functions declarations." |
c801d85f KB |
89 | #endif //Win/UNIX |
90 | ||
91 | #include <stdio.h> // SEEK_xxx constants | |
92 | #include <fcntl.h> // O_RDONLY &c | |
a3ef5bf5 | 93 | |
4ea2c29f | 94 | #if !defined(__MWERKS__) || defined(__WXMSW__) |
de85a884 VZ |
95 | #include <sys/types.h> // needed for stat |
96 | #include <sys/stat.h> // stat | |
469e1e5c | 97 | #endif |
c801d85f | 98 | |
4ea2c29f VZ |
99 | // Windows compilers don't have these constants |
100 | #ifndef W_OK | |
101 | enum | |
102 | { | |
103 | F_OK = 0, // test for existence | |
104 | X_OK = 1, // execute permission | |
105 | W_OK = 2, // write | |
106 | R_OK = 4 // read | |
107 | }; | |
108 | #endif // W_OK | |
34138703 | 109 | |
b12915c1 VZ |
110 | // there is no distinction between text and binary files under Unix, so define |
111 | // O_BINARY as 0 if the system headers don't do it already | |
112 | #if defined(__UNIX__) && !defined(O_BINARY) | |
49d5d881 | 113 | #define O_BINARY (0) |
246037e2 | 114 | #endif //__UNIX__ |
c801d85f | 115 | |
a3ef5bf5 | 116 | #ifdef __SALFORDC__ |
3f4a0c5b | 117 | #include <unix.h> |
a3ef5bf5 JS |
118 | #endif |
119 | ||
81d66cf3 | 120 | #ifndef MAX_PATH |
3f4a0c5b | 121 | #define MAX_PATH 512 |
81d66cf3 | 122 | #endif |
c801d85f | 123 | |
49d5d881 VZ |
124 | // some broken compilers don't have 3rd argument in open() and creat() |
125 | #ifdef __SALFORDC__ | |
126 | #define ACCESS(access) | |
127 | #define stat _stat | |
128 | #else // normal compiler | |
129 | #define ACCESS(access) , (access) | |
130 | #endif // Salford C | |
131 | ||
f6bcfd97 | 132 | // wxWindows |
ade35f11 VZ |
133 | #ifndef WX_PRECOMP |
134 | #include "wx/string.h" | |
135 | #include "wx/intl.h" | |
ade35f11 VZ |
136 | #include "wx/log.h" |
137 | #endif // !WX_PRECOMP | |
138 | ||
139 | #include "wx/filename.h" | |
44d568b6 | 140 | #include "wx/file.h" |
4ea2c29f | 141 | #include "wx/filefn.h" |
f6bcfd97 | 142 | |
28f5082b VS |
143 | #ifdef __WXMSW__ |
144 | #include "wx/msw/mslu.h" | |
145 | #endif | |
146 | ||
c801d85f KB |
147 | // ============================================================================ |
148 | // implementation of wxFile | |
149 | // ============================================================================ | |
150 | ||
151 | // ---------------------------------------------------------------------------- | |
152 | // static functions | |
153 | // ---------------------------------------------------------------------------- | |
4ea2c29f | 154 | |
50920146 | 155 | bool wxFile::Exists(const wxChar *name) |
246037e2 | 156 | { |
4ea2c29f | 157 | return wxFileExists(name); |
d1427b70 VZ |
158 | } |
159 | ||
50920146 | 160 | bool wxFile::Access(const wxChar *name, OpenMode mode) |
d1427b70 | 161 | { |
4ea2c29f VZ |
162 | int how; |
163 | ||
164 | switch ( mode ) | |
165 | { | |
166 | default: | |
167 | wxFAIL_MSG(wxT("bad wxFile::Access mode parameter.")); | |
168 | // fall through | |
d1427b70 | 169 | |
49d5d881 VZ |
170 | case read: |
171 | how = R_OK; | |
172 | break; | |
d1427b70 | 173 | |
49d5d881 VZ |
174 | case write: |
175 | how = W_OK; | |
176 | break; | |
d1427b70 | 177 | |
4ea2c29f VZ |
178 | case read_write: |
179 | how = R_OK | W_OK; | |
180 | break; | |
49d5d881 | 181 | } |
d1427b70 | 182 | |
4ea2c29f | 183 | return wxAccess(name, how) == 0; |
c801d85f KB |
184 | } |
185 | ||
186 | // ---------------------------------------------------------------------------- | |
187 | // opening/closing | |
188 | // ---------------------------------------------------------------------------- | |
189 | ||
190 | // ctors | |
50920146 | 191 | wxFile::wxFile(const wxChar *szFileName, OpenMode mode) |
c801d85f | 192 | { |
49d5d881 VZ |
193 | m_fd = fd_invalid; |
194 | m_error = FALSE; | |
c801d85f | 195 | |
49d5d881 | 196 | Open(szFileName, mode); |
c801d85f KB |
197 | } |
198 | ||
c801d85f | 199 | // create the file, fail if it already exists and bOverwrite |
50920146 | 200 | bool wxFile::Create(const wxChar *szFileName, bool bOverwrite, int accessMode) |
c801d85f | 201 | { |
49d5d881 VZ |
202 | // if bOverwrite we create a new file or truncate the existing one, |
203 | // otherwise we only create the new file and fail if it already exists | |
5fde6fcc | 204 | #if defined(__WXMAC__) && !defined(__UNIX__) |
92980e90 RR |
205 | // Dominic Mazzoni [dmazzoni+@cs.cmu.edu] reports that open is still broken on the mac, so we replace |
206 | // int fd = open(wxUnix2MacFilename( szFileName ), O_CREAT | (bOverwrite ? O_TRUNC : O_EXCL), access); | |
207 | int fd = creat( szFileName , accessMode); | |
7c74e7fe | 208 | #else |
92980e90 RR |
209 | int fd = wxOpen( szFileName, |
210 | O_BINARY | O_WRONLY | O_CREAT | | |
211 | (bOverwrite ? O_TRUNC : O_EXCL) | |
212 | ACCESS(accessMode) ); | |
7c74e7fe | 213 | #endif |
92980e90 RR |
214 | if ( fd == -1 ) |
215 | { | |
49d5d881 VZ |
216 | wxLogSysError(_("can't create file '%s'"), szFileName); |
217 | return FALSE; | |
218 | } | |
92980e90 RR |
219 | else |
220 | { | |
49d5d881 VZ |
221 | Attach(fd); |
222 | return TRUE; | |
223 | } | |
c801d85f KB |
224 | } |
225 | ||
226 | // open the file | |
50920146 | 227 | bool wxFile::Open(const wxChar *szFileName, OpenMode mode, int accessMode) |
c801d85f | 228 | { |
49d5d881 | 229 | int flags = O_BINARY; |
c801d85f | 230 | |
92980e90 RR |
231 | switch ( mode ) |
232 | { | |
49d5d881 VZ |
233 | case read: |
234 | flags |= O_RDONLY; | |
235 | break; | |
c801d85f | 236 | |
f6bcfd97 BP |
237 | case write_append: |
238 | if ( wxFile::Exists(szFileName) ) | |
239 | { | |
240 | flags |= O_WRONLY | O_APPEND; | |
241 | break; | |
242 | } | |
243 | //else: fall through as write_append is the same as write if the | |
244 | // file doesn't exist | |
245 | ||
49d5d881 VZ |
246 | case write: |
247 | flags |= O_WRONLY | O_CREAT | O_TRUNC; | |
248 | break; | |
61b02744 | 249 | |
68164137 RL |
250 | case write_excl: |
251 | flags |= O_WRONLY | O_CREAT | O_EXCL; | |
252 | break; | |
253 | ||
49d5d881 VZ |
254 | case read_write: |
255 | flags |= O_RDWR; | |
256 | break; | |
257 | } | |
c801d85f | 258 | |
92980e90 RR |
259 | int fd = wxOpen( szFileName, flags ACCESS(accessMode)); |
260 | if ( fd == -1 ) | |
261 | { | |
49d5d881 VZ |
262 | wxLogSysError(_("can't open file '%s'"), szFileName); |
263 | return FALSE; | |
264 | } | |
265 | else { | |
266 | Attach(fd); | |
267 | return TRUE; | |
268 | } | |
c801d85f KB |
269 | } |
270 | ||
271 | // close | |
61b02744 | 272 | bool wxFile::Close() |
c801d85f | 273 | { |
49d5d881 VZ |
274 | if ( IsOpened() ) { |
275 | if ( close(m_fd) == -1 ) { | |
276 | wxLogSysError(_("can't close file descriptor %d"), m_fd); | |
277 | m_fd = fd_invalid; | |
278 | return FALSE; | |
279 | } | |
280 | else | |
281 | m_fd = fd_invalid; | |
61b02744 | 282 | } |
61b02744 | 283 | |
49d5d881 | 284 | return TRUE; |
c801d85f KB |
285 | } |
286 | ||
287 | // ---------------------------------------------------------------------------- | |
288 | // read/write | |
289 | // ---------------------------------------------------------------------------- | |
290 | ||
291 | // read | |
292 | off_t wxFile::Read(void *pBuf, off_t nCount) | |
293 | { | |
49d5d881 | 294 | wxCHECK( (pBuf != NULL) && IsOpened(), 0 ); |
c801d85f | 295 | |
469e1e5c | 296 | #ifdef __MWERKS__ |
49d5d881 | 297 | int iRc = ::read(m_fd, (char*) pBuf, nCount); |
469e1e5c | 298 | #else |
49d5d881 | 299 | int iRc = ::read(m_fd, pBuf, nCount); |
469e1e5c | 300 | #endif |
49d5d881 VZ |
301 | if ( iRc == -1 ) { |
302 | wxLogSysError(_("can't read from file descriptor %d"), m_fd); | |
303 | return wxInvalidOffset; | |
304 | } | |
305 | else | |
306 | return (size_t)iRc; | |
c801d85f KB |
307 | } |
308 | ||
309 | // write | |
c86f1403 | 310 | size_t wxFile::Write(const void *pBuf, size_t nCount) |
c801d85f | 311 | { |
49d5d881 | 312 | wxCHECK( (pBuf != NULL) && IsOpened(), 0 ); |
c801d85f | 313 | |
469e1e5c | 314 | #ifdef __MWERKS__ |
5b781a67 SC |
315 | #if __MSL__ >= 0x6000 |
316 | int iRc = ::write(m_fd, (void*) pBuf, nCount); | |
317 | #else | |
49d5d881 | 318 | int iRc = ::write(m_fd, (const char*) pBuf, nCount); |
5b781a67 | 319 | #endif |
469e1e5c | 320 | #else |
49d5d881 | 321 | int iRc = ::write(m_fd, pBuf, nCount); |
469e1e5c | 322 | #endif |
49d5d881 VZ |
323 | if ( iRc == -1 ) { |
324 | wxLogSysError(_("can't write to file descriptor %d"), m_fd); | |
325 | m_error = TRUE; | |
326 | return 0; | |
327 | } | |
328 | else | |
329 | return iRc; | |
c801d85f KB |
330 | } |
331 | ||
332 | // flush | |
333 | bool wxFile::Flush() | |
334 | { | |
49d5d881 VZ |
335 | if ( IsOpened() ) { |
336 | #if defined(__VISUALC__) || wxHAVE_FSYNC | |
f6bcfd97 | 337 | if ( wxFsync(m_fd) == -1 ) |
09914df7 VZ |
338 | { |
339 | wxLogSysError(_("can't flush file descriptor %d"), m_fd); | |
340 | return FALSE; | |
341 | } | |
49d5d881 | 342 | #else // no fsync |
09914df7 | 343 | // just do nothing |
49d5d881 VZ |
344 | #endif // fsync |
345 | } | |
c801d85f | 346 | |
49d5d881 | 347 | return TRUE; |
c801d85f KB |
348 | } |
349 | ||
350 | // ---------------------------------------------------------------------------- | |
351 | // seek | |
352 | // ---------------------------------------------------------------------------- | |
353 | ||
354 | // seek | |
79c3e0e1 | 355 | off_t wxFile::Seek(off_t ofs, wxSeekMode mode) |
c801d85f | 356 | { |
49d5d881 VZ |
357 | wxASSERT( IsOpened() ); |
358 | ||
a1b82138 | 359 | int origin; |
49d5d881 | 360 | switch ( mode ) { |
a1b82138 VZ |
361 | default: |
362 | wxFAIL_MSG(_("unknown seek origin")); | |
363 | ||
49d5d881 | 364 | case wxFromStart: |
a1b82138 | 365 | origin = SEEK_SET; |
49d5d881 VZ |
366 | break; |
367 | ||
368 | case wxFromCurrent: | |
a1b82138 | 369 | origin = SEEK_CUR; |
49d5d881 VZ |
370 | break; |
371 | ||
372 | case wxFromEnd: | |
a1b82138 | 373 | origin = SEEK_END; |
49d5d881 | 374 | break; |
49d5d881 VZ |
375 | } |
376 | ||
a1b82138 | 377 | int iRc = lseek(m_fd, ofs, origin); |
49d5d881 VZ |
378 | if ( iRc == -1 ) { |
379 | wxLogSysError(_("can't seek on file descriptor %d"), m_fd); | |
380 | return wxInvalidOffset; | |
381 | } | |
382 | else | |
383 | return (off_t)iRc; | |
c801d85f KB |
384 | } |
385 | ||
386 | // get current off_t | |
387 | off_t wxFile::Tell() const | |
388 | { | |
49d5d881 VZ |
389 | wxASSERT( IsOpened() ); |
390 | ||
f6bcfd97 | 391 | int iRc = wxTell(m_fd); |
49d5d881 VZ |
392 | if ( iRc == -1 ) { |
393 | wxLogSysError(_("can't get seek position on file descriptor %d"), m_fd); | |
394 | return wxInvalidOffset; | |
395 | } | |
396 | else | |
397 | return (off_t)iRc; | |
c801d85f KB |
398 | } |
399 | ||
400 | // get current file length | |
401 | off_t wxFile::Length() const | |
402 | { | |
49d5d881 | 403 | wxASSERT( IsOpened() ); |
c801d85f | 404 | |
49d5d881 | 405 | #ifdef __VISUALC__ |
c801d85f | 406 | int iRc = _filelength(m_fd); |
49d5d881 | 407 | #else // !VC++ |
f6bcfd97 | 408 | int iRc = wxTell(m_fd); |
c801d85f | 409 | if ( iRc != -1 ) { |
49d5d881 VZ |
410 | // @ have to use const_cast :-( |
411 | int iLen = ((wxFile *)this)->SeekEnd(); | |
412 | if ( iLen != -1 ) { | |
413 | // restore old position | |
414 | if ( ((wxFile *)this)->Seek(iRc) == -1 ) { | |
415 | // error | |
416 | iLen = -1; | |
417 | } | |
c801d85f | 418 | } |
c801d85f | 419 | |
49d5d881 VZ |
420 | iRc = iLen; |
421 | } | |
422 | #endif // VC++ | |
423 | ||
424 | if ( iRc == -1 ) { | |
425 | wxLogSysError(_("can't find length of file on file descriptor %d"), m_fd); | |
426 | return wxInvalidOffset; | |
c801d85f | 427 | } |
49d5d881 VZ |
428 | else |
429 | return (off_t)iRc; | |
c801d85f KB |
430 | } |
431 | ||
432 | // is end of file reached? | |
433 | bool wxFile::Eof() const | |
434 | { | |
49d5d881 | 435 | wxASSERT( IsOpened() ); |
c801d85f | 436 | |
49d5d881 | 437 | int iRc; |
61b02744 | 438 | |
d3b4d710 | 439 | #if defined(__DOS__) || defined(__UNIX__) || defined(__GNUWIN32__) || defined( __MWERKS__ ) || defined(__SALFORDC__) |
61b02744 VZ |
440 | // @@ this doesn't work, of course, on unseekable file descriptors |
441 | off_t ofsCur = Tell(), | |
49d5d881 | 442 | ofsMax = Length(); |
1678ad78 | 443 | if ( ofsCur == wxInvalidOffset || ofsMax == wxInvalidOffset ) |
49d5d881 | 444 | iRc = -1; |
61b02744 | 445 | else |
49d5d881 VZ |
446 | iRc = ofsCur == ofsMax; |
447 | #else // Windows and "native" compiler | |
61b02744 | 448 | iRc = eof(m_fd); |
49d5d881 | 449 | #endif // Windows/Unix |
c801d85f | 450 | |
49d5d881 VZ |
451 | switch ( iRc ) { |
452 | case 1: | |
453 | break; | |
c801d85f | 454 | |
49d5d881 VZ |
455 | case 0: |
456 | return FALSE; | |
c801d85f | 457 | |
49d5d881 | 458 | case -1: |
8e3f1261 | 459 | wxLogSysError(_("can't determine if the end of file is reached on descriptor %d"), m_fd); |
49d5d881 | 460 | break; |
c801d85f | 461 | |
49d5d881 VZ |
462 | default: |
463 | wxFAIL_MSG(_("invalid eof() return value.")); | |
464 | } | |
c801d85f | 465 | |
49d5d881 | 466 | return TRUE; |
c801d85f KB |
467 | } |
468 | ||
469 | // ============================================================================ | |
470 | // implementation of wxTempFile | |
471 | // ============================================================================ | |
472 | ||
473 | // ---------------------------------------------------------------------------- | |
474 | // construction | |
475 | // ---------------------------------------------------------------------------- | |
44b62d54 | 476 | |
c801d85f KB |
477 | wxTempFile::wxTempFile(const wxString& strName) |
478 | { | |
49d5d881 | 479 | Open(strName); |
c801d85f KB |
480 | } |
481 | ||
482 | bool wxTempFile::Open(const wxString& strName) | |
483 | { | |
44b62d54 VZ |
484 | // we must have an absolute filename because otherwise CreateTempFileName() |
485 | // would create the temp file in $TMP (i.e. the system standard location | |
486 | // for the temp files) which might be on another volume/drive/mount and | |
487 | // wxRename()ing it later to m_strName from Commit() would then fail | |
488 | // | |
489 | // with the absolute filename, the temp file is created in the same | |
490 | // directory as this one which ensures that wxRename() may work later | |
491 | wxFileName fn(strName); | |
492 | if ( !fn.IsAbsolute() ) | |
493 | { | |
494 | fn.Normalize(wxPATH_NORM_ABSOLUTE); | |
495 | } | |
496 | ||
497 | m_strName = fn.GetFullPath(); | |
246037e2 | 498 | |
44b62d54 | 499 | m_strTemp = wxFileName::CreateTempFileName(m_strName, &m_file); |
ade35f11 VZ |
500 | |
501 | if ( m_strTemp.empty() ) | |
502 | { | |
503 | // CreateTempFileName() failed | |
504 | return FALSE; | |
505 | } | |
49d5d881 | 506 | |
49d5d881 | 507 | #ifdef __UNIX__ |
ade35f11 VZ |
508 | // the temp file should have the same permissions as the original one |
509 | mode_t mode; | |
ca11abde | 510 | |
f6bcfd97 | 511 | wxStructStat st; |
ca11abde | 512 | if ( stat( (const char*) m_strName.fn_str(), &st) == 0 ) |
49d5d881 | 513 | { |
ade35f11 | 514 | mode = st.st_mode; |
49d5d881 VZ |
515 | } |
516 | else | |
517 | { | |
ade35f11 | 518 | // file probably didn't exist, just give it the default mode _using_ |
68164137 | 519 | // user's umask (new files creation should respect umask) |
ade35f11 VZ |
520 | mode_t mask = umask(0777); |
521 | mode = 0666 & ~mask; | |
522 | umask(mask); | |
49d5d881 | 523 | } |
49d5d881 | 524 | |
ca11abde | 525 | if ( chmod( (const char*) m_strTemp.fn_str(), mode) == -1 ) |
fe99e285 | 526 | { |
ade35f11 | 527 | wxLogSysError(_("Failed to set temporary file permissions")); |
fe99e285 | 528 | } |
49d5d881 | 529 | #endif // Unix |
246037e2 | 530 | |
ade35f11 | 531 | return TRUE; |
c801d85f KB |
532 | } |
533 | ||
534 | // ---------------------------------------------------------------------------- | |
535 | // destruction | |
536 | // ---------------------------------------------------------------------------- | |
537 | ||
538 | wxTempFile::~wxTempFile() | |
539 | { | |
49d5d881 VZ |
540 | if ( IsOpened() ) |
541 | Discard(); | |
c801d85f KB |
542 | } |
543 | ||
544 | bool wxTempFile::Commit() | |
545 | { | |
49d5d881 | 546 | m_file.Close(); |
c801d85f | 547 | |
f6bcfd97 | 548 | if ( wxFile::Exists(m_strName) && wxRemove(m_strName) != 0 ) { |
49d5d881 VZ |
549 | wxLogSysError(_("can't remove file '%s'"), m_strName.c_str()); |
550 | return FALSE; | |
551 | } | |
c801d85f | 552 | |
f6bcfd97 | 553 | if ( wxRename(m_strTemp, m_strName) != 0 ) { |
49d5d881 VZ |
554 | wxLogSysError(_("can't commit changes to file '%s'"), m_strName.c_str()); |
555 | return FALSE; | |
556 | } | |
c801d85f | 557 | |
49d5d881 | 558 | return TRUE; |
c801d85f KB |
559 | } |
560 | ||
561 | void wxTempFile::Discard() | |
562 | { | |
49d5d881 | 563 | m_file.Close(); |
f6bcfd97 | 564 | if ( wxRemove(m_strTemp) != 0 ) |
49d5d881 | 565 | wxLogSysError(_("can't remove temporary file '%s'"), m_strTemp.c_str()); |
c801d85f | 566 | } |
ce4169a4 | 567 | |
ade35f11 | 568 | #endif // wxUSE_FILE |
cc985fac | 569 |