diff options
Diffstat (limited to 'l10ntools/source/export2.cxx')
-rw-r--r-- | l10ntools/source/export2.cxx | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/l10ntools/source/export2.cxx b/l10ntools/source/export2.cxx index 34df550280fb..fb9df40b966e 100644 --- a/l10ntools/source/export2.cxx +++ b/l10ntools/source/export2.cxx @@ -36,6 +36,7 @@ #include <tools/urlobj.hxx> #include <time.h> #include <stdlib.h> +#include <boost/shared_ptr.hpp> using namespace std; // @@ -339,9 +340,6 @@ void Export::RemoveUTF8ByteOrderMarkerFromFile( const ByteString &rFilename ){ bool Export::CopyFile( const ByteString& source , const ByteString& dest ) { // cout << "CopyFile( " << source.GetBuffer() << " , " << dest.GetBuffer() << " )\n"; - const int BUFFERSIZE = 8192; - char buf[ BUFFERSIZE ]; - FILE* IN_FILE = fopen( source.GetBuffer() , "r" ); if( IN_FILE == NULL ) { @@ -357,27 +355,34 @@ bool Export::CopyFile( const ByteString& source , const ByteString& dest ) return false; } - while( fgets( buf , BUFFERSIZE , IN_FILE ) != NULL ) + static const int BUFFERSIZE = 0x100000; + boost::shared_ptr<char> aScopedBuffer( new char[BUFFERSIZE] ); + char* buf = aScopedBuffer.get(); + + bool bOk = true; + while( bOk ) { - if( fputs( buf , OUT_FILE ) == EOF ) + if( feof( IN_FILE ) ) + break; + const size_t nBytesRead = fread( buf, 1, BUFFERSIZE, IN_FILE ); + if( nBytesRead <= 0 ) + { + if( ferror( IN_FILE ) ) + { + cerr << "Export::CopyFile WARNING: Read problems " << dest.GetBuffer() << "\n"; + bOk = false; + } + } + else if( fwrite( buf, 1, nBytesRead, OUT_FILE ) <= 0 ) { cerr << "Export::CopyFile WARNING: Write problems " << source.GetBuffer() << "\n"; - fclose( IN_FILE ); - fclose( OUT_FILE ); - return false; + bOk = false; } } - if( ferror( IN_FILE ) ) - { - cerr << "Export::CopyFile WARNING: Read problems " << dest.GetBuffer() << "\n"; - fclose( IN_FILE ); - fclose( OUT_FILE ); - return false; - } fclose ( IN_FILE ); fclose ( OUT_FILE ); - return true; + return bOk; } /*****************************************************************************/ |