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

Unified Diff: util/file/file_reader.h

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_io.h ('k') | util/file/file_reader.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/file/file_reader.h
diff --git a/util/file/file_reader.h b/util/file/file_reader.h
index 0c6856f1a804913ea0835a86956379030ca510c9..58f58651ad10cb5ffb8c51e06e5b5d5309b22d41 100644
--- a/util/file/file_reader.h
+++ b/util/file/file_reader.h
@@ -15,6 +15,7 @@
#ifndef CRASHPAD_UTIL_FILE_FILE_READER_H_
#define CRASHPAD_UTIL_FILE_FILE_READER_H_
+#include <stdio.h>
#include <sys/types.h>
#include "base/basictypes.h"
@@ -28,6 +29,8 @@ namespace crashpad {
//! semantics matching the underlying platform (POSIX or Windows).
class FileReaderInterface : public virtual FileSeekerInterface {
public:
+ virtual ~FileReaderInterface() {}
+
//! \brief Wraps ReadFile(), or provides an implementation with identical
//! semantics.
//!
@@ -44,9 +47,6 @@ class FileReaderInterface : public virtual FileSeekerInterface {
//! \return `true` if the operation succeeded, `false` if it failed, with an
//! error message logged. Short reads are treated as failures.
bool ReadExactly(void* data, size_t size);
-
- protected:
- ~FileReaderInterface() {}
};
//! \brief A file reader backed by a FileHandle.
@@ -66,7 +66,7 @@ class FileReaderInterface : public virtual FileSeekerInterface {
class WeakFileHandleFileReader : public FileReaderInterface {
public:
explicit WeakFileHandleFileReader(FileHandle file_handle);
- ~WeakFileHandleFileReader();
+ ~WeakFileHandleFileReader() override;
// FileReaderInterface:
ssize_t Read(void* data, size_t size) override;
@@ -99,7 +99,7 @@ class WeakFileHandleFileReader : public FileReaderInterface {
class FileReader : public FileReaderInterface {
public:
FileReader();
- ~FileReader();
+ ~FileReader() override;
// FileReaderInterface:
@@ -142,6 +142,40 @@ class FileReader : public FileReaderInterface {
DISALLOW_COPY_AND_ASSIGN(FileReader);
};
+//! \brief A file reader backed by a standard input/output `FILE*`.
+//!
+//! This class accepts an already-open `FILE*`. It is not responsible for
+//! opening or closing this `FILE*`. Users of this class must ensure that the
+//! `FILE*` is closed appropriately elsewhere. Objects of this class may be used
+//! to read from `FILE*` objects not associated with filesystem-based files,
+//! although special attention should be paid to the Seek() method, which may
+//! not function on `FILE*` objects that do not refer to disk-based files.
+//!
+//! This class is expected to be used when other code is responsible for
+//! opening `FILE*` objects and already provides `FILE*` objects. A good use
+//! would be a WeakStdioFileReader for `stdin`.
+class WeakStdioFileReader : public FileReaderInterface {
+ public:
+ explicit WeakStdioFileReader(FILE* file);
+ ~WeakStdioFileReader() override;
+
+ // FileReaderInterface:
+ ssize_t Read(void* data, size_t size) override;
+
+ // FileSeekerInterface:
+
+ //! \copydoc FileReaderInterface::Seek()
+ //!
+ //! \note This method is only guaranteed to function on `FILE*` objects
+ //! referring to disk-based files.
+ FileOffset Seek(FileOffset offset, int whence) override;
+
+ private:
+ FILE* file_; // weak
+
+ DISALLOW_COPY_AND_ASSIGN(WeakStdioFileReader);
+};
+
} // namespace crashpad
#endif // CRASHPAD_UTIL_FILE_FILE_READER_H_
« no previous file with comments | « util/file/file_io.h ('k') | util/file/file_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698