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

Unified Diff: util/file/file_reader.cc

Issue 1023943003: crashpad_database_util: Accept --new-report=- to read a new report from standard input (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@crashpad_database_util_new_report
Patch Set: Fix Windows Created 5 years, 4 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 | « util/file/file_reader.h ('k') | util/file/file_writer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/file/file_reader.cc
diff --git a/util/file/file_reader.cc b/util/file/file_reader.cc
index edb3312632f5c57070b9ba76041e06238c3aa382..aad55cf7698b4aff7c7c57145eb39ba1a0e1152c 100644
--- a/util/file/file_reader.cc
+++ b/util/file/file_reader.cc
@@ -16,6 +16,7 @@
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
+#include "build/build_config.h"
namespace crashpad {
@@ -97,4 +98,39 @@ FileOffset FileReader::Seek(FileOffset offset, int whence) {
return weak_file_handle_file_reader_.Seek(offset, whence);
}
+WeakStdioFileReader::WeakStdioFileReader(FILE* file)
+ : file_(file) {
+}
+
+WeakStdioFileReader::~WeakStdioFileReader() {
+}
+
+ssize_t WeakStdioFileReader::Read(void* data, size_t size) {
+ DCHECK(file_);
+
+ size_t rv = fread(data, 1, size, file_);
+ if (rv < size && ferror(file_)) {
+ STDIO_PLOG(ERROR) << "fread";
+ return -1;
+ }
+
+ return rv;
+}
+
+FileOffset WeakStdioFileReader::Seek(FileOffset offset, int whence) {
+ DCHECK(file_);
+ if (fseeko(file_, offset, whence) == -1) {
+ STDIO_PLOG(ERROR) << "fseeko";
+ return -1;
+ }
+
+ FileOffset new_offset = ftello(file_);
+ if (new_offset == -1) {
+ STDIO_PLOG(ERROR) << "ftello";
+ return -1;
+ }
+
+ return new_offset;
+}
+
} // namespace crashpad
« no previous file with comments | « util/file/file_reader.h ('k') | util/file/file_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698