+ // remove file2, if it exists. This is needed for creating
+ // file2 with the correct permissions in the next step
+ if ( wxFileExists(file2) && !wxRemoveFile(file2) )
+ {
+ wxLogSysError(_("Impossible to overwrite the file '%s'"),
+ file2.c_str());
+ return FALSE;
+ }
+
+#ifdef __UNIX__
+ // reset the umask as we want to create the file with exactly the same
+ // permissions as the original one
+ mode_t oldUmask = umask( 0 );
+#endif // __UNIX__
+
+ // create file2 with the same permissions than file1 and open it for
+ // writing
+ wxFile fileOut;
+ if ( !fileOut.Create(file2, TRUE, fbuf.st_mode & 0777) )
+ return FALSE;
+
+#ifdef __UNIX__
+ /// restore the old umask
+ umask(oldUmask);
+#endif // __UNIX__
+
+ // 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;
+ }
+
+#if !defined(__VISAGECPP__) && !defined(__WXMAC__)
+// no chmod in VA. SHould be some permission API for HPFS386 partitions however
+ if ( chmod(file2, fbuf.st_mode) != 0 )
+ {
+ wxLogSysError(_("Impossible to set permissions for the file '%s'"),
+ file2.c_str());
+ return FALSE;
+ }
+#endif
+ return TRUE;