From b0c5cd0ff3f5b57a4c0988ea58fc2d2cb0efe3a5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?W=C5=82odzimierz=20Skiba?= Date: Tue, 7 Jun 2005 18:46:10 +0000 Subject: [PATCH] Reuse wxTempFile and wxFile in wxConcatFiles. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34579 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/filefn.cpp | 75 +++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 18620e0a5c..ed73e4bd70 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -189,7 +189,7 @@ void wxPathList::AddEnvList (const wxString& envVariable) wxT(" :;"); #endif - wxString val ; + wxString val ; if (wxGetEnv (WXSTRINGCAST envVariable, &val)) { wxChar *s = MYcopystring (val); @@ -360,17 +360,17 @@ wxIsAbsolutePath (const wxString& filename) void wxStripExtension(wxChar *buffer) { - int len = wxStrlen(buffer); - int i = len-1; - while (i > 0) - { - if (buffer[i] == wxT('.')) + int len = wxStrlen(buffer); + int i = len-1; + while (i > 0) { - buffer[i] = 0; - break; + if (buffer[i] == wxT('.')) + { + buffer[i] = 0; + break; + } + i --; } - i --; - } } void wxStripExtension(wxString& buffer) @@ -959,39 +959,38 @@ wxUnix2DosFilename (wxChar *WXUNUSED(s) ) bool wxConcatFiles (const wxString& file1, const wxString& file2, const wxString& file3) { - wxString outfile; - if ( !wxGetTempFileName( wxT("cat"), outfile) ) - return false; - - FILE *fp1 wxDUMMY_INITIALIZE(NULL); - FILE *fp2 = NULL; - FILE *fp3 = NULL; - // Open the inputs and outputs - if ((fp1 = wxFopen ( file1, wxT("rb"))) == NULL || - (fp2 = wxFopen ( file2, wxT("rb"))) == NULL || - (fp3 = wxFopen ( outfile, wxT("wb"))) == NULL) +#if wxUSE_FILE + + wxFile in1(file1), in2(file2); + wxTempFile out(file3); + + if ( !in1.IsOpened() || !in2.IsOpened() || !out.IsOpened() ) + return false; + + ssize_t ofs; + unsigned char buf[1024]; + + for( int i=0; i<2; i++) { - if (fp1) - fclose (fp1); - if (fp2) - fclose (fp2); - if (fp3) - fclose (fp3); - return false; + wxFile *in = i==0 ? &in1 : &in2; + do{ + if ( (ofs = in->Read(buf,WXSIZEOF(buf))) == wxInvalidOffset ) return false; + if ( ofs > 0 ) + if ( !out.Write(buf,ofs) ) + return false; + } while ( ofs == (ssize_t)WXSIZEOF(buf) ); } - int ch; - while ((ch = getc (fp1)) != EOF) - (void) putc (ch, fp3); - fclose (fp1); + return out.Commit(); + +#else - while ((ch = getc (fp2)) != EOF) - (void) putc (ch, fp3); - fclose (fp2); + wxUnusedVar(file1); + wxUnusedVar(file2); + wxUnusedVar(file3); + return false; - fclose (fp3); - bool result = wxRenameFile(outfile, file3); - return result; +#endif } // Copy files -- 2.45.2