+// helper of generic implementation of wxCopyFile()
+#if !(defined(__WIN32__) || defined(__OS2__) || defined(__PALMOS__)) && \
+ wxUSE_FILE
+
+static bool
+wxDoCopyFile(wxFile& fileIn,
+ const wxStructStat& fbuf,
+ const wxString& filenameDst,
+ bool overwrite)
+{
+ // 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(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
+