-#ifdef __WXMAC__
- wxStrcpy( gwxMacFileName , file1 ) ;
- wxUnix2MacFilename( gwxMacFileName ) ;
- wxStrcpy( gwxMacFileName2 , file2) ;
- wxUnix2MacFilename( gwxMacFileName2 ) ;
-
- if ((fd1 = fopen (gwxMacFileName, "rb")) == NULL)
- return FALSE;
- if ((fd2 = fopen (gwxMacFileName2, "wb")) == NULL)
-#else
- if ((fd1 = fopen (FNSTRINGCAST file1.fn_str(), "rb")) == NULL)
- return FALSE;
- if ((fd2 = fopen (FNSTRINGCAST file2.fn_str(), "wb")) == NULL)
-#endif
+ return false;
+ }
+#elif defined(__OS2__)
+ if ( ::DosCopy((PSZ)file1.c_str(), (PSZ)file2.c_str(), overwrite ? DCPY_EXISTING : 0) != 0 )
+ return false;
+#elif defined(__PALMOS__)
+ // TODO with http://www.palmos.com/dev/support/docs/protein_books/Memory_Databases_Files/
+ return false;
+#elif wxUSE_FILE // !Win32
+
+ wxStructStat fbuf;
+ // get permissions of file1
+ if ( wxStat( file1.c_str(), &fbuf) != 0 )
+ {
+ // the file probably doesn't exist or we haven't the rights to read
+ // from it anyhow
+ wxLogSysError(_("Impossible to get permissions for file '%s'"),
+ file1.c_str());
+ return false;
+ }
+
+ // open file1 for reading
+ wxFile fileIn(file1, wxFile::read);
+ if ( !fileIn.IsOpened() )
+ return false;
+
+ // remove file2, if it exists. This is needed for creating
+ // file2 with the correct permissions in the next step
+ if ( wxFileExists(file2) && (!overwrite || !wxRemoveFile(file2)))
+ {
+ wxLogSysError(_("Impossible to overwrite the file '%s'"),
+ file2.c_str());
+ return false;
+ }
+
+ // reset the umask as we want to create the file with exactly the same
+ // permissions as the original one
+ wxCHANGE_UMASK(0);
+
+ // create file2 with the same permissions than file1 and open it for
+ // writing
+
+ wxFile fileOut;
+ if ( !fileOut.Create(file2, overwrite, fbuf.st_mode & 0777) )
+ return false;
+
+ // copy contents of file1 to file2
+ char buf[4096];
+ size_t count;
+ for ( ;; )
+ {
+ count = fileIn.Read(buf, WXSIZEOF(buf));
+ if ( fileIn.Error() )
+ return false;
+
+ // end of file?
+ if ( !count )
+ break;
+
+ if ( fileOut.Write(buf, count) < count )
+ return false;
+ }
+
+ // we can expect fileIn to be closed successfully, but we should ensure
+ // that fileOut was closed as some write errors (disk full) might not be
+ // detected before doing this
+ if ( !fileIn.Close() || !fileOut.Close() )
+ return false;
+
+#if !defined(__VISAGECPP__) && !defined(__WXMAC__) || defined(__UNIX__)
+ // no chmod in VA. Should be some permission API for HPFS386 partitions
+ // however
+ if ( chmod(OS_FILENAME(file2), fbuf.st_mode) != 0 )