+ // create file2 with the same permissions than file1 and open it for
+ // writing
+
+ wxFile fileOut;
+ if ( !fileOut.Create(filenameDst, overwrite, fbuf.st_mode & 0777) )
+ return false;
+
+ // copy contents of file1 to file2
+ char buf[4096];
+ for ( ;; )
+ {
+ ssize_t count = fileIn.Read(buf, WXSIZEOF(buf));
+ if ( count == wxInvalidOffset )
+ return false;
+
+ // end of file?
+ if ( !count )
+ break;
+
+ if ( fileOut.Write(buf, count) < (size_t)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
+ return fileIn.Close() && fileOut.Close();
+}
+
+#endif // generic implementation of wxCopyFile
+
+// Copy files
+bool
+wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite)
+{
+#if defined(__WIN32__) && !defined(__WXMICROWIN__)
+ // CopyFile() copies file attributes and modification time too, so use it
+ // instead of our code if available
+ //
+ // NB: 3rd parameter is bFailIfExists i.e. the inverse of overwrite
+ if ( !::CopyFile(file1.t_str(), file2.t_str(), !overwrite) )
+ {
+ wxLogSysError(_("Failed to copy the file '%s' to '%s'"),
+ file1.c_str(), file2.c_str());
+
+ return false;
+ }
+#elif defined(__OS2__)
+ if ( ::DosCopy(file1.c_str(), file2.c_str(), overwrite ? DCPY_EXISTING : 0) != 0 )
+ return false;
+#elif wxUSE_FILE // !Win32
+
+ wxStructStat fbuf;
+ // get permissions of file1
+ if ( wxStat( file1, &fbuf) != 0 )
+ {
+ // the file probably doesn't exist or we haven't the rights to read
+ // from it anyhow