Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: tools/android/md5sum/md5sum.cc

Issue 1128733002: Update from https://crrev.com/328418 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/re2/util/util.h ('k') | tools/android/run_pie/run_pie.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/android/md5sum/md5sum.cc
diff --git a/tools/android/md5sum/md5sum.cc b/tools/android/md5sum/md5sum.cc
index 07ce2c290c8079230bbc7e1571d436c215f67a50..a204569d1fdc99eba0965416bd481bfddf0c0f96 100644
--- a/tools/android/md5sum/md5sum.cc
+++ b/tools/android/md5sum/md5sum.cc
@@ -18,25 +18,21 @@
namespace {
-const int kBufferSize = 1024;
-
// Returns whether |path|'s MD5 was successfully written to |digest_string|.
bool MD5Sum(const char* path, std::string* digest_string) {
- std::ifstream stream(path);
- if (!stream.good()) {
+ base::ScopedFILE file(fopen(path, "rb"));
+ if (!file) {
LOG(ERROR) << "Could not open file " << path;
return false;
}
base::MD5Context ctx;
base::MD5Init(&ctx);
- char buf[kBufferSize];
- while (stream.good()) {
- std::streamsize bytes_read = stream.readsome(buf, sizeof(buf));
- if (bytes_read == 0)
- break;
- base::MD5Update(&ctx, base::StringPiece(buf, bytes_read));
- }
- if (stream.fail()) {
+ const size_t kBufferSize = 1 << 16;
+ scoped_ptr<char[]> buf(new char[kBufferSize]);
+ size_t len;
+ while ((len = fread(buf.get(), 1, kBufferSize, file.get())) > 0)
+ base::MD5Update(&ctx, base::StringPiece(buf.get(), len));
+ if (ferror(file.get())) {
LOG(ERROR) << "Error reading file " << path;
return false;
}
« no previous file with comments | « third_party/re2/util/util.h ('k') | tools/android/run_pie/run_pie.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698