Chromium Code Reviews| Index: util/file/file_writer.h |
| diff --git a/util/file/file_writer.h b/util/file/file_writer.h |
| index 54c59c923378f58f9e8bffe5a8207e9ae764b0c4..a05545b422a40f977ca680a622d72bf5f8b45985 100644 |
| --- a/util/file/file_writer.h |
| +++ b/util/file/file_writer.h |
| @@ -17,15 +17,22 @@ |
| #include <fcntl.h> |
| #include <stddef.h> |
| -#include <sys/uio.h> |
| -#include <unistd.h> |
| #include <string> |
| #include <vector> |
| #include "base/basictypes.h" |
| #include "base/files/file_path.h" |
| +#include "build/build_config.h" |
| +#include "util/file/file_io.h" |
| + |
| +#if defined(OS_POSIX) |
| +#include <sys/uio.h> |
| +#include <unistd.h> |
| #include "base/files/scoped_file.h" |
| +#elif defined(OS_WIN) |
| +#include "util/win/scoped_handle.h" |
| +#endif |
| namespace crashpad { |
| @@ -43,21 +50,23 @@ struct WritableIoVec { |
| size_t iov_len; |
| }; |
| -//! \brief An interface to write to files and other file-like objects with POSIX |
| -//! semantics. |
| +//! \brief An interface to write to files and other file-like objects with |
| +//! semantics matching the underlying platform (POSIX or Windows). |
| 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 |
|
Mark Mentovai
2014/12/19 18:57:44
Aside from WriteIoVec, none of these functions dir
scottmg
2014/12/19 19:37:53
Done.
|
| + //! implementation with identical semantics. This method will write the |
| + //! entire buffer, continuing after a short write or after being |
| + //! interrupted on POSIX. |
| //! |
| //! \return `true` if the operation succeeded, `false` if it failed, with an |
| //! error message logged. |
| virtual bool Write(const void* data, size_t size) = 0; |
| //! \brief Wraps `writev()` or provides an alternate implementation with |
| - //! identical semantics. This method will write the entire buffer, |
| - //! continuing after a short write or after being interrupted. |
| + //! identical semantics on POSIX. This method will write entire buffers, |
|
Mark Mentovai
2014/12/19 18:57:44
“on POSIX” is confusing here, put it after writev(
scottmg
2014/12/19 19:37:53
Done.
|
| + //! continuing after a short write or after being interrupted. On |
| + //! non-POSIX this is a simple wrapper around Write(). |
| //! |
| //! \return `true` if the operation succeeded, `false` if it failed, with an |
| //! error message logged. |
| @@ -65,34 +74,36 @@ 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 `SetFilePointerEx()` 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() {} |
| }; |
| -//! \brief A file writer implementation that wraps traditional POSIX file |
| +//! \brief A file writer implementation that wraps traditional system file |
| //! operations on files accessed through the filesystem. |
| class FileWriter : public FileWriterInterface { |
| public: |
| 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, |
|
Mark Mentovai
2014/12/19 18:57:44
There’s one caller of this method, in tools/genera
scottmg
2014/12/19 19:37:54
Done.
|
| + FileWriteMode write_mode, |
| + bool world_readable); |
| - //! \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 +128,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_; |
|
Mark Mentovai
2014/12/19 18:57:44
Maybe file_io.h should provide a typedef for the s
scottmg
2014/12/19 19:37:53
Done.
|
| +#elif defined(OS_WIN) |
| + ScopedFileHANDLE file_; |
| +#endif |
| DISALLOW_COPY_AND_ASSIGN(FileWriter); |
| }; |