Codereview comments from r1685

This commit is contained in:
David Sansome 2010-08-12 16:35:43 +00:00
parent bf85a92f54
commit 1dbb1817e8
1 changed files with 13 additions and 18 deletions

View File

@ -28,6 +28,8 @@
# include <windows.h> # include <windows.h>
#endif #endif
#include <boost/scoped_array.hpp>
namespace Utilities { namespace Utilities {
static QString tr(const char* str) { static QString tr(const char* str) {
@ -144,35 +146,28 @@ bool Copy(QIODevice* source, QIODevice* destination) {
return false; return false;
const qint64 bytes = source->size(); const qint64 bytes = source->size();
char* data = new char[bytes]; boost::scoped_array<char> data(new char[bytes]);
qint64 pos = 0; qint64 pos = 0;
forever { qint64 bytes_read;
const qint64 bytes_read = source->read(data + pos, bytes - pos); do {
if (bytes_read == -1) { bytes_read = source->read(data.get() + pos, bytes - pos);
delete[] data; if (bytes_read == -1)
return false; return false;
}
pos += bytes_read; pos += bytes_read;
if (bytes_read == 0 || pos == bytes) } while (bytes_read > 0 && pos != bytes);
break;
}
pos = 0; pos = 0;
forever { qint64 bytes_written;
const qint64 bytes_written = destination->write(data + pos, bytes - pos); do {
if (bytes_written == -1) { bytes_written = destination->write(data.get() + pos, bytes - pos);
delete[] data; if (bytes_written == -1)
return false; return false;
}
pos += bytes_written; pos += bytes_written;
if (bytes_written == 0 || pos == bytes) } while (bytes_written > 0 && pos != bytes);
break;
}
delete[] data;
return true; return true;
} }