Index: util/file/file_writer.h |
diff --git a/util/file/file_writer.h b/util/file/file_writer.h |
index 54c59c923378f58f9e8bffe5a8207e9ae764b0c4..1fe46cb56a33cc7c95e7461a261945fbed4f6429 100644 |
--- a/util/file/file_writer.h |
+++ b/util/file/file_writer.h |
@@ -16,9 +16,8 @@ |
#define CRASHPAD_UTIL_FILE_FILE_WRITER_H_ |
#include <fcntl.h> |
+#include <inttypes.h> |
#include <stddef.h> |
-#include <sys/uio.h> |
-#include <unistd.h> |
#include <string> |
#include <vector> |
@@ -26,6 +25,16 @@ |
#include "base/basictypes.h" |
#include "base/files/file_path.h" |
#include "base/files/scoped_file.h" |
+#include "build/build_config.h" |
+ |
+#if defined(OS_POSIX) |
+#include <sys/uio.h> |
+#include <unistd.h> |
+using FileOffset = off_t; |
+#elif defined(OS_WIN) |
+#include "util/win/scoped_handle.h" |
+using FileOffset = int64_t; |
+#endif |
namespace crashpad { |
@@ -34,7 +43,7 @@ namespace crashpad { |
//! This structure is intended to be used for write operations. |
// |
// Type compatibility with iovec is tested with static assertions in the |
-// implementation file. |
+// POSIX implementation file. |
struct WritableIoVec { |
//! \brief The base address of a memory region for output. |
const void* iov_base; |
@@ -47,9 +56,10 @@ struct WritableIoVec { |
//! semantics. |
class FileWriterInterface { |
public: |
- //! \brief Wraps `write()` or provides an alternate implementation with |
- //! identical semantics. This method will write the entire buffer, |
- //! continuing after a short write or after being interrupted. |
+ //! \brief Wraps `write()` or `WriteFile()` or provides an alternate |
+ //! implementation with identical semantics. This method will write the |
+ //! entire buffer, continuing after a short write or after being |
+ //! interrupted. |
//! |
//! \return `true` if the operation succeeded, `false` if it failed, with an |
//! error message logged. |
@@ -65,12 +75,12 @@ class FileWriterInterface { |
//! \note The contents of \a iovecs are undefined when this method returns. |
virtual bool WriteIoVec(std::vector<WritableIoVec>* iovecs) = 0; |
- //! \brief Wraps `lseek()` or provides an alternate implementation with |
- //! identical semantics. |
+ //! \brief Wraps `lseek()` or `SetFilePointer` or provides an alternate |
+ //! implementation with identical semantics. |
//! |
- //! \return The return value of `lseek()`. `-1` on failure, with an error |
- //! message logged. |
- virtual off_t Seek(off_t offset, int whence) = 0; |
+ //! \return The return value of the underlying function. `-1` on failure, |
+ //! with an error message logged. |
+ virtual FileOffset Seek(FileOffset offset, int whence) = 0; |
protected: |
~FileWriterInterface() {} |
@@ -83,16 +93,16 @@ class FileWriter : public FileWriterInterface { |
FileWriter(); |
~FileWriter(); |
- //! \brief Wraps `open()`. |
+ //! \brief Wraps `open()` or `CreateFile()`. |
//! |
//! \return `true` if the operation succeeded, `false` if it failed, with an |
//! error message logged. |
//! |
//! \note After a successful call, this method cannot be called again until |
//! after Close(). |
- bool Open(const base::FilePath& path, int oflag, mode_t mode); |
+ bool Open(const base::FilePath& path, int oflag, uint32_t mode); |
- //! \brief Wraps `close().` |
+ //! \brief Wraps `close()` or `CloseHandle()`. |
//! |
//! \note It is only valid to call this method on an object that has had a |
//! successful Open() that has not yet been matched by a subsequent call |
@@ -117,10 +127,14 @@ class FileWriter : public FileWriterInterface { |
//! |
//! \note It is only valid to call this method between a successful Open() and |
//! a Close(). |
- off_t Seek(off_t offset, int whence) override; |
+ FileOffset Seek(FileOffset offset, int whence) override; |
private: |
- base::ScopedFD fd_; |
+#if defined(OS_POSIX) |
+ base::ScopedFD file_; |
+#else |
+ win::ScopedFileHandle file_; |
+#endif |
DISALLOW_COPY_AND_ASSIGN(FileWriter); |
}; |